Skip to content

Commit 0e201e4

Browse files
authored
Merge pull request #567 from stapelberg/protodelim
switch to protodelim package (which pbutil now calls)
2 parents 53f76e7 + 1143fec commit 0e201e4

File tree

7 files changed

+26
-19
lines changed

7 files changed

+26
-19
lines changed

expfmt/bench_test.go

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,15 @@
1414
package expfmt
1515

1616
import (
17+
"bufio"
1718
"bytes"
1819
"compress/gzip"
1920
"errors"
2021
"io"
2122
"os"
2223
"testing"
2324

24-
"github.com/matttproud/golang_protobuf_extensions/v2/pbutil"
25+
"google.golang.org/protobuf/encoding/protodelim"
2526

2627
dto "github.com/prometheus/client_model/go"
2728
)
@@ -98,10 +99,13 @@ func BenchmarkParseProto(b *testing.B) {
9899

99100
for i := 0; i < b.N; i++ {
100101
family := &dto.MetricFamily{}
101-
in := bytes.NewReader(data)
102+
in := bufio.NewReader(bytes.NewReader(data))
103+
unmarshaler := protodelim.UnmarshalOptions{
104+
MaxSize: -1,
105+
}
102106
for {
103107
family.Reset()
104-
if _, err := pbutil.ReadDelimited(in, family); err != nil {
108+
if err := unmarshaler.UnmarshalFrom(in, family); err != nil {
105109
if errors.Is(err, io.EOF) {
106110
break
107111
}
@@ -123,13 +127,17 @@ func BenchmarkParseProtoGzip(b *testing.B) {
123127

124128
for i := 0; i < b.N; i++ {
125129
family := &dto.MetricFamily{}
126-
in, err := gzip.NewReader(bytes.NewReader(data))
130+
gz, err := gzip.NewReader(bytes.NewReader(data))
127131
if err != nil {
128132
b.Fatal(err)
129133
}
134+
in := bufio.NewReader(gz)
135+
unmarshaler := protodelim.UnmarshalOptions{
136+
MaxSize: -1,
137+
}
130138
for {
131139
family.Reset()
132-
if _, err := pbutil.ReadDelimited(in, family); err != nil {
140+
if err := unmarshaler.UnmarshalFrom(in, family); err != nil {
133141
if errors.Is(err, io.EOF) {
134142
break
135143
}
@@ -153,10 +161,13 @@ func BenchmarkParseProtoMap(b *testing.B) {
153161

154162
for i := 0; i < b.N; i++ {
155163
families := map[string]*dto.MetricFamily{}
156-
in := bytes.NewReader(data)
164+
in := bufio.NewReader(bytes.NewReader(data))
165+
unmarshaler := protodelim.UnmarshalOptions{
166+
MaxSize: -1,
167+
}
157168
for {
158169
family := &dto.MetricFamily{}
159-
if _, err := pbutil.ReadDelimited(in, family); err != nil {
170+
if err := unmarshaler.UnmarshalFrom(in, family); err != nil {
160171
if errors.Is(err, io.EOF) {
161172
break
162173
}

expfmt/decode.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
package expfmt
1515

1616
import (
17+
"bufio"
1718
"fmt"
1819
"io"
1920
"math"
2021
"mime"
2122
"net/http"
2223

2324
dto "github.com/prometheus/client_model/go"
24-
25-
"github.com/matttproud/golang_protobuf_extensions/v2/pbutil"
25+
"google.golang.org/protobuf/encoding/protodelim"
2626

2727
"github.com/prometheus/common/model"
2828
)
@@ -87,8 +87,10 @@ type protoDecoder struct {
8787

8888
// Decode implements the Decoder interface.
8989
func (d *protoDecoder) Decode(v *dto.MetricFamily) error {
90-
_, err := pbutil.ReadDelimited(d.r, v)
91-
if err != nil {
90+
opts := protodelim.UnmarshalOptions{
91+
MaxSize: -1,
92+
}
93+
if err := opts.UnmarshalFrom(bufio.NewReader(d.r), v); err != nil {
9294
return err
9395
}
9496
if !model.IsValidMetricName(model.LabelValue(v.GetName())) {

expfmt/encode.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"io"
1919
"net/http"
2020

21-
"github.com/matttproud/golang_protobuf_extensions/v2/pbutil"
21+
"google.golang.org/protobuf/encoding/protodelim"
2222
"google.golang.org/protobuf/encoding/prototext"
2323

2424
"github.com/prometheus/common/internal/bitbucket.org/ww/goautoneg"
@@ -121,7 +121,7 @@ func NewEncoder(w io.Writer, format Format) Encoder {
121121
case FmtProtoDelim:
122122
return encoderCloser{
123123
encode: func(v *dto.MetricFamily) error {
124-
_, err := pbutil.WriteDelimited(w, v)
124+
_, err := protodelim.MarshalTo(w, v)
125125
return err
126126
},
127127
close: func() error { return nil },

go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ require (
66
github.com/alecthomas/kingpin/v2 v2.4.0
77
github.com/go-kit/log v0.2.1
88
github.com/julienschmidt/httprouter v1.3.0
9-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
109
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f
1110
github.com/prometheus/client_golang v1.18.0
1211
github.com/prometheus/client_model v0.5.0

go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
2727
github.com/kr/pty v1.1.1/go.mod h1:pFQYn66WHrOpPYNljwOMqo10TkYh1fy3cYio2l3bCsQ=
2828
github.com/kr/text v0.1.0 h1:45sCR5RtlFHMR4UwH9sdQ5TC8v0qDQCHnXt+kaKSTVE=
2929
github.com/kr/text v0.1.0/go.mod h1:4Jbv+DJW3UT/LiOwJeYQe1efqtUx/iVham/4vfdArNI=
30-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
31-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
3230
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
3331
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
3432
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

sigv4/go.mod

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@ require (
2020
github.com/jmespath/go-jmespath v0.4.0 // indirect
2121
github.com/jpillora/backoff v1.0.0 // indirect
2222
github.com/kr/text v0.2.0 // indirect
23-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 // indirect
2423
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f // indirect
2524
github.com/pmezard/go-difflib v1.0.0 // indirect
2625
github.com/prometheus/client_model v0.5.0 // indirect

sigv4/go.sum

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ github.com/jpillora/backoff v1.0.0/go.mod h1:J/6gKK9jxlEcS3zixgDgUAsiuZ7yrSoa/FX
2323
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
2424
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
2525
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
26-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 h1:jWpvCLoY8Z/e3VKvlsiIGKtc+UG6U5vzxaoagmhXfyg=
27-
github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0/go.mod h1:QUyp042oQthUoa9bqDv0ER0wrtXnBruoNd7aNjkbP+k=
2826
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f h1:KUppIJq7/+SVif2QVs3tOP0zanoHgBEVAwHxUSIzRqU=
2927
github.com/mwitkow/go-conntrack v0.0.0-20190716064945-2f068394615f/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
3028
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=

0 commit comments

Comments
 (0)