Skip to content

Commit

Permalink
Add gogoproto wire compatibility test
Browse files Browse the repository at this point in the history
  • Loading branch information
tigrannajaryan committed Jun 5, 2020
1 parent b37edbf commit 8197aaa
Show file tree
Hide file tree
Showing 5 changed files with 50 additions and 19 deletions.
24 changes: 12 additions & 12 deletions encodings/otlp/generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,25 +214,25 @@ func GenMetricDescriptor(i int) *otlpmetric.MetricDescriptor {
descr := &otlpmetric.MetricDescriptor{
Name: "metric" + strconv.Itoa(i),
Description: "some description: " + strconv.Itoa(i),
Type: otlpmetric.MetricDescriptor_GAUGE_INT64,
Labels: []*otlpcommon.StringKeyValue{
{
Key: "label1",
Value: "val1",
},
{
Key: "label2",
Value: "val2",
},
},
Type: otlpmetric.MetricDescriptor_INT64,
//Labels: []*otlpcommon.StringKeyValue{
// {
// Key: "label1",
// Value: "val1",
// },
// {
// Key: "label2",
// Value: "val2",
// },
//},
}
return descr
}

func genHistogram(startTime time.Time, i int, labelKeys []string, valuesPerTimeseries int) *otlpmetric.Metric {
// Add Histogram
descr := GenMetricDescriptor(i)
descr.Type = otlpmetric.MetricDescriptor_GAUGE_HISTOGRAM
descr.Type = otlpmetric.MetricDescriptor_INT64

var timeseries2 []*otlpmetric.HistogramDataPoint
for j := 0; j < 1; j++ {
Expand Down
31 changes: 31 additions & 0 deletions encodings/otlp_gogo/compatibility_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package otlp_gogo

import (
"testing"

otlpgogo "github.com/tigrannajaryan/exp-otelproto/encodings/otlp_gogo/collector/trace/v1"

gogoproto "github.com/gogo/protobuf/proto"
"github.com/golang/protobuf/proto"
otlptrace "github.com/open-telemetry/opentelemetry-proto/gen/go/collector/trace/v1"
"github.com/stretchr/testify/assert"
"github.com/tigrannajaryan/exp-otelproto/encodings/otlp"
)

func TestCompatibility(t *testing.T) {
gen := otlp.NewGenerator()
batch := gen.GenerateSpanBatch(3, 10, 5)
request := batch.(*otlptrace.ExportTraceServiceRequest)
wire, err := proto.Marshal(request)
assert.NotNil(t, wire)
assert.NoError(t, err)

var gogoRequest otlpgogo.ExportTraceServiceRequest
err = gogoproto.Unmarshal(wire, &gogoRequest)
assert.NoError(t, err)

wire2, err := gogoproto.Marshal(&gogoRequest)
assert.NoError(t, err)

assert.EqualValues(t, wire, wire2)
}
3 changes: 2 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ require (
github.com/jaegertracing/jaeger v1.15.1
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.1 // indirect
github.com/open-telemetry/opentelemetry-proto v0.3.0
github.com/open-telemetry/opentelemetry-proto v0.3.1-0.20200602210206-b54688569186
github.com/prometheus/client_golang v1.1.0
github.com/shirou/gopsutil v2.18.12+incompatible
github.com/signalfx/sapm-proto v0.5.1
github.com/stretchr/testify v1.4.0
google.golang.org/genproto v0.0.0-20190927181202-20e1ac93f88c
google.golang.org/grpc v1.24.0
)
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/open-telemetry/opentelemetry-proto v0.3.0 h1:+ASAtcayvoELyCF40+rdCMlBOhZIn5TPDez85zSYc30=
github.com/open-telemetry/opentelemetry-proto v0.3.0/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/open-telemetry/opentelemetry-proto v0.3.1-0.20200602210206-b54688569186 h1:VATRg93wSdk5GNpnxmLKUg48BUgIaoNM1pY0LZ2x8JY=
github.com/open-telemetry/opentelemetry-proto v0.3.1-0.20200602210206-b54688569186/go.mod h1:PMR5GI0F7BSpio+rBGFxNm6SLzg3FypDTcFuQZnO+F8=
github.com/opentracing/opentracing-go v1.1.0 h1:pWlfV3Bxv7k65HYwkikxat0+s3pV4bsqf19k25Ur8rU=
github.com/opentracing/opentracing-go v1.1.0/go.mod h1:UkNAQd3GIcIGf0SeVgPpRdFStlNbqXla1AfSYxPUl2o=
github.com/pavius/impi v0.0.0-20180302134524-c1cbdcb8df2b/go.mod h1:x/hU0bfdWIhuOT1SKwiJg++yvkk6EuOtJk8WtDZqgr8=
Expand Down Expand Up @@ -234,6 +236,7 @@ gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.3/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.5 h1:ymVxjfMaHvXD8RqPRmzHHsB3VvucivSkIAvJFDI5O3c=
gopkg.in/yaml.v2 v2.2.5/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
gopkg.in/yaml.v2 v2.2.7 h1:VUgggvou5XRW9mHwD/yXxIYSMtY0zoKQf/v226p2nyo=
gopkg.in/yaml.v2 v2.2.7/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
Expand Down
8 changes: 2 additions & 6 deletions makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ export DOCKER_REGISTRY
export IMAGE_NAME
export PROTOCOL

all: gen build test

gen:

# Function to execute a command.
# Accepts command to execute as first parameter.
define exec-command
Expand All @@ -29,9 +25,9 @@ endef
OTLP_PROTO_FILES := $(wildcard encodings/otlp_gogo/opentelemetry/proto/*/v1/*.proto encodings/otlp_gogo/opentelemetry/proto/collector/*/v1/*.proto)


all: genprotobuf build test
all: gen build test

genprotobuf:
gen:
$(foreach file,$(OTLP_PROTO_FILES),$(call exec-command,protoc -Iencodings/otlp_gogo/ --gogofaster_out=plugins=grpc:encodings/otlp_gogo $(file)))
cp -R encodings/otlp_gogo/github.com/tigrannajaryan/exp-otelproto/encodings/otlp_gogo/* encodings/otlp_gogo/
rm -rf encodings/otlp_gogo/github.com/
Expand Down

0 comments on commit 8197aaa

Please sign in to comment.