From 8de21bec4feb5ee1ae273a28ea9277044bfc17b1 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Thu, 2 Dec 2021 10:34:38 +0000 Subject: [PATCH 1/3] bump husky to v0.3.0 --- go.mod | 2 +- go.sum | 4 ++-- route/otlp_trace.go | 26 ++++++++------------------ 3 files changed, 11 insertions(+), 21 deletions(-) diff --git a/go.mod b/go.mod index fbc797e057..fa9c5acd7b 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/gorilla/mux v1.6.3-0.20190108142930-08e7f807d38d github.com/hashicorp/golang-lru v0.5.4 github.com/honeycombio/dynsampler-go v0.2.1 - github.com/honeycombio/husky v0.2.0 + github.com/honeycombio/husky v0.3.0 github.com/honeycombio/libhoney-go v1.15.6 github.com/jessevdk/go-flags v1.5.0 github.com/json-iterator/go v1.1.12 diff --git a/go.sum b/go.sum index eafe20de69..b7cf145907 100644 --- a/go.sum +++ b/go.sum @@ -228,8 +228,8 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= 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.2.0 h1:vjuUU9HtQnNLOk+VLUG7AQ7b/1oO7gL13N10nFTUaXs= -github.com/honeycombio/husky v0.2.0/go.mod h1:OKDdF3gAoP6GtQsMgFJKUqApY+x6T0mWv1S+VHpbH8A= +github.com/honeycombio/husky v0.3.0 h1:8H0PsBlp2KW/VfHZ2W1ScSKode8TeL+rrnb28Ya6LBQ= +github.com/honeycombio/husky v0.3.0/go.mod h1:OKDdF3gAoP6GtQsMgFJKUqApY+x6T0mWv1S+VHpbH8A= github.com/honeycombio/libhoney-go v1.15.6 h1:zbwfdo74Gsedmu6OT/oAHv4pfKNoseTXRMA/4e5XWew= github.com/honeycombio/libhoney-go v1.15.6/go.mod h1:8NyBoM746bz+nw3yQzQF8gtJO/z4mkr/MD5C4r4uC2Y= 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 4e98729ebf..df6a2ecf59 100644 --- a/route/otlp_trace.go +++ b/route/otlp_trace.go @@ -4,7 +4,6 @@ import ( "context" "errors" "net/http" - "time" huskyotlp "github.com/honeycombio/husky/otlp" "github.com/honeycombio/refinery/types" @@ -23,13 +22,13 @@ func (router *Router) postOTLP(w http.ResponseWriter, req *http.Request) { return } - batch, err := huskyotlp.TranslateHttpTraceRequest(req.Body, ri) + result, err := huskyotlp.TranslateTraceRequestFromReader(req.Body, ri) if err != nil { router.handlerReturnWithError(w, ErrUpstreamFailed, err) return } - if err := processTraceRequest(req.Context(), router, batch, ri.ApiKey, ri.Dataset); err != nil { + if err := processTraceRequest(req.Context(), router, result.Events, ri.ApiKey, ri.Dataset); err != nil { router.handlerReturnWithError(w, ErrUpstreamFailed, err) } } @@ -40,12 +39,12 @@ func (router *Router) Export(ctx context.Context, req *collectortrace.ExportTrac return nil, huskyotlp.AsGRPCError(err) } - batch, err := huskyotlp.TranslateGrpcTraceRequest(req) + result, err := huskyotlp.TranslateTraceRequest(req) if err != nil { return nil, huskyotlp.AsGRPCError(err) } - if err := processTraceRequest(ctx, router, batch, ri.ApiKey, ri.Dataset); err != nil { + if err := processTraceRequest(ctx, router, result.Events, ri.ApiKey, ri.Dataset); err != nil { return nil, huskyotlp.AsGRPCError(err) } @@ -55,13 +54,11 @@ func (router *Router) Export(ctx context.Context, req *collectortrace.ExportTrac func processTraceRequest( ctx context.Context, router *Router, - batch []map[string]interface{}, + batch []huskyotlp.Event, apiKey string, datasetName string) error { var requestID types.RequestIDContextKey - debugLog := router.iopLogger.Debug().WithField("request_id", requestID) - apiHost, err := router.Config.GetHoneycombAPI() if err != nil { router.Logger.Error().Logf("Unable to retrieve APIHost from config while processing OTLP batch") @@ -69,21 +66,14 @@ func processTraceRequest( } for _, ev := range batch { - attrs := ev["data"].(map[string]interface{}) - timestamp := ev["time"].(time.Time) - sampleRate, err := getSampleRateFromAttributes(attrs) - if err != nil { - debugLog.WithField("error", err.Error()).WithField("sampleRate", attrs["sampleRate"]).Logf("error parsing sampleRate") - } - event := &types.Event{ Context: ctx, APIHost: apiHost, APIKey: apiKey, Dataset: datasetName, - SampleRate: uint(sampleRate), - Timestamp: timestamp, - Data: attrs, + SampleRate: uint(ev.SampleRate), + Timestamp: ev.Timestamp, + Data: ev.Attributes, } if err = router.processEvent(event, requestID); err != nil { router.Logger.Error().Logf("Error processing event: " + err.Error()) From e4cba5cf14dcb493d824bdeb6e6e469040150651 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Thu, 2 Dec 2021 10:36:11 +0000 Subject: [PATCH 2/3] remove duplicated get sample rate code and tests --- route/route.go | 40 ------------------------ route/route_test.go | 75 --------------------------------------------- 2 files changed, 115 deletions(-) diff --git a/route/route.go b/route/route.go index 218c3085ac..d0f7ee8005 100644 --- a/route/route.go +++ b/route/route.go @@ -626,43 +626,3 @@ func getFirstValueFromMetadata(key string, md metadata.MD) string { } return "" } - -func getSampleRateFromAttributes(attrs map[string]interface{}) (int, error) { - var sampleRateKey string - if attrs["sampleRate"] != nil { - sampleRateKey = "sampleRate" - } else if attrs["SampleRate"] != nil { - sampleRateKey = "SampleRate" - } - if len(sampleRateKey) == 0 || attrs[sampleRateKey] == nil { - return defaultSampleRate, nil - } - var sampleRate int - var err error - switch v := attrs[sampleRateKey].(type) { - case string: - var i int64 - i, err = strconv.ParseInt(v, 10, 32) - sampleRate = int(i) - case int: - if v > math.MaxInt32 { - sampleRate = math.MaxInt32 - } else { - sampleRate = v - } - case int32: - sampleRate = int(v) - case int64: - if v > math.MaxInt32 { - sampleRate = math.MaxInt32 - } else { - sampleRate = int(v) - } - default: - err = fmt.Errorf("unrecognised sampleRate datatype - %T", sampleRate) - sampleRate = defaultSampleRate - } - // remove sampleRate from event fields - delete(attrs, sampleRateKey) - return sampleRate, err -} diff --git a/route/route_test.go b/route/route_test.go index 2080396a87..47b90364fe 100644 --- a/route/route_test.go +++ b/route/route_test.go @@ -6,7 +6,6 @@ import ( "fmt" "io" "io/ioutil" - "math" "net/http" "net/http/httptest" "strings" @@ -304,80 +303,6 @@ func TestGetAPIKeyAndDatasetFromMetadataCaseInsensitive(t *testing.T) { } } -func TestGetSampleRateFromAttributes(t *testing.T) { - const ( - defaultSampleRate = 1 - ) - tests := []struct { - name string - attrKey string - attrValue interface{} - expectedValue int - }{ - { - name: "missing attr gets default value", - attrKey: "", - attrValue: nil, - expectedValue: defaultSampleRate, - }, - { - name: "can parse integer value", - attrKey: "sampleRate", - attrValue: 5, - expectedValue: 5, - }, - { - name: "can parse string value", - attrKey: "sampleRate", - attrValue: "5", - expectedValue: 5, - }, - { - name: "can parse int64 value (less than int32 max)", - attrKey: "sampleRate", - attrValue: int64(100), - expectedValue: 100, - }, - { - name: "can parse int64 value (greater than int32 max)", - attrKey: "sampleRate", - attrValue: int64(math.MaxInt32 + 100), - expectedValue: math.MaxInt32, - }, - { - name: "does not parse float, gets default value", - attrKey: "sampleRate", - attrValue: 0.25, - expectedValue: defaultSampleRate, - }, - { - name: "does not parse bool, gets default value", - attrKey: "sampleRate", - attrValue: true, - expectedValue: defaultSampleRate, - }, - { - name: "does not parse struct, gets default value", - attrKey: "sampleRate", - attrValue: struct{}{}, - expectedValue: defaultSampleRate, - }, - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - attrs := map[string]interface{}{ - tt.attrKey: tt.attrValue, - } - - sampleRate, _ := getSampleRateFromAttributes(attrs) - if sampleRate != tt.expectedValue { - t.Errorf("got: %d\n\twant: %d", sampleRate, tt.expectedValue) - } - }) - } -} - func TestDebugTrace(t *testing.T) { req, _ := http.NewRequest("GET", "/debug/trace/123abcdef", nil) req = mux.SetURLVars(req, map[string]string{"traceID": "123abcdef"}) From 8140ccf09c9fe592a52745509032b579c00bb270 Mon Sep 17 00:00:00 2001 From: Mike Goldsmth Date: Mon, 6 Dec 2021 15:34:15 +0000 Subject: [PATCH 3/3] bump husky to v0.4.0 --- go.mod | 4 ++-- go.sum | 8 ++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/go.mod b/go.mod index fa9c5acd7b..36de63a7b7 100644 --- a/go.mod +++ b/go.mod @@ -15,7 +15,7 @@ require ( github.com/gorilla/mux v1.6.3-0.20190108142930-08e7f807d38d github.com/hashicorp/golang-lru v0.5.4 github.com/honeycombio/dynsampler-go v0.2.1 - github.com/honeycombio/husky v0.3.0 + github.com/honeycombio/husky v0.4.0 github.com/honeycombio/libhoney-go v1.15.6 github.com/jessevdk/go-flags v1.5.0 github.com/json-iterator/go v1.1.12 @@ -28,7 +28,7 @@ require ( github.com/spf13/viper v1.9.0 github.com/stretchr/testify v1.7.0 github.com/vmihailenco/msgpack/v4 v4.3.11 - go.opentelemetry.io/proto/otlp v0.11.0 + go.opentelemetry.io/proto/otlp v0.9.0 google.golang.org/grpc v1.42.0 gopkg.in/alexcesaro/statsd.v2 v2.0.0 gopkg.in/go-playground/assert.v1 v1.2.1 // indirect diff --git a/go.sum b/go.sum index b7cf145907..21ac7d7784 100644 --- a/go.sum +++ b/go.sum @@ -228,8 +228,8 @@ github.com/hashicorp/memberlist v0.2.2/go.mod h1:MS2lj3INKhZjWNqd3N0m3J+Jxf3DAOn github.com/hashicorp/serf v0.9.5/go.mod h1:UWDWwZeL5cuWDJdl0C6wrvrUwEqtQ4ZKBKKENpqIUyk= 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.3.0 h1:8H0PsBlp2KW/VfHZ2W1ScSKode8TeL+rrnb28Ya6LBQ= -github.com/honeycombio/husky v0.3.0/go.mod h1:OKDdF3gAoP6GtQsMgFJKUqApY+x6T0mWv1S+VHpbH8A= +github.com/honeycombio/husky v0.4.0 h1:wTp7gXe0GTFkHi4kf1kaC5JT6ApHKhHxd0XgC4429Nw= +github.com/honeycombio/husky v0.4.0/go.mod h1:KltmTfiasGGV0L3Hv6KEzm9YSvv3vRTz/JRSq1K+d78= github.com/honeycombio/libhoney-go v1.15.6 h1:zbwfdo74Gsedmu6OT/oAHv4pfKNoseTXRMA/4e5XWew= github.com/honeycombio/libhoney-go v1.15.6/go.mod h1:8NyBoM746bz+nw3yQzQF8gtJO/z4mkr/MD5C4r4uC2Y= github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc= @@ -368,8 +368,8 @@ go.opencensus.io v0.22.4/go.mod h1:yxeiOL68Rb0Xd1ddK5vPZ/oVn4vY4Ynel7k9FzqtOIw= go.opencensus.io v0.22.5/go.mod h1:5pWMHQbX5EPX2/62yrJeAkowc+lfs/XD7Uxpq3pI6kk= go.opencensus.io v0.23.0/go.mod h1:XItmlyltB5F7CS4xOC1DcqMoFqwtC6OG2xF7mCv7P7E= go.opentelemetry.io/proto/otlp v0.7.0/go.mod h1:PqfVotwruBrMGOCsRd/89rSnXhoiJIqeYNgFYFoEGnI= -go.opentelemetry.io/proto/otlp v0.11.0 h1:cLDgIBTf4lLOlztkhzAEdQsJ4Lj+i5Wc9k6Nn0K1VyU= -go.opentelemetry.io/proto/otlp v0.11.0/go.mod h1:QpEjXPrNQzrFDZgoTo49dgHR9RYRSrg3NAKnUGl9YpQ= +go.opentelemetry.io/proto/otlp v0.9.0 h1:C0g6TWmQYvjKRnljRULLWUVJGy8Uvu0NEL/5frY2/t4= +go.opentelemetry.io/proto/otlp v0.9.0/go.mod h1:1vKfU9rv61e9EVGthD1zNvUbiwPcimSsOPU9brfSHJg= go.uber.org/atomic v1.7.0/go.mod h1:fEN4uk6kAWBTFdckzkM89CLk9XfWZrxpCo0nPH17wJc= go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU= go.uber.org/zap v1.17.0/go.mod h1:MXVU+bhUf/A7Xi2HNOnopQOrmycQ5Ih87HtOu4q5SSo=