Repository: honeycombio/refinery
Pull request #505 (2022-09-07 14:01:12)

Update Husky to latest

## Which problem is this PR solving?

- Updates Husky to our 0.15.0
- Closes #493 

## Short description of the changes

- Update husky
- Replace otel package imports with husky versions,  eg[go.opentelemetry.io/otel](http://go.opentelemetry.io/otel) => [github.com/honeycombio/husky/otel](http://github.com/honeycombio/husky/otel)
- Replace any usage of InstrumentationLibrary* with Scope equivalents, eg InstrumentationLibrary => InstrumentationScope
- Fix test that verified that OTLP/HTTP didn't work to one that shows it does (at a basic level)




Patch:
diff --git a/go.mod b/go.mod
index 82d01e1..312221d 100644
--- a/go.mod
+++ b/go.mod
@@ -12,7 +12,7 @@ require (
 	github.com/gorilla/mux v1.8.0
 	github.com/hashicorp/golang-lru v0.5.4
 	github.com/honeycombio/dynsampler-go v0.2.1
-	github.com/honeycombio/husky v0.10.6
+	github.com/honeycombio/husky v0.15.0
 	github.com/honeycombio/libhoney-go v1.16.0
 	github.com/jessevdk/go-flags v1.5.0
 	github.com/json-iterator/go v1.1.12
@@ -45,6 +45,7 @@ require (
 	github.com/go-playground/universal-translator v0.17.0 // indirect
 	github.com/golang/protobuf v1.5.2 // indirect
 	github.com/grpc-ecosystem/grpc-gateway v1.16.0 // indirect
+	github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.1 // indirect
 	github.com/hashicorp/hcl v1.0.0 // indirect
 	github.com/leodido/go-urn v1.2.0 // indirect
 	github.com/magiconair/properties v1.8.6 // indirect
diff --git a/go.sum b/go.sum
index ef04f2a..89b1b2a 100644
--- a/go.sum
+++ b/go.sum
@@ -115,6 +115,7 @@ github.com/go-playground/validator v9.31.0+incompatible/go.mod h1:yrEkQXlcI+Pugk
 github.com/go-stack/stack v1.8.0/go.mod h1:v0f6uXyyMGvRgIKkXu+yp6POWl0qKG85gN/melR3HDY=
 github.com/gogo/protobuf v1.1.1/go.mod h1:r8qH/GZQm5c6nD/R0oafs1akxWv10x8SbQlK7atdtwQ=
 github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
+github.com/golang/glog v1.0.0 h1:nfP3RFugxnNRyKgeWd4oI1nYvXpxrx8ck8ZrcizshdQ=
 github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
 github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
@@ -180,6 +181,8 @@ github.com/gorilla/mux v1.8.0 h1:i40aqfkR1h2SlN9hojwV5ZA91wcXFOvkdNIeFDP5koI=
 github.com/gorilla/mux v1.8.0/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
 github.com/grpc-ecosystem/grpc-gateway v1.16.0 h1:gmcG1KaJ57LophUzW0Hy8NmPhnMZb4M0+kPpLofRdBo=
 github.com/grpc-ecosystem/grpc-gateway v1.16.0/go.mod h1:BDjrQk3hbvj6Nolgz8mAMFbcEtjT1g+wF4CSlocrBnw=
+github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.1 h1:/sDbPb60SusIXjiJGYLUoS/rAQurQmvGWmwn2bBPM9c=
+github.com/grpc-ecosystem/grpc-gateway/v2 v2.11.1/go.mod h1:G+WkljZi4mflcqVxYSgvt8MNctRQHjEH8ubKtt1Ka3w=
 github.com/hashicorp/golang-lru v0.5.0/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/golang-lru v0.5.1/go.mod h1:/m3WP610KZHVQ1SGc6re/UDhFvYD7pJ4Ao+sR/qLZy8=
 github.com/hashicorp/golang-lru v0.5.4 h1:YDjusn29QI/Das2iO9M0BHnIbxPeyuCHsjMW+lJfyTc=
@@ -188,8 +191,8 @@ github.com/hashicorp/hcl v1.0.0 h1:0Anlzjpi4vEasTeNFn2mLJgTSwt0+6sfsiTG8qcWGx4=
 github.com/hashicorp/hcl v1.0.0/go.mod h1:E5yfLk+7swimpb2L/Alb/PJmXilQ/rhwaUYs4T20WEQ=
 github.com/honeycombio/dynsampler-go v0.2.1 h1:IbhjbdB0IbLSZn7xVYuk6jjk/ZDk/EO+DJ5OXFZliv8=
 github.com/honeycombio/dynsampler-go v0.2.1/go.mod h1:BOeTUPT6fCRH5X/+QqF6Kza3IyLp9uSq/rWgEtI4aZI=
-github.com/honeycombio/husky v0.10.6 h1:jU/lXqo7Qz6e9eUJErIH3Lst2gjKWSJ4oAXYjFSXkn0=
-github.com/honeycombio/husky v0.10.6/go.mod h1:i69+3xApIcsQn9PPeFRndTOOw6edNG66TxTTd+L6oq0=
+github.com/honeycombio/husky v0.15.0 h1:RuYmKC1jHSB6y3C7pSXf889w8AaSzZ1JkIkLaiXlC5o=
+github.com/honeycombio/husky v0.15.0/go.mod h1:ZO2AzJnnJkUoXbIQ5qLCvQuWdQOG/BZEup8pf2y5ua0=
 github.com/honeycombio/libhoney-go v1.16.0 h1:kPpqoz6vbOzgp7jC6SR7SkNj7rua7rgxvznI6M3KdHc=
 github.com/honeycombio/libhoney-go v1.16.0/go.mod h1:izP4fbREuZ3vqC4HlCAmPrcPT9gxyxejRjGtCYpmBn0=
 github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
diff --git a/route/otlp_trace.go b/route/otlp_trace.go
index 6b75b29..f4e86c4 100644
--- a/route/otlp_trace.go
+++ b/route/otlp_trace.go
@@ -8,7 +8,7 @@ import (
 	huskyotlp "github.com/honeycombio/husky/otlp"
 	"github.com/honeycombio/refinery/types"
 
-	collectortrace "go.opentelemetry.io/proto/otlp/collector/trace/v1"
+	collectortrace "github.com/honeycombio/husky/proto/otlp/collector/trace/v1"
 )
 
 func (router *Router) postOTLP(w http.ResponseWriter, req *http.Request) {
diff --git a/route/route.go b/route/route.go
index 18af0b0..8fbac4f 100644
--- a/route/route.go
+++ b/route/route.go
@@ -39,7 +39,7 @@ import (
 	"github.com/honeycombio/refinery/transmit"
 	"github.com/honeycombio/refinery/types"
 
-	collectortrace "go.opentelemetry.io/proto/otlp/collector/trace/v1"
+	collectortrace "github.com/honeycombio/husky/proto/otlp/collector/trace/v1"
 )
 
 const (


Test patch:
diff --git a/route/otlp_trace_test.go b/route/otlp_trace_test.go
index 1e7e875..bd1adde 100644
--- a/route/otlp_trace_test.go
+++ b/route/otlp_trace_test.go
@@ -12,17 +12,18 @@ import (
 	"time"
 
 	huskyotlp "github.com/honeycombio/husky/otlp"
+	collectortrace "github.com/honeycombio/husky/proto/otlp/collector/trace/v1"
+	common "github.com/honeycombio/husky/proto/otlp/common/v1"
+	resource "github.com/honeycombio/husky/proto/otlp/resource/v1"
+	trace "github.com/honeycombio/husky/proto/otlp/trace/v1"
 	"github.com/honeycombio/refinery/config"
 	"github.com/honeycombio/refinery/logger"
 	"github.com/honeycombio/refinery/metrics"
 	"github.com/honeycombio/refinery/transmit"
 	"github.com/klauspost/compress/zstd"
 	"github.com/stretchr/testify/assert"
-	collectortrace "go.opentelemetry.io/proto/otlp/collector/trace/v1"
-	common "go.opentelemetry.io/proto/otlp/common/v1"
-	resource "go.opentelemetry.io/proto/otlp/resource/v1"
-	trace "go.opentelemetry.io/proto/otlp/trace/v1"
 	"google.golang.org/grpc/metadata"
+	"google.golang.org/protobuf/encoding/protojson"
 	"google.golang.org/protobuf/proto"
 )
 
@@ -67,7 +68,7 @@ func TestOTLPHandler(t *testing.T) {
 	t.Run("span with status", func(t *testing.T) {
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: helperOTLPRequestSpansWithStatus(),
 				}},
 			}},
@@ -83,7 +84,7 @@ func TestOTLPHandler(t *testing.T) {
 	t.Run("span without status", func(t *testing.T) {
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: helperOTLPRequestSpansWithoutStatus(),
 				}},
 			}},
@@ -105,7 +106,7 @@ func TestOTLPHandler(t *testing.T) {
 		spanID := []byte{1, 0, 0, 0, 0}
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: []*trace.Span{{
 						TraceId: traceID,
 						SpanId:  spanID,
@@ -153,7 +154,7 @@ func TestOTLPHandler(t *testing.T) {
 
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: []*trace.Span{{
 						Name:    "span_with_link",
 						TraceId: traceID,
@@ -191,7 +192,7 @@ func TestOTLPHandler(t *testing.T) {
 	t.Run("can receive OTLP over HTTP/protobuf", func(t *testing.T) {
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: helperOTLPRequestSpansWithStatus(),
 				}},
 			}},
@@ -218,7 +219,7 @@ func TestOTLPHandler(t *testing.T) {
 	t.Run("can receive OTLP over HTTP/protobuf with gzip encoding", func(t *testing.T) {
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: helperOTLPRequestSpansWithStatus(),
 				}},
 			}},
@@ -254,7 +255,7 @@ func TestOTLPHandler(t *testing.T) {
 	t.Run("can receive OTLP over HTTP/protobuf with zstd encoding", func(t *testing.T) {
 		req := &collectortrace.ExportTraceServiceRequest{
 			ResourceSpans: []*trace.ResourceSpans{{
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: helperOTLPRequestSpansWithStatus(),
 				}},
 			}},
@@ -290,8 +291,20 @@ func TestOTLPHandler(t *testing.T) {
 		mockTransmission.Flush()
 	})
 
-	t.Run("rejects OTLP over HTTP/JSON ", func(t *testing.T) {
-		request, _ := http.NewRequest("POST", "/v1/traces", strings.NewReader("{}"))
+	t.Run("accepts OTLP over HTTP/JSON ", func(t *testing.T) {
+		req := &collectortrace.ExportTraceServiceRequest{
+			ResourceSpans: []*trace.ResourceSpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
+					Spans: helperOTLPRequestSpansWithStatus(),
+				}},
+			}},
+		}
+		body, err := protojson.Marshal(req)
+		if err != nil {
+			t.Error(err)
+		}
+
+		request, _ := http.NewRequest("POST", "/v1/traces", bytes.NewReader(body))
 		request.Header = http.Header{}
 		request.Header.Set("content-type", "application/json")
 		request.Header.Set("x-honeycomb-team", legacyAPIKey)
@@ -299,10 +312,10 @@ func TestOTLPHandler(t *testing.T) {
 
 		w := httptest.NewRecorder()
 		router.postOTLP(w, request)
-		assert.Equal(t, w.Code, http.StatusNotImplemented)
-		assert.Equal(t, `{"source":"refinery","error":"invalid content-type - only 'application/protobuf' is supported"}`, string(w.Body.String()))
+		assert.Equal(t, w.Code, http.StatusOK)
+		assert.Equal(t, "", w.Body.String())
 
-		assert.Equal(t, 0, len(mockTransmission.Events))
+		assert.Equal(t, 2, len(mockTransmission.Events))
 		mockTransmission.Flush()
 	})
 
@@ -317,7 +330,7 @@ func TestOTLPHandler(t *testing.T) {
 						{Key: "service.name", Value: &common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: "my-service"}}},
 					},
 				},
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: []*trace.Span{{
 						Name: "my-span",
 					}},
@@ -350,7 +363,7 @@ func TestOTLPHandler(t *testing.T) {
 						{Key: "service.name", Value: &common.AnyValue{Value: &common.AnyValue_StringValue{StringValue: "my-service"}}},
 					},
 				},
-				InstrumentationLibrarySpans: []*trace.InstrumentationLibrarySpans{{
+				ScopeSpans: []*trace.ScopeSpans{{
 					Spans: []*trace.Span{{
 						Name: "my-span",
 					}},