From bcd0f5694fdd29040a983e1a30c5bcc6bddad42a Mon Sep 17 00:00:00 2001 From: SuperQ Date: Sun, 10 Mar 2024 13:26:21 +0100 Subject: Refactor plugin scrape test Replace retired[0] pbutil library with protodelim package. [0]: https://matttproud.com/blog/posts/retiring-pbutil.html Signed-off-by: SuperQ --- plugin/test/scrape.go | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) (limited to 'plugin/test/scrape.go') diff --git a/plugin/test/scrape.go b/plugin/test/scrape.go index 7ac22d531..de78f8e12 100644 --- a/plugin/test/scrape.go +++ b/plugin/test/scrape.go @@ -22,15 +22,17 @@ package test import ( + "bufio" + "bytes" "fmt" "io" "mime" "net/http" "strconv" - "github.com/matttproud/golang_protobuf_extensions/pbutil" dto "github.com/prometheus/client_model/go" "github.com/prometheus/common/expfmt" + "google.golang.org/protobuf/encoding/protodelim" ) type ( @@ -234,9 +236,17 @@ func fetchMetricFamilies(url string, ch chan<- *dto.MetricFamily) { if err == nil && mediatype == "application/vnd.google.protobuf" && params["encoding"] == "delimited" && params["proto"] == "io.prometheus.client.MetricFamily" { + unmarshaler := protodelim.UnmarshalOptions{ + MaxSize: -1, + } for { mf := &dto.MetricFamily{} - if _, err = pbutil.ReadDelimited(resp.Body, mf); err != nil { + body, err := io.ReadAll(resp.Body) + if err != nil { + return + } + in := bufio.NewReader(bytes.NewReader(body)) + if err = unmarshaler.UnmarshalFrom(in, mf); err != nil { if err == io.EOF { break } -- cgit v1.2.3