From a6f3300b8dc75a6254f15e03ca225e6eef557702 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 7 Apr 2015 10:32:54 +0200 Subject: [PATCH 1/4] s/ext/pbutil/g The dependency matttproud/golang_protobuf_extensions changed its package layout and thereby broke the Prometheus client_golang build. This fixes it. --- extraction/metricfamilyprocessor.go | 4 ++-- text/proto.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/extraction/metricfamilyprocessor.go b/extraction/metricfamilyprocessor.go index 5edb49c..5a8f40b 100644 --- a/extraction/metricfamilyprocessor.go +++ b/extraction/metricfamilyprocessor.go @@ -20,7 +20,7 @@ import ( dto "github.com/prometheus/client_model/go" - "github.com/matttproud/golang_protobuf_extensions/ext" + "github.com/matttproud/golang_protobuf_extensions/pbutil" "github.com/prometheus/client_golang/model" ) @@ -40,7 +40,7 @@ func (m *metricFamilyProcessor) ProcessSingle(i io.Reader, out Ingester, o *Proc for { family.Reset() - if _, err := ext.ReadDelimited(i, family); err != nil { + if _, err := pbutil.ReadDelimited(i, family); err != nil { if err == io.EOF { return nil } diff --git a/text/proto.go b/text/proto.go index 058adfc..e82bbb3 100644 --- a/text/proto.go +++ b/text/proto.go @@ -18,7 +18,7 @@ import ( "io" "github.com/golang/protobuf/proto" - "github.com/matttproud/golang_protobuf_extensions/ext" + "github.com/matttproud/golang_protobuf_extensions/pbutil" dto "github.com/prometheus/client_model/go" ) @@ -27,7 +27,7 @@ import ( // protobuf format and returns the number of bytes written and any error // encountered. func WriteProtoDelimited(w io.Writer, p *dto.MetricFamily) (int, error) { - return ext.WriteDelimited(w, p) + return pbutil.WriteDelimited(w, p) } // WriteProtoText writes the MetricFamily to the writer in text format and From 0d94dc38c3e7f5d3132ffdfbbe0fc5927e0eead7 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 7 Apr 2015 10:44:42 +0200 Subject: [PATCH 2/4] Update Godeps for new matttproud/golang_protobuf_extensions/pbutil --- Godeps/Godeps.json | 6 +- .../{ext => pbutil}/all_test.go | 55 ++++--------------- .../{ext => pbutil}/decode.go | 2 +- .../{ext => pbutil}/doc.go | 4 +- .../{ext => pbutil}/encode.go | 2 +- .../{ext => pbutil}/fixtures_test.go | 2 +- 6 files changed, 20 insertions(+), 51 deletions(-) rename Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/{ext => pbutil}/all_test.go (87%) rename Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/{ext => pbutil}/decode.go (99%) rename Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/{ext => pbutil}/doc.go (86%) rename Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/{ext => pbutil}/encode.go (99%) rename Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/{ext => pbutil}/fixtures_test.go (99%) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index c12451f..7fb58ce 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -20,7 +20,11 @@ }, { "ImportPath": "github.com/matttproud/golang_protobuf_extensions/ext", - "Rev": "ba7d65ac66e9da93a714ca18f6d1bc7a0c09100c" + "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a" + }, + { + "ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil", + "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a" }, { "ImportPath": "github.com/prometheus/client_model/go", diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/all_test.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go similarity index 87% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/all_test.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go index 7270b67..094156e 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/all_test.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/all_test.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ext +package pbutil import ( "bytes" @@ -21,6 +21,8 @@ import ( "testing" "testing/quick" + "github.com/matttproud/golang_protobuf_extensions/pbtest" + . "github.com/golang/protobuf/proto" . "github.com/golang/protobuf/proto/testdata" ) @@ -138,10 +140,10 @@ I expect it may. Let's hope you enjoy testing as much as we do.`), func TestEndToEndValid(t *testing.T) { for _, test := range [][]Message{ - []Message{&Empty{}}, - []Message{&GoEnum{Foo: FOO_FOO1.Enum()}, &Empty{}, &GoEnum{Foo: FOO_FOO1.Enum()}}, - []Message{&GoEnum{Foo: FOO_FOO1.Enum()}}, - []Message{&Strings{ + {&Empty{}}, + {&GoEnum{Foo: FOO_FOO1.Enum()}, &Empty{}, &GoEnum{Foo: FOO_FOO1.Enum()}}, + {&GoEnum{Foo: FOO_FOO1.Enum()}}, + {&Strings{ StringField: String(`This is my gigantic, unhappy string. It exceeds the encoding size of a single byte varint. We are using it to fuzz test the correctness of the header decoding mechanisms, which may prove problematic. @@ -176,45 +178,6 @@ I expect it may. Let's hope you enjoy testing as much as we do.`), } } -// visitMessage empties the private state fields of the quick.Value()-generated -// Protocol Buffer messages, for they cause an inordinate amount of problems. -// This is because we are using an automated fuzz generator on a type with -// private fields. -func visitMessage(m Message) { - t := reflect.TypeOf(m) - if t.Kind() != reflect.Ptr { - return - } - derefed := t.Elem() - if derefed.Kind() != reflect.Struct { - return - } - v := reflect.ValueOf(m) - elem := v.Elem() - for i := 0; i < elem.NumField(); i++ { - field := elem.FieldByIndex([]int{i}) - fieldType := field.Type() - if fieldType.Implements(reflect.TypeOf((*Message)(nil)).Elem()) { - visitMessage(field.Interface().(Message)) - } - if field.Kind() == reflect.Slice { - for i := 0; i < field.Len(); i++ { - elem := field.Index(i) - elemType := elem.Type() - if elemType.Implements(reflect.TypeOf((*Message)(nil)).Elem()) { - visitMessage(elem.Interface().(Message)) - } - } - } - } - if field := elem.FieldByName("XXX_unrecognized"); field.IsValid() { - field.Set(reflect.ValueOf([]byte{})) - } - if field := elem.FieldByName("XXX_extensions"); field.IsValid() { - field.Set(reflect.ValueOf(nil)) - } -} - // rndMessage generates a random valid Protocol Buffer message. func rndMessage(r *rand.Rand) Message { var t reflect.Type @@ -307,7 +270,9 @@ func rndMessage(r *rand.Rand) Message { if !ok { panic("attempt to generate illegal item; consult item 11") } - visitMessage(v.Interface().(Message)) + if err := pbtest.SanitizeGenerated(v.Interface().(Message)); err != nil { + panic(err) + } return v.Interface().(Message) } diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/decode.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go similarity index 99% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/decode.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go index 28b520e..66d9b54 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/decode.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/decode.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ext +package pbutil import ( "encoding/binary" diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/doc.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go similarity index 86% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/doc.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go index 652907b..c318385 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/doc.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/doc.go @@ -12,5 +12,5 @@ // See the License for the specific language governing permissions and // limitations under the License. -// Package ext enables record length-delimited Protocol Buffer streaming. -package ext +// Package pbutil provides record length-delimited Protocol Buffer streaming. +package pbutil diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/encode.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go similarity index 99% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/encode.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go index 473b31d..4b76ea9 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/encode.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/encode.go @@ -12,7 +12,7 @@ // See the License for the specific language governing permissions and // limitations under the License. -package ext +package pbutil import ( "encoding/binary" diff --git a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/fixtures_test.go b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go similarity index 99% rename from Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/fixtures_test.go rename to Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go index 07e75c5..d6d9b25 100644 --- a/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/ext/fixtures_test.go +++ b/Godeps/_workspace/src/github.com/matttproud/golang_protobuf_extensions/pbutil/fixtures_test.go @@ -27,7 +27,7 @@ // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -package ext +package pbutil import ( . "github.com/golang/protobuf/proto" From 20696dd8410f28e6c05afdff40d7bd96cb90d124 Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 7 Apr 2015 10:48:27 +0200 Subject: [PATCH 3/4] Fix text/bench_test.go --- text/bench_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/text/bench_test.go b/text/bench_test.go index df887e0..a97409e 100644 --- a/text/bench_test.go +++ b/text/bench_test.go @@ -21,7 +21,7 @@ import ( "testing" dto "github.com/prometheus/client_model/go" - "github.com/matttproud/golang_protobuf_extensions/ext" + "github.com/matttproud/golang_protobuf_extensions/pbutil" ) // Benchmarks to show how much penalty text format parsing actually inflicts. @@ -101,7 +101,7 @@ func BenchmarkParseProto(b *testing.B) { in := bytes.NewReader(data) for { family.Reset() - if _, err := ext.ReadDelimited(in, family); err != nil { + if _, err := pbutil.ReadDelimited(in, family); err != nil { if err == io.EOF { break } @@ -129,7 +129,7 @@ func BenchmarkParseProtoGzip(b *testing.B) { } for { family.Reset() - if _, err := ext.ReadDelimited(in, family); err != nil { + if _, err := pbutil.ReadDelimited(in, family); err != nil { if err == io.EOF { break } @@ -156,7 +156,7 @@ func BenchmarkParseProtoMap(b *testing.B) { in := bytes.NewReader(data) for { family := &dto.MetricFamily{} - if _, err := ext.ReadDelimited(in, family); err != nil { + if _, err := pbutil.ReadDelimited(in, family); err != nil { if err == io.EOF { break } From 53034378aaeaf665858b0977dda231d25e5b253f Mon Sep 17 00:00:00 2001 From: Peter Bourgon Date: Tue, 7 Apr 2015 12:35:11 +0200 Subject: [PATCH 4/4] Godep: remove reference to matttproud/golang_protobuf_extensions/ext --- Godeps/Godeps.json | 4 ---- 1 file changed, 4 deletions(-) diff --git a/Godeps/Godeps.json b/Godeps/Godeps.json index 7fb58ce..ae10a96 100644 --- a/Godeps/Godeps.json +++ b/Godeps/Godeps.json @@ -18,10 +18,6 @@ "ImportPath": "github.com/golang/protobuf/proto", "Rev": "c22ae3cf020a21ebb7ae566dccbe90fc8ea4f9ea" }, - { - "ImportPath": "github.com/matttproud/golang_protobuf_extensions/ext", - "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a" - }, { "ImportPath": "github.com/matttproud/golang_protobuf_extensions/pbutil", "Rev": "fc2b8d3a73c4867e51861bbdd5ae3c1f0869dd6a"