Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bump husky to v0.4.0 #361

Merged
merged 3 commits into from
Dec 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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.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
Expand All @@ -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
Expand Down
8 changes: 4 additions & 4 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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.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=
Expand Down Expand Up @@ -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=
Expand Down
26 changes: 8 additions & 18 deletions route/otlp_trace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"context"
"errors"
"net/http"
"time"

huskyotlp "github.com/honeycombio/husky/otlp"
"github.com/honeycombio/refinery/types"
Expand All @@ -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)
}
}
Expand All @@ -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)
}

Expand All @@ -55,35 +54,26 @@ 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")
return err
}

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())
Expand Down
40 changes: 0 additions & 40 deletions route/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
75 changes: 0 additions & 75 deletions route/route_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import (
"fmt"
"io"
"io/ioutil"
"math"
"net/http"
"net/http/httptest"
"strings"
Expand Down Expand Up @@ -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"})
Expand Down