diff --git a/go.mod b/go.mod index 7931cbda..7832cf14 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/go.sum b/go.sum index 9bb249fb..42e5f60b 100644 --- a/go.sum +++ b/go.sum @@ -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= @@ -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= @@ -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= diff --git a/handler/handler_test.go b/handler/handler_test.go index 5c33a15d..eb9cdbfc 100644 --- a/handler/handler_test.go +++ b/handler/handler_test.go @@ -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" @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ @@ -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{ diff --git a/handler/push.go b/handler/push.go index a9f0defc..45a64b46 100644 --- a/handler/push.go +++ b/handler/push.go @@ -14,6 +14,7 @@ package handler import ( + "bufio" "encoding/base64" "fmt" "io" @@ -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" @@ -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 }