Skip to content

Commit

Permalink
Migrate from pbutil to protodelim
Browse files Browse the repository at this point in the history
To be precise: From
github.com/matttproud/golang_protobuf_extensions/pbutil
to google.golang.org/protobuf/encoding/protodelim .

Signed-off-by: beorn7 <[email protected]>
  • Loading branch information
beorn7 committed Oct 10, 2024
1 parent b437438 commit b8c2691
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 14 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ require (
github.com/alecthomas/kingpin/v2 v2.4.0
github.com/golang/protobuf v1.5.4
github.com/golang/snappy v0.0.4
github.com/matttproud/golang_protobuf_extensions v1.0.4
github.com/prometheus/client_golang v1.20.4
github.com/prometheus/client_model v0.6.1
github.com/prometheus/common v0.60.0
Expand Down
4 changes: 0 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSs
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1VwoXQT9A3Wy9MM3WgvqSxFWenqJduM=
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/godbus/dbus/v5 v5.0.4/go.mod h1:xhWf0FNVPg57R7Z0UbKHbJfkEywrmjJnf7w5xrFpKfA=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM=
Expand All @@ -32,8 +31,6 @@ github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/kylelemons/godebug v1.1.0 h1:RPNrshWIDI6G2gRW9EHilWtl7Z6Sb1BR0xunSBf0SNc=
github.com/kylelemons/godebug v1.1.0/go.mod h1:9/0rRGxNHcop5bhtWyNeEfOS8JIWk580+fNqagV/RAw=
github.com/matttproud/golang_protobuf_extensions v1.0.4 h1:mmDVorXM7PCGKw94cs5zkfA9PSy5pEvNWRP0ET0TIVo=
github.com/matttproud/golang_protobuf_extensions v1.0.4/go.mod h1:BSXmuO+STAnVfrANrmjBb36TMTDstsz7MSK+HVaYKv4=
github.com/mdlayher/socket v0.4.1 h1:eM9y2/jlbs1M615oshPQOHZzj6R6wMT7bX5NPiQvn2U=
github.com/mdlayher/socket v0.4.1/go.mod h1:cAqeGjoufqdxWkD7DkpyS+wcefOtmu5OQ8KuoJGIReA=
github.com/mdlayher/vsock v1.2.1 h1:pC1mTJTvjo1r9n9fbm7S1j04rCgCzhCOS5DY0zqHlnQ=
Expand Down Expand Up @@ -80,7 +77,6 @@ golang.org/x/net v0.29.0 h1:5ORfpBpCs4HzDYoodCDBbwHzdR5UrLBZ3sOnUJmFoHo=
golang.org/x/net v0.29.0/go.mod h1:gLkgy8jTGERgjzMic6DS9+SP0ajcu6Xu3Orq/SpETg0=
golang.org/x/oauth2 v0.23.0 h1:PbgcYx2W7i4LvjJWEbf0ngHV6qJYr86PkAV3bXdLEbs=
golang.org/x/oauth2 v0.23.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI=
golang.org/x/sync v0.0.0-20181221193216-37e7f081c4d4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.8.0 h1:3NFvSEYkUoMifnESzZl15y791HH1qU2xm6eCJU5ZPXQ=
golang.org/x/sync v0.8.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk=
golang.org/x/sys v0.25.0 h1:r+8e+loiHxRqhXVl6ML1nO3l1+oFoWbnlu2Ehimmi34=
Expand Down
14 changes: 7 additions & 7 deletions handler/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ import (
"testing"
"time"

"github.com/matttproud/golang_protobuf_extensions/pbutil"
"github.com/prometheus/common/model"
"github.com/prometheus/common/promslog"
"github.com/prometheus/common/route"
"google.golang.org/protobuf/encoding/protodelim"
"google.golang.org/protobuf/encoding/prototext"
"google.golang.org/protobuf/proto"

Expand Down Expand Up @@ -335,7 +335,7 @@ func TestPush(t *testing.T) {
// With job name and instance name and protobuf content.
mms.lastWriteRequest = storage.WriteRequest{}
buf := &bytes.Buffer{}
_, err = pbutil.WriteDelimited(buf, &dto.MetricFamily{
_, err = protodelim.MarshalTo(buf, &dto.MetricFamily{
Name: proto.String("some_metric"),
Type: dto.MetricType_UNTYPED.Enum(),
Metric: []*dto.Metric{
Expand All @@ -350,7 +350,7 @@ func TestPush(t *testing.T) {
t.Fatal(err)
}

_, err = pbutil.WriteDelimited(buf, &dto.MetricFamily{
_, err = protodelim.MarshalTo(buf, &dto.MetricFamily{
Name: proto.String("another_metric"),
Type: dto.MetricType_UNTYPED.Enum(),
Metric: []*dto.Metric{
Expand All @@ -365,7 +365,7 @@ func TestPush(t *testing.T) {
t.Fatal(err)
}

_, err = pbutil.WriteDelimited(buf, &dto.MetricFamily{
_, err = protodelim.MarshalTo(buf, &dto.MetricFamily{
Name: proto.String("histogram_metric"),
Type: dto.MetricType_HISTOGRAM.Enum(),
Metric: []*dto.Metric{
Expand Down Expand Up @@ -518,7 +518,7 @@ func TestPushUTF8(t *testing.T) {
// With job name, instance name, UTF-8 escaped label name in params, UTF-8 metric names and protobuf content.
mms.lastWriteRequest = storage.WriteRequest{}
buf := &bytes.Buffer{}
_, err = pbutil.WriteDelimited(buf, &dto.MetricFamily{
_, err = protodelim.MarshalTo(buf, &dto.MetricFamily{
Name: proto.String("some.metric"),
Type: dto.MetricType_UNTYPED.Enum(),
Metric: []*dto.Metric{
Expand All @@ -533,7 +533,7 @@ func TestPushUTF8(t *testing.T) {
t.Fatal(err)
}

_, err = pbutil.WriteDelimited(buf, &dto.MetricFamily{
_, err = protodelim.MarshalTo(buf, &dto.MetricFamily{
Name: proto.String("another.metric"),
Type: dto.MetricType_UNTYPED.Enum(),
Metric: []*dto.Metric{
Expand All @@ -548,7 +548,7 @@ func TestPushUTF8(t *testing.T) {
t.Fatal(err)
}

_, err = pbutil.WriteDelimited(buf, &dto.MetricFamily{
_, err = protodelim.MarshalTo(buf, &dto.MetricFamily{
Name: proto.String("histogram.metric"),
Type: dto.MetricType_HISTOGRAM.Enum(),
Metric: []*dto.Metric{
Expand Down
9 changes: 7 additions & 2 deletions handler/push.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
package handler

import (
"bufio"
"encoding/base64"
"fmt"
"io"
Expand All @@ -23,11 +24,11 @@ import (
"strings"
"time"

"github.com/matttproud/golang_protobuf_extensions/pbutil"
"github.com/prometheus/client_golang/prometheus/promhttp"
"github.com/prometheus/common/expfmt"
"github.com/prometheus/common/model"
"github.com/prometheus/common/route"
"google.golang.org/protobuf/encoding/protodelim"

dto "github.com/prometheus/client_model/go"

Expand Down Expand Up @@ -89,9 +90,13 @@ func Push(
ctParams["encoding"] == "delimited" &&
ctParams["proto"] == "io.prometheus.client.MetricFamily" {
metricFamilies = map[string]*dto.MetricFamily{}
unmarshaler := protodelim.UnmarshalOptions{
MaxSize: -1,
}
in := bufio.NewReader(r.Body)
for {
mf := &dto.MetricFamily{}
if _, err = pbutil.ReadDelimited(r.Body, mf); err != nil {
if err = unmarshaler.UnmarshalFrom(in, mf); err != nil {
if err == io.EOF {
err = nil
}
Expand Down

0 comments on commit b8c2691

Please sign in to comment.