diff --git a/codec/fullevent_test.go b/codec/fullevent_test.go index 4e2a9d7d..bc95548e 100644 --- a/codec/fullevent_test.go +++ b/codec/fullevent_test.go @@ -38,7 +38,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Value: []string{"bar"}, }, }, - AgeMillis: int64Ptr(2), + AgeMillis: uint64Ptr(2), QueueName: "queuename", RoutingKey: "routingkey", }, @@ -73,7 +73,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Name: "name", Stacktrace: []*modelpb.StacktraceFrame{ { - Vars: randomKvPb(t), + Vars: randomKv(t), Lineno: uintPtr(1), Colno: uintPtr(2), Filename: "frame_filename", @@ -158,7 +158,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Value: []string{"bar"}, }, }, - AgeMillis: int64Ptr(2), + AgeMillis: uint64Ptr(2), QueueName: "queuename", RoutingKey: "routingkey", }, @@ -168,7 +168,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Id: "id", DurationHistogram: &modelpb.Histogram{ Values: []float64{4}, - Counts: []int64{5}, + Counts: []uint64{5}, }, DroppedSpansStats: []*modelpb.DroppedSpanStats{ { @@ -200,7 +200,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Unit: "unit", Histogram: &modelpb.Histogram{ Values: []float64{1}, - Counts: []int64{2}, + Counts: []uint64{2}, }, Summary: &modelpb.SummaryMetric{ Count: 3, @@ -216,7 +216,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Message: "ex_message", Module: "ex_module", Code: "ex_code", - Attributes: randomKvPb(t), + Attributes: randomKv(t), Type: "ex_type", Handled: boolPtr(true), Cause: []*modelpb.Exception{ @@ -357,8 +357,8 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Http: &modelpb.HTTP{ Request: &modelpb.HTTPRequest{ Headers: randomHTTPHeaders(t), - Env: randomKvPb(t), - Cookies: randomKvPb(t), + Env: randomKv(t), + Cookies: randomKv(t), Id: "id", Method: "method", Referrer: "referrer", @@ -367,9 +367,9 @@ func fullEvent(t *testing.B) *modelpb.APMEvent { Headers: randomHTTPHeaders(t), Finished: boolPtr(true), HeadersSent: boolPtr(true), - TransferSize: int64Ptr(1), - EncodedBodySize: int64Ptr(2), - DecodedBodySize: int64Ptr(3), + TransferSize: uint64Ptr(1), + EncodedBodySize: uint64Ptr(2), + DecodedBodySize: uint64Ptr(3), StatusCode: 200, }, Version: "version", diff --git a/codec/utils_test.go b/codec/utils_test.go index 80a9fd5d..94498013 100644 --- a/codec/utils_test.go +++ b/codec/utils_test.go @@ -23,34 +23,26 @@ import ( "testing" "github.com/elastic/apm-data/model/modelpb" + "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/structpb" ) -func randomKv(t testing.TB) ([]*modelpb.KeyValue, map[string]any) { - m := map[string]any{ - t.Name() + ".key." + randString(): t.Name() + ".value." + randString(), - } +func randomKv(t testing.TB) []*modelpb.KeyValue { + value, err := structpb.NewValue(t.Name() + ".value." + randString()) + require.NoError(t, err) - kv := []*modelpb.KeyValue{} - for k, v := range m { - value, _ := structpb.NewValue(v) - kv = append(kv, &modelpb.KeyValue{ - Key: k, + kv := []*modelpb.KeyValue{ + { + Key: t.Name() + ".key." + randString(), Value: value, - }) + }, } - - return kv, m -} - -func randomKvPb(t testing.TB) []*modelpb.KeyValue { - k, _ := randomKv(t) - return k + return kv } func randomHTTPHeaders(t testing.TB) []*modelpb.HTTPHeader { return []*modelpb.HTTPHeader{ - &modelpb.HTTPHeader{ + { Key: t.Name() + ".key." + randString(), Value: []string{t.Name() + ".value." + randString()}, }, @@ -61,7 +53,7 @@ func uintPtr(i uint32) *uint32 { return &i } -func int64Ptr(i int64) *int64 { +func uint64Ptr(i uint64) *uint64 { return &i } diff --git a/input/elasticapm/internal/modeldecoder/generator/jsonschema.go b/input/elasticapm/internal/modeldecoder/generator/jsonschema.go index 6aed2475..04384825 100644 --- a/input/elasticapm/internal/modeldecoder/generator/jsonschema.go +++ b/input/elasticapm/internal/modeldecoder/generator/jsonschema.go @@ -216,6 +216,8 @@ var ( nullableTypeInt: TypeNameInteger, "int": TypeNameInteger, "int64": TypeNameInteger, + "uint": TypeNameInteger, + "uint64": TypeNameInteger, nullableTypeTimeMicrosUnix: TypeNameInteger, nullableTypeString: TypeNameString, "string": TypeNameString, diff --git a/input/elasticapm/internal/modeldecoder/generator/slice.go b/input/elasticapm/internal/modeldecoder/generator/slice.go index 0ec4a05d..026e4537 100644 --- a/input/elasticapm/internal/modeldecoder/generator/slice.go +++ b/input/elasticapm/internal/modeldecoder/generator/slice.go @@ -87,6 +87,7 @@ for _, elem := range val.%s{ func sliceRuleMinVals(w io.Writer, f structField, rule validationRule) error { fmt.Fprintf(w, ` for _, elem := range val.%s{ + //lint:ignore SA4003 don't reject the check for uint if elem %s %s{ return fmt.Errorf("'%s': validation rule '%s(%s)' violated") } diff --git a/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go b/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go index 187a6b42..d402e969 100644 --- a/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go +++ b/input/elasticapm/internal/modeldecoder/modeldecodertest/populator.go @@ -135,6 +135,10 @@ func SetStructValues(in interface{}, values *Values, opts ...SetStructValuesOpti elemVal = reflect.ValueOf(values.Int) case []int64: elemVal = reflect.ValueOf(int64(values.Int)) + case []uint: + elemVal = reflect.ValueOf(uint(values.Int)) + case []uint64: + elemVal = reflect.ValueOf(uint64(values.Int)) case []uint8: elemVal = reflect.ValueOf(uint8(values.Int)) case []float64: @@ -302,9 +306,14 @@ func AssertStructValues(t *testing.T, i interface{}, isException func(string) bo newVal = values.Int case int64: newVal = int64(values.Int) + case uint64: + newVal = uint64(values.Int) case *int64: val := int64(values.Int) newVal = &val + case *uint64: + val := uint64(values.Int) + newVal = &val case *int: newVal = &values.Int case int32: diff --git a/input/elasticapm/internal/modeldecoder/modeldecoderutil/metrics.go b/input/elasticapm/internal/modeldecoder/modeldecoderutil/metrics.go index 68f96190..a0f55111 100644 --- a/input/elasticapm/internal/modeldecoder/modeldecoderutil/metrics.go +++ b/input/elasticapm/internal/modeldecoder/modeldecoderutil/metrics.go @@ -47,7 +47,7 @@ func SetInternalMetrics(event *modelpb.APMEvent) bool { if event.Span.SelfTime == nil { event.Span.SelfTime = &modelpb.AggregatedDuration{} } - event.Span.SelfTime.Count = int64(v.Value) + event.Span.SelfTime.Count = uint64(v.Value) haveMetrics = true case "span.self_time.sum.us": if event.Span.SelfTime == nil { diff --git a/input/elasticapm/internal/modeldecoder/rumv3/decoder.go b/input/elasticapm/internal/modeldecoder/rumv3/decoder.go index 136aa476..bd6e5919 100644 --- a/input/elasticapm/internal/modeldecoder/rumv3/decoder.go +++ b/input/elasticapm/internal/modeldecoder/rumv3/decoder.go @@ -406,7 +406,7 @@ func mapToTransactionMetricsetModel(from *transactionMetricset, event *modelpb.A if event.Span != nil { if value := from.Samples.SpanSelfTimeCount.Value; value.IsSet() { event.Span.SelfTime = populateNil(event.Span.SelfTime) - event.Span.SelfTime.Count = int64(value.Val) + event.Span.SelfTime.Count = uint64(value.Val) ok = true } if value := from.Samples.SpanSelfTimeSum.Value; value.IsSet() { @@ -424,18 +424,18 @@ func mapToResponseModel(from contextResponse, out *modelpb.HTTPResponse) { out.Headers = modeldecoderutil.HTTPHeadersToModelpb(from.Headers.Val) } if from.StatusCode.IsSet() { - out.StatusCode = int32(from.StatusCode.Val) + out.StatusCode = uint32(from.StatusCode.Val) } if from.TransferSize.IsSet() { - val := int64(from.TransferSize.Val) + val := uint64(from.TransferSize.Val) out.TransferSize = &val } if from.EncodedBodySize.IsSet() { - val := int64(from.EncodedBodySize.Val) + val := uint64(from.EncodedBodySize.Val) out.EncodedBodySize = &val } if from.DecodedBodySize.IsSet() { - val := int64(from.DecodedBodySize.Val) + val := uint64(from.DecodedBodySize.Val) out.DecodedBodySize = &val } } @@ -556,7 +556,7 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) { if from.Context.HTTP.StatusCode.IsSet() { event.Http = populateNil(event.Http) event.Http.Response = &response - event.Http.Response.StatusCode = int32(from.Context.HTTP.StatusCode.Val) + event.Http.Response.StatusCode = uint32(from.Context.HTTP.StatusCode.Val) } if from.Context.HTTP.URL.IsSet() { event.Url = populateNil(event.Url) @@ -566,15 +566,15 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) { event.Http = populateNil(event.Http) event.Http.Response = &response if from.Context.HTTP.Response.DecodedBodySize.IsSet() { - val := int64(from.Context.HTTP.Response.DecodedBodySize.Val) + val := uint64(from.Context.HTTP.Response.DecodedBodySize.Val) event.Http.Response.DecodedBodySize = &val } if from.Context.HTTP.Response.EncodedBodySize.IsSet() { - val := int64(from.Context.HTTP.Response.EncodedBodySize.Val) + val := uint64(from.Context.HTTP.Response.EncodedBodySize.Val) event.Http.Response.EncodedBodySize = &val } if from.Context.HTTP.Response.TransferSize.IsSet() { - val := int64(from.Context.HTTP.Response.TransferSize.Val) + val := uint64(from.Context.HTTP.Response.TransferSize.Val) event.Http.Response.TransferSize = &val } } @@ -784,7 +784,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { if from.Session.ID.IsSet() { event.Session = &modelpb.Session{ Id: from.Session.ID.Val, - Sequence: int64(from.Session.Sequence.Val), + Sequence: uint64(from.Session.Sequence.Val), } } if from.SpanCount.Dropped.IsSet() { @@ -810,7 +810,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { CumulativeLayoutShift: -1, FirstInputDelay: -1, TotalBlockingTime: -1, - LongTask: &modelpb.LongtaskMetrics{Count: -1}, + LongTask: nil, } if from.UserExperience.CumulativeLayoutShift.IsSet() { out.UserExperience.CumulativeLayoutShift = from.UserExperience.CumulativeLayoutShift.Val @@ -823,7 +823,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { } if from.UserExperience.Longtask.IsSet() { out.UserExperience.LongTask = &modelpb.LongtaskMetrics{ - Count: int64(from.UserExperience.Longtask.Count.Val), + Count: uint64(from.UserExperience.Longtask.Count.Val), Sum: from.UserExperience.Longtask.Sum.Val, Max: from.UserExperience.Longtask.Max.Val, } diff --git a/input/elasticapm/internal/modeldecoder/v2/decoder.go b/input/elasticapm/internal/modeldecoder/v2/decoder.go index e917ce62..8b286d3d 100644 --- a/input/elasticapm/internal/modeldecoder/v2/decoder.go +++ b/input/elasticapm/internal/modeldecoder/v2/decoder.go @@ -323,7 +323,7 @@ func mapToDroppedSpansModel(from []transactionDroppedSpanStats, tx *modelpb.Tran } if f.Duration.IsSet() { to.Duration = &modelpb.AggregatedDuration{} - to.Duration.Count = int64(f.Duration.Count.Val) + to.Duration.Count = uint64(f.Duration.Count.Val) sum := f.Duration.Sum if sum.IsSet() { to.Duration.Sum = durationpb.New(time.Duration(sum.Us.Val) * time.Microsecond) @@ -737,7 +737,7 @@ func mapToMetricsetModel(from *metricset, event *modelpb.APMEvent) bool { if len(from.Samples) > 0 { samples := make([]*modelpb.MetricsetSample, 0, len(from.Samples)) for name, sample := range from.Samples { - var counts []int64 + var counts []uint64 var values []float64 var histogram *modelpb.Histogram if n := len(sample.Values); n > 0 { @@ -745,7 +745,7 @@ func mapToMetricsetModel(from *metricset, event *modelpb.APMEvent) bool { copy(values, sample.Values) } if n := len(sample.Counts); n > 0 { - counts = make([]int64, n) + counts = make([]uint64, n) copy(counts, sample.Counts) } if len(counts) != 0 || len(values) != 0 { @@ -871,18 +871,18 @@ func mapToResponseModel(from contextResponse, out *modelpb.HTTPResponse) { out.HeadersSent = &val } if from.StatusCode.IsSet() { - out.StatusCode = int32(from.StatusCode.Val) + out.StatusCode = uint32(from.StatusCode.Val) } if from.TransferSize.IsSet() { - val := int64(from.TransferSize.Val) + val := uint64(from.TransferSize.Val) out.TransferSize = &val } if from.EncodedBodySize.IsSet() { - val := int64(from.EncodedBodySize.Val) + val := uint64(from.EncodedBodySize.Val) out.EncodedBodySize = &val } if from.DecodedBodySize.IsSet() { - val := int64(from.DecodedBodySize.Val) + val := uint64(from.DecodedBodySize.Val) out.DecodedBodySize = &val } } @@ -1068,21 +1068,21 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) { event.Http = populateNil(event.Http) response := modelpb.HTTPResponse{} if from.Context.HTTP.Response.DecodedBodySize.IsSet() { - val := int64(from.Context.HTTP.Response.DecodedBodySize.Val) + val := uint64(from.Context.HTTP.Response.DecodedBodySize.Val) response.DecodedBodySize = &val } if from.Context.HTTP.Response.EncodedBodySize.IsSet() { - val := int64(from.Context.HTTP.Response.EncodedBodySize.Val) + val := uint64(from.Context.HTTP.Response.EncodedBodySize.Val) response.EncodedBodySize = &val } if from.Context.HTTP.Response.Headers.IsSet() { response.Headers = modeldecoderutil.HTTPHeadersToModelpb(from.Context.HTTP.Response.Headers.Val) } if from.Context.HTTP.Response.StatusCode.IsSet() { - response.StatusCode = int32(from.Context.HTTP.Response.StatusCode.Val) + response.StatusCode = uint32(from.Context.HTTP.Response.StatusCode.Val) } if from.Context.HTTP.Response.TransferSize.IsSet() { - val := int64(from.Context.HTTP.Response.TransferSize.Val) + val := uint64(from.Context.HTTP.Response.TransferSize.Val) response.TransferSize = &val } event.Http.Response = &response @@ -1090,7 +1090,7 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) { if from.Context.HTTP.StatusCode.IsSet() { event.Http = populateNil(event.Http) event.Http.Response = populateNil(event.Http.Response) - event.Http.Response.StatusCode = int32(from.Context.HTTP.StatusCode.Val) + event.Http.Response.StatusCode = uint32(from.Context.HTTP.StatusCode.Val) } if from.Context.HTTP.URL.IsSet() { event.Url = populateNil(event.Url) @@ -1106,7 +1106,7 @@ func mapToSpanModel(from *span, event *modelpb.APMEvent) { message.Headers = modeldecoderutil.HTTPHeadersToModelpb(from.Context.Message.Headers.Val) } if from.Context.Message.Age.Milliseconds.IsSet() { - val := int64(from.Context.Message.Age.Milliseconds.Val) + val := uint64(from.Context.Message.Age.Milliseconds.Val) message.AgeMillis = &val } if from.Context.Message.Queue.Name.IsSet() { @@ -1291,7 +1291,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { if from.Context.Message.IsSet() { out.Message = &modelpb.Message{} if from.Context.Message.Age.IsSet() { - val := int64(from.Context.Message.Age.Milliseconds.Val) + val := uint64(from.Context.Message.Age.Milliseconds.Val) out.Message.AgeMillis = &val } if from.Context.Message.Body.IsSet() { @@ -1397,7 +1397,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { if from.Session.ID.IsSet() { event.Session = &modelpb.Session{ Id: from.Session.ID.Val, - Sequence: int64(from.Session.Sequence.Val), + Sequence: uint64(from.Session.Sequence.Val), } } if from.SpanCount.Dropped.IsSet() { @@ -1426,7 +1426,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { CumulativeLayoutShift: -1, FirstInputDelay: -1, TotalBlockingTime: -1, - LongTask: &modelpb.LongtaskMetrics{Count: -1}, + LongTask: nil, } if from.UserExperience.CumulativeLayoutShift.IsSet() { out.UserExperience.CumulativeLayoutShift = from.UserExperience.CumulativeLayoutShift.Val @@ -1440,7 +1440,7 @@ func mapToTransactionModel(from *transaction, event *modelpb.APMEvent) { } if from.UserExperience.Longtask.IsSet() { out.UserExperience.LongTask = &modelpb.LongtaskMetrics{ - Count: int64(from.UserExperience.Longtask.Count.Val), + Count: uint64(from.UserExperience.Longtask.Count.Val), Sum: from.UserExperience.Longtask.Sum.Val, Max: from.UserExperience.Longtask.Max.Val, } @@ -1507,7 +1507,7 @@ func mapToLogModel(from *log, event *modelpb.APMEvent) { event.Log = populateNil(event.Log) event.Log.Origin = populateNil(event.Log.Origin) event.Log.Origin.File = populateNil(event.Log.Origin.File) - event.Log.Origin.File.Line = int32(from.OriginFileLine.Val) + event.Log.Origin.File.Line = uint32(from.OriginFileLine.Val) } if from.OriginFileName.IsSet() { event.Log = populateNil(event.Log) diff --git a/input/elasticapm/internal/modeldecoder/v2/log_test.go b/input/elasticapm/internal/modeldecoder/v2/log_test.go index 7e03d3f7..c002808d 100644 --- a/input/elasticapm/internal/modeldecoder/v2/log_test.go +++ b/input/elasticapm/internal/modeldecoder/v2/log_test.go @@ -56,7 +56,7 @@ func TestDecodeNestedLog(t *testing.T) { assert.Equal(t, "warn", batch[0].Log.Level) assert.Equal(t, "testLogger", batch[0].Log.Logger) assert.Equal(t, "testFile", batch[0].Log.Origin.File.Name) - assert.Equal(t, int32(10), batch[0].Log.Origin.File.Line) + assert.Equal(t, uint32(10), batch[0].Log.Origin.File.Line) assert.Equal(t, "testFunc", batch[0].Log.Origin.FunctionName) assert.Equal(t, "testsvc", batch[0].Service.Name) assert.Equal(t, "v1.2.0", batch[0].Service.Version) @@ -90,7 +90,7 @@ func TestDecodeNestedLog(t *testing.T) { assert.Equal(t, "error", batch[0].Log.Level) assert.Equal(t, "testLogger", batch[0].Log.Logger) assert.Equal(t, "testFile", batch[0].Log.Origin.File.Name) - assert.Equal(t, int32(10), batch[0].Log.Origin.File.Line) + assert.Equal(t, uint32(10), batch[0].Log.Origin.File.Line) assert.Equal(t, "testFunc", batch[0].Log.Origin.FunctionName) assert.Equal(t, "testsvc", batch[0].Service.Name) assert.Equal(t, "v1.2.0", batch[0].Service.Version) @@ -117,7 +117,7 @@ func TestDecodeNestedLog(t *testing.T) { assert.Equal(t, "error", batch[0].Log.Level) assert.Equal(t, "testLogger", batch[0].Log.Logger) assert.Equal(t, "testFile", batch[0].Log.Origin.File.Name) - assert.Equal(t, int32(10), batch[0].Log.Origin.File.Line) + assert.Equal(t, uint32(10), batch[0].Log.Origin.File.Line) assert.Equal(t, "testFunc", batch[0].Log.Origin.FunctionName) assert.Equal(t, "testsvc", batch[0].Service.Name) assert.Equal(t, "v1.2.0", batch[0].Service.Version) @@ -144,7 +144,7 @@ func TestDecodeNestedLog(t *testing.T) { assert.Equal(t, "error", batch[0].Log.Level) assert.Equal(t, "testLogger", batch[0].Log.Logger) assert.Equal(t, "testFile", batch[0].Log.Origin.File.Name) - assert.Equal(t, int32(10), batch[0].Log.Origin.File.Line) + assert.Equal(t, uint32(10), batch[0].Log.Origin.File.Line) assert.Equal(t, "testFunc", batch[0].Log.Origin.FunctionName) assert.Equal(t, "testsvc", batch[0].Service.Name) assert.Equal(t, "v1.2.0", batch[0].Service.Version) @@ -188,7 +188,7 @@ func TestDecodeMapToLogModel(t *testing.T) { assert.Equal(t, "warn", out.Log.Level) assert.Equal(t, "testlogger", out.Log.Logger) assert.Equal(t, "testfile", out.Log.Origin.File.Name) - assert.Equal(t, int32(10), out.Log.Origin.File.Line) + assert.Equal(t, uint32(10), out.Log.Origin.File.Line) assert.Equal(t, "testfunc", out.Log.Origin.FunctionName) }) diff --git a/input/elasticapm/internal/modeldecoder/v2/metricset_test.go b/input/elasticapm/internal/modeldecoder/v2/metricset_test.go index c0d6c00c..617286bc 100644 --- a/input/elasticapm/internal/modeldecoder/v2/metricset_test.go +++ b/input/elasticapm/internal/modeldecoder/v2/metricset_test.go @@ -140,7 +140,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) { Unit: defaultVal.Str, Value: defaultVal.Float, Histogram: &modelpb.Histogram{ - Counts: repeatInt64(int64(defaultVal.Int), defaultVal.N), + Counts: repeatUint64(uint64(defaultVal.Int), defaultVal.N), Values: repeatFloat64(defaultVal.Float, defaultVal.N), }, }, @@ -150,7 +150,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) { Unit: defaultVal.Str, Value: defaultVal.Float, Histogram: &modelpb.Histogram{ - Counts: repeatInt64(int64(defaultVal.Int), defaultVal.N), + Counts: repeatUint64(uint64(defaultVal.Int), defaultVal.N), Values: repeatFloat64(defaultVal.Float, defaultVal.N), }, }, @@ -160,7 +160,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) { Unit: defaultVal.Str, Value: defaultVal.Float, Histogram: &modelpb.Histogram{ - Counts: repeatInt64(int64(defaultVal.Int), defaultVal.N), + Counts: repeatUint64(uint64(defaultVal.Int), defaultVal.N), Values: repeatFloat64(defaultVal.Float, defaultVal.N), }, }, @@ -185,7 +185,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) { Unit: otherVal.Str, Value: otherVal.Float, Histogram: &modelpb.Histogram{ - Counts: repeatInt64(int64(otherVal.Int), otherVal.N), + Counts: repeatUint64(uint64(otherVal.Int), otherVal.N), Values: repeatFloat64(otherVal.Float, otherVal.N), }, }, @@ -195,7 +195,7 @@ func TestDecodeMapToMetricsetModel(t *testing.T) { Unit: otherVal.Str, Value: otherVal.Float, Histogram: &modelpb.Histogram{ - Counts: repeatInt64(int64(otherVal.Int), otherVal.N), + Counts: repeatUint64(uint64(otherVal.Int), otherVal.N), Values: repeatFloat64(otherVal.Float, otherVal.N), }, }, @@ -453,8 +453,8 @@ func TestDecodeMetricsetServiceVersion(t *testing.T) { }}, batch, protocmp.Transform())) } -func repeatInt64(v int64, n int) []int64 { - vs := make([]int64, n) +func repeatUint64(v uint64, n int) []uint64 { + vs := make([]uint64, n) for i := range vs { vs[i] = v } diff --git a/input/elasticapm/internal/modeldecoder/v2/model.go b/input/elasticapm/internal/modeldecoder/v2/model.go index 4e4b3286..63f0c5ac 100644 --- a/input/elasticapm/internal/modeldecoder/v2/model.go +++ b/input/elasticapm/internal/modeldecoder/v2/model.go @@ -680,7 +680,7 @@ type metricsetSampleValue struct { // If Counts is specified, then Values is expected to be // specified with the same number of elements, and with the // same order. - Counts []int64 `json:"counts" validate:"requiredIfAny=values,minVals=0"` + Counts []uint64 `json:"counts" validate:"requiredIfAny=values,minVals=0"` // Value holds the value of a single metric sample. Value nullable.Float64 `json:"value"` } diff --git a/input/elasticapm/internal/modeldecoder/v2/model_generated.go b/input/elasticapm/internal/modeldecoder/v2/model_generated.go index 175fa2d8..3c4d578d 100644 --- a/input/elasticapm/internal/modeldecoder/v2/model_generated.go +++ b/input/elasticapm/internal/modeldecoder/v2/model_generated.go @@ -1952,6 +1952,7 @@ func (val *metricsetSampleValue) validate() error { } } for _, elem := range val.Counts { + //lint:ignore SA4003 don't reject the check for uint if elem < 0 { return fmt.Errorf("'counts': validation rule 'minVals(0)' violated") } diff --git a/input/otlp/logs.go b/input/otlp/logs.go index 7f51b2bd..1ffca4d4 100644 --- a/input/otlp/logs.go +++ b/input/otlp/logs.go @@ -105,7 +105,7 @@ func (c *Consumer) convertLogRecord( initEventLabels(event) event.Timestamp = timestamppb.New(record.Timestamp().AsTime().Add(timeDelta)) event.Event = populateNil(event.Event) - event.Event.Severity = int64(record.SeverityNumber()) + event.Event.Severity = uint64(record.SeverityNumber()) event.Log = populateNil(event.Log) event.Log.Level = record.SeverityText() if body := record.Body(); body.Type() != pcommon.ValueTypeEmpty { diff --git a/input/otlp/logs_test.go b/input/otlp/logs_test.go index 6149bbfd..54f843c3 100644 --- a/input/otlp/logs_test.go +++ b/input/otlp/logs_test.go @@ -79,7 +79,7 @@ func TestConsumerConsumeLogs(t *testing.T) { }, Message: "a random log message", Event: &modelpb.Event{ - Severity: int64(plog.SeverityNumberInfo), + Severity: uint64(plog.SeverityNumberInfo), }, Log: &modelpb.Log{Level: "Info"}, Span: &modelpb.Span{Id: "0200000000000000"}, @@ -317,7 +317,7 @@ Caused by: LowLevelException Version: "unknown", }, Event: &modelpb.Event{ - Severity: int64(plog.SeverityNumberInfo), + Severity: uint64(plog.SeverityNumberInfo), Kind: "event", Category: "device", Type: "error", diff --git a/input/otlp/metrics.go b/input/otlp/metrics.go index d191afd2..aff21e0e 100644 --- a/input/otlp/metrics.go +++ b/input/otlp/metrics.go @@ -210,7 +210,7 @@ func summarySample(dp pmetric.SummaryDataPoint) *modelpb.MetricsetSample { return &modelpb.MetricsetSample{ Type: modelpb.MetricType_METRIC_TYPE_SUMMARY, Summary: &modelpb.SummaryMetric{ - Count: int64(dp.Count()), + Count: uint64(dp.Count()), Sum: dp.Sum(), }, } @@ -243,7 +243,7 @@ func histogramSample(bucketCounts pcommon.UInt64Slice, explicitBounds pcommon.Fl // case, the usual linear interpolation is applied within that bucket. Otherwise, the upper // bound of the lowest bucket is returned for quantiles located in the lowest bucket." values := make([]float64, 0, bucketCounts.Len()) - counts := make([]int64, 0, bucketCounts.Len()) + counts := make([]uint64, 0, bucketCounts.Len()) for i := 0; i < bucketCounts.Len(); i++ { count := bucketCounts.At(i) if count == 0 { @@ -269,7 +269,7 @@ func histogramSample(bucketCounts pcommon.UInt64Slice, explicitBounds pcommon.Fl value = explicitBounds.At(i-1) + (explicitBounds.At(i)-explicitBounds.At(i-1))/2.0 } - counts = append(counts, int64(count)) + counts = append(counts, uint64(count)) values = append(values, value) } return &modelpb.MetricsetSample{ diff --git a/input/otlp/metrics_test.go b/input/otlp/metrics_test.go index 389506c5..cbf7efc9 100644 --- a/input/otlp/metrics_test.go +++ b/input/otlp/metrics_test.go @@ -151,7 +151,7 @@ func TestConsumeMetrics(t *testing.T) { Name: "histogram_metric", Type: modelpb.MetricType_METRIC_TYPE_HISTOGRAM, Histogram: &modelpb.Histogram{ - Counts: []int64{1, 1, 2, 3}, + Counts: []uint64{1, 1, 2, 3}, Values: []float64{-1, 0.5, 2.75, 3.5}, }, }, @@ -654,7 +654,7 @@ func TestConsumeMetrics_JVM(t *testing.T) { Name: "process.runtime.jvm.gc.duration", Type: modelpb.MetricType_METRIC_TYPE_HISTOGRAM, Histogram: &modelpb.Histogram{ - Counts: []int64{1, 1, 2, 3}, + Counts: []uint64{1, 1, 2, 3}, Values: []float64{0.25, 1, 2, 2.5}, }, }, diff --git a/input/otlp/traces.go b/input/otlp/traces.go index f6f5708d..0cdc8eb2 100644 --- a/input/otlp/traces.go +++ b/input/otlp/traces.go @@ -261,7 +261,7 @@ func TranslateTransaction( switch kDots { case semconv.AttributeHTTPStatusCode: isHTTP = true - httpResponse.StatusCode = int32(v.Int()) + httpResponse.StatusCode = uint32(v.Int()) http.Response = &httpResponse case semconv.AttributeNetPeerPort: event.Source = populateNil(event.Source) @@ -295,7 +295,7 @@ func TranslateTransaction( case semconv.AttributeHTTPStatusCode: if intv, err := strconv.Atoi(stringval); err == nil { isHTTP = true - httpResponse.StatusCode = int32(intv) + httpResponse.StatusCode = uint32(intv) http.Response = &httpResponse } case "http.protocol": @@ -536,7 +536,7 @@ func TranslateSpan(spanKind ptrace.SpanKind, attributes pcommon.Map, event *mode case pcommon.ValueTypeInt: switch kDots { case "http.status_code": - httpResponse.StatusCode = int32(v.Int()) + httpResponse.StatusCode = uint32(v.Int()) http.Response = &httpResponse isHTTP = true case semconv.AttributeNetPeerPort, "peer.port": diff --git a/input/otlp/traces_test.go b/input/otlp/traces_test.go index f1a54b82..faec12c2 100644 --- a/input/otlp/traces_test.go +++ b/input/otlp/traces_test.go @@ -49,6 +49,7 @@ import ( jaegertranslator "github.com/open-telemetry/opentelemetry-collector-contrib/pkg/translator/jaeger" "github.com/stretchr/testify/assert" "github.com/stretchr/testify/require" + "go.elastic.co/fastjson" "go.opentelemetry.io/collector/pdata/pcommon" "go.opentelemetry.io/collector/pdata/ptrace" semconv "go.opentelemetry.io/collector/semconv/v1.5.0" @@ -57,6 +58,7 @@ import ( "google.golang.org/protobuf/testing/protocmp" "github.com/elastic/apm-data/input/otlp" + "github.com/elastic/apm-data/model/modeljson" "github.com/elastic/apm-data/model/modelpb" ) @@ -436,7 +438,7 @@ func TestHTTPTransactionStatusCode(t *testing.T) { event := transformTransactionWithAttributes(t, map[string]interface{}{ "http.status_code": 200, }) - assert.Equal(t, int32(200), event.Http.Response.StatusCode) + assert.Equal(t, uint32(200), event.Http.Response.StatusCode) } func TestDatabaseSpan(t *testing.T) { @@ -1594,8 +1596,10 @@ func encodeBatch(t testing.TB, batches ...*modelpb.Batch) [][]byte { var docs [][]byte for _, batch := range batches { for _, event := range *batch { - data, err := event.MarshalJSON() + var w fastjson.Writer + err := modeljson.MarshalAPMEvent(event, &w) require.NoError(t, err) + data := w.Bytes() docs = append(docs, data) } } diff --git a/model/modelpb/agent.pb.json.go b/model/modeljson/agent.pb.json.go similarity index 82% rename from model/modelpb/agent.pb.json.go rename to model/modeljson/agent.pb.json.go index 96a3a17f..d3bb8e6e 100644 --- a/model/modelpb/agent.pb.json.go +++ b/model/modeljson/agent.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (a *Agent) toModelJSON(out *modeljson.Agent) { +func AgentModelJSON(a *modelpb.Agent, out *modeljson.Agent) { *out = modeljson.Agent{ Name: a.Name, Version: a.Version, diff --git a/model/modelpb/agent.pb.json_test.go b/model/modeljson/agent.pb.json_test.go similarity index 86% rename from model/modelpb/agent.pb.json_test.go rename to model/modeljson/agent.pb.json_test.go index 43aff3ee..72063830 100644 --- a/model/modelpb/agent.pb.json_test.go +++ b/model/modeljson/agent.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestAgentToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Agent + proto *modelpb.Agent expected *modeljson.Agent }{ "empty": { - proto: &Agent{}, + proto: &modelpb.Agent{}, expected: &modeljson.Agent{}, }, "full": { - proto: &Agent{ + proto: &modelpb.Agent{ Name: "name", Version: "version", EphemeralId: "ephemeralid", @@ -52,7 +53,7 @@ func TestAgentToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Agent - tc.proto.toModelJSON(&out) + AgentModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/apmevent.pb.json.go b/model/modeljson/apmevent.pb.json.go similarity index 79% rename from model/modelpb/apmevent.pb.json.go rename to model/modeljson/apmevent.pb.json.go index 5a924429..4fd26663 100644 --- a/model/modelpb/apmevent.pb.json.go +++ b/model/modeljson/apmevent.pb.json.go @@ -15,22 +15,15 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "go.elastic.co/fastjson" ) -func (e *APMEvent) MarshalJSON() ([]byte, error) { - var w fastjson.Writer - if err := e.MarshalFastJSON(&w); err != nil { - return nil, err - } - return w.Bytes(), nil -} - -func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { +func MarshalAPMEvent(e *modelpb.APMEvent, w *fastjson.Writer) error { var labels map[string]modeljson.Label if n := len(e.Labels); n > 0 { labels = make(map[string]modeljson.Label) @@ -74,32 +67,32 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { var transaction modeljson.Transaction if e.Transaction != nil { - e.Transaction.toModelJSON(&transaction, e.Metricset != nil) + TransactionModelJSON(e.Transaction, &transaction, e.Metricset != nil) doc.Transaction = &transaction } var span modeljson.Span if e.Span != nil { - e.Span.toModelJSON(&span) + SpanModelJSON(e.Span, &span) doc.Span = &span } var metricset modeljson.Metricset if e.Metricset != nil { - e.Metricset.toModelJSON(&metricset) + MetricsetModelJSON(e.Metricset, &metricset) doc.Metricset = &metricset doc.DocCount = e.Metricset.DocCount } var errorStruct modeljson.Error if e.Error != nil { - e.Error.toModelJSON(&errorStruct) + ErrorModelJSON(e.Error, &errorStruct) doc.Error = &errorStruct } var event modeljson.Event if e.Event != nil { - e.Event.toModelJSON(&event) + EventModelJSON(e.Event, &event) doc.Event = &event } @@ -109,7 +102,7 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { var timestampStruct modeljson.Timestamp if e.Timestamp != nil && !e.Timestamp.AsTime().IsZero() { switch e.Type() { - case TransactionEventType, SpanEventType, ErrorEventType: + case modelpb.TransactionEventType, modelpb.SpanEventType, modelpb.ErrorEventType: timestampStruct.US = int(e.Timestamp.AsTime().UnixNano() / 1000) doc.TimestampStruct = ×tampStruct } @@ -117,49 +110,49 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { var cloud modeljson.Cloud if e.Cloud != nil { - e.Cloud.toModelJSON(&cloud) + CloudModelJSON(e.Cloud, &cloud) doc.Cloud = &cloud } var fass modeljson.FAAS if e.Faas != nil { - e.Faas.toModelJSON(&fass) + FaasModelJSON(e.Faas, &fass) doc.FAAS = &fass } var device modeljson.Device if e.Device != nil { - e.Device.toModelJSON(&device) + DeviceModelJSON(e.Device, &device) doc.Device = &device } var network modeljson.Network if e.Network != nil { - e.Network.toModelJSON(&network) + NetworkModelJSON(e.Network, &network) doc.Network = &network } var observer modeljson.Observer if e.Observer != nil { - e.Observer.toModelJSON(&observer) + ObserverModelJSON(e.Observer, &observer) doc.Observer = &observer } var container modeljson.Container if e.Container != nil { - e.Container.toModelJSON(&container) + ContainerModelJSON(e.Container, &container) doc.Container = &container } var kubernetes modeljson.Kubernetes if e.Kubernetes != nil { - e.Kubernetes.toModelJSON(&kubernetes) + KubernetesModelJSON(e.Kubernetes, &kubernetes) doc.Kubernetes = &kubernetes } var agent modeljson.Agent if e.Agent != nil { - e.Agent.toModelJSON(&agent) + AgentModelJSON(e.Agent, &agent) doc.Agent = &agent } @@ -171,13 +164,13 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { var user modeljson.User if e.User != nil { - e.User.toModelJSON(&user) + UserModelJSON(e.User, &user) doc.User = &user } var source modeljson.Source if e.Source != nil { - e.Source.toModelJSON(&source) + SourceModelJSON(e.Source, &source) doc.Source = &source } @@ -195,7 +188,7 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { var client modeljson.Client if e.Client != nil { - e.Client.toModelJSON(&client) + ClientModelJSON(e.Client, &client) doc.Client = &client } @@ -208,43 +201,43 @@ func (e *APMEvent) MarshalFastJSON(w *fastjson.Writer) error { var service modeljson.Service if e.Service != nil { - e.Service.toModelJSON(&service) + ServiceModelJSON(e.Service, &service) doc.Service = &service } var httpStruct modeljson.HTTP if e.Http != nil { - e.Http.toModelJSON(&httpStruct) + HTTPModelJSON(e.Http, &httpStruct) doc.HTTP = &httpStruct } var host modeljson.Host if e.Host != nil { - e.Host.toModelJSON(&host) + HostModelJSON(e.Host, &host) doc.Host = &host } var url modeljson.URL if e.Url != nil { - e.Url.toModelJSON(&url) + URLModelJSON(e.Url, &url) doc.URL = &url } var logStruct modeljson.Log if e.Log != nil { - e.Log.toModelJSON(&logStruct) + LogModelJSON(e.Log, &logStruct) doc.Log = &logStruct } var process modeljson.Process if e.Process != nil { - e.Process.toModelJSON(&process) + ProcessModelJSON(e.Process, &process) doc.Process = &process } var destination modeljson.Destination if e.Destination != nil { - e.Destination.toModelJSON(&destination) + DestinationModelJSON(e.Destination, &destination) doc.Destination = &destination } diff --git a/model/modelpb/apmevent.pb.json_test.go b/model/modeljson/apmevent.pb.json_test.go similarity index 72% rename from model/modelpb/apmevent.pb.json_test.go rename to model/modeljson/apmevent.pb.json_test.go index 48df68b7..1de5b7e2 100644 --- a/model/modelpb/apmevent.pb.json_test.go +++ b/model/modeljson/apmevent.pb.json_test.go @@ -15,66 +15,69 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" "time" - "github.com/stretchr/testify/assert" + "github.com/elastic/apm-data/model/modelpb" "github.com/stretchr/testify/require" + "go.elastic.co/fastjson" durationpb "google.golang.org/protobuf/types/known/durationpb" "google.golang.org/protobuf/types/known/timestamppb" ) func TestFullEvent(t *testing.T) { + var w fastjson.Writer event := fullEvent(t) - d, err := event.MarshalJSON() + err := MarshalAPMEvent(event, &w) require.NoError(t, err) - assert.NotNil(t, d) } func BenchmarkAPMEventToJSON(b *testing.B) { + var w fastjson.Writer event := fullEvent(b) b.Run("to-json", func(b *testing.B) { for i := 0; i < b.N; i++ { - event.MarshalJSON() + w.Reset() + MarshalAPMEvent(event, &w) } }) } -func fullEvent(t testing.TB) *APMEvent { - return &APMEvent{ +func fullEvent(t testing.TB) *modelpb.APMEvent { + return &modelpb.APMEvent{ Timestamp: timestamppb.New(time.Unix(1, 1)), - Span: &Span{ - Message: &Message{ + Span: &modelpb.Span{ + Message: &modelpb.Message{ Body: "body", - Headers: []*HTTPHeader{ + Headers: []*modelpb.HTTPHeader{ { Key: "foo", Value: []string{"bar"}, }, }, - AgeMillis: int64Ptr(2), + AgeMillis: uint64Ptr(2), QueueName: "queuename", RoutingKey: "routingkey", }, - Composite: &Composite{ - CompressionStrategy: CompressionStrategy_COMPRESSION_STRATEGY_EXACT_MATCH, + Composite: &modelpb.Composite{ + CompressionStrategy: modelpb.CompressionStrategy_COMPRESSION_STRATEGY_EXACT_MATCH, Count: 1, Sum: 2, }, - DestinationService: &DestinationService{ + DestinationService: &modelpb.DestinationService{ Type: "destination_type", Name: "destination_name", Resource: "destination_resource", - ResponseTime: &AggregatedDuration{ + ResponseTime: &modelpb.AggregatedDuration{ Count: 3, Sum: durationpb.New(4 * time.Second), }, }, - Db: &DB{ + Db: &modelpb.DB{ RowsAffected: uintPtr(5), Instance: "db_instace", Statement: "db_statement", @@ -89,9 +92,9 @@ func fullEvent(t testing.TB) *APMEvent { Id: "id", Type: "type", Name: "name", - Stacktrace: []*StacktraceFrame{ + Stacktrace: []*modelpb.StacktraceFrame{ { - Vars: randomKvPb(t), + Vars: randomKv(t), Lineno: uintPtr(1), Colno: uintPtr(2), Filename: "frame_filename", @@ -101,7 +104,7 @@ func fullEvent(t testing.TB) *APMEvent { Function: "frame_function", AbsPath: "frame_abspath", SourcemapError: "frame_sourcemaperror", - Original: &Original{ + Original: &modelpb.Original{ AbsPath: "orig_abspath", Filename: "orig_filename", Classname: "orig_classname", @@ -117,26 +120,26 @@ func fullEvent(t testing.TB) *APMEvent { ExcludeFromGrouping: true, }, }, - Links: []*SpanLink{ + Links: []*modelpb.SpanLink{ { TraceId: "trace_id", SpanId: "id1", }, }, - SelfTime: &AggregatedDuration{ + SelfTime: &modelpb.AggregatedDuration{ Count: 6, Sum: durationpb.New(7 * time.Second), }, RepresentativeCount: 8, }, - NumericLabels: map[string]*NumericLabelValue{ + NumericLabels: map[string]*modelpb.NumericLabelValue{ "foo": { Values: []float64{1, 2, 3}, Value: 1, Global: true, }, }, - Labels: map[string]*LabelValue{ + Labels: map[string]*modelpb.LabelValue{ "bar": { Value: "a", Values: []string{"a", "b", "c"}, @@ -144,16 +147,16 @@ func fullEvent(t testing.TB) *APMEvent { }, }, Message: "message", - Transaction: &Transaction{ - SpanCount: &SpanCount{ + Transaction: &modelpb.Transaction{ + SpanCount: &modelpb.SpanCount{ Started: uintPtr(1), Dropped: uintPtr(2), }, - UserExperience: &UserExperience{ + UserExperience: &modelpb.UserExperience{ CumulativeLayoutShift: 1, FirstInputDelay: 2, TotalBlockingTime: 3, - LongTask: &LongtaskMetrics{ + LongTask: &modelpb.LongtaskMetrics{ Count: 4, Sum: 5, Max: 6, @@ -161,22 +164,22 @@ func fullEvent(t testing.TB) *APMEvent { }, // TODO investigat valid values Custom: nil, - Marks: map[string]*TransactionMark{ + Marks: map[string]*modelpb.TransactionMark{ "foo": { Measurements: map[string]float64{ "bar": 3, }, }, }, - Message: &Message{ + Message: &modelpb.Message{ Body: "body", - Headers: []*HTTPHeader{ + Headers: []*modelpb.HTTPHeader{ { Key: "foo", Value: []string{"bar"}, }, }, - AgeMillis: int64Ptr(2), + AgeMillis: uint64Ptr(2), QueueName: "queuename", RoutingKey: "routingkey", }, @@ -184,23 +187,23 @@ func fullEvent(t testing.TB) *APMEvent { Name: "name", Result: "result", Id: "id", - DurationHistogram: &Histogram{ + DurationHistogram: &modelpb.Histogram{ Values: []float64{4}, - Counts: []int64{5}, + Counts: []uint64{5}, }, - DroppedSpansStats: []*DroppedSpanStats{ + DroppedSpansStats: []*modelpb.DroppedSpanStats{ { DestinationServiceResource: "destinationserviceresource", ServiceTargetType: "servicetargetype", ServiceTargetName: "servicetargetname", Outcome: "outcome", - Duration: &AggregatedDuration{ + Duration: &modelpb.AggregatedDuration{ Count: 4, Sum: durationpb.New(5 * time.Second), }, }, }, - DurationSummary: &SummaryMetric{ + DurationSummary: &modelpb.SummaryMetric{ Count: 6, Sum: 7, }, @@ -208,19 +211,19 @@ func fullEvent(t testing.TB) *APMEvent { Sampled: true, Root: true, }, - Metricset: &Metricset{ + Metricset: &modelpb.Metricset{ Name: "name", Interval: "interval", - Samples: []*MetricsetSample{ + Samples: []*modelpb.MetricsetSample{ { - Type: MetricType_METRIC_TYPE_COUNTER, + Type: modelpb.MetricType_METRIC_TYPE_COUNTER, Name: "name", Unit: "unit", - Histogram: &Histogram{ + Histogram: &modelpb.Histogram{ Values: []float64{1}, - Counts: []int64{2}, + Counts: []uint64{2}, }, - Summary: &SummaryMetric{ + Summary: &modelpb.SummaryMetric{ Count: 3, Sum: 4, }, @@ -229,15 +232,15 @@ func fullEvent(t testing.TB) *APMEvent { }, DocCount: 1, }, - Error: &Error{ - Exception: &Exception{ + Error: &modelpb.Error{ + Exception: &modelpb.Exception{ Message: "ex_message", Module: "ex_module", Code: "ex_code", - Attributes: randomKvPb(t), + Attributes: randomKv(t), Type: "ex_type", Handled: boolPtr(true), - Cause: []*Exception{ + Cause: []*modelpb.Exception{ { Message: "ex1_message", Module: "ex1_module", @@ -246,7 +249,7 @@ func fullEvent(t testing.TB) *APMEvent { }, }, }, - Log: &ErrorLog{ + Log: &modelpb.ErrorLog{ Message: "log_message", Level: "log_level", ParamMessage: "log_parammessage", @@ -259,8 +262,8 @@ func fullEvent(t testing.TB) *APMEvent { Message: "message", Type: "type", }, - Cloud: &Cloud{ - Origin: &CloudOrigin{ + Cloud: &modelpb.Cloud{ + Origin: &modelpb.CloudOrigin{ AccountId: "origin_accountid", Provider: "origin_provider", Region: "origin_region", @@ -278,36 +281,36 @@ func fullEvent(t testing.TB) *APMEvent { Region: "region", ServiceName: "servicename", }, - Service: &Service{ - Origin: &ServiceOrigin{ + Service: &modelpb.Service{ + Origin: &modelpb.ServiceOrigin{ Id: "origin_id", Name: "origin_name", Version: "origin_version", }, - Target: &ServiceTarget{ + Target: &modelpb.ServiceTarget{ Name: "target_name", Type: "target_type", }, - Language: &Language{ + Language: &modelpb.Language{ Name: "language_name", Version: "language_version", }, - Runtime: &Runtime{ + Runtime: &modelpb.Runtime{ Name: "runtime_name", Version: "runtime_version", }, - Framework: &Framework{ + Framework: &modelpb.Framework{ Name: "framework_name", Version: "framework_version", }, Name: "name", Version: "version", Environment: "environment", - Node: &ServiceNode{ + Node: &modelpb.ServiceNode{ Name: "node_name", }, }, - Faas: &Faas{ + Faas: &modelpb.Faas{ Id: "id", ColdStart: boolPtr(true), Execution: "execution", @@ -316,92 +319,92 @@ func fullEvent(t testing.TB) *APMEvent { Name: "name", Version: "version", }, - Network: &Network{ - Connection: &NetworkConnection{ + Network: &modelpb.Network{ + Connection: &modelpb.NetworkConnection{ Type: "type", Subtype: "subtype", }, - Carrier: &NetworkCarrier{ + Carrier: &modelpb.NetworkCarrier{ Name: "name", Mcc: "mcc", Mnc: "mnc", Icc: "icc", }, }, - Container: &Container{ + Container: &modelpb.Container{ Id: "id", Name: "name", Runtime: "runtime", ImageName: "imagename", ImageTag: "imagetag", }, - User: &User{ + User: &modelpb.User{ Domain: "domain", Id: "id", Email: "email", Name: "name", }, - Device: &Device{ + Device: &modelpb.Device{ Id: "id", - Model: &DeviceModel{ + Model: &modelpb.DeviceModel{ Name: "name", Identifier: "identifier", }, Manufacturer: "manufacturer", }, - Kubernetes: &Kubernetes{ + Kubernetes: &modelpb.Kubernetes{ Namespace: "namespace", NodeName: "nodename", PodName: "podname", PodUid: "poduid", }, - Observer: &Observer{ + Observer: &modelpb.Observer{ Hostname: "hostname", Name: "name", Type: "type", Version: "version", }, - DataStream: &DataStream{ + DataStream: &modelpb.DataStream{ Type: "type", Dataset: "dataset", Namespace: "namespace", }, - Agent: &Agent{ + Agent: &modelpb.Agent{ Name: "name", Version: "version", EphemeralId: "ephemeralid", ActivationMethod: "activationmethod", }, - Http: &HTTP{ - Request: &HTTPRequest{ + Http: &modelpb.HTTP{ + Request: &modelpb.HTTPRequest{ Headers: randomHTTPHeaders(t), - Env: randomKvPb(t), - Cookies: randomKvPb(t), + Env: randomKv(t), + Cookies: randomKv(t), Id: "id", Method: "method", Referrer: "referrer", }, - Response: &HTTPResponse{ + Response: &modelpb.HTTPResponse{ Headers: randomHTTPHeaders(t), Finished: boolPtr(true), HeadersSent: boolPtr(true), - TransferSize: int64Ptr(1), - EncodedBodySize: int64Ptr(2), - DecodedBodySize: int64Ptr(3), + TransferSize: uint64Ptr(1), + EncodedBodySize: uint64Ptr(2), + DecodedBodySize: uint64Ptr(3), StatusCode: 200, }, Version: "version", }, - UserAgent: &UserAgent{ + UserAgent: &modelpb.UserAgent{ Original: "original", Name: "name", }, ParentId: "id", - Trace: &Trace{ + Trace: &modelpb.Trace{ Id: "id", }, - Host: &Host{ - Os: &OS{ + Host: &modelpb.Host{ + Os: &modelpb.OS{ Name: "name", Version: "version", Platform: "platform", @@ -413,11 +416,11 @@ func fullEvent(t testing.TB) *APMEvent { Id: "id", Architecture: "architecture", Type: "type", - Ip: []*IP{ - MustParseIP("127.0.0.1"), + Ip: []*modelpb.IP{ + modelpb.MustParseIP("127.0.0.1"), }, }, - Url: &URL{ + Url: &modelpb.URL{ Original: "original", Scheme: "scheme", Full: "full", @@ -427,42 +430,42 @@ func fullEvent(t testing.TB) *APMEvent { Fragment: "fragment", Port: 443, }, - Log: &Log{ + Log: &modelpb.Log{ Level: "level", Logger: "logger", - Origin: &LogOrigin{ + Origin: &modelpb.LogOrigin{ FunctionName: "functionname", - File: &LogOriginFile{ + File: &modelpb.LogOriginFile{ Name: "name", Line: 1, }, }, }, - Source: &Source{ - Ip: MustParseIP("127.0.0.1"), - Nat: &NAT{ - Ip: MustParseIP("127.0.0.2"), + Source: &modelpb.Source{ + Ip: modelpb.MustParseIP("127.0.0.1"), + Nat: &modelpb.NAT{ + Ip: modelpb.MustParseIP("127.0.0.2"), }, Domain: "domain", Port: 443, }, - Client: &Client{ - Ip: MustParseIP("127.0.0.1"), + Client: &modelpb.Client{ + Ip: modelpb.MustParseIP("127.0.0.1"), Domain: "example.com", Port: 443, }, ChildIds: []string{"id"}, - Destination: &Destination{ + Destination: &modelpb.Destination{ Address: "127.0.0.1", Port: 443, }, - Session: &Session{ + Session: &modelpb.Session{ Id: "id", Sequence: 1, }, - Process: &Process{ + Process: &modelpb.Process{ Ppid: 1, - Thread: &ProcessThread{ + Thread: &modelpb.ProcessThread{ Name: "name", Id: 2, }, @@ -472,14 +475,14 @@ func fullEvent(t testing.TB) *APMEvent { Argv: []string{"argv"}, Pid: 3, }, - Event: &Event{ + Event: &modelpb.Event{ Outcome: "outcome", Action: "action", Dataset: "dataset", Kind: "kind", Category: "category", Type: "type", - SuccessCount: &SummaryMetric{ + SuccessCount: &modelpb.SummaryMetric{ Count: 1, Sum: 2, }, diff --git a/model/modelpb/client.pb.json.go b/model/modeljson/client.pb.json.go similarity index 79% rename from model/modelpb/client.pb.json.go rename to model/modeljson/client.pb.json.go index 438139ea..c77acce8 100644 --- a/model/modelpb/client.pb.json.go +++ b/model/modeljson/client.pb.json.go @@ -15,16 +15,17 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -func (c *Client) toModelJSON(out *modeljson.Client) { +func ClientModelJSON(c *modelpb.Client, out *modeljson.Client) { *out = modeljson.Client{ Domain: c.Domain, Port: int(c.Port), } - out.IP = IP2String(c.Ip) + out.IP = modelpb.IP2String(c.Ip) } diff --git a/model/modelpb/client.pb.json_test.go b/model/modeljson/client.pb.json_test.go similarity index 82% rename from model/modelpb/client.pb.json_test.go rename to model/modeljson/client.pb.json_test.go index bbdac165..13495f13 100644 --- a/model/modelpb/client.pb.json_test.go +++ b/model/modeljson/client.pb.json_test.go @@ -15,28 +15,29 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestClientToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Client + proto *modelpb.Client expected *modeljson.Client }{ "empty": { - proto: &Client{}, + proto: &modelpb.Client{}, expected: &modeljson.Client{}, }, "full": { - proto: &Client{ - Ip: MustParseIP("127.0.0.1"), + proto: &modelpb.Client{ + Ip: modelpb.MustParseIP("127.0.0.1"), Domain: "example.com", Port: 443, }, @@ -50,7 +51,7 @@ func TestClientToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Client - tc.proto.toModelJSON(&out) + ClientModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/cloud.pb.json.go b/model/modeljson/cloud.pb.json.go similarity index 88% rename from model/modelpb/cloud.pb.json.go rename to model/modeljson/cloud.pb.json.go index f527226b..90cb9b58 100644 --- a/model/modelpb/cloud.pb.json.go +++ b/model/modeljson/cloud.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (c *Cloud) toModelJSON(out *modeljson.Cloud) { +func CloudModelJSON(c *modelpb.Cloud, out *modeljson.Cloud) { *out = modeljson.Cloud{ AvailabilityZone: c.AvailabilityZone, Provider: c.Provider, diff --git a/model/modelpb/cloud.pb.json_test.go b/model/modeljson/cloud.pb.json_test.go similarity index 92% rename from model/modelpb/cloud.pb.json_test.go rename to model/modeljson/cloud.pb.json_test.go index dab1b26f..40756011 100644 --- a/model/modelpb/cloud.pb.json_test.go +++ b/model/modeljson/cloud.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestCloudToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Cloud + proto *modelpb.Cloud expected *modeljson.Cloud }{ "empty": { - proto: &Cloud{}, + proto: &modelpb.Cloud{}, expected: &modeljson.Cloud{}, }, "no pointers": { - proto: &Cloud{ + proto: &modelpb.Cloud{ AccountId: "accountid", AccountName: "accountname", AvailabilityZone: "availabilityzone", @@ -73,8 +74,8 @@ func TestCloudToModelJSON(t *testing.T) { }, }, "full": { - proto: &Cloud{ - Origin: &CloudOrigin{ + proto: &modelpb.Cloud{ + Origin: &modelpb.CloudOrigin{ AccountId: "origin_accountid", Provider: "origin_provider", Region: "origin_region", @@ -133,7 +134,7 @@ func TestCloudToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Cloud - tc.proto.toModelJSON(&out) + CloudModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/container.pb.json.go b/model/modeljson/container.pb.json.go similarity index 81% rename from model/modelpb/container.pb.json.go rename to model/modeljson/container.pb.json.go index b93e00a2..c06d6c27 100644 --- a/model/modelpb/container.pb.json.go +++ b/model/modeljson/container.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (c *Container) toModelJSON(out *modeljson.Container) { +func ContainerModelJSON(c *modelpb.Container, out *modeljson.Container) { *out = modeljson.Container{ ID: c.Id, Name: c.Name, diff --git a/model/modelpb/container.pb.json_test.go b/model/modeljson/container.pb.json_test.go similarity index 85% rename from model/modelpb/container.pb.json_test.go rename to model/modeljson/container.pb.json_test.go index e0e3f6d8..bb86c99d 100644 --- a/model/modelpb/container.pb.json_test.go +++ b/model/modeljson/container.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestContainerToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Container + proto *modelpb.Container expected *modeljson.Container }{ "empty": { - proto: &Container{}, + proto: &modelpb.Container{}, expected: &modeljson.Container{}, }, "full": { - proto: &Container{ + proto: &modelpb.Container{ Id: "id", Name: "name", Runtime: "runtime", @@ -56,7 +57,7 @@ func TestContainerToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Container - tc.proto.toModelJSON(&out) + ContainerModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/context.go b/model/modeljson/context.go similarity index 84% rename from model/modelpb/context.go rename to model/modeljson/context.go index dc8b7a64..760a80af 100644 --- a/model/modelpb/context.go +++ b/model/modeljson/context.go @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson + +import "github.com/elastic/apm-data/model/modelpb" // updateFields transforms in, returning a copy with sanitized keys, // suitable for storing as "custom" in transaction and error documents. -func updateFields(in map[string]any) { - for k, v := range in { - if lk := sanitizeLabelKey(k); lk != k { - delete(in, k) - in[lk] = v - } +func updateFields(in []*modelpb.KeyValue) { + for _, kv := range in { + kv.Key = sanitizeLabelKey(kv.Key) } } diff --git a/model/modelpb/destination.pb.json.go b/model/modeljson/destination.pb.json.go similarity index 82% rename from model/modelpb/destination.pb.json.go rename to model/modeljson/destination.pb.json.go index 1d19ec41..0451b4db 100644 --- a/model/modelpb/destination.pb.json.go +++ b/model/modeljson/destination.pb.json.go @@ -15,15 +15,16 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "net/netip" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -func (d *Destination) toModelJSON(out *modeljson.Destination) { +func DestinationModelJSON(d *modelpb.Destination, out *modeljson.Destination) { *out = modeljson.Destination{ Address: d.Address, Port: int(d.Port), diff --git a/model/modelpb/destination.pb.json_test.go b/model/modeljson/destination.pb.json_test.go similarity index 84% rename from model/modelpb/destination.pb.json_test.go rename to model/modeljson/destination.pb.json_test.go index 3e0c89aa..2f10311c 100644 --- a/model/modelpb/destination.pb.json_test.go +++ b/model/modeljson/destination.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestDestinationToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Destination + proto *modelpb.Destination expected *modeljson.Destination }{ "empty": { - proto: &Destination{}, + proto: &modelpb.Destination{}, expected: &modeljson.Destination{}, }, "full": { - proto: &Destination{ + proto: &modelpb.Destination{ Address: "127.0.0.1", Port: 443, }, @@ -49,7 +50,7 @@ func TestDestinationToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Destination - tc.proto.toModelJSON(&out) + DestinationModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/device.pb.json.go b/model/modeljson/device.pb.json.go similarity index 83% rename from model/modelpb/device.pb.json.go rename to model/modeljson/device.pb.json.go index 162107f6..f0fbdb21 100644 --- a/model/modelpb/device.pb.json.go +++ b/model/modeljson/device.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (d *Device) toModelJSON(out *modeljson.Device) { +func DeviceModelJSON(d *modelpb.Device, out *modeljson.Device) { *out = modeljson.Device{ ID: d.Id, Manufacturer: d.Manufacturer, diff --git a/model/modelpb/device.pb.json_test.go b/model/modeljson/device.pb.json_test.go similarity index 84% rename from model/modelpb/device.pb.json_test.go rename to model/modeljson/device.pb.json_test.go index f3b1a2a2..9dfab570 100644 --- a/model/modelpb/device.pb.json_test.go +++ b/model/modeljson/device.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestDeviceToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Device + proto *modelpb.Device expected *modeljson.Device }{ "empty": { - proto: &Device{}, + proto: &modelpb.Device{}, expected: &modeljson.Device{}, }, "no pointers": { - proto: &Device{ + proto: &modelpb.Device{ Id: "id", Manufacturer: "manufacturer", }, @@ -45,9 +46,9 @@ func TestDeviceToModelJSON(t *testing.T) { }, }, "full": { - proto: &Device{ + proto: &modelpb.Device{ Id: "id", - Model: &DeviceModel{ + Model: &modelpb.DeviceModel{ Name: "name", Identifier: "identifier", }, @@ -66,7 +67,7 @@ func TestDeviceToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Device - tc.proto.toModelJSON(&out) + DeviceModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/error.pb.json.go b/model/modeljson/error.pb.json.go similarity index 77% rename from model/modelpb/error.pb.json.go rename to model/modeljson/error.pb.json.go index 6471e0c9..87834dad 100644 --- a/model/modelpb/error.pb.json.go +++ b/model/modeljson/error.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (e *Error) toModelJSON(out *modeljson.Error) { +func ErrorModelJSON(e *modelpb.Error, out *modeljson.Error) { *out = modeljson.Error{ ID: e.Id, GroupingKey: e.GroupingKey, @@ -29,13 +32,12 @@ func (e *Error) toModelJSON(out *modeljson.Error) { StackTrace: e.StackTrace, } if e.Custom != nil { - m := kvToMap(e.Custom) - updateFields(m) - out.Custom = m + updateFields(e.Custom) + out.Custom = e.Custom } if e.Exception != nil { out.Exception = &modeljson.Exception{} - e.Exception.toModelJSON(out.Exception) + ExceptionModelJSON(e.Exception, out.Exception) } if e.Log != nil { out.Log = &modeljson.ErrorLog{ @@ -48,14 +50,14 @@ func (e *Error) toModelJSON(out *modeljson.Error) { out.Log.Stacktrace = make([]modeljson.StacktraceFrame, n) for i, frame := range e.Log.Stacktrace { if frame != nil { - frame.toModelJSON(&out.Log.Stacktrace[i]) + StacktraceFrameModelJSON(frame, &out.Log.Stacktrace[i]) } } } } } -func (e *Exception) toModelJSON(out *modeljson.Exception) { +func ExceptionModelJSON(e *modelpb.Exception, out *modeljson.Exception) { *out = modeljson.Exception{ Message: e.Message, Module: e.Module, @@ -64,13 +66,13 @@ func (e *Exception) toModelJSON(out *modeljson.Exception) { Handled: e.Handled, } if e.Attributes != nil { - out.Attributes = kvToMap(e.Attributes) + out.Attributes = e.Attributes } if n := len(e.Cause); n > 0 { out.Cause = make([]modeljson.Exception, n) for i, cause := range e.Cause { if cause != nil { - cause.toModelJSON(&out.Cause[i]) + ExceptionModelJSON(cause, &out.Cause[i]) } } } @@ -78,7 +80,7 @@ func (e *Exception) toModelJSON(out *modeljson.Exception) { out.Stacktrace = make([]modeljson.StacktraceFrame, n) for i, frame := range e.Stacktrace { if frame != nil { - frame.toModelJSON(&out.Stacktrace[i]) + StacktraceFrameModelJSON(frame, &out.Stacktrace[i]) } } } diff --git a/model/modelpb/error.pb.json_test.go b/model/modeljson/error.pb.json_test.go similarity index 84% rename from model/modelpb/error.pb.json_test.go rename to model/modeljson/error.pb.json_test.go index 5e446b0a..97b83377 100644 --- a/model/modelpb/error.pb.json_test.go +++ b/model/modeljson/error.pb.json_test.go @@ -15,39 +15,41 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/testing/protocmp" ) func TestErrorToModelJSON(t *testing.T) { handled := true - attrs, attrsMap := randomKv(t) + attrs := randomKv(t) testCases := map[string]struct { - proto *Error + proto *modelpb.Error expected *modeljson.Error }{ "empty": { - proto: &Error{}, + proto: &modelpb.Error{}, expected: &modeljson.Error{}, }, "full": { - proto: &Error{ - Exception: &Exception{ + proto: &modelpb.Error{ + Exception: &modelpb.Exception{ Message: "ex_message", Module: "ex_module", Code: "ex_code", Attributes: attrs, Type: "ex_type", Handled: &handled, - Cause: []*Exception{ + Cause: []*modelpb.Exception{ { Message: "ex1_message", Module: "ex1_module", @@ -56,7 +58,7 @@ func TestErrorToModelJSON(t *testing.T) { }, }, }, - Log: &ErrorLog{ + Log: &modelpb.ErrorLog{ Message: "log_message", Level: "log_level", ParamMessage: "log_parammessage", @@ -74,7 +76,7 @@ func TestErrorToModelJSON(t *testing.T) { Message: "ex_message", Module: "ex_module", Code: "ex_code", - Attributes: attrsMap, + Attributes: attrs, Type: "ex_type", Handled: &handled, Cause: []modeljson.Exception{ @@ -108,8 +110,8 @@ func TestErrorToModelJSON(t *testing.T) { Exception: &modeljson.Exception{}, Log: &modeljson.ErrorLog{}, } - tc.proto.toModelJSON(&out) - diff := cmp.Diff(*tc.expected, out) + ErrorModelJSON(tc.proto, &out) + diff := cmp.Diff(*tc.expected, out, protocmp.Transform()) require.Empty(t, diff) }) } diff --git a/model/modelpb/event.pb.json.go b/model/modeljson/event.pb.json.go similarity index 86% rename from model/modelpb/event.pb.json.go rename to model/modeljson/event.pb.json.go index 79b4806d..22bfb201 100644 --- a/model/modelpb/event.pb.json.go +++ b/model/modeljson/event.pb.json.go @@ -15,13 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -func (e *Event) toModelJSON(out *modeljson.Event) { +func EventModelJSON(e *modelpb.Event, out *modeljson.Event) { *out = modeljson.Event{ Outcome: e.Outcome, Action: e.Action, diff --git a/model/modelpb/event.pb.json_test.go b/model/modeljson/event.pb.json_test.go similarity index 88% rename from model/modelpb/event.pb.json_test.go rename to model/modeljson/event.pb.json_test.go index 4fbdf5f9..458592ad 100644 --- a/model/modelpb/event.pb.json_test.go +++ b/model/modeljson/event.pb.json_test.go @@ -15,13 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" "time" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/durationpb" @@ -37,22 +38,22 @@ func TestEventToModelJSON(t *testing.T) { require.NoError(t, err) testCases := map[string]struct { - proto *Event + proto *modelpb.Event expected *modeljson.Event }{ "empty": { - proto: &Event{}, + proto: &modelpb.Event{}, expected: &modeljson.Event{}, }, "full": { - proto: &Event{ + proto: &modelpb.Event{ Outcome: "outcome", Action: "action", Dataset: "dataset", Kind: "kind", Category: "category", Type: "type", - SuccessCount: &SummaryMetric{ + SuccessCount: &modelpb.SummaryMetric{ Count: 1, Sum: 2, }, @@ -80,7 +81,7 @@ func TestEventToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Event - tc.proto.toModelJSON(&out) + EventModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out, cmp.Comparer(func(a modeljson.Time, b modeljson.Time) bool { return time.Time(a).Equal(time.Time(b)) diff --git a/model/modelpb/experience.pb.json.go b/model/modeljson/experience.pb.json.go similarity index 83% rename from model/modelpb/experience.pb.json.go rename to model/modeljson/experience.pb.json.go index 09454448..00cdec77 100644 --- a/model/modelpb/experience.pb.json.go +++ b/model/modeljson/experience.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (u *UserExperience) toModelJSON(out *modeljson.UserExperience) { +func UserExperienceModelJSON(u *modelpb.UserExperience, out *modeljson.UserExperience) { *out = modeljson.UserExperience{ CumulativeLayoutShift: u.CumulativeLayoutShift, FirstInputDelay: u.FirstInputDelay, diff --git a/model/modelpb/experience.pb.json_test.go b/model/modeljson/experience.pb.json_test.go similarity index 83% rename from model/modelpb/experience.pb.json_test.go rename to model/modeljson/experience.pb.json_test.go index 8fe07014..c3b92aef 100644 --- a/model/modelpb/experience.pb.json_test.go +++ b/model/modeljson/experience.pb.json_test.go @@ -15,31 +15,32 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestUserExperienceToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *UserExperience + proto *modelpb.UserExperience expected *modeljson.UserExperience }{ "empty": { - proto: &UserExperience{}, + proto: &modelpb.UserExperience{}, expected: &modeljson.UserExperience{}, }, "no pointers": { - proto: &UserExperience{ + proto: &modelpb.UserExperience{ CumulativeLayoutShift: 1, FirstInputDelay: 2, TotalBlockingTime: 3, - LongTask: &LongtaskMetrics{ + LongTask: &modelpb.LongtaskMetrics{ Count: 4, Sum: 5, Max: 6, @@ -57,11 +58,11 @@ func TestUserExperienceToModelJSON(t *testing.T) { }, }, "full": { - proto: &UserExperience{ + proto: &modelpb.UserExperience{ CumulativeLayoutShift: 1, FirstInputDelay: 2, TotalBlockingTime: 3, - LongTask: &LongtaskMetrics{ + LongTask: &modelpb.LongtaskMetrics{ Count: 4, Sum: 5, Max: 6, @@ -82,7 +83,7 @@ func TestUserExperienceToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.UserExperience - tc.proto.toModelJSON(&out) + UserExperienceModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/faas.pb.json.go b/model/modeljson/faas.pb.json.go similarity index 83% rename from model/modelpb/faas.pb.json.go rename to model/modeljson/faas.pb.json.go index 32b58346..12dac060 100644 --- a/model/modelpb/faas.pb.json.go +++ b/model/modeljson/faas.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (f *Faas) toModelJSON(out *modeljson.FAAS) { +func FaasModelJSON(f *modelpb.Faas, out *modeljson.FAAS) { *out = modeljson.FAAS{ ID: f.Id, Name: f.Name, diff --git a/model/modelpb/faas.pb.json_test.go b/model/modeljson/faas.pb.json_test.go similarity index 87% rename from model/modelpb/faas.pb.json_test.go rename to model/modeljson/faas.pb.json_test.go index ec961d2d..3d3edda6 100644 --- a/model/modelpb/faas.pb.json_test.go +++ b/model/modeljson/faas.pb.json_test.go @@ -15,12 +15,13 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) @@ -29,15 +30,15 @@ func TestFaasToModelJSON(t *testing.T) { coldstart := true testCases := map[string]struct { - proto *Faas + proto *modelpb.Faas expected *modeljson.FAAS }{ "empty": { - proto: &Faas{}, + proto: &modelpb.Faas{}, expected: &modeljson.FAAS{}, }, "full": { - proto: &Faas{ + proto: &modelpb.Faas{ Id: "id", ColdStart: &coldstart, Execution: "execution", @@ -62,7 +63,7 @@ func TestFaasToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.FAAS - tc.proto.toModelJSON(&out) + FaasModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/host.pb.json.go b/model/modeljson/host.pb.json.go similarity index 81% rename from model/modelpb/host.pb.json.go rename to model/modeljson/host.pb.json.go index 936a6b81..c50c958b 100644 --- a/model/modelpb/host.pb.json.go +++ b/model/modeljson/host.pb.json.go @@ -15,13 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -func (h *Host) toModelJSON(out *modeljson.Host) { +func HostModelJSON(h *modelpb.Host, out *modeljson.Host) { *out = modeljson.Host{ Hostname: h.Hostname, Name: h.Name, @@ -33,14 +34,14 @@ func (h *Host) toModelJSON(out *modeljson.Host) { if n := len(h.Ip); n != 0 { ips := make([]string, 0, n) for _, ip := range h.Ip { - ips = append(ips, IP2String(ip)) + ips = append(ips, modelpb.IP2String(ip)) } out.IP = ips } if h.Os != nil { var os modeljson.OS - h.Os.toModelJSON(&os) + OSModelJSON(h.Os, &os) out.OS = &os } } diff --git a/model/modelpb/host.pb.json_test.go b/model/modeljson/host.pb.json_test.go similarity index 85% rename from model/modelpb/host.pb.json_test.go rename to model/modeljson/host.pb.json_test.go index 27fcc7f8..59a108b9 100644 --- a/model/modelpb/host.pb.json_test.go +++ b/model/modeljson/host.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestHostToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Host + proto *modelpb.Host expected *modeljson.Host }{ "empty": { - proto: &Host{}, + proto: &modelpb.Host{}, expected: &modeljson.Host{}, }, "no pointers": { - proto: &Host{ + proto: &modelpb.Host{ Hostname: "hostname", Name: "name", Id: "id", @@ -51,14 +52,14 @@ func TestHostToModelJSON(t *testing.T) { }, }, "full": { - proto: &Host{ + proto: &modelpb.Host{ Hostname: "hostname", Name: "name", Id: "id", Architecture: "architecture", Type: "type", - Ip: []*IP{ - MustParseIP("127.0.0.1"), + Ip: []*modelpb.IP{ + modelpb.MustParseIP("127.0.0.1"), }, }, expected: &modeljson.Host{ @@ -74,7 +75,7 @@ func TestHostToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Host - tc.proto.toModelJSON(&out) + HostModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/http.pb.json.go b/model/modeljson/http.pb.json.go similarity index 75% rename from model/modelpb/http.pb.json.go rename to model/modeljson/http.pb.json.go index c4f9511d..77702ec1 100644 --- a/model/modelpb/http.pb.json.go +++ b/model/modeljson/http.pb.json.go @@ -15,15 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( - "net/http" - - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -func (h *HTTP) toModelJSON(out *modeljson.HTTP) { +func HTTPModelJSON(h *modelpb.HTTP, out *modeljson.HTTP) { *out = modeljson.HTTP{ Version: h.Version, } @@ -34,13 +33,13 @@ func (h *HTTP) toModelJSON(out *modeljson.HTTP) { Referrer: h.Request.Referrer, } if h.Request.Headers != nil { - out.Request.Headers = ToHTTPHeaders(h.Request.Headers) + out.Request.Headers = h.Request.Headers } if h.Request.Env != nil { - out.Request.Env = kvToMap(h.Request.Env) + out.Request.Env = h.Request.Env } if h.Request.Cookies != nil { - out.Request.Cookies = kvToMap(h.Request.Cookies) + out.Request.Cookies = h.Request.Cookies } if h.Request.Body != nil { out.Request.Body = &modeljson.HTTPRequestBody{ @@ -58,18 +57,7 @@ func (h *HTTP) toModelJSON(out *modeljson.HTTP) { DecodedBodySize: h.Response.DecodedBodySize, } if h.Response.Headers != nil { - out.Response.Headers = ToHTTPHeaders(h.Response.Headers) + out.Response.Headers = h.Response.Headers } } } - -func ToHTTPHeaders(h []*HTTPHeader) http.Header { - if len(h) == 0 { - return nil - } - headers := make(http.Header, len(h)) - for _, v := range h { - headers[v.Key] = v.Value - } - return headers -} diff --git a/model/modelpb/http.pb.json_test.go b/model/modeljson/http.pb.json_test.go similarity index 69% rename from model/modelpb/http.pb.json_test.go rename to model/modeljson/http.pb.json_test.go index 938fdb3c..91a9e9d8 100644 --- a/model/modelpb/http.pb.json_test.go +++ b/model/modeljson/http.pb.json_test.go @@ -15,36 +15,36 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/testing/protocmp" ) func TestHTTPToModelJSON(t *testing.T) { headers := randomHTTPHeaders(t) - headersMap := ToHTTPHeaders(headers) headers2 := randomHTTPHeaders(t) - headersMap2 := ToHTTPHeaders(headers2) - cookies, cookiesMap := randomKv(t) - envs, envsMap := randomKv(t) + cookies := randomKv(t) + envs := randomKv(t) tru := true testCases := map[string]struct { - proto *HTTP + proto *modelpb.HTTP expected *modeljson.HTTP }{ "empty": { - proto: &HTTP{}, + proto: &modelpb.HTTP{}, expected: &modeljson.HTTP{}, }, "request": { - proto: &HTTP{ - Request: &HTTPRequest{ + proto: &modelpb.HTTP{ + Request: &modelpb.HTTPRequest{ Headers: headers, Env: envs, Cookies: cookies, @@ -55,9 +55,9 @@ func TestHTTPToModelJSON(t *testing.T) { }, expected: &modeljson.HTTP{ Request: &modeljson.HTTPRequest{ - Headers: headersMap, - Env: envsMap, - Cookies: cookiesMap, + Headers: headers, + Env: envs, + Cookies: cookies, ID: "id", Method: "method", Referrer: "referrer", @@ -65,14 +65,14 @@ func TestHTTPToModelJSON(t *testing.T) { }, }, "response": { - proto: &HTTP{ - Response: &HTTPResponse{ + proto: &modelpb.HTTP{ + Response: &modelpb.HTTPResponse{ Headers: headers2, Finished: &tru, HeadersSent: &tru, - TransferSize: int64Ptr(1), - EncodedBodySize: int64Ptr(2), - DecodedBodySize: int64Ptr(3), + TransferSize: uint64Ptr(1), + EncodedBodySize: uint64Ptr(2), + DecodedBodySize: uint64Ptr(3), StatusCode: 200, }, }, @@ -80,22 +80,22 @@ func TestHTTPToModelJSON(t *testing.T) { Response: &modeljson.HTTPResponse{ Finished: &tru, HeadersSent: &tru, - TransferSize: int64Ptr(1), - EncodedBodySize: int64Ptr(2), - DecodedBodySize: int64Ptr(3), - Headers: headersMap2, + TransferSize: uint64Ptr(1), + EncodedBodySize: uint64Ptr(2), + DecodedBodySize: uint64Ptr(3), + Headers: headers2, StatusCode: 200, }, }, }, "no pointers": { - proto: &HTTP{ - Request: &HTTPRequest{ + proto: &modelpb.HTTP{ + Request: &modelpb.HTTPRequest{ Id: "id", Method: "method", Referrer: "referrer", }, - Response: &HTTPResponse{ + Response: &modelpb.HTTPResponse{ StatusCode: 200, }, Version: "version", @@ -113,8 +113,8 @@ func TestHTTPToModelJSON(t *testing.T) { }, }, "full": { - proto: &HTTP{ - Request: &HTTPRequest{ + proto: &modelpb.HTTP{ + Request: &modelpb.HTTPRequest{ Headers: headers, Env: envs, Cookies: cookies, @@ -122,22 +122,22 @@ func TestHTTPToModelJSON(t *testing.T) { Method: "method", Referrer: "referrer", }, - Response: &HTTPResponse{ + Response: &modelpb.HTTPResponse{ Headers: headers2, Finished: &tru, HeadersSent: &tru, - TransferSize: int64Ptr(1), - EncodedBodySize: int64Ptr(2), - DecodedBodySize: int64Ptr(3), + TransferSize: uint64Ptr(1), + EncodedBodySize: uint64Ptr(2), + DecodedBodySize: uint64Ptr(3), StatusCode: 200, }, Version: "version", }, expected: &modeljson.HTTP{ Request: &modeljson.HTTPRequest{ - Headers: headersMap, - Env: envsMap, - Cookies: cookiesMap, + Headers: headers, + Env: envs, + Cookies: cookies, ID: "id", Method: "method", Referrer: "referrer", @@ -145,10 +145,10 @@ func TestHTTPToModelJSON(t *testing.T) { Response: &modeljson.HTTPResponse{ Finished: &tru, HeadersSent: &tru, - TransferSize: int64Ptr(1), - EncodedBodySize: int64Ptr(2), - DecodedBodySize: int64Ptr(3), - Headers: headersMap2, + TransferSize: uint64Ptr(1), + EncodedBodySize: uint64Ptr(2), + DecodedBodySize: uint64Ptr(3), + Headers: headers2, StatusCode: 200, }, Version: "version", @@ -161,8 +161,8 @@ func TestHTTPToModelJSON(t *testing.T) { Request: &modeljson.HTTPRequest{}, Response: &modeljson.HTTPResponse{}, } - tc.proto.toModelJSON(&out) - diff := cmp.Diff(*tc.expected, out) + HTTPModelJSON(tc.proto, &out) + diff := cmp.Diff(*tc.expected, out, protocmp.Transform()) require.Empty(t, diff) }) } diff --git a/model/internal/modeljson/agent.go b/model/modeljson/internal/agent.go similarity index 100% rename from model/internal/modeljson/agent.go rename to model/modeljson/internal/agent.go diff --git a/model/internal/modeljson/child.go b/model/modeljson/internal/child.go similarity index 100% rename from model/internal/modeljson/child.go rename to model/modeljson/internal/child.go diff --git a/model/internal/modeljson/client.go b/model/modeljson/internal/client.go similarity index 100% rename from model/internal/modeljson/client.go rename to model/modeljson/internal/client.go diff --git a/model/internal/modeljson/cloud.go b/model/modeljson/internal/cloud.go similarity index 100% rename from model/internal/modeljson/cloud.go rename to model/modeljson/internal/cloud.go diff --git a/model/internal/modeljson/container.go b/model/modeljson/internal/container.go similarity index 100% rename from model/internal/modeljson/container.go rename to model/modeljson/internal/container.go diff --git a/model/internal/modeljson/destination.go b/model/modeljson/internal/destination.go similarity index 100% rename from model/internal/modeljson/destination.go rename to model/modeljson/internal/destination.go diff --git a/model/internal/modeljson/device.go b/model/modeljson/internal/device.go similarity index 100% rename from model/internal/modeljson/device.go rename to model/modeljson/internal/device.go diff --git a/model/internal/modeljson/document.go b/model/modeljson/internal/document.go similarity index 98% rename from model/internal/modeljson/document.go rename to model/modeljson/internal/document.go index 1a3f8424..56f56eeb 100644 --- a/model/internal/modeljson/document.go +++ b/model/modeljson/internal/document.go @@ -71,7 +71,7 @@ type Document struct { Timestamp Time `json:"@timestamp"` DataStream *DataStream `json:"data_stream,omitempty"` Message string `json:"message,omitempty"` - DocCount int64 `json:"_doc_count,omitempty"` + DocCount uint64 `json:"_doc_count,omitempty"` } type Time time.Time diff --git a/model/internal/modeljson/error.go b/model/modeljson/internal/error.go similarity index 84% rename from model/internal/modeljson/error.go rename to model/modeljson/internal/error.go index 9216c884..773722cd 100644 --- a/model/internal/modeljson/error.go +++ b/model/modeljson/internal/error.go @@ -20,15 +20,15 @@ package modeljson import "go.elastic.co/fastjson" type Error struct { - Exception *Exception `json:"exception,omitempty"` - Log *ErrorLog `json:"log,omitempty"` - Custom map[string]any `json:"custom,omitempty"` - ID string `json:"id,omitempty"` - GroupingKey string `json:"grouping_key,omitempty"` - Culprit string `json:"culprit,omitempty"` - Message string `json:"message,omitempty"` - Type string `json:"type,omitempty"` - StackTrace string `json:"stack_trace,omitempty"` + Exception *Exception `json:"exception,omitempty"` + Log *ErrorLog `json:"log,omitempty"` + ID string `json:"id,omitempty"` + GroupingKey string `json:"grouping_key,omitempty"` + Culprit string `json:"culprit,omitempty"` + Message string `json:"message,omitempty"` + Type string `json:"type,omitempty"` + StackTrace string `json:"stack_trace,omitempty"` + Custom KeyValueSlice `json:"custom,omitempty"` } type ErrorLog struct { @@ -43,7 +43,7 @@ type Exception struct { Message string Module string Code string - Attributes any + Attributes KeyValueSlice Stacktrace []StacktraceFrame Type string Handled *bool @@ -101,7 +101,7 @@ func (e *Exception) marshalOne(w *fastjson.Writer, offset, parentOffset int) (in if e.Attributes != nil { maybeComma() w.RawString(`"attributes":`) - if err := fastjson.Marshal(w, e.Attributes); err != nil { + if err := e.Attributes.MarshalFastJSON(w); err != nil { return -1, err } } diff --git a/model/internal/modeljson/event.go b/model/modeljson/internal/event.go similarity index 95% rename from model/internal/modeljson/event.go rename to model/modeljson/internal/event.go index 27e1178f..4bce6d12 100644 --- a/model/internal/modeljson/event.go +++ b/model/modeljson/internal/event.go @@ -27,5 +27,5 @@ type Event struct { Type string `json:"type,omitempty"` SuccessCount SummaryMetric `json:"success_count,omitempty"` Duration int64 `json:"duration,omitempty"` - Severity int64 `json:"severity,omitempty"` + Severity uint64 `json:"severity,omitempty"` } diff --git a/model/internal/modeljson/experience.go b/model/modeljson/internal/experience.go similarity index 100% rename from model/internal/modeljson/experience.go rename to model/modeljson/internal/experience.go diff --git a/model/internal/modeljson/faas.go b/model/modeljson/internal/faas.go similarity index 100% rename from model/internal/modeljson/faas.go rename to model/modeljson/internal/faas.go diff --git a/model/internal/modeljson/host.go b/model/modeljson/internal/host.go similarity index 100% rename from model/internal/modeljson/host.go rename to model/modeljson/internal/host.go diff --git a/model/internal/modeljson/http.go b/model/modeljson/internal/http.go similarity index 78% rename from model/internal/modeljson/http.go rename to model/modeljson/internal/http.go index 1679249c..e3709abb 100644 --- a/model/internal/modeljson/http.go +++ b/model/modeljson/internal/http.go @@ -17,8 +17,6 @@ package modeljson -import "net/http" - type HTTP struct { Request *HTTPRequest `json:"request,omitempty"` Response *HTTPResponse `json:"response,omitempty"` @@ -27,12 +25,12 @@ type HTTP struct { type HTTPRequest struct { Body *HTTPRequestBody `json:"body,omitempty"` - Headers http.Header `json:"headers,omitempty"` // Non-ECS field. - Env map[string]any `json:"env,omitempty"` // Non-ECS field. - Cookies map[string]any `json:"cookies,omitempty"` // Non-ECS field. + Headers HTTPHeaders `json:"headers,omitempty"` // Non-ECS field. ID string `json:"id,omitempty"` Method string `json:"method,omitempty"` Referrer string `json:"referrer,omitempty"` + Env KeyValueSlice `json:"env,omitempty"` // Non-ECS field. + Cookies KeyValueSlice `json:"cookies,omitempty"` // Non-ECS field. } type HTTPRequestBody struct { @@ -42,9 +40,9 @@ type HTTPRequestBody struct { type HTTPResponse struct { Finished *bool `json:"finished,omitempty"` // Non-ECS field. HeadersSent *bool `json:"headers_sent,omitempty"` // Non-ECS field. - TransferSize *int64 `json:"transfer_size,omitempty"` // Non-ECS field. - EncodedBodySize *int64 `json:"encoded_body_size,omitempty"` // Non-ECS field. - DecodedBodySize *int64 `json:"decoded_body_size,omitempty"` // Non-ECS field. - Headers http.Header `json:"headers,omitempty"` // Non-ECS field. + TransferSize *uint64 `json:"transfer_size,omitempty"` // Non-ECS field. + EncodedBodySize *uint64 `json:"encoded_body_size,omitempty"` // Non-ECS field. + DecodedBodySize *uint64 `json:"decoded_body_size,omitempty"` // Non-ECS field. + Headers HTTPHeaders `json:"headers,omitempty"` // Non-ECS field. StatusCode int `json:"status_code,omitempty"` } diff --git a/model/modelpb/keyvalue.pb.json.go b/model/modeljson/internal/httpheader.go similarity index 54% rename from model/modelpb/keyvalue.pb.json.go rename to model/modeljson/internal/httpheader.go index 0d99f04b..05298daa 100644 --- a/model/modelpb/keyvalue.pb.json.go +++ b/model/modeljson/internal/httpheader.go @@ -15,30 +15,34 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import structpb "google.golang.org/protobuf/types/known/structpb" +import ( + "github.com/elastic/apm-data/model/modelpb" + "go.elastic.co/fastjson" +) -func kvToMap(h []*KeyValue) map[string]any { - if len(h) == 0 { - return nil - } - m := make(map[string]any, len(h)) - for _, v := range h { - switch v.Value.GetKind().(type) { - case *structpb.Value_NullValue: - m[v.Key] = nil - case *structpb.Value_NumberValue: - m[v.Key] = v.Value.GetNumberValue() - case *structpb.Value_StringValue: - m[v.Key] = v.Value.GetStringValue() - case *structpb.Value_BoolValue: - m[v.Key] = v.Value.GetBoolValue() - case *structpb.Value_StructValue: - m[v.Key] = v.Value.GetStructValue() - case *structpb.Value_ListValue: - m[v.Key] = v.Value.GetListValue() +type HTTPHeaders []*modelpb.HTTPHeader + +func (s *HTTPHeaders) MarshalFastJSON(w *fastjson.Writer) error { + w.RawByte('{') + { + for i, kv := range *s { + if i != 0 { + w.RawByte(',') + } + w.String(kv.Key) + w.RawByte(':') + w.RawByte('[') + for i, v := range kv.Value { + if i != 0 { + w.RawByte(',') + } + w.String(v) + } + w.RawByte(']') } } - return m + w.RawByte('}') + return nil } diff --git a/model/internal/modeljson/ip.go b/model/modeljson/internal/ip.go similarity index 100% rename from model/internal/modeljson/ip.go rename to model/modeljson/internal/ip.go diff --git a/model/modeljson/internal/keyvalue.go b/model/modeljson/internal/keyvalue.go new file mode 100644 index 00000000..ecf59a4f --- /dev/null +++ b/model/modeljson/internal/keyvalue.go @@ -0,0 +1,44 @@ +// Licensed to Elasticsearch B.V. under one or more contributor +// license agreements. See the NOTICE file distributed with +// this work for additional information regarding copyright +// ownership. Elasticsearch B.V. licenses this file to you under +// the Apache License, Version 2.0 (the "License"); you may +// not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, +// software distributed under the License is distributed on an +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +// KIND, either express or implied. See the License for the +// specific language governing permissions and limitations +// under the License. + +package modeljson + +import ( + "github.com/elastic/apm-data/model/modelpb" + "go.elastic.co/fastjson" +) + +type KeyValueSlice []*modelpb.KeyValue + +func (s *KeyValueSlice) MarshalFastJSON(w *fastjson.Writer) error { + var firstErr error + w.RawByte('{') + { + for i, kv := range *s { + if i != 0 { + w.RawByte(',') + } + w.String(kv.Key) + w.RawByte(':') + if err := fastjson.Marshal(w, kv.Value.AsInterface()); err != nil && firstErr == nil { + firstErr = err + } + } + } + w.RawByte('}') + return firstErr +} diff --git a/model/internal/modeljson/kubernetes.go b/model/modeljson/internal/kubernetes.go similarity index 100% rename from model/internal/modeljson/kubernetes.go rename to model/modeljson/internal/kubernetes.go diff --git a/model/internal/modeljson/labels.go b/model/modeljson/internal/labels.go similarity index 100% rename from model/internal/modeljson/labels.go rename to model/modeljson/internal/labels.go diff --git a/model/internal/modeljson/log.go b/model/modeljson/internal/log.go similarity index 100% rename from model/internal/modeljson/log.go rename to model/modeljson/internal/log.go diff --git a/model/internal/modeljson/marshal_fastjson.go b/model/modeljson/internal/marshal_fastjson.go similarity index 96% rename from model/internal/modeljson/marshal_fastjson.go rename to model/modeljson/internal/marshal_fastjson.go index eed7b50a..11fe585c 100644 --- a/model/internal/modeljson/marshal_fastjson.go +++ b/model/modeljson/internal/marshal_fastjson.go @@ -575,7 +575,7 @@ func (v *Document) MarshalFastJSON(w *fastjson.Writer) error { } if v.DocCount != 0 { w.RawString(",\"_doc_count\":") - w.Int64(v.DocCount) + w.Uint64(v.DocCount) } if v.Agent != nil { w.RawString(",\"agent\":") @@ -864,23 +864,9 @@ func (v *Error) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Custom { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - if err := fastjson.Marshal(w, v); err != nil && firstErr == nil { - firstErr = err - } - } + if err := v.Custom.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if v.Exception != nil { const prefix = ",\"exception\":" @@ -1111,7 +1097,7 @@ func (v *Event) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.Int64(v.Severity) + w.Uint64(v.Severity) } if !v.SuccessCount.isZero() { const prefix = ",\"success_count\":" @@ -1401,23 +1387,9 @@ func (v *HTTPRequest) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Cookies { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - if err := fastjson.Marshal(w, v); err != nil && firstErr == nil { - firstErr = err - } - } + if err := v.Cookies.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if v.Env != nil { const prefix = ",\"env\":" @@ -1427,23 +1399,9 @@ func (v *HTTPRequest) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Env { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - if err := fastjson.Marshal(w, v); err != nil && firstErr == nil { - firstErr = err - } - } + if err := v.Env.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if v.Headers != nil { const prefix = ",\"headers\":" @@ -1453,28 +1411,9 @@ func (v *HTTPRequest) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Headers { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - w.RawByte('[') - for i, v := range v { - if i != 0 { - w.RawByte(',') - } - w.String(v) - } - w.RawByte(']') - } + if err := v.Headers.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if v.ID != "" { const prefix = ",\"id\":" @@ -1524,6 +1463,7 @@ func (v *HTTPRequestBody) MarshalFastJSON(w *fastjson.Writer) error { } func (v *HTTPResponse) MarshalFastJSON(w *fastjson.Writer) error { + var firstErr error w.RawByte('{') first := true if v.DecodedBodySize != nil { @@ -1534,7 +1474,7 @@ func (v *HTTPResponse) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.Int64(*v.DecodedBodySize) + w.Uint64(*v.DecodedBodySize) } if v.EncodedBodySize != nil { const prefix = ",\"encoded_body_size\":" @@ -1544,7 +1484,7 @@ func (v *HTTPResponse) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.Int64(*v.EncodedBodySize) + w.Uint64(*v.EncodedBodySize) } if v.Finished != nil { const prefix = ",\"finished\":" @@ -1564,28 +1504,9 @@ func (v *HTTPResponse) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Headers { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - w.RawByte('[') - for i, v := range v { - if i != 0 { - w.RawByte(',') - } - w.String(v) - } - w.RawByte(']') - } + if err := v.Headers.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if v.HeadersSent != nil { const prefix = ",\"headers_sent\":" @@ -1615,10 +1536,10 @@ func (v *HTTPResponse) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.Int64(*v.TransferSize) + w.Uint64(*v.TransferSize) } w.RawByte('}') - return nil + return firstErr } func (v *Kubernetes) MarshalFastJSON(w *fastjson.Writer) error { @@ -1814,28 +1735,9 @@ func (v *Message) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Headers { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - w.RawByte('[') - for i, v := range v { - if i != 0 { - w.RawByte(',') - } - w.String(v) - } - w.RawByte(']') - } + if err := v.Headers.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if !v.Queue.isZero() { const prefix = ",\"queue\":" @@ -1867,7 +1769,7 @@ func (v *MessageAge) MarshalFastJSON(w *fastjson.Writer) error { w.RawByte('{') if v.Millis != nil { w.RawString("\"ms\":") - w.Int64(*v.Millis) + w.Uint64(*v.Millis) } w.RawByte('}') return nil @@ -1941,7 +1843,7 @@ func (v *Histogram) MarshalFastJSON(w *fastjson.Writer) error { if i != 0 { w.RawByte(',') } - w.Int64(v) + w.Uint64(v) } w.RawByte(']') } @@ -1967,7 +1869,7 @@ func (v *SummaryMetric) MarshalFastJSON(w *fastjson.Writer) error { w.RawString("\"sum\":") w.Float64(v.Sum) w.RawString(",\"value_count\":") - w.Int64(v.Count) + w.Uint64(v.Count) w.RawByte('}') return nil } @@ -2574,7 +2476,7 @@ func (v *Session) MarshalFastJSON(w *fastjson.Writer) error { w.String(v.ID) if v.Sequence != 0 { w.RawString(",\"sequence\":") - w.Int64(v.Sequence) + w.Uint64(v.Sequence) } w.RawByte('}') return nil @@ -3098,23 +3000,9 @@ func (v *StacktraceFrame) MarshalFastJSON(w *fastjson.Writer) error { } if v.Vars != nil { w.RawString(",\"vars\":") - w.RawByte('{') - { - first := true - for k, v := range v.Vars { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - if err := fastjson.Marshal(w, v); err != nil && firstErr == nil { - firstErr = err - } - } + if err := v.Vars.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } w.RawByte('}') return firstErr @@ -3332,23 +3220,9 @@ func (v *Transaction) MarshalFastJSON(w *fastjson.Writer) error { } else { w.RawString(prefix) } - w.RawByte('{') - { - first := true - for k, v := range v.Custom { - if first { - first = false - } else { - w.RawByte(',') - } - w.String(k) - w.RawByte(':') - if err := fastjson.Marshal(w, v); err != nil && firstErr == nil { - firstErr = err - } - } + if err := v.Custom.MarshalFastJSON(w); err != nil && firstErr == nil { + firstErr = err } - w.RawByte('}') } if v.DroppedSpansStats != nil { const prefix = ",\"dropped_spans_stats\":" diff --git a/model/internal/modeljson/message.go b/model/modeljson/internal/message.go similarity index 76% rename from model/internal/modeljson/message.go rename to model/modeljson/internal/message.go index 9a4a31c0..ce84b083 100644 --- a/model/internal/modeljson/message.go +++ b/model/modeljson/internal/message.go @@ -18,15 +18,15 @@ package modeljson type Message struct { - Body string `json:"body,omitempty"` - Headers map[string][]string `json:"headers,omitempty"` - Age MessageAge `json:"age,omitempty"` - Queue MessageQueue `json:"queue,omitempty"` - RoutingKey string `json:"routing_key,omitempty"` + Body string `json:"body,omitempty"` + Age MessageAge `json:"age,omitempty"` + Queue MessageQueue `json:"queue,omitempty"` + RoutingKey string `json:"routing_key,omitempty"` + Headers HTTPHeaders `json:"headers,omitempty"` } type MessageAge struct { - Millis *int64 `json:"ms,omitempty"` + Millis *uint64 `json:"ms,omitempty"` } func (a MessageAge) isZero() bool { diff --git a/model/internal/modeljson/metricset.go b/model/modeljson/internal/metricset.go similarity index 94% rename from model/internal/modeljson/metricset.go rename to model/modeljson/internal/metricset.go index c799cf90..a940cad8 100644 --- a/model/internal/modeljson/metricset.go +++ b/model/modeljson/internal/metricset.go @@ -40,7 +40,7 @@ type MetricsetSample struct { type Histogram struct { Values []float64 `json:"values"` - Counts []int64 `json:"counts"` + Counts []uint64 `json:"counts"` } func (h Histogram) isZero() bool { @@ -48,7 +48,7 @@ func (h Histogram) isZero() bool { } type SummaryMetric struct { - Count int64 `json:"value_count"` + Count uint64 `json:"value_count"` Sum float64 `json:"sum"` } @@ -83,12 +83,12 @@ func (ms *MetricsetSample) MarshalFastJSON(w *fastjson.Writer) error { if i > 0 { w.RawByte(',') } - w.Int64(count) + w.Int64(int64(count)) } w.RawByte(']') case "summary": w.RawString(`,"value_count":`) - w.Int64(ms.Summary.Count) + w.Int64(int64(ms.Summary.Count)) w.RawString(`,"sum":`) w.Float64(ms.Summary.Sum) default: @@ -100,7 +100,7 @@ func (ms *MetricsetSample) MarshalFastJSON(w *fastjson.Writer) error { } type AggregatedDuration struct { - Count int64 + Count uint64 Sum time.Duration } diff --git a/model/internal/modeljson/network.go b/model/modeljson/internal/network.go similarity index 100% rename from model/internal/modeljson/network.go rename to model/modeljson/internal/network.go diff --git a/model/internal/modeljson/observer.go b/model/modeljson/internal/observer.go similarity index 100% rename from model/internal/modeljson/observer.go rename to model/modeljson/internal/observer.go diff --git a/model/internal/modeljson/os.go b/model/modeljson/internal/os.go similarity index 100% rename from model/internal/modeljson/os.go rename to model/modeljson/internal/os.go diff --git a/model/internal/modeljson/parent.go b/model/modeljson/internal/parent.go similarity index 100% rename from model/internal/modeljson/parent.go rename to model/modeljson/internal/parent.go diff --git a/model/internal/modeljson/process.go b/model/modeljson/internal/process.go similarity index 100% rename from model/internal/modeljson/process.go rename to model/modeljson/internal/process.go diff --git a/model/internal/modeljson/service.go b/model/modeljson/internal/service.go similarity index 100% rename from model/internal/modeljson/service.go rename to model/modeljson/internal/service.go diff --git a/model/internal/modeljson/session.go b/model/modeljson/internal/session.go similarity index 95% rename from model/internal/modeljson/session.go rename to model/modeljson/internal/session.go index b45689fe..c9d141ae 100644 --- a/model/internal/modeljson/session.go +++ b/model/modeljson/internal/session.go @@ -19,5 +19,5 @@ package modeljson type Session struct { ID string `json:"id"` - Sequence int64 `json:"sequence,omitempty"` + Sequence uint64 `json:"sequence,omitempty"` } diff --git a/model/internal/modeljson/source.go b/model/modeljson/internal/source.go similarity index 100% rename from model/internal/modeljson/source.go rename to model/modeljson/internal/source.go diff --git a/model/internal/modeljson/span.go b/model/modeljson/internal/span.go similarity index 100% rename from model/internal/modeljson/span.go rename to model/modeljson/internal/span.go diff --git a/model/internal/modeljson/spanlink.go b/model/modeljson/internal/spanlink.go similarity index 100% rename from model/internal/modeljson/spanlink.go rename to model/modeljson/internal/spanlink.go diff --git a/model/internal/modeljson/stacktrace.go b/model/modeljson/internal/stacktrace.go similarity index 97% rename from model/internal/modeljson/stacktrace.go rename to model/modeljson/internal/stacktrace.go index 0d6a5b55..64ae9069 100644 --- a/model/internal/modeljson/stacktrace.go +++ b/model/modeljson/internal/stacktrace.go @@ -22,12 +22,12 @@ type StacktraceFrame struct { Original *StacktraceFrameOriginal `json:"original,omitempty"` Context *StacktraceFrameContext `json:"context,omitempty"` Line *StacktraceFrameLine `json:"line,omitempty"` - Vars map[string]any `json:"vars,omitempty"` Filename string `json:"filename,omitempty"` Classname string `json:"classname,omitempty"` Module string `json:"module,omitempty"` Function string `json:"function,omitempty"` AbsPath string `json:"abs_path,omitempty"` + Vars KeyValueSlice `json:"vars,omitempty"` LibraryFrame bool `json:"library_frame,omitempty"` ExcludeFromGrouping bool `json:"exclude_from_grouping"` } diff --git a/model/internal/modeljson/timestamp.go b/model/modeljson/internal/timestamp.go similarity index 100% rename from model/internal/modeljson/timestamp.go rename to model/modeljson/internal/timestamp.go diff --git a/model/internal/modeljson/trace.go b/model/modeljson/internal/trace.go similarity index 100% rename from model/internal/modeljson/trace.go rename to model/modeljson/internal/trace.go diff --git a/model/internal/modeljson/transaction.go b/model/modeljson/internal/transaction.go similarity index 97% rename from model/internal/modeljson/transaction.go rename to model/modeljson/internal/transaction.go index e5fe798a..b1070353 100644 --- a/model/internal/modeljson/transaction.go +++ b/model/modeljson/internal/transaction.go @@ -20,7 +20,7 @@ package modeljson type Transaction struct { SpanCount SpanCount `json:"span_count,omitempty"` UserExperience *UserExperience `json:"experience,omitempty"` - Custom map[string]any `json:"custom,omitempty"` + Custom KeyValueSlice `json:"custom,omitempty"` Marks map[string]map[string]float64 `json:"marks,omitempty"` Message *Message `json:"message,omitempty"` Type string `json:"type,omitempty"` diff --git a/model/internal/modeljson/url.go b/model/modeljson/internal/url.go similarity index 100% rename from model/internal/modeljson/url.go rename to model/modeljson/internal/url.go diff --git a/model/internal/modeljson/user.go b/model/modeljson/internal/user.go similarity index 100% rename from model/internal/modeljson/user.go rename to model/modeljson/internal/user.go diff --git a/model/internal/modeljson/useragent.go b/model/modeljson/internal/useragent.go similarity index 100% rename from model/internal/modeljson/useragent.go rename to model/modeljson/internal/useragent.go diff --git a/model/modelpb/kubernetes.pb.json.go b/model/modeljson/kubernetes.pb.json.go similarity index 82% rename from model/modelpb/kubernetes.pb.json.go rename to model/modeljson/kubernetes.pb.json.go index 10ba919d..4f329568 100644 --- a/model/modelpb/kubernetes.pb.json.go +++ b/model/modeljson/kubernetes.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (k *Kubernetes) toModelJSON(out *modeljson.Kubernetes) { +func KubernetesModelJSON(k *modelpb.Kubernetes, out *modeljson.Kubernetes) { *out = modeljson.Kubernetes{ Namespace: k.Namespace, Node: modeljson.KubernetesNode{ diff --git a/model/modelpb/kubernetes.pb.json_test.go b/model/modeljson/kubernetes.pb.json_test.go similarity index 85% rename from model/modelpb/kubernetes.pb.json_test.go rename to model/modeljson/kubernetes.pb.json_test.go index ec64c6db..5ad44286 100644 --- a/model/modelpb/kubernetes.pb.json_test.go +++ b/model/modeljson/kubernetes.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestKubernetesToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Kubernetes + proto *modelpb.Kubernetes expected *modeljson.Kubernetes }{ "empty": { - proto: &Kubernetes{}, + proto: &modelpb.Kubernetes{}, expected: &modeljson.Kubernetes{}, }, "full": { - proto: &Kubernetes{ + proto: &modelpb.Kubernetes{ Namespace: "namespace", NodeName: "nodename", PodName: "podname", @@ -56,7 +57,7 @@ func TestKubernetesToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Kubernetes - tc.proto.toModelJSON(&out) + KubernetesModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/labels.util.go b/model/modeljson/labels.go similarity index 98% rename from model/modelpb/labels.util.go rename to model/modeljson/labels.go index c6c8a48a..532f723e 100644 --- a/model/modelpb/labels.util.go +++ b/model/modeljson/labels.go @@ -15,7 +15,7 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import "strings" diff --git a/model/modelpb/log.pb.json.go b/model/modeljson/log.pb.json.go similarity index 85% rename from model/modelpb/log.pb.json.go rename to model/modeljson/log.pb.json.go index 0a460740..2fff14cf 100644 --- a/model/modelpb/log.pb.json.go +++ b/model/modeljson/log.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (l *Log) toModelJSON(out *modeljson.Log) { +func LogModelJSON(l *modelpb.Log, out *modeljson.Log) { *out = modeljson.Log{ Level: l.Level, Logger: l.Logger, diff --git a/model/modelpb/log.pb.json_test.go b/model/modeljson/log.pb.json_test.go similarity index 84% rename from model/modelpb/log.pb.json_test.go rename to model/modeljson/log.pb.json_test.go index f6fff3f0..54b5554f 100644 --- a/model/modelpb/log.pb.json_test.go +++ b/model/modeljson/log.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestLogToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Log + proto *modelpb.Log expected *modeljson.Log }{ "empty": { - proto: &Log{}, + proto: &modelpb.Log{}, expected: &modeljson.Log{}, }, "no pointers": { - proto: &Log{ + proto: &modelpb.Log{ Level: "level", Logger: "logger", }, @@ -45,12 +46,12 @@ func TestLogToModelJSON(t *testing.T) { }, }, "full": { - proto: &Log{ + proto: &modelpb.Log{ Level: "level", Logger: "logger", - Origin: &LogOrigin{ + Origin: &modelpb.LogOrigin{ FunctionName: "functionname", - File: &LogOriginFile{ + File: &modelpb.LogOriginFile{ Name: "name", Line: 1, }, @@ -72,7 +73,7 @@ func TestLogToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Log - tc.proto.toModelJSON(&out) + LogModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/message.pb.json.go b/model/modeljson/message.pb.json.go similarity index 77% rename from model/modelpb/message.pb.json.go rename to model/modeljson/message.pb.json.go index fb76f2ec..e026d539 100644 --- a/model/modelpb/message.pb.json.go +++ b/model/modeljson/message.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (m *Message) toModelJSON(out *modeljson.Message) { +func MessageModelJSON(m *modelpb.Message, out *modeljson.Message) { *out = modeljson.Message{ Body: m.Body, Age: modeljson.MessageAge{Millis: m.AgeMillis}, @@ -27,12 +30,6 @@ func (m *Message) toModelJSON(out *modeljson.Message) { RoutingKey: m.RoutingKey, } if n := len(m.Headers); n > 0 { - headers := make(map[string][]string, n) - for _, hv := range m.Headers { - if hv != nil { - headers[hv.Key] = hv.Value - } - } - out.Headers = headers + out.Headers = m.Headers } } diff --git a/model/modelpb/message.pb.json_test.go b/model/modeljson/message.pb.json_test.go similarity index 75% rename from model/modelpb/message.pb.json_test.go rename to model/modeljson/message.pb.json_test.go index 4d10ebd7..a13e80e8 100644 --- a/model/modelpb/message.pb.json_test.go +++ b/model/modeljson/message.pb.json_test.go @@ -15,31 +15,33 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/testing/protocmp" ) func TestMessageToModelJSON(t *testing.T) { - millis := int64(1) + millis := uint64(1) testCases := map[string]struct { - proto *Message + proto *modelpb.Message expected *modeljson.Message }{ "empty": { - proto: &Message{}, + proto: &modelpb.Message{}, expected: &modeljson.Message{}, }, "full": { - proto: &Message{ + proto: &modelpb.Message{ Body: "body", - Headers: []*HTTPHeader{ + Headers: []*modelpb.HTTPHeader{ { Key: "foo", Value: []string{"bar"}, @@ -51,8 +53,11 @@ func TestMessageToModelJSON(t *testing.T) { }, expected: &modeljson.Message{ Body: "body", - Headers: map[string][]string{ - "foo": {"bar"}, + Headers: []*modelpb.HTTPHeader{ + { + Key: "foo", + Value: []string{"bar"}, + }, }, Age: modeljson.MessageAge{ Millis: &millis, @@ -67,8 +72,8 @@ func TestMessageToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Message - tc.proto.toModelJSON(&out) - diff := cmp.Diff(*tc.expected, out) + MessageModelJSON(tc.proto, &out) + diff := cmp.Diff(*tc.expected, out, protocmp.Transform()) require.Empty(t, diff) }) } diff --git a/model/modelpb/metricset.pb.json.go b/model/modeljson/metricset.pb.json.go similarity index 77% rename from model/modelpb/metricset.pb.json.go rename to model/modeljson/metricset.pb.json.go index 8ebe2ed2..26fe9635 100644 --- a/model/modelpb/metricset.pb.json.go +++ b/model/modeljson/metricset.pb.json.go @@ -15,18 +15,21 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -var metricTypeText = map[MetricType]string{ - MetricType_METRIC_TYPE_GAUGE: "gauge", - MetricType_METRIC_TYPE_COUNTER: "counter", - MetricType_METRIC_TYPE_HISTOGRAM: "histogram", - MetricType_METRIC_TYPE_SUMMARY: "summary", +var metricTypeText = map[modelpb.MetricType]string{ + modelpb.MetricType_METRIC_TYPE_GAUGE: "gauge", + modelpb.MetricType_METRIC_TYPE_COUNTER: "counter", + modelpb.MetricType_METRIC_TYPE_HISTOGRAM: "histogram", + modelpb.MetricType_METRIC_TYPE_SUMMARY: "summary", } -func (me *Metricset) toModelJSON(out *modeljson.Metricset) { +func MetricsetModelJSON(me *modelpb.Metricset, out *modeljson.Metricset) { var samples []modeljson.MetricsetSample if n := len(me.Samples); n > 0 { samples = make([]modeljson.MetricsetSample, n) diff --git a/model/modelpb/metricset.pb.json_test.go b/model/modeljson/metricset.pb.json_test.go similarity index 79% rename from model/modelpb/metricset.pb.json_test.go rename to model/modeljson/metricset.pb.json_test.go index 88c894c0..7038aa43 100644 --- a/model/modelpb/metricset.pb.json_test.go +++ b/model/modeljson/metricset.pb.json_test.go @@ -15,39 +15,40 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestMetricsetToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Metricset + proto *modelpb.Metricset expected *modeljson.Metricset }{ "empty": { - proto: &Metricset{}, + proto: &modelpb.Metricset{}, expected: &modeljson.Metricset{}, }, "full": { - proto: &Metricset{ + proto: &modelpb.Metricset{ Name: "name", Interval: "interval", - Samples: []*MetricsetSample{ + Samples: []*modelpb.MetricsetSample{ { - Type: MetricType_METRIC_TYPE_COUNTER, + Type: modelpb.MetricType_METRIC_TYPE_COUNTER, Name: "name", Unit: "unit", - Histogram: &Histogram{ + Histogram: &modelpb.Histogram{ Values: []float64{1}, - Counts: []int64{2}, + Counts: []uint64{2}, }, - Summary: &SummaryMetric{ + Summary: &modelpb.SummaryMetric{ Count: 3, Sum: 4, }, @@ -66,7 +67,7 @@ func TestMetricsetToModelJSON(t *testing.T) { Unit: "unit", Histogram: modeljson.Histogram{ Values: []float64{1}, - Counts: []int64{2}, + Counts: []uint64{2}, }, Summary: modeljson.SummaryMetric{ Count: 3, @@ -81,7 +82,7 @@ func TestMetricsetToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Metricset - tc.proto.toModelJSON(&out) + MetricsetModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/network.pb.json.go b/model/modeljson/network.pb.json.go similarity index 84% rename from model/modelpb/network.pb.json.go rename to model/modeljson/network.pb.json.go index a3ab38c0..4809cf34 100644 --- a/model/modelpb/network.pb.json.go +++ b/model/modeljson/network.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (n *Network) toModelJSON(out *modeljson.Network) { +func NetworkModelJSON(n *modelpb.Network, out *modeljson.Network) { *out = modeljson.Network{} if n.Connection != nil { out.Connection = modeljson.NetworkConnection{ diff --git a/model/modelpb/network.pb.json_test.go b/model/modeljson/network.pb.json_test.go similarity index 81% rename from model/modelpb/network.pb.json_test.go rename to model/modeljson/network.pb.json_test.go index 7752b0ce..58f90780 100644 --- a/model/modelpb/network.pb.json_test.go +++ b/model/modeljson/network.pb.json_test.go @@ -15,28 +15,29 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestNetworkToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Network + proto *modelpb.Network expected *modeljson.Network }{ "empty": { - proto: &Network{}, + proto: &modelpb.Network{}, expected: &modeljson.Network{}, }, "connection": { - proto: &Network{ - Connection: &NetworkConnection{ + proto: &modelpb.Network{ + Connection: &modelpb.NetworkConnection{ Type: "type", Subtype: "subtype", }, @@ -49,8 +50,8 @@ func TestNetworkToModelJSON(t *testing.T) { }, }, "carrier": { - proto: &Network{ - Carrier: &NetworkCarrier{ + proto: &modelpb.Network{ + Carrier: &modelpb.NetworkCarrier{ Name: "name", Mcc: "mcc", Mnc: "mnc", @@ -67,12 +68,12 @@ func TestNetworkToModelJSON(t *testing.T) { }, }, "full": { - proto: &Network{ - Connection: &NetworkConnection{ + proto: &modelpb.Network{ + Connection: &modelpb.NetworkConnection{ Type: "type", Subtype: "subtype", }, - Carrier: &NetworkCarrier{ + Carrier: &modelpb.NetworkCarrier{ Name: "name", Mcc: "mcc", Mnc: "mnc", @@ -96,7 +97,7 @@ func TestNetworkToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Network - tc.proto.toModelJSON(&out) + NetworkModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/observer.pb.json.go b/model/modeljson/observer.pb.json.go similarity index 81% rename from model/modelpb/observer.pb.json.go rename to model/modeljson/observer.pb.json.go index c7609da0..2061edaa 100644 --- a/model/modelpb/observer.pb.json.go +++ b/model/modeljson/observer.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (o *Observer) toModelJSON(out *modeljson.Observer) { +func ObserverModelJSON(o *modelpb.Observer, out *modeljson.Observer) { *out = modeljson.Observer{ Hostname: o.Hostname, Name: o.Name, diff --git a/model/modelpb/observer.pb.json_test.go b/model/modeljson/observer.pb.json_test.go similarity index 85% rename from model/modelpb/observer.pb.json_test.go rename to model/modeljson/observer.pb.json_test.go index 8d1c9230..0494c120 100644 --- a/model/modelpb/observer.pb.json_test.go +++ b/model/modeljson/observer.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestObserverToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Observer + proto *modelpb.Observer expected *modeljson.Observer }{ "empty": { - proto: &Observer{}, + proto: &modelpb.Observer{}, expected: &modeljson.Observer{}, }, "full": { - proto: &Observer{ + proto: &modelpb.Observer{ Hostname: "hostname", Name: "name", Type: "type", @@ -52,7 +53,7 @@ func TestObserverToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Observer - tc.proto.toModelJSON(&out) + ObserverModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/os.pb.json.go b/model/modeljson/os.pb.json.go similarity index 82% rename from model/modelpb/os.pb.json.go rename to model/modeljson/os.pb.json.go index a6c10d97..f489a4b6 100644 --- a/model/modelpb/os.pb.json.go +++ b/model/modeljson/os.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (o *OS) toModelJSON(out *modeljson.OS) { +func OSModelJSON(o *modelpb.OS, out *modeljson.OS) { *out = modeljson.OS{ Name: o.Name, Version: o.Version, diff --git a/model/modelpb/os.pb.json_test.go b/model/modeljson/os.pb.json_test.go similarity index 86% rename from model/modelpb/os.pb.json_test.go rename to model/modeljson/os.pb.json_test.go index 0083a01b..a35a55dc 100644 --- a/model/modelpb/os.pb.json_test.go +++ b/model/modeljson/os.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestOSToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *OS + proto *modelpb.OS expected *modeljson.OS }{ "empty": { - proto: &OS{}, + proto: &modelpb.OS{}, expected: &modeljson.OS{}, }, "full": { - proto: &OS{ + proto: &modelpb.OS{ Name: "name", Version: "version", Platform: "platform", @@ -54,7 +55,7 @@ func TestOSToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.OS - tc.proto.toModelJSON(&out) + OSModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/process.pb.json.go b/model/modeljson/process.pb.json.go similarity index 84% rename from model/modelpb/process.pb.json.go rename to model/modeljson/process.pb.json.go index 031c8b4a..d9b8bfb5 100644 --- a/model/modelpb/process.pb.json.go +++ b/model/modeljson/process.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (p *Process) toModelJSON(out *modeljson.Process) { +func ProcessModelJSON(p *modelpb.Process, out *modeljson.Process) { *out = modeljson.Process{ Pid: int(p.Pid), Title: p.Title, diff --git a/model/modelpb/process.pb.json_test.go b/model/modeljson/process.pb.json_test.go similarity index 86% rename from model/modelpb/process.pb.json_test.go rename to model/modeljson/process.pb.json_test.go index e1ea2709..3ce587c9 100644 --- a/model/modelpb/process.pb.json_test.go +++ b/model/modeljson/process.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestProcessToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Process + proto *modelpb.Process expected *modeljson.Process }{ "empty": { - proto: &Process{}, + proto: &modelpb.Process{}, expected: &modeljson.Process{}, }, "no pointers": { - proto: &Process{ + proto: &modelpb.Process{ Title: "title", CommandLine: "commandline", Executable: "executable", @@ -49,9 +50,9 @@ func TestProcessToModelJSON(t *testing.T) { }, }, "full": { - proto: &Process{ + proto: &modelpb.Process{ Ppid: 1, - Thread: &ProcessThread{ + Thread: &modelpb.ProcessThread{ Name: "name", Id: 2, }, @@ -80,7 +81,7 @@ func TestProcessToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Process - tc.proto.toModelJSON(&out) + ProcessModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/service.pb.json.go b/model/modeljson/service.pb.json.go similarity index 88% rename from model/modelpb/service.pb.json.go rename to model/modeljson/service.pb.json.go index 4b17a06e..678e198c 100644 --- a/model/modelpb/service.pb.json.go +++ b/model/modeljson/service.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (s *Service) toModelJSON(out *modeljson.Service) { +func ServiceModelJSON(s *modelpb.Service, out *modeljson.Service) { *out = modeljson.Service{ Name: s.Name, Version: s.Version, diff --git a/model/modelpb/service.pb.json_test.go b/model/modeljson/service.pb.json_test.go similarity index 85% rename from model/modelpb/service.pb.json_test.go rename to model/modeljson/service.pb.json_test.go index f0afa38a..18e6b735 100644 --- a/model/modelpb/service.pb.json_test.go +++ b/model/modeljson/service.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestServiceToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Service + proto *modelpb.Service expected *modeljson.Service }{ "empty": { - proto: &Service{}, + proto: &modelpb.Service{}, expected: &modeljson.Service{}, }, "no pointers": { - proto: &Service{ + proto: &modelpb.Service{ Name: "name", Version: "version", Environment: "environment", @@ -47,32 +48,32 @@ func TestServiceToModelJSON(t *testing.T) { }, }, "full": { - proto: &Service{ - Origin: &ServiceOrigin{ + proto: &modelpb.Service{ + Origin: &modelpb.ServiceOrigin{ Id: "origin_id", Name: "origin_name", Version: "origin_version", }, - Target: &ServiceTarget{ + Target: &modelpb.ServiceTarget{ Name: "target_name", Type: "target_type", }, - Language: &Language{ + Language: &modelpb.Language{ Name: "language_name", Version: "language_version", }, - Runtime: &Runtime{ + Runtime: &modelpb.Runtime{ Name: "runtime_name", Version: "runtime_version", }, - Framework: &Framework{ + Framework: &modelpb.Framework{ Name: "framework_name", Version: "framework_version", }, Name: "name", Version: "version", Environment: "environment", - Node: &ServiceNode{ + Node: &modelpb.ServiceNode{ Name: "node_name", }, }, @@ -117,7 +118,7 @@ func TestServiceToModelJSON(t *testing.T) { Origin: &modeljson.ServiceOrigin{}, Target: &modeljson.ServiceTarget{}, } - tc.proto.toModelJSON(&out) + ServiceModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/source.pb.json.go b/model/modeljson/source.pb.json.go similarity index 75% rename from model/modelpb/source.pb.json.go rename to model/modeljson/source.pb.json.go index 70a1545c..b05995e4 100644 --- a/model/modelpb/source.pb.json.go +++ b/model/modeljson/source.pb.json.go @@ -15,19 +15,20 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -func (s *Source) toModelJSON(out *modeljson.Source) { +func SourceModelJSON(s *modelpb.Source, out *modeljson.Source) { *out = modeljson.Source{ Domain: s.Domain, Port: int(s.Port), } - out.IP = modeljson.IP(IP2Addr(s.Ip)) + out.IP = modeljson.IP(modelpb.IP2Addr(s.Ip)) if s.Nat != nil { - out.NAT.IP = modeljson.IP(IP2Addr(s.Nat.Ip)) + out.NAT.IP = modeljson.IP(modelpb.IP2Addr(s.Nat.Ip)) } } diff --git a/model/modelpb/source.pb.json_test.go b/model/modeljson/source.pb.json_test.go similarity index 82% rename from model/modelpb/source.pb.json_test.go rename to model/modeljson/source.pb.json_test.go index 5652ffed..4c1a01db 100644 --- a/model/modelpb/source.pb.json_test.go +++ b/model/modeljson/source.pb.json_test.go @@ -15,31 +15,32 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "net/netip" "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestSourceToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Source + proto *modelpb.Source expected *modeljson.Source }{ "empty": { - proto: &Source{}, + proto: &modelpb.Source{}, expected: &modeljson.Source{}, }, "full": { - proto: &Source{ - Ip: MustParseIP("127.0.0.1"), - Nat: &NAT{ - Ip: MustParseIP("127.0.0.2"), + proto: &modelpb.Source{ + Ip: modelpb.MustParseIP("127.0.0.1"), + Nat: &modelpb.NAT{ + Ip: modelpb.MustParseIP("127.0.0.2"), }, Domain: "domain", Port: 443, @@ -57,7 +58,7 @@ func TestSourceToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Source - tc.proto.toModelJSON(&out) + SourceModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out, cmp.Comparer(func(a modeljson.IP, b modeljson.IP) bool { return netip.Addr(a).Compare(netip.Addr(b)) == 0 diff --git a/model/modelpb/span.pb.json.go b/model/modeljson/span.pb.json.go similarity index 79% rename from model/modelpb/span.pb.json.go rename to model/modeljson/span.pb.json.go index a7ba8ccc..f66871f2 100644 --- a/model/modelpb/span.pb.json.go +++ b/model/modeljson/span.pb.json.go @@ -15,20 +15,21 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "time" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" ) -var compressionStrategyText = map[CompressionStrategy]string{ - CompressionStrategy_COMPRESSION_STRATEGY_EXACT_MATCH: "exact_match", - CompressionStrategy_COMPRESSION_STRATEGY_SAME_KIND: "same_kind", +var compressionStrategyText = map[modelpb.CompressionStrategy]string{ + modelpb.CompressionStrategy_COMPRESSION_STRATEGY_EXACT_MATCH: "exact_match", + modelpb.CompressionStrategy_COMPRESSION_STRATEGY_SAME_KIND: "same_kind", } -func (db *DB) toModelJSON(out *modeljson.DB) { +func DBModelJSON(db *modelpb.DB, out *modeljson.DB) { *out = modeljson.DB{ Instance: db.Instance, Statement: db.Statement, @@ -39,7 +40,7 @@ func (db *DB) toModelJSON(out *modeljson.DB) { } } -func (c *Composite) toModelJSON(out *modeljson.SpanComposite) { +func CompositeModelJSON(c *modelpb.Composite, out *modeljson.SpanComposite) { sumDuration := time.Duration(c.Sum * float64(time.Millisecond)) *out = modeljson.SpanComposite{ CompressionStrategy: compressionStrategyText[c.CompressionStrategy], @@ -48,7 +49,7 @@ func (c *Composite) toModelJSON(out *modeljson.SpanComposite) { } } -func (e *Span) toModelJSON(out *modeljson.Span) { +func SpanModelJSON(e *modelpb.Span, out *modeljson.Span) { *out = modeljson.Span{ ID: e.Id, Name: e.Name, @@ -67,15 +68,15 @@ func (e *Span) toModelJSON(out *modeljson.Span) { } if e.Db != nil { out.DB = &modeljson.DB{} - e.Db.toModelJSON(out.DB) + DBModelJSON(e.Db, out.DB) } if e.Message != nil { out.Message = &modeljson.Message{} - e.Message.toModelJSON(out.Message) + MessageModelJSON(e.Message, out.Message) } if e.Composite != nil { out.Composite = &modeljson.SpanComposite{} - e.Composite.toModelJSON(out.Composite) + CompositeModelJSON(e.Composite, out.Composite) } if e.DestinationService != nil { out.Destination = &modeljson.SpanDestination{ @@ -104,7 +105,7 @@ func (e *Span) toModelJSON(out *modeljson.Span) { if n := len(e.Stacktrace); n > 0 { out.Stacktrace = make([]modeljson.StacktraceFrame, n) for i, frame := range e.Stacktrace { - frame.toModelJSON(&out.Stacktrace[i]) + StacktraceFrameModelJSON(frame, &out.Stacktrace[i]) } } } diff --git a/model/modelpb/span.pb.json_test.go b/model/modeljson/span.pb.json_test.go similarity index 87% rename from model/modelpb/span.pb.json_test.go rename to model/modeljson/span.pb.json_test.go index 5628a8d4..96939783 100644 --- a/model/modelpb/span.pb.json_test.go +++ b/model/modeljson/span.pb.json_test.go @@ -15,13 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" "time" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/durationpb" @@ -31,15 +32,15 @@ func TestSpanToModelJSON(t *testing.T) { sync := true testCases := map[string]struct { - proto *Span + proto *modelpb.Span expected *modeljson.Span }{ "empty": { - proto: &Span{}, + proto: &modelpb.Span{}, expected: &modeljson.Span{}, }, "no pointers": { - proto: &Span{ + proto: &modelpb.Span{ Kind: "kind", Action: "action", Subtype: "subtype", @@ -59,22 +60,22 @@ func TestSpanToModelJSON(t *testing.T) { }, }, "full": { - proto: &Span{ - Composite: &Composite{ - CompressionStrategy: CompressionStrategy_COMPRESSION_STRATEGY_EXACT_MATCH, + proto: &modelpb.Span{ + Composite: &modelpb.Composite{ + CompressionStrategy: modelpb.CompressionStrategy_COMPRESSION_STRATEGY_EXACT_MATCH, Count: 1, Sum: 2, }, - DestinationService: &DestinationService{ + DestinationService: &modelpb.DestinationService{ Type: "destination_type", Name: "destination_name", Resource: "destination_resource", - ResponseTime: &AggregatedDuration{ + ResponseTime: &modelpb.AggregatedDuration{ Count: 3, Sum: durationpb.New(4 * time.Second), }, }, - Db: &DB{ + Db: &modelpb.DB{ RowsAffected: uintPtr(5), Instance: "db_instace", Statement: "db_statement", @@ -89,13 +90,13 @@ func TestSpanToModelJSON(t *testing.T) { Id: "id", Type: "type", Name: "name", - Links: []*SpanLink{ + Links: []*modelpb.SpanLink{ { TraceId: "trace_id", SpanId: "id1", }, }, - SelfTime: &AggregatedDuration{ + SelfTime: &modelpb.AggregatedDuration{ Count: 6, Sum: durationpb.New(7 * time.Second), }, @@ -164,7 +165,7 @@ func TestSpanToModelJSON(t *testing.T) { Destination: &modeljson.SpanDestination{}, DB: &modeljson.DB{}, } - tc.proto.toModelJSON(&out) + SpanModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/stacktrace.pb.json.go b/model/modeljson/stacktrace.pb.json.go similarity index 89% rename from model/modelpb/stacktrace.pb.json.go rename to model/modeljson/stacktrace.pb.json.go index 953a21eb..4c7cbd65 100644 --- a/model/modelpb/stacktrace.pb.json.go +++ b/model/modeljson/stacktrace.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (s *StacktraceFrame) toModelJSON(out *modeljson.StacktraceFrame) { +func StacktraceFrameModelJSON(s *modelpb.StacktraceFrame, out *modeljson.StacktraceFrame) { *out = modeljson.StacktraceFrame{ Filename: s.Filename, Classname: s.Classname, @@ -31,7 +34,7 @@ func (s *StacktraceFrame) toModelJSON(out *modeljson.StacktraceFrame) { } if s.Vars != nil { - out.Vars = kvToMap(s.Vars) + out.Vars = s.Vars } if len(s.PreContext) != 0 || len(s.PostContext) != 0 { diff --git a/model/modelpb/stacktrace.pb.json_test.go b/model/modeljson/stacktrace.pb.json_test.go similarity index 88% rename from model/modelpb/stacktrace.pb.json_test.go rename to model/modeljson/stacktrace.pb.json_test.go index 03263fc5..c0822de4 100644 --- a/model/modelpb/stacktrace.pb.json_test.go +++ b/model/modeljson/stacktrace.pb.json_test.go @@ -15,29 +15,31 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" + "google.golang.org/protobuf/testing/protocmp" ) func TestStacktraceToModelJSON(t *testing.T) { - vars, varsMap := randomKv(t) + vars := randomKv(t) testCases := map[string]struct { - proto *StacktraceFrame + proto *modelpb.StacktraceFrame expected *modeljson.StacktraceFrame }{ "empty": { - proto: &StacktraceFrame{}, + proto: &modelpb.StacktraceFrame{}, expected: &modeljson.StacktraceFrame{}, }, "no pointers": { - proto: &StacktraceFrame{ + proto: &modelpb.StacktraceFrame{ Filename: "frame1_filename", Classname: "frame1_classname", ContextLine: "frame1_contextline", @@ -45,7 +47,7 @@ func TestStacktraceToModelJSON(t *testing.T) { Function: "frame1_function", AbsPath: "frame1_abspath", SourcemapError: "frame1_sourcemaperror", - Original: &Original{ + Original: &modelpb.Original{ AbsPath: "orig1_abspath", Filename: "orig1_filename", Classname: "orig1_classname", @@ -81,7 +83,7 @@ func TestStacktraceToModelJSON(t *testing.T) { }, }, "full": { - proto: &StacktraceFrame{ + proto: &modelpb.StacktraceFrame{ Vars: vars, Lineno: uintPtr(1), Colno: uintPtr(2), @@ -92,7 +94,7 @@ func TestStacktraceToModelJSON(t *testing.T) { Function: "frame_function", AbsPath: "frame_abspath", SourcemapError: "frame_sourcemaperror", - Original: &Original{ + Original: &modelpb.Original{ AbsPath: "orig_abspath", Filename: "orig_filename", Classname: "orig_classname", @@ -112,7 +114,7 @@ func TestStacktraceToModelJSON(t *testing.T) { Error: "frame_sourcemaperror", Updated: true, }, - Vars: varsMap, + Vars: vars, Line: &modeljson.StacktraceFrameLine{ Number: uintPtr(1), Column: uintPtr(2), @@ -145,8 +147,8 @@ func TestStacktraceToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.StacktraceFrame - tc.proto.toModelJSON(&out) - diff := cmp.Diff(*tc.expected, out) + StacktraceFrameModelJSON(tc.proto, &out) + diff := cmp.Diff(*tc.expected, out, protocmp.Transform()) require.Empty(t, diff) }) } diff --git a/model/modelpb/transaction.pb.json.go b/model/modeljson/transaction.pb.json.go similarity index 88% rename from model/modelpb/transaction.pb.json.go rename to model/modeljson/transaction.pb.json.go index f727987f..f280229a 100644 --- a/model/modelpb/transaction.pb.json.go +++ b/model/modeljson/transaction.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (e *Transaction) toModelJSON(out *modeljson.Transaction, metricset bool) { +func TransactionModelJSON(e *modelpb.Transaction, out *modeljson.Transaction, metricset bool) { *out = modeljson.Transaction{ ID: e.Id, Type: e.Type, @@ -31,9 +34,8 @@ func (e *Transaction) toModelJSON(out *modeljson.Transaction, metricset bool) { } if e.Custom != nil { - m := kvToMap(e.Custom) - updateFields(m) - out.Custom = m + updateFields(e.Custom) + out.Custom = e.Custom } if n := len(e.Marks); n > 0 { @@ -49,12 +51,12 @@ func (e *Transaction) toModelJSON(out *modeljson.Transaction, metricset bool) { } if e.Message != nil { var message modeljson.Message - e.Message.toModelJSON(&message) + MessageModelJSON(e.Message, &message) out.Message = &message } if e.UserExperience != nil { var userExperience modeljson.UserExperience - e.UserExperience.toModelJSON(&userExperience) + UserExperienceModelJSON(e.UserExperience, &userExperience) out.UserExperience = &userExperience } if metricset { diff --git a/model/modelpb/transaction.pb.json_test.go b/model/modeljson/transaction.pb.json_test.go similarity index 86% rename from model/modelpb/transaction.pb.json_test.go rename to model/modeljson/transaction.pb.json_test.go index f6766946..a0b1007a 100644 --- a/model/modelpb/transaction.pb.json_test.go +++ b/model/modeljson/transaction.pb.json_test.go @@ -15,13 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" "time" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" "google.golang.org/protobuf/types/known/durationpb" @@ -29,17 +30,17 @@ import ( func TestTransactionToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *Transaction + proto *modelpb.Transaction expectedNoMetricset *modeljson.Transaction expectedMetricset *modeljson.Transaction }{ "empty": { - proto: &Transaction{}, + proto: &modelpb.Transaction{}, expectedNoMetricset: &modeljson.Transaction{}, expectedMetricset: &modeljson.Transaction{}, }, "no pointers": { - proto: &Transaction{ + proto: &modelpb.Transaction{ Type: "type", Name: "name", Result: "result", @@ -68,14 +69,14 @@ func TestTransactionToModelJSON(t *testing.T) { }, }, "full": { - proto: &Transaction{ - SpanCount: &SpanCount{ + proto: &modelpb.Transaction{ + SpanCount: &modelpb.SpanCount{ Started: uintPtr(1), Dropped: uintPtr(2), }, // TODO investigat valid values Custom: nil, - Marks: map[string]*TransactionMark{ + Marks: map[string]*modelpb.TransactionMark{ "foo": { Measurements: map[string]float64{ "bar": 3, @@ -86,23 +87,23 @@ func TestTransactionToModelJSON(t *testing.T) { Name: "name", Result: "result", Id: "id", - DurationHistogram: &Histogram{ + DurationHistogram: &modelpb.Histogram{ Values: []float64{4}, - Counts: []int64{5}, + Counts: []uint64{5}, }, - DroppedSpansStats: []*DroppedSpanStats{ + DroppedSpansStats: []*modelpb.DroppedSpanStats{ { DestinationServiceResource: "destinationserviceresource", ServiceTargetType: "servicetargetype", ServiceTargetName: "servicetargetname", Outcome: "outcome", - Duration: &AggregatedDuration{ + Duration: &modelpb.AggregatedDuration{ Count: 4, Sum: durationpb.New(5 * time.Second), }, }, }, - DurationSummary: &SummaryMetric{ + DurationSummary: &modelpb.SummaryMetric{ Count: 6, Sum: 7, }, @@ -128,7 +129,7 @@ func TestTransactionToModelJSON(t *testing.T) { ID: "id", DurationHistogram: modeljson.Histogram{ Values: []float64{4}, - Counts: []int64{5}, + Counts: []uint64{5}, }, DurationSummary: modeljson.SummaryMetric{ Count: 6, @@ -156,7 +157,7 @@ func TestTransactionToModelJSON(t *testing.T) { ID: "id", DurationHistogram: modeljson.Histogram{ Values: []float64{4}, - Counts: []int64{5}, + Counts: []uint64{5}, }, DroppedSpansStats: []modeljson.DroppedSpanStats{ { @@ -183,11 +184,11 @@ func TestTransactionToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.Transaction - tc.proto.toModelJSON(&out, false) + TransactionModelJSON(tc.proto, &out, false) require.Empty(t, cmp.Diff(*tc.expectedNoMetricset, out)) var out2 modeljson.Transaction - tc.proto.toModelJSON(&out2, true) + TransactionModelJSON(tc.proto, &out2, true) require.Empty(t, cmp.Diff(*tc.expectedMetricset, out2)) }) } diff --git a/model/modelpb/url.pb.json.go b/model/modeljson/url.pb.json.go similarity index 83% rename from model/modelpb/url.pb.json.go rename to model/modeljson/url.pb.json.go index 3122706c..867bbd72 100644 --- a/model/modelpb/url.pb.json.go +++ b/model/modeljson/url.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (u *URL) toModelJSON(out *modeljson.URL) { +func URLModelJSON(u *modelpb.URL, out *modeljson.URL) { *out = modeljson.URL{ Original: u.Original, Scheme: u.Scheme, diff --git a/model/modelpb/url.pb.json_test.go b/model/modeljson/url.pb.json_test.go similarity index 87% rename from model/modelpb/url.pb.json_test.go rename to model/modeljson/url.pb.json_test.go index 85b16fd6..1834f358 100644 --- a/model/modelpb/url.pb.json_test.go +++ b/model/modeljson/url.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestURLToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *URL + proto *modelpb.URL expected *modeljson.URL }{ "empty": { - proto: &URL{}, + proto: &modelpb.URL{}, expected: &modeljson.URL{}, }, "full": { - proto: &URL{ + proto: &modelpb.URL{ Original: "original", Scheme: "scheme", Full: "full", @@ -60,7 +61,7 @@ func TestURLToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.URL - tc.proto.toModelJSON(&out) + URLModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/user.pb.json.go b/model/modeljson/user.pb.json.go similarity index 81% rename from model/modelpb/user.pb.json.go rename to model/modeljson/user.pb.json.go index 03b59185..cc94bc9c 100644 --- a/model/modelpb/user.pb.json.go +++ b/model/modeljson/user.pb.json.go @@ -15,11 +15,14 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson -import "github.com/elastic/apm-data/model/internal/modeljson" +import ( + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" +) -func (u *User) toModelJSON(out *modeljson.User) { +func UserModelJSON(u *modelpb.User, out *modeljson.User) { *out = modeljson.User{ Domain: u.Domain, ID: u.Id, diff --git a/model/modelpb/user.pb.json_test.go b/model/modeljson/user.pb.json_test.go similarity index 85% rename from model/modelpb/user.pb.json_test.go rename to model/modeljson/user.pb.json_test.go index 271c6d02..8b7d4063 100644 --- a/model/modelpb/user.pb.json_test.go +++ b/model/modeljson/user.pb.json_test.go @@ -15,27 +15,28 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "testing" - "github.com/elastic/apm-data/model/internal/modeljson" + modeljson "github.com/elastic/apm-data/model/modeljson/internal" + "github.com/elastic/apm-data/model/modelpb" "github.com/google/go-cmp/cmp" "github.com/stretchr/testify/require" ) func TestUserToModelJSON(t *testing.T) { testCases := map[string]struct { - proto *User + proto *modelpb.User expected *modeljson.User }{ "empty": { - proto: &User{}, + proto: &modelpb.User{}, expected: &modeljson.User{}, }, "full": { - proto: &User{ + proto: &modelpb.User{ Domain: "domain", Id: "id", Email: "email", @@ -52,7 +53,7 @@ func TestUserToModelJSON(t *testing.T) { for name, tc := range testCases { t.Run(name, func(t *testing.T) { var out modeljson.User - tc.proto.toModelJSON(&out) + UserModelJSON(tc.proto, &out) diff := cmp.Diff(*tc.expected, out) require.Empty(t, diff) }) diff --git a/model/modelpb/util_test.go b/model/modeljson/util_test.go similarity index 73% rename from model/modelpb/util_test.go rename to model/modeljson/util_test.go index 45342ee1..41a3cf91 100644 --- a/model/modelpb/util_test.go +++ b/model/modeljson/util_test.go @@ -15,41 +15,34 @@ // specific language governing permissions and limitations // under the License. -package modelpb +package modeljson import ( "math/rand" "strings" "testing" + "github.com/elastic/apm-data/model/modelpb" + "github.com/stretchr/testify/require" structpb "google.golang.org/protobuf/types/known/structpb" ) -func randomKv(t testing.TB) ([]*KeyValue, map[string]any) { - m := map[string]any{ - t.Name() + ".key." + randString(): t.Name() + ".value." + randString(), - } +func randomKv(t testing.TB) []*modelpb.KeyValue { + value, err := structpb.NewValue(t.Name() + ".value." + randString()) + require.NoError(t, err) - kv := []*KeyValue{} - for k, v := range m { - value, _ := structpb.NewValue(v) - kv = append(kv, &KeyValue{ - Key: k, + kv := []*modelpb.KeyValue{ + &modelpb.KeyValue{ + Key: t.Name() + ".key." + randString(), Value: value, - }) + }, } - - return kv, m -} - -func randomKvPb(t testing.TB) []*KeyValue { - k, _ := randomKv(t) - return k + return kv } -func randomHTTPHeaders(t testing.TB) []*HTTPHeader { - return []*HTTPHeader{ - &HTTPHeader{ +func randomHTTPHeaders(t testing.TB) []*modelpb.HTTPHeader { + return []*modelpb.HTTPHeader{ + { Key: t.Name() + ".key." + randString(), Value: []string{t.Name() + ".value." + randString()}, }, @@ -60,7 +53,7 @@ func uintPtr(i uint32) *uint32 { return &i } -func int64Ptr(i int64) *int64 { +func uint64Ptr(i uint64) *uint64 { return &i } diff --git a/model/modelpb/agent_vtproto.pb.go b/model/modelpb/agent_vtproto.pb.go index 75164283..4129da40 100644 --- a/model/modelpb/agent_vtproto.pb.go +++ b/model/modelpb/agent_vtproto.pb.go @@ -25,6 +25,7 @@ import ( fmt "fmt" io "io" bits "math/bits" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -130,6 +131,25 @@ func encodeVarint(dAtA []byte, offset int, v uint64) int { dAtA[offset] = uint8(v) return base } + +var vtprotoPool_Agent = sync.Pool{ + New: func() interface{} { + return &Agent{} + }, +} + +func (m *Agent) ResetVT() { + m.Reset() +} +func (m *Agent) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Agent.Put(m) + } +} +func AgentFromVTPool() *Agent { + return vtprotoPool_Agent.Get().(*Agent) +} func (m *Agent) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/apmevent_vtproto.pb.go b/model/modelpb/apmevent_vtproto.pb.go index 5bdbe1aa..09aab650 100644 --- a/model/modelpb/apmevent_vtproto.pb.go +++ b/model/modelpb/apmevent_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -537,6 +538,53 @@ func (m *APMEvent) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_APMEvent = sync.Pool{ + New: func() interface{} { + return &APMEvent{} + }, +} + +func (m *APMEvent) ResetVT() { + m.Span.ReturnToVTPool() + m.Transaction.ReturnToVTPool() + m.Metricset.ReturnToVTPool() + m.Error.ReturnToVTPool() + m.Cloud.ReturnToVTPool() + m.Service.ReturnToVTPool() + m.Faas.ReturnToVTPool() + m.Network.ReturnToVTPool() + m.Container.ReturnToVTPool() + m.User.ReturnToVTPool() + m.Device.ReturnToVTPool() + m.Kubernetes.ReturnToVTPool() + m.Observer.ReturnToVTPool() + m.DataStream.ReturnToVTPool() + m.Agent.ReturnToVTPool() + m.Http.ReturnToVTPool() + m.UserAgent.ReturnToVTPool() + m.Trace.ReturnToVTPool() + m.Host.ReturnToVTPool() + m.Url.ReturnToVTPool() + m.Log.ReturnToVTPool() + m.Source.ReturnToVTPool() + m.Client.ReturnToVTPool() + f0 := m.ChildIds[:0] + m.Destination.ReturnToVTPool() + m.Session.ReturnToVTPool() + m.Process.ReturnToVTPool() + m.Event.ReturnToVTPool() + m.Reset() + m.ChildIds = f0 +} +func (m *APMEvent) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_APMEvent.Put(m) + } +} +func APMEventFromVTPool() *APMEvent { + return vtprotoPool_APMEvent.Get().(*APMEvent) +} func (m *APMEvent) SizeVT() (n int) { if m == nil { return 0 @@ -808,7 +856,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Span == nil { - m.Span = &Span{} + m.Span = SpanFromVTPool() } if err := m.Span.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1102,7 +1150,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Transaction == nil { - m.Transaction = &Transaction{} + m.Transaction = TransactionFromVTPool() } if err := m.Transaction.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1138,7 +1186,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Metricset == nil { - m.Metricset = &Metricset{} + m.Metricset = MetricsetFromVTPool() } if err := m.Metricset.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1174,7 +1222,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Error == nil { - m.Error = &Error{} + m.Error = ErrorFromVTPool() } if err := m.Error.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1210,7 +1258,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Cloud == nil { - m.Cloud = &Cloud{} + m.Cloud = CloudFromVTPool() } if err := m.Cloud.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1246,7 +1294,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Service == nil { - m.Service = &Service{} + m.Service = ServiceFromVTPool() } if err := m.Service.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1282,7 +1330,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Faas == nil { - m.Faas = &Faas{} + m.Faas = FaasFromVTPool() } if err := m.Faas.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1318,7 +1366,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Network == nil { - m.Network = &Network{} + m.Network = NetworkFromVTPool() } if err := m.Network.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1354,7 +1402,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Container == nil { - m.Container = &Container{} + m.Container = ContainerFromVTPool() } if err := m.Container.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1390,7 +1438,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.User == nil { - m.User = &User{} + m.User = UserFromVTPool() } if err := m.User.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1426,7 +1474,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Device == nil { - m.Device = &Device{} + m.Device = DeviceFromVTPool() } if err := m.Device.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1462,7 +1510,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Kubernetes == nil { - m.Kubernetes = &Kubernetes{} + m.Kubernetes = KubernetesFromVTPool() } if err := m.Kubernetes.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1498,7 +1546,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Observer == nil { - m.Observer = &Observer{} + m.Observer = ObserverFromVTPool() } if err := m.Observer.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1534,7 +1582,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.DataStream == nil { - m.DataStream = &DataStream{} + m.DataStream = DataStreamFromVTPool() } if err := m.DataStream.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1570,7 +1618,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Agent == nil { - m.Agent = &Agent{} + m.Agent = AgentFromVTPool() } if err := m.Agent.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1606,7 +1654,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Http == nil { - m.Http = &HTTP{} + m.Http = HTTPFromVTPool() } if err := m.Http.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1642,7 +1690,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.UserAgent == nil { - m.UserAgent = &UserAgent{} + m.UserAgent = UserAgentFromVTPool() } if err := m.UserAgent.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1742,7 +1790,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Trace == nil { - m.Trace = &Trace{} + m.Trace = TraceFromVTPool() } if err := m.Trace.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1778,7 +1826,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Host == nil { - m.Host = &Host{} + m.Host = HostFromVTPool() } if err := m.Host.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1814,7 +1862,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Url == nil { - m.Url = &URL{} + m.Url = URLFromVTPool() } if err := m.Url.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1850,7 +1898,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Log == nil { - m.Log = &Log{} + m.Log = LogFromVTPool() } if err := m.Log.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1886,7 +1934,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Source == nil { - m.Source = &Source{} + m.Source = SourceFromVTPool() } if err := m.Source.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1922,7 +1970,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Client == nil { - m.Client = &Client{} + m.Client = ClientFromVTPool() } if err := m.Client.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1990,7 +2038,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Destination == nil { - m.Destination = &Destination{} + m.Destination = DestinationFromVTPool() } if err := m.Destination.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -2026,7 +2074,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Session == nil { - m.Session = &Session{} + m.Session = SessionFromVTPool() } if err := m.Session.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -2062,7 +2110,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Process == nil { - m.Process = &Process{} + m.Process = ProcessFromVTPool() } if err := m.Process.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -2098,7 +2146,7 @@ func (m *APMEvent) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Event == nil { - m.Event = &Event{} + m.Event = EventFromVTPool() } if err := m.Event.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/client_vtproto.pb.go b/model/modelpb/client_vtproto.pb.go index 91627079..c74c5160 100644 --- a/model/modelpb/client_vtproto.pb.go +++ b/model/modelpb/client_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -111,6 +112,25 @@ func (m *Client) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Client = sync.Pool{ + New: func() interface{} { + return &Client{} + }, +} + +func (m *Client) ResetVT() { + m.Ip.ReturnToVTPool() + m.Reset() +} +func (m *Client) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Client.Put(m) + } +} +func ClientFromVTPool() *Client { + return vtprotoPool_Client.Get().(*Client) +} func (m *Client) SizeVT() (n int) { if m == nil { return 0 @@ -191,7 +211,7 @@ func (m *Client) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Ip == nil { - m.Ip = &IP{} + m.Ip = IPFromVTPool() } if err := m.Ip.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/cloud_vtproto.pb.go b/model/modelpb/cloud_vtproto.pb.go index bd49f054..6a24baed 100644 --- a/model/modelpb/cloud_vtproto.pb.go +++ b/model/modelpb/cloud_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -267,6 +268,44 @@ func (m *CloudOrigin) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Cloud = sync.Pool{ + New: func() interface{} { + return &Cloud{} + }, +} + +func (m *Cloud) ResetVT() { + m.Origin.ReturnToVTPool() + m.Reset() +} +func (m *Cloud) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Cloud.Put(m) + } +} +func CloudFromVTPool() *Cloud { + return vtprotoPool_Cloud.Get().(*Cloud) +} + +var vtprotoPool_CloudOrigin = sync.Pool{ + New: func() interface{} { + return &CloudOrigin{} + }, +} + +func (m *CloudOrigin) ResetVT() { + m.Reset() +} +func (m *CloudOrigin) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_CloudOrigin.Put(m) + } +} +func CloudOriginFromVTPool() *CloudOrigin { + return vtprotoPool_CloudOrigin.Get().(*CloudOrigin) +} func (m *Cloud) SizeVT() (n int) { if m == nil { return 0 @@ -410,7 +449,7 @@ func (m *Cloud) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Origin == nil { - m.Origin = &CloudOrigin{} + m.Origin = CloudOriginFromVTPool() } if err := m.Origin.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/container_vtproto.pb.go b/model/modelpb/container_vtproto.pb.go index 7500ff63..0ff2530a 100644 --- a/model/modelpb/container_vtproto.pb.go +++ b/model/modelpb/container_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -126,6 +127,24 @@ func (m *Container) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Container = sync.Pool{ + New: func() interface{} { + return &Container{} + }, +} + +func (m *Container) ResetVT() { + m.Reset() +} +func (m *Container) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Container.Put(m) + } +} +func ContainerFromVTPool() *Container { + return vtprotoPool_Container.Get().(*Container) +} func (m *Container) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/datastream_vtproto.pb.go b/model/modelpb/datastream_vtproto.pb.go index 495d7bf1..10f14424 100644 --- a/model/modelpb/datastream_vtproto.pb.go +++ b/model/modelpb/datastream_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -110,6 +111,24 @@ func (m *DataStream) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_DataStream = sync.Pool{ + New: func() interface{} { + return &DataStream{} + }, +} + +func (m *DataStream) ResetVT() { + m.Reset() +} +func (m *DataStream) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_DataStream.Put(m) + } +} +func DataStreamFromVTPool() *DataStream { + return vtprotoPool_DataStream.Get().(*DataStream) +} func (m *DataStream) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/destination_vtproto.pb.go b/model/modelpb/destination_vtproto.pb.go index 51612769..791095e1 100644 --- a/model/modelpb/destination_vtproto.pb.go +++ b/model/modelpb/destination_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -100,6 +101,24 @@ func (m *Destination) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Destination = sync.Pool{ + New: func() interface{} { + return &Destination{} + }, +} + +func (m *Destination) ResetVT() { + m.Reset() +} +func (m *Destination) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Destination.Put(m) + } +} +func DestinationFromVTPool() *Destination { + return vtprotoPool_Destination.Get().(*Destination) +} func (m *Destination) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/device_vtproto.pb.go b/model/modelpb/device_vtproto.pb.go index e980124e..27aa42bb 100644 --- a/model/modelpb/device_vtproto.pb.go +++ b/model/modelpb/device_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -179,6 +180,44 @@ func (m *DeviceModel) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Device = sync.Pool{ + New: func() interface{} { + return &Device{} + }, +} + +func (m *Device) ResetVT() { + m.Model.ReturnToVTPool() + m.Reset() +} +func (m *Device) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Device.Put(m) + } +} +func DeviceFromVTPool() *Device { + return vtprotoPool_Device.Get().(*Device) +} + +var vtprotoPool_DeviceModel = sync.Pool{ + New: func() interface{} { + return &DeviceModel{} + }, +} + +func (m *DeviceModel) ResetVT() { + m.Reset() +} +func (m *DeviceModel) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_DeviceModel.Put(m) + } +} +func DeviceModelFromVTPool() *DeviceModel { + return vtprotoPool_DeviceModel.Get().(*DeviceModel) +} func (m *Device) SizeVT() (n int) { if m == nil { return 0 @@ -310,7 +349,7 @@ func (m *Device) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Model == nil { - m.Model = &DeviceModel{} + m.Model = DeviceModelFromVTPool() } if err := m.Model.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/error_vtproto.pb.go b/model/modelpb/error_vtproto.pb.go index 4615e788..ec4ae629 100644 --- a/model/modelpb/error_vtproto.pb.go +++ b/model/modelpb/error_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -429,6 +430,79 @@ func (m *ErrorLog) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Error = sync.Pool{ + New: func() interface{} { + return &Error{} + }, +} + +func (m *Error) ResetVT() { + for _, mm := range m.Custom { + mm.ResetVT() + } + m.Exception.ReturnToVTPool() + m.Log.ReturnToVTPool() + m.Reset() +} +func (m *Error) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Error.Put(m) + } +} +func ErrorFromVTPool() *Error { + return vtprotoPool_Error.Get().(*Error) +} + +var vtprotoPool_Exception = sync.Pool{ + New: func() interface{} { + return &Exception{} + }, +} + +func (m *Exception) ResetVT() { + for _, mm := range m.Attributes { + mm.ResetVT() + } + for _, mm := range m.Stacktrace { + mm.ResetVT() + } + for _, mm := range m.Cause { + mm.ResetVT() + } + m.Reset() +} +func (m *Exception) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Exception.Put(m) + } +} +func ExceptionFromVTPool() *Exception { + return vtprotoPool_Exception.Get().(*Exception) +} + +var vtprotoPool_ErrorLog = sync.Pool{ + New: func() interface{} { + return &ErrorLog{} + }, +} + +func (m *ErrorLog) ResetVT() { + for _, mm := range m.Stacktrace { + mm.ResetVT() + } + m.Reset() +} +func (m *ErrorLog) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_ErrorLog.Put(m) + } +} +func ErrorLogFromVTPool() *ErrorLog { + return vtprotoPool_ErrorLog.Get().(*ErrorLog) +} func (m *Error) SizeVT() (n int) { if m == nil { return 0 @@ -614,7 +688,14 @@ func (m *Error) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Custom = append(m.Custom, &KeyValue{}) + if len(m.Custom) == cap(m.Custom) { + m.Custom = append(m.Custom, &KeyValue{}) + } else { + m.Custom = m.Custom[:len(m.Custom)+1] + if m.Custom[len(m.Custom)-1] == nil { + m.Custom[len(m.Custom)-1] = &KeyValue{} + } + } if err := m.Custom[len(m.Custom)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -649,7 +730,7 @@ func (m *Error) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Exception == nil { - m.Exception = &Exception{} + m.Exception = ExceptionFromVTPool() } if err := m.Exception.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -685,7 +766,7 @@ func (m *Error) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Log == nil { - m.Log = &ErrorLog{} + m.Log = ErrorLogFromVTPool() } if err := m.Log.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1059,7 +1140,14 @@ func (m *Exception) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Attributes = append(m.Attributes, &KeyValue{}) + if len(m.Attributes) == cap(m.Attributes) { + m.Attributes = append(m.Attributes, &KeyValue{}) + } else { + m.Attributes = m.Attributes[:len(m.Attributes)+1] + if m.Attributes[len(m.Attributes)-1] == nil { + m.Attributes[len(m.Attributes)-1] = &KeyValue{} + } + } if err := m.Attributes[len(m.Attributes)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1093,7 +1181,14 @@ func (m *Exception) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Stacktrace = append(m.Stacktrace, &StacktraceFrame{}) + if len(m.Stacktrace) == cap(m.Stacktrace) { + m.Stacktrace = append(m.Stacktrace, &StacktraceFrame{}) + } else { + m.Stacktrace = m.Stacktrace[:len(m.Stacktrace)+1] + if m.Stacktrace[len(m.Stacktrace)-1] == nil { + m.Stacktrace[len(m.Stacktrace)-1] = &StacktraceFrame{} + } + } if err := m.Stacktrace[len(m.Stacktrace)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1180,7 +1275,14 @@ func (m *Exception) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Cause = append(m.Cause, &Exception{}) + if len(m.Cause) == cap(m.Cause) { + m.Cause = append(m.Cause, &Exception{}) + } else { + m.Cause = m.Cause[:len(m.Cause)+1] + if m.Cause[len(m.Cause)-1] == nil { + m.Cause[len(m.Cause)-1] = &Exception{} + } + } if err := m.Cause[len(m.Cause)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1393,7 +1495,14 @@ func (m *ErrorLog) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Stacktrace = append(m.Stacktrace, &StacktraceFrame{}) + if len(m.Stacktrace) == cap(m.Stacktrace) { + m.Stacktrace = append(m.Stacktrace, &StacktraceFrame{}) + } else { + m.Stacktrace = m.Stacktrace[:len(m.Stacktrace)+1] + if m.Stacktrace[len(m.Stacktrace)-1] == nil { + m.Stacktrace[len(m.Stacktrace)-1] = &StacktraceFrame{} + } + } if err := m.Stacktrace[len(m.Stacktrace)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/model/modelpb/event.pb.go b/model/modelpb/event.pb.go index 01b5b576..9bdc0277 100644 --- a/model/modelpb/event.pb.go +++ b/model/modelpb/event.pb.go @@ -53,7 +53,7 @@ type Event struct { Type string `protobuf:"bytes,6,opt,name=type,proto3" json:"type,omitempty"` SuccessCount *SummaryMetric `protobuf:"bytes,7,opt,name=success_count,json=successCount,proto3" json:"success_count,omitempty"` Duration *durationpb.Duration `protobuf:"bytes,8,opt,name=duration,proto3" json:"duration,omitempty"` - Severity int64 `protobuf:"varint,9,opt,name=severity,proto3" json:"severity,omitempty"` + Severity uint64 `protobuf:"varint,9,opt,name=severity,proto3" json:"severity,omitempty"` Received *timestamppb.Timestamp `protobuf:"bytes,10,opt,name=received,proto3" json:"received,omitempty"` } @@ -145,7 +145,7 @@ func (x *Event) GetDuration() *durationpb.Duration { return nil } -func (x *Event) GetSeverity() int64 { +func (x *Event) GetSeverity() uint64 { if x != nil { return x.Severity } @@ -187,7 +187,7 @@ var file_event_proto_rawDesc = []byte{ 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x08, 0x64, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, - 0x18, 0x09, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, + 0x18, 0x09, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x65, 0x76, 0x65, 0x72, 0x69, 0x74, 0x79, 0x12, 0x36, 0x0a, 0x08, 0x72, 0x65, 0x63, 0x65, 0x69, 0x76, 0x65, 0x64, 0x18, 0x0a, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x1a, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x54, 0x69, 0x6d, 0x65, 0x73, 0x74, 0x61, 0x6d, 0x70, 0x52, 0x08, diff --git a/model/modelpb/event_vtproto.pb.go b/model/modelpb/event_vtproto.pb.go index 2f370460..dfdb3889 100644 --- a/model/modelpb/event_vtproto.pb.go +++ b/model/modelpb/event_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -211,6 +212,25 @@ func (m *Event) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Event = sync.Pool{ + New: func() interface{} { + return &Event{} + }, +} + +func (m *Event) ResetVT() { + m.SuccessCount.ReturnToVTPool() + m.Reset() +} +func (m *Event) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Event.Put(m) + } +} +func EventFromVTPool() *Event { + return vtprotoPool_Event.Get().(*Event) +} func (m *Event) SizeVT() (n int) { if m == nil { return 0 @@ -523,7 +543,7 @@ func (m *Event) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.SuccessCount == nil { - m.SuccessCount = &SummaryMetric{} + m.SuccessCount = SummaryMetricFromVTPool() } if err := m.SuccessCount.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -587,7 +607,7 @@ func (m *Event) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Severity |= int64(b&0x7F) << shift + m.Severity |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/experience.pb.go b/model/modelpb/experience.pb.go index 35d6dde0..cf1c8a43 100644 --- a/model/modelpb/experience.pb.go +++ b/model/modelpb/experience.pb.go @@ -114,7 +114,7 @@ type LongtaskMetrics struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` + Count uint64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` Sum float64 `protobuf:"fixed64,2,opt,name=sum,proto3" json:"sum,omitempty"` Max float64 `protobuf:"fixed64,3,opt,name=max,proto3" json:"max,omitempty"` } @@ -151,7 +151,7 @@ func (*LongtaskMetrics) Descriptor() ([]byte, []int) { return file_experience_proto_rawDescGZIP(), []int{1} } -func (x *LongtaskMetrics) GetCount() int64 { +func (x *LongtaskMetrics) GetCount() uint64 { if x != nil { return x.Count } @@ -193,7 +193,7 @@ var file_experience_proto_rawDesc = []byte{ 0x6e, 0x67, 0x74, 0x61, 0x73, 0x6b, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x52, 0x08, 0x6c, 0x6f, 0x6e, 0x67, 0x54, 0x61, 0x73, 0x6b, 0x22, 0x4b, 0x0a, 0x0f, 0x4c, 0x6f, 0x6e, 0x67, 0x74, 0x61, 0x73, 0x6b, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, - 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, + 0x75, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x12, 0x10, 0x0a, 0x03, 0x6d, 0x61, 0x78, 0x18, 0x03, 0x20, 0x01, 0x28, 0x01, 0x52, 0x03, 0x6d, 0x61, 0x78, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, diff --git a/model/modelpb/experience_vtproto.pb.go b/model/modelpb/experience_vtproto.pb.go index 7b9eb540..d81ef818 100644 --- a/model/modelpb/experience_vtproto.pb.go +++ b/model/modelpb/experience_vtproto.pb.go @@ -26,6 +26,7 @@ import ( fmt "fmt" io "io" math "math" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -190,6 +191,44 @@ func (m *LongtaskMetrics) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_UserExperience = sync.Pool{ + New: func() interface{} { + return &UserExperience{} + }, +} + +func (m *UserExperience) ResetVT() { + m.LongTask.ReturnToVTPool() + m.Reset() +} +func (m *UserExperience) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_UserExperience.Put(m) + } +} +func UserExperienceFromVTPool() *UserExperience { + return vtprotoPool_UserExperience.Get().(*UserExperience) +} + +var vtprotoPool_LongtaskMetrics = sync.Pool{ + New: func() interface{} { + return &LongtaskMetrics{} + }, +} + +func (m *LongtaskMetrics) ResetVT() { + m.Reset() +} +func (m *LongtaskMetrics) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_LongtaskMetrics.Put(m) + } +} +func LongtaskMetricsFromVTPool() *LongtaskMetrics { + return vtprotoPool_LongtaskMetrics.Get().(*LongtaskMetrics) +} func (m *UserExperience) SizeVT() (n int) { if m == nil { return 0 @@ -324,7 +363,7 @@ func (m *UserExperience) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.LongTask == nil { - m.LongTask = &LongtaskMetrics{} + m.LongTask = LongtaskMetricsFromVTPool() } if err := m.LongTask.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -395,7 +434,7 @@ func (m *LongtaskMetrics) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Count |= int64(b&0x7F) << shift + m.Count |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/faas_vtproto.pb.go b/model/modelpb/faas_vtproto.pb.go index 859b6ca5..2c94726d 100644 --- a/model/modelpb/faas_vtproto.pb.go +++ b/model/modelpb/faas_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -148,6 +149,24 @@ func (m *Faas) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Faas = sync.Pool{ + New: func() interface{} { + return &Faas{} + }, +} + +func (m *Faas) ResetVT() { + m.Reset() +} +func (m *Faas) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Faas.Put(m) + } +} +func FaasFromVTPool() *Faas { + return vtprotoPool_Faas.Get().(*Faas) +} func (m *Faas) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/headers_vtproto.pb.go b/model/modelpb/headers_vtproto.pb.go index 1b100e39..23bde909 100644 --- a/model/modelpb/headers_vtproto.pb.go +++ b/model/modelpb/headers_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -108,6 +109,26 @@ func (m *HTTPHeader) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_HTTPHeader = sync.Pool{ + New: func() interface{} { + return &HTTPHeader{} + }, +} + +func (m *HTTPHeader) ResetVT() { + f0 := m.Value[:0] + m.Reset() + m.Value = f0 +} +func (m *HTTPHeader) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_HTTPHeader.Put(m) + } +} +func HTTPHeaderFromVTPool() *HTTPHeader { + return vtprotoPool_HTTPHeader.Get().(*HTTPHeader) +} func (m *HTTPHeader) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/host_vtproto.pb.go b/model/modelpb/host_vtproto.pb.go index 3935d87b..ca2105cb 100644 --- a/model/modelpb/host_vtproto.pb.go +++ b/model/modelpb/host_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -156,6 +157,28 @@ func (m *Host) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Host = sync.Pool{ + New: func() interface{} { + return &Host{} + }, +} + +func (m *Host) ResetVT() { + m.Os.ReturnToVTPool() + for _, mm := range m.Ip { + mm.ResetVT() + } + m.Reset() +} +func (m *Host) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Host.Put(m) + } +} +func HostFromVTPool() *Host { + return vtprotoPool_Host.Get().(*Host) +} func (m *Host) SizeVT() (n int) { if m == nil { return 0 @@ -255,7 +278,7 @@ func (m *Host) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Os == nil { - m.Os = &OS{} + m.Os = OSFromVTPool() } if err := m.Os.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -450,7 +473,14 @@ func (m *Host) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Ip = append(m.Ip, &IP{}) + if len(m.Ip) == cap(m.Ip) { + m.Ip = append(m.Ip, &IP{}) + } else { + m.Ip = m.Ip[:len(m.Ip)+1] + if m.Ip[len(m.Ip)-1] == nil { + m.Ip[len(m.Ip)-1] = &IP{} + } + } if err := m.Ip[len(m.Ip)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } diff --git a/model/modelpb/http.pb.go b/model/modelpb/http.pb.go index a2c854cd..c7f522a5 100644 --- a/model/modelpb/http.pb.go +++ b/model/modelpb/http.pb.go @@ -205,10 +205,10 @@ type HTTPResponse struct { Headers []*HTTPHeader `protobuf:"bytes,1,rep,name=headers,proto3" json:"headers,omitempty"` Finished *bool `protobuf:"varint,2,opt,name=finished,proto3,oneof" json:"finished,omitempty"` HeadersSent *bool `protobuf:"varint,3,opt,name=headers_sent,json=headersSent,proto3,oneof" json:"headers_sent,omitempty"` - TransferSize *int64 `protobuf:"varint,4,opt,name=transfer_size,json=transferSize,proto3,oneof" json:"transfer_size,omitempty"` - EncodedBodySize *int64 `protobuf:"varint,5,opt,name=encoded_body_size,json=encodedBodySize,proto3,oneof" json:"encoded_body_size,omitempty"` - DecodedBodySize *int64 `protobuf:"varint,6,opt,name=decoded_body_size,json=decodedBodySize,proto3,oneof" json:"decoded_body_size,omitempty"` - StatusCode int32 `protobuf:"varint,7,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` + TransferSize *uint64 `protobuf:"varint,4,opt,name=transfer_size,json=transferSize,proto3,oneof" json:"transfer_size,omitempty"` + EncodedBodySize *uint64 `protobuf:"varint,5,opt,name=encoded_body_size,json=encodedBodySize,proto3,oneof" json:"encoded_body_size,omitempty"` + DecodedBodySize *uint64 `protobuf:"varint,6,opt,name=decoded_body_size,json=decodedBodySize,proto3,oneof" json:"decoded_body_size,omitempty"` + StatusCode uint32 `protobuf:"varint,7,opt,name=status_code,json=statusCode,proto3" json:"status_code,omitempty"` } func (x *HTTPResponse) Reset() { @@ -264,28 +264,28 @@ func (x *HTTPResponse) GetHeadersSent() bool { return false } -func (x *HTTPResponse) GetTransferSize() int64 { +func (x *HTTPResponse) GetTransferSize() uint64 { if x != nil && x.TransferSize != nil { return *x.TransferSize } return 0 } -func (x *HTTPResponse) GetEncodedBodySize() int64 { +func (x *HTTPResponse) GetEncodedBodySize() uint64 { if x != nil && x.EncodedBodySize != nil { return *x.EncodedBodySize } return 0 } -func (x *HTTPResponse) GetDecodedBodySize() int64 { +func (x *HTTPResponse) GetDecodedBodySize() uint64 { if x != nil && x.DecodedBodySize != nil { return *x.DecodedBodySize } return 0 } -func (x *HTTPResponse) GetStatusCode() int32 { +func (x *HTTPResponse) GetStatusCode() uint32 { if x != nil { return x.StatusCode } @@ -337,16 +337,16 @@ var file_http_proto_rawDesc = []byte{ 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x5f, 0x73, 0x65, 0x6e, 0x74, 0x18, 0x03, 0x20, 0x01, 0x28, 0x08, 0x48, 0x01, 0x52, 0x0b, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x53, 0x65, 0x6e, 0x74, 0x88, 0x01, 0x01, 0x12, 0x28, 0x0a, 0x0d, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x5f, - 0x73, 0x69, 0x7a, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x48, 0x02, 0x52, 0x0c, 0x74, 0x72, + 0x73, 0x69, 0x7a, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x48, 0x02, 0x52, 0x0c, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x53, 0x69, 0x7a, 0x65, 0x88, 0x01, 0x01, 0x12, 0x2f, 0x0a, 0x11, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x5f, 0x62, 0x6f, 0x64, 0x79, 0x5f, 0x73, 0x69, - 0x7a, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x03, 0x48, 0x03, 0x52, 0x0f, 0x65, 0x6e, 0x63, 0x6f, + 0x7a, 0x65, 0x18, 0x05, 0x20, 0x01, 0x28, 0x04, 0x48, 0x03, 0x52, 0x0f, 0x65, 0x6e, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x42, 0x6f, 0x64, 0x79, 0x53, 0x69, 0x7a, 0x65, 0x88, 0x01, 0x01, 0x12, 0x2f, 0x0a, 0x11, 0x64, 0x65, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x5f, 0x62, 0x6f, 0x64, 0x79, 0x5f, 0x73, - 0x69, 0x7a, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x03, 0x48, 0x04, 0x52, 0x0f, 0x64, 0x65, 0x63, + 0x69, 0x7a, 0x65, 0x18, 0x06, 0x20, 0x01, 0x28, 0x04, 0x48, 0x04, 0x52, 0x0f, 0x64, 0x65, 0x63, 0x6f, 0x64, 0x65, 0x64, 0x42, 0x6f, 0x64, 0x79, 0x53, 0x69, 0x7a, 0x65, 0x88, 0x01, 0x01, 0x12, 0x1f, 0x0a, 0x0b, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x5f, 0x63, 0x6f, 0x64, 0x65, 0x18, 0x07, - 0x20, 0x01, 0x28, 0x05, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, + 0x20, 0x01, 0x28, 0x0d, 0x52, 0x0a, 0x73, 0x74, 0x61, 0x74, 0x75, 0x73, 0x43, 0x6f, 0x64, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x5f, 0x66, 0x69, 0x6e, 0x69, 0x73, 0x68, 0x65, 0x64, 0x42, 0x0f, 0x0a, 0x0d, 0x5f, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x5f, 0x73, 0x65, 0x6e, 0x74, 0x42, 0x10, 0x0a, 0x0e, 0x5f, 0x74, 0x72, 0x61, 0x6e, 0x73, 0x66, 0x65, 0x72, 0x5f, 0x73, 0x69, 0x7a, 0x65, diff --git a/model/modelpb/http_vtproto.pb.go b/model/modelpb/http_vtproto.pb.go index cda6b446..f00dc9ff 100644 --- a/model/modelpb/http_vtproto.pb.go +++ b/model/modelpb/http_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -407,6 +408,76 @@ func (m *HTTPResponse) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_HTTP = sync.Pool{ + New: func() interface{} { + return &HTTP{} + }, +} + +func (m *HTTP) ResetVT() { + m.Request.ReturnToVTPool() + m.Response.ReturnToVTPool() + m.Reset() +} +func (m *HTTP) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_HTTP.Put(m) + } +} +func HTTPFromVTPool() *HTTP { + return vtprotoPool_HTTP.Get().(*HTTP) +} + +var vtprotoPool_HTTPRequest = sync.Pool{ + New: func() interface{} { + return &HTTPRequest{} + }, +} + +func (m *HTTPRequest) ResetVT() { + for _, mm := range m.Headers { + mm.ResetVT() + } + for _, mm := range m.Env { + mm.ResetVT() + } + for _, mm := range m.Cookies { + mm.ResetVT() + } + m.Reset() +} +func (m *HTTPRequest) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_HTTPRequest.Put(m) + } +} +func HTTPRequestFromVTPool() *HTTPRequest { + return vtprotoPool_HTTPRequest.Get().(*HTTPRequest) +} + +var vtprotoPool_HTTPResponse = sync.Pool{ + New: func() interface{} { + return &HTTPResponse{} + }, +} + +func (m *HTTPResponse) ResetVT() { + for _, mm := range m.Headers { + mm.ResetVT() + } + m.Reset() +} +func (m *HTTPResponse) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_HTTPResponse.Put(m) + } +} +func HTTPResponseFromVTPool() *HTTPResponse { + return vtprotoPool_HTTPResponse.Get().(*HTTPResponse) +} func (m *HTTP) SizeVT() (n int) { if m == nil { return 0 @@ -572,7 +643,7 @@ func (m *HTTP) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Request == nil { - m.Request = &HTTPRequest{} + m.Request = HTTPRequestFromVTPool() } if err := m.Request.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -608,7 +679,7 @@ func (m *HTTP) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Response == nil { - m.Response = &HTTPResponse{} + m.Response = HTTPResponseFromVTPool() } if err := m.Response.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -770,7 +841,14 @@ func (m *HTTPRequest) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Headers = append(m.Headers, &HTTPHeader{}) + if len(m.Headers) == cap(m.Headers) { + m.Headers = append(m.Headers, &HTTPHeader{}) + } else { + m.Headers = m.Headers[:len(m.Headers)+1] + if m.Headers[len(m.Headers)-1] == nil { + m.Headers[len(m.Headers)-1] = &HTTPHeader{} + } + } if err := m.Headers[len(m.Headers)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -804,7 +882,14 @@ func (m *HTTPRequest) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Env = append(m.Env, &KeyValue{}) + if len(m.Env) == cap(m.Env) { + m.Env = append(m.Env, &KeyValue{}) + } else { + m.Env = m.Env[:len(m.Env)+1] + if m.Env[len(m.Env)-1] == nil { + m.Env[len(m.Env)-1] = &KeyValue{} + } + } if err := m.Env[len(m.Env)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -838,7 +923,14 @@ func (m *HTTPRequest) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Cookies = append(m.Cookies, &KeyValue{}) + if len(m.Cookies) == cap(m.Cookies) { + m.Cookies = append(m.Cookies, &KeyValue{}) + } else { + m.Cookies = m.Cookies[:len(m.Cookies)+1] + if m.Cookies[len(m.Cookies)-1] == nil { + m.Cookies[len(m.Cookies)-1] = &KeyValue{} + } + } if err := m.Cookies[len(m.Cookies)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1019,7 +1111,14 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Headers = append(m.Headers, &HTTPHeader{}) + if len(m.Headers) == cap(m.Headers) { + m.Headers = append(m.Headers, &HTTPHeader{}) + } else { + m.Headers = m.Headers[:len(m.Headers)+1] + if m.Headers[len(m.Headers)-1] == nil { + m.Headers[len(m.Headers)-1] = &HTTPHeader{} + } + } if err := m.Headers[len(m.Headers)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1070,7 +1169,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field TransferSize", wireType) } - var v int64 + var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflow @@ -1080,7 +1179,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1090,7 +1189,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field EncodedBodySize", wireType) } - var v int64 + var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflow @@ -1100,7 +1199,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1110,7 +1209,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field DecodedBodySize", wireType) } - var v int64 + var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflow @@ -1120,7 +1219,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1140,7 +1239,7 @@ func (m *HTTPResponse) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.StatusCode |= int32(b&0x7F) << shift + m.StatusCode |= uint32(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/ip_vtproto.pb.go b/model/modelpb/ip_vtproto.pb.go index 41123238..cafb37ad 100644 --- a/model/modelpb/ip_vtproto.pb.go +++ b/model/modelpb/ip_vtproto.pb.go @@ -25,6 +25,7 @@ import ( binary "encoding/binary" fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -106,6 +107,26 @@ func (m *IP) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_IP = sync.Pool{ + New: func() interface{} { + return &IP{} + }, +} + +func (m *IP) ResetVT() { + f0 := m.V6[:0] + m.Reset() + m.V6 = f0 +} +func (m *IP) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_IP.Put(m) + } +} +func IPFromVTPool() *IP { + return vtprotoPool_IP.Get().(*IP) +} func (m *IP) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/keyvalue_vtproto.pb.go b/model/modelpb/keyvalue_vtproto.pb.go index ea1463cc..b4860159 100644 --- a/model/modelpb/keyvalue_vtproto.pb.go +++ b/model/modelpb/keyvalue_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -124,6 +125,24 @@ func (m *KeyValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_KeyValue = sync.Pool{ + New: func() interface{} { + return &KeyValue{} + }, +} + +func (m *KeyValue) ResetVT() { + m.Reset() +} +func (m *KeyValue) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_KeyValue.Put(m) + } +} +func KeyValueFromVTPool() *KeyValue { + return vtprotoPool_KeyValue.Get().(*KeyValue) +} func (m *KeyValue) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/kubernetes_vtproto.pb.go b/model/modelpb/kubernetes_vtproto.pb.go index cac82257..62a721e0 100644 --- a/model/modelpb/kubernetes_vtproto.pb.go +++ b/model/modelpb/kubernetes_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -118,6 +119,24 @@ func (m *Kubernetes) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Kubernetes = sync.Pool{ + New: func() interface{} { + return &Kubernetes{} + }, +} + +func (m *Kubernetes) ResetVT() { + m.Reset() +} +func (m *Kubernetes) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Kubernetes.Put(m) + } +} +func KubernetesFromVTPool() *Kubernetes { + return vtprotoPool_Kubernetes.Get().(*Kubernetes) +} func (m *Kubernetes) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/labels_vtproto.pb.go b/model/modelpb/labels_vtproto.pb.go index cccd298c..1e22eae2 100644 --- a/model/modelpb/labels_vtproto.pb.go +++ b/model/modelpb/labels_vtproto.pb.go @@ -26,6 +26,7 @@ import ( fmt "fmt" io "io" math "math" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -204,6 +205,47 @@ func (m *NumericLabelValue) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_LabelValue = sync.Pool{ + New: func() interface{} { + return &LabelValue{} + }, +} + +func (m *LabelValue) ResetVT() { + f0 := m.Values[:0] + m.Reset() + m.Values = f0 +} +func (m *LabelValue) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_LabelValue.Put(m) + } +} +func LabelValueFromVTPool() *LabelValue { + return vtprotoPool_LabelValue.Get().(*LabelValue) +} + +var vtprotoPool_NumericLabelValue = sync.Pool{ + New: func() interface{} { + return &NumericLabelValue{} + }, +} + +func (m *NumericLabelValue) ResetVT() { + f0 := m.Values[:0] + m.Reset() + m.Values = f0 +} +func (m *NumericLabelValue) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_NumericLabelValue.Put(m) + } +} +func NumericLabelValueFromVTPool() *NumericLabelValue { + return vtprotoPool_NumericLabelValue.Get().(*NumericLabelValue) +} func (m *LabelValue) SizeVT() (n int) { if m == nil { return 0 @@ -448,7 +490,7 @@ func (m *NumericLabelValue) UnmarshalVT(dAtA []byte) error { } var elementCount int elementCount = packedLen / 8 - if elementCount != 0 && len(m.Values) == 0 { + if elementCount != 0 && len(m.Values) == 0 && cap(m.Values) < elementCount { m.Values = make([]float64, 0, elementCount) } for iNdEx < postIndex { diff --git a/model/modelpb/log.pb.go b/model/modelpb/log.pb.go index 60644f9e..fb643556 100644 --- a/model/modelpb/log.pb.go +++ b/model/modelpb/log.pb.go @@ -162,7 +162,7 @@ type LogOriginFile struct { unknownFields protoimpl.UnknownFields Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Line int32 `protobuf:"varint,2,opt,name=line,proto3" json:"line,omitempty"` + Line uint32 `protobuf:"varint,2,opt,name=line,proto3" json:"line,omitempty"` } func (x *LogOriginFile) Reset() { @@ -204,7 +204,7 @@ func (x *LogOriginFile) GetName() string { return "" } -func (x *LogOriginFile) GetLine() int32 { +func (x *LogOriginFile) GetLine() uint32 { if x != nil { return x.Line } @@ -231,7 +231,7 @@ var file_log_proto_rawDesc = []byte{ 0x6c, 0x65, 0x52, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x22, 0x37, 0x0a, 0x0d, 0x4c, 0x6f, 0x67, 0x4f, 0x72, 0x69, 0x67, 0x69, 0x6e, 0x46, 0x69, 0x6c, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x12, 0x0a, - 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x04, 0x6c, 0x69, 0x6e, + 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x04, 0x6c, 0x69, 0x6e, 0x65, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x6c, 0x61, 0x73, 0x74, 0x69, 0x63, 0x2f, 0x61, 0x70, 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x70, 0x62, 0x62, 0x06, diff --git a/model/modelpb/log_vtproto.pb.go b/model/modelpb/log_vtproto.pb.go index 3b3bb5d9..c100614a 100644 --- a/model/modelpb/log_vtproto.pb.go +++ b/model/modelpb/log_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -246,6 +247,64 @@ func (m *LogOriginFile) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Log = sync.Pool{ + New: func() interface{} { + return &Log{} + }, +} + +func (m *Log) ResetVT() { + m.Origin.ReturnToVTPool() + m.Reset() +} +func (m *Log) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Log.Put(m) + } +} +func LogFromVTPool() *Log { + return vtprotoPool_Log.Get().(*Log) +} + +var vtprotoPool_LogOrigin = sync.Pool{ + New: func() interface{} { + return &LogOrigin{} + }, +} + +func (m *LogOrigin) ResetVT() { + m.File.ReturnToVTPool() + m.Reset() +} +func (m *LogOrigin) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_LogOrigin.Put(m) + } +} +func LogOriginFromVTPool() *LogOrigin { + return vtprotoPool_LogOrigin.Get().(*LogOrigin) +} + +var vtprotoPool_LogOriginFile = sync.Pool{ + New: func() interface{} { + return &LogOriginFile{} + }, +} + +func (m *LogOriginFile) ResetVT() { + m.Reset() +} +func (m *LogOriginFile) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_LogOriginFile.Put(m) + } +} +func LogOriginFileFromVTPool() *LogOriginFile { + return vtprotoPool_LogOriginFile.Get().(*LogOriginFile) +} func (m *Log) SizeVT() (n int) { if m == nil { return 0 @@ -426,7 +485,7 @@ func (m *Log) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Origin == nil { - m.Origin = &LogOrigin{} + m.Origin = LogOriginFromVTPool() } if err := m.Origin.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -545,7 +604,7 @@ func (m *LogOrigin) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.File == nil { - m.File = &LogOriginFile{} + m.File = LogOriginFileFromVTPool() } if err := m.File.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -648,7 +707,7 @@ func (m *LogOriginFile) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Line |= int32(b&0x7F) << shift + m.Line |= uint32(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/message.pb.go b/model/modelpb/message.pb.go index f9a5f340..b6a81fb8 100644 --- a/model/modelpb/message.pb.go +++ b/model/modelpb/message.pb.go @@ -45,7 +45,7 @@ type Message struct { Body string `protobuf:"bytes,1,opt,name=body,proto3" json:"body,omitempty"` Headers []*HTTPHeader `protobuf:"bytes,2,rep,name=headers,proto3" json:"headers,omitempty"` - AgeMillis *int64 `protobuf:"varint,3,opt,name=age_millis,json=ageMillis,proto3,oneof" json:"age_millis,omitempty"` + AgeMillis *uint64 `protobuf:"varint,3,opt,name=age_millis,json=ageMillis,proto3,oneof" json:"age_millis,omitempty"` QueueName string `protobuf:"bytes,4,opt,name=queue_name,json=queueName,proto3" json:"queue_name,omitempty"` RoutingKey string `protobuf:"bytes,5,opt,name=routing_key,json=routingKey,proto3" json:"routing_key,omitempty"` } @@ -96,7 +96,7 @@ func (x *Message) GetHeaders() []*HTTPHeader { return nil } -func (x *Message) GetAgeMillis() int64 { +func (x *Message) GetAgeMillis() uint64 { if x != nil && x.AgeMillis != nil { return *x.AgeMillis } @@ -129,7 +129,7 @@ var file_message_proto_rawDesc = []byte{ 0x1a, 0x2e, 0x65, 0x6c, 0x61, 0x73, 0x74, 0x69, 0x63, 0x2e, 0x61, 0x70, 0x6d, 0x2e, 0x76, 0x31, 0x2e, 0x48, 0x54, 0x54, 0x50, 0x48, 0x65, 0x61, 0x64, 0x65, 0x72, 0x52, 0x07, 0x68, 0x65, 0x61, 0x64, 0x65, 0x72, 0x73, 0x12, 0x22, 0x0a, 0x0a, 0x61, 0x67, 0x65, 0x5f, 0x6d, 0x69, 0x6c, 0x6c, - 0x69, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x03, 0x48, 0x00, 0x52, 0x09, 0x61, 0x67, 0x65, 0x4d, + 0x69, 0x73, 0x18, 0x03, 0x20, 0x01, 0x28, 0x04, 0x48, 0x00, 0x52, 0x09, 0x61, 0x67, 0x65, 0x4d, 0x69, 0x6c, 0x6c, 0x69, 0x73, 0x88, 0x01, 0x01, 0x12, 0x1d, 0x0a, 0x0a, 0x71, 0x75, 0x65, 0x75, 0x65, 0x5f, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x71, 0x75, 0x65, 0x75, 0x65, 0x4e, 0x61, 0x6d, 0x65, 0x12, 0x1f, 0x0a, 0x0b, 0x72, 0x6f, 0x75, 0x74, 0x69, diff --git a/model/modelpb/message_vtproto.pb.go b/model/modelpb/message_vtproto.pb.go index 0ba80290..ec99c045 100644 --- a/model/modelpb/message_vtproto.pb.go +++ b/model/modelpb/message_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -138,6 +139,27 @@ func (m *Message) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Message = sync.Pool{ + New: func() interface{} { + return &Message{} + }, +} + +func (m *Message) ResetVT() { + for _, mm := range m.Headers { + mm.ResetVT() + } + m.Reset() +} +func (m *Message) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Message.Put(m) + } +} +func MessageFromVTPool() *Message { + return vtprotoPool_Message.Get().(*Message) +} func (m *Message) SizeVT() (n int) { if m == nil { return 0 @@ -259,7 +281,14 @@ func (m *Message) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Headers = append(m.Headers, &HTTPHeader{}) + if len(m.Headers) == cap(m.Headers) { + m.Headers = append(m.Headers, &HTTPHeader{}) + } else { + m.Headers = m.Headers[:len(m.Headers)+1] + if m.Headers[len(m.Headers)-1] == nil { + m.Headers[len(m.Headers)-1] = &HTTPHeader{} + } + } if err := m.Headers[len(m.Headers)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -268,7 +297,7 @@ func (m *Message) UnmarshalVT(dAtA []byte) error { if wireType != 0 { return fmt.Errorf("proto: wrong wireType = %d for field AgeMillis", wireType) } - var v int64 + var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflow @@ -278,7 +307,7 @@ func (m *Message) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/metricset.pb.go b/model/modelpb/metricset.pb.go index d4b9ff18..e33fb7ef 100644 --- a/model/modelpb/metricset.pb.go +++ b/model/modelpb/metricset.pb.go @@ -102,7 +102,7 @@ type Metricset struct { Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` Interval string `protobuf:"bytes,2,opt,name=interval,proto3" json:"interval,omitempty"` Samples []*MetricsetSample `protobuf:"bytes,3,rep,name=samples,proto3" json:"samples,omitempty"` - DocCount int64 `protobuf:"varint,4,opt,name=doc_count,json=docCount,proto3" json:"doc_count,omitempty"` + DocCount uint64 `protobuf:"varint,4,opt,name=doc_count,json=docCount,proto3" json:"doc_count,omitempty"` } func (x *Metricset) Reset() { @@ -158,7 +158,7 @@ func (x *Metricset) GetSamples() []*MetricsetSample { return nil } -func (x *Metricset) GetDocCount() int64 { +func (x *Metricset) GetDocCount() uint64 { if x != nil { return x.DocCount } @@ -258,7 +258,7 @@ type Histogram struct { unknownFields protoimpl.UnknownFields Values []float64 `protobuf:"fixed64,1,rep,packed,name=values,proto3" json:"values,omitempty"` - Counts []int64 `protobuf:"varint,2,rep,packed,name=counts,proto3" json:"counts,omitempty"` + Counts []uint64 `protobuf:"varint,2,rep,packed,name=counts,proto3" json:"counts,omitempty"` } func (x *Histogram) Reset() { @@ -300,7 +300,7 @@ func (x *Histogram) GetValues() []float64 { return nil } -func (x *Histogram) GetCounts() []int64 { +func (x *Histogram) GetCounts() []uint64 { if x != nil { return x.Counts } @@ -312,7 +312,7 @@ type SummaryMetric struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` + Count uint64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` Sum float64 `protobuf:"fixed64,2,opt,name=sum,proto3" json:"sum,omitempty"` } @@ -348,7 +348,7 @@ func (*SummaryMetric) Descriptor() ([]byte, []int) { return file_metricset_proto_rawDescGZIP(), []int{3} } -func (x *SummaryMetric) GetCount() int64 { +func (x *SummaryMetric) GetCount() uint64 { if x != nil { return x.Count } @@ -367,7 +367,7 @@ type AggregatedDuration struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Count int64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` + Count uint64 `protobuf:"varint,1,opt,name=count,proto3" json:"count,omitempty"` Sum *durationpb.Duration `protobuf:"bytes,2,opt,name=sum,proto3" json:"sum,omitempty"` } @@ -403,7 +403,7 @@ func (*AggregatedDuration) Descriptor() ([]byte, []int) { return file_metricset_proto_rawDescGZIP(), []int{4} } -func (x *AggregatedDuration) GetCount() int64 { +func (x *AggregatedDuration) GetCount() uint64 { if x != nil { return x.Count } @@ -432,7 +432,7 @@ var file_metricset_proto_rawDesc = []byte{ 0x32, 0x1f, 0x2e, 0x65, 0x6c, 0x61, 0x73, 0x74, 0x69, 0x63, 0x2e, 0x61, 0x70, 0x6d, 0x2e, 0x76, 0x31, 0x2e, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x65, 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x52, 0x07, 0x73, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x73, 0x12, 0x1b, 0x0a, 0x09, 0x64, 0x6f, - 0x63, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x64, + 0x63, 0x5f, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x18, 0x04, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x64, 0x6f, 0x63, 0x43, 0x6f, 0x75, 0x6e, 0x74, 0x22, 0xf1, 0x01, 0x0a, 0x0f, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x73, 0x65, 0x74, 0x53, 0x61, 0x6d, 0x70, 0x6c, 0x65, 0x12, 0x2e, 0x0a, 0x04, 0x74, 0x79, 0x70, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1a, 0x2e, 0x65, 0x6c, 0x61, 0x73, @@ -451,14 +451,14 @@ var file_metricset_proto_rawDesc = []byte{ 0x20, 0x01, 0x28, 0x01, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x22, 0x3b, 0x0a, 0x09, 0x48, 0x69, 0x73, 0x74, 0x6f, 0x67, 0x72, 0x61, 0x6d, 0x12, 0x16, 0x0a, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x01, 0x52, 0x06, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x73, - 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x03, + 0x12, 0x16, 0x0a, 0x06, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x04, 0x52, 0x06, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x73, 0x22, 0x37, 0x0a, 0x0d, 0x53, 0x75, 0x6d, 0x6d, 0x61, 0x72, 0x79, 0x4d, 0x65, 0x74, 0x72, 0x69, 0x63, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, - 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, + 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x10, 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x01, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x22, 0x57, 0x0a, 0x12, 0x41, 0x67, 0x67, 0x72, 0x65, 0x67, 0x61, 0x74, 0x65, 0x64, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x12, 0x14, 0x0a, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, - 0x18, 0x01, 0x20, 0x01, 0x28, 0x03, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2b, 0x0a, + 0x18, 0x01, 0x20, 0x01, 0x28, 0x04, 0x52, 0x05, 0x63, 0x6f, 0x75, 0x6e, 0x74, 0x12, 0x2b, 0x0a, 0x03, 0x73, 0x75, 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x19, 0x2e, 0x67, 0x6f, 0x6f, 0x67, 0x6c, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x75, 0x66, 0x2e, 0x44, 0x75, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x52, 0x03, 0x73, 0x75, 0x6d, 0x2a, 0x8d, 0x01, 0x0a, 0x0a, 0x4d, diff --git a/model/modelpb/metricset_vtproto.pb.go b/model/modelpb/metricset_vtproto.pb.go index 7fffbccd..9c0e9815 100644 --- a/model/modelpb/metricset_vtproto.pb.go +++ b/model/modelpb/metricset_vtproto.pb.go @@ -26,6 +26,7 @@ import ( fmt "fmt" io "io" math "math" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -100,7 +101,7 @@ func (m *Histogram) CloneVT() *Histogram { r.Values = tmpContainer } if rhs := m.Counts; rhs != nil { - tmpContainer := make([]int64, len(rhs)) + tmpContainer := make([]uint64, len(rhs)) copy(tmpContainer, rhs) r.Counts = tmpContainer } @@ -338,8 +339,7 @@ func (m *Histogram) MarshalToSizedBufferVT(dAtA []byte) (int, error) { } i -= pksize2 j1 := i - for _, num1 := range m.Counts { - num := uint64(num1) + for _, num := range m.Counts { for num >= 1<<7 { dAtA[j1] = uint8(uint64(num)&0x7f | 0x80) num >>= 7 @@ -469,6 +469,109 @@ func (m *AggregatedDuration) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Metricset = sync.Pool{ + New: func() interface{} { + return &Metricset{} + }, +} + +func (m *Metricset) ResetVT() { + for _, mm := range m.Samples { + mm.ResetVT() + } + m.Reset() +} +func (m *Metricset) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Metricset.Put(m) + } +} +func MetricsetFromVTPool() *Metricset { + return vtprotoPool_Metricset.Get().(*Metricset) +} + +var vtprotoPool_MetricsetSample = sync.Pool{ + New: func() interface{} { + return &MetricsetSample{} + }, +} + +func (m *MetricsetSample) ResetVT() { + m.Histogram.ReturnToVTPool() + m.Summary.ReturnToVTPool() + m.Reset() +} +func (m *MetricsetSample) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_MetricsetSample.Put(m) + } +} +func MetricsetSampleFromVTPool() *MetricsetSample { + return vtprotoPool_MetricsetSample.Get().(*MetricsetSample) +} + +var vtprotoPool_Histogram = sync.Pool{ + New: func() interface{} { + return &Histogram{} + }, +} + +func (m *Histogram) ResetVT() { + f0 := m.Values[:0] + f1 := m.Counts[:0] + m.Reset() + m.Values = f0 + m.Counts = f1 +} +func (m *Histogram) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Histogram.Put(m) + } +} +func HistogramFromVTPool() *Histogram { + return vtprotoPool_Histogram.Get().(*Histogram) +} + +var vtprotoPool_SummaryMetric = sync.Pool{ + New: func() interface{} { + return &SummaryMetric{} + }, +} + +func (m *SummaryMetric) ResetVT() { + m.Reset() +} +func (m *SummaryMetric) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_SummaryMetric.Put(m) + } +} +func SummaryMetricFromVTPool() *SummaryMetric { + return vtprotoPool_SummaryMetric.Get().(*SummaryMetric) +} + +var vtprotoPool_AggregatedDuration = sync.Pool{ + New: func() interface{} { + return &AggregatedDuration{} + }, +} + +func (m *AggregatedDuration) ResetVT() { + m.Reset() +} +func (m *AggregatedDuration) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_AggregatedDuration.Put(m) + } +} +func AggregatedDurationFromVTPool() *AggregatedDuration { + return vtprotoPool_AggregatedDuration.Get().(*AggregatedDuration) +} func (m *Metricset) SizeVT() (n int) { if m == nil { return 0 @@ -709,7 +812,14 @@ func (m *Metricset) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Samples = append(m.Samples, &MetricsetSample{}) + if len(m.Samples) == cap(m.Samples) { + m.Samples = append(m.Samples, &MetricsetSample{}) + } else { + m.Samples = m.Samples[:len(m.Samples)+1] + if m.Samples[len(m.Samples)-1] == nil { + m.Samples[len(m.Samples)-1] = &MetricsetSample{} + } + } if err := m.Samples[len(m.Samples)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -728,7 +838,7 @@ func (m *Metricset) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.DocCount |= int64(b&0x7F) << shift + m.DocCount |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -897,7 +1007,7 @@ func (m *MetricsetSample) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Histogram == nil { - m.Histogram = &Histogram{} + m.Histogram = HistogramFromVTPool() } if err := m.Histogram.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -933,7 +1043,7 @@ func (m *MetricsetSample) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Summary == nil { - m.Summary = &SummaryMetric{} + m.Summary = SummaryMetricFromVTPool() } if err := m.Summary.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1039,7 +1149,7 @@ func (m *Histogram) UnmarshalVT(dAtA []byte) error { } var elementCount int elementCount = packedLen / 8 - if elementCount != 0 && len(m.Values) == 0 { + if elementCount != 0 && len(m.Values) == 0 && cap(m.Values) < elementCount { m.Values = make([]float64, 0, elementCount) } for iNdEx < postIndex { @@ -1057,7 +1167,7 @@ func (m *Histogram) UnmarshalVT(dAtA []byte) error { } case 2: if wireType == 0 { - var v int64 + var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflow @@ -1067,7 +1177,7 @@ func (m *Histogram) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1107,11 +1217,11 @@ func (m *Histogram) UnmarshalVT(dAtA []byte) error { } } elementCount = count - if elementCount != 0 && len(m.Counts) == 0 { - m.Counts = make([]int64, 0, elementCount) + if elementCount != 0 && len(m.Counts) == 0 && cap(m.Counts) < elementCount { + m.Counts = make([]uint64, 0, elementCount) } for iNdEx < postIndex { - var v int64 + var v uint64 for shift := uint(0); ; shift += 7 { if shift >= 64 { return ErrIntOverflow @@ -1121,7 +1231,7 @@ func (m *Histogram) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - v |= int64(b&0x7F) << shift + v |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1196,7 +1306,7 @@ func (m *SummaryMetric) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Count |= int64(b&0x7F) << shift + m.Count |= uint64(b&0x7F) << shift if b < 0x80 { break } @@ -1277,7 +1387,7 @@ func (m *AggregatedDuration) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Count |= int64(b&0x7F) << shift + m.Count |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/network_vtproto.pb.go b/model/modelpb/network_vtproto.pb.go index 7fc83931..dfe4def5 100644 --- a/model/modelpb/network_vtproto.pb.go +++ b/model/modelpb/network_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -256,6 +257,64 @@ func (m *NetworkCarrier) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Network = sync.Pool{ + New: func() interface{} { + return &Network{} + }, +} + +func (m *Network) ResetVT() { + m.Connection.ReturnToVTPool() + m.Carrier.ReturnToVTPool() + m.Reset() +} +func (m *Network) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Network.Put(m) + } +} +func NetworkFromVTPool() *Network { + return vtprotoPool_Network.Get().(*Network) +} + +var vtprotoPool_NetworkConnection = sync.Pool{ + New: func() interface{} { + return &NetworkConnection{} + }, +} + +func (m *NetworkConnection) ResetVT() { + m.Reset() +} +func (m *NetworkConnection) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_NetworkConnection.Put(m) + } +} +func NetworkConnectionFromVTPool() *NetworkConnection { + return vtprotoPool_NetworkConnection.Get().(*NetworkConnection) +} + +var vtprotoPool_NetworkCarrier = sync.Pool{ + New: func() interface{} { + return &NetworkCarrier{} + }, +} + +func (m *NetworkCarrier) ResetVT() { + m.Reset() +} +func (m *NetworkCarrier) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_NetworkCarrier.Put(m) + } +} +func NetworkCarrierFromVTPool() *NetworkCarrier { + return vtprotoPool_NetworkCarrier.Get().(*NetworkCarrier) +} func (m *Network) SizeVT() (n int) { if m == nil { return 0 @@ -377,7 +436,7 @@ func (m *Network) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Connection == nil { - m.Connection = &NetworkConnection{} + m.Connection = NetworkConnectionFromVTPool() } if err := m.Connection.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -413,7 +472,7 @@ func (m *Network) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Carrier == nil { - m.Carrier = &NetworkCarrier{} + m.Carrier = NetworkCarrierFromVTPool() } if err := m.Carrier.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/observer_vtproto.pb.go b/model/modelpb/observer_vtproto.pb.go index 88933a07..67cb3e6b 100644 --- a/model/modelpb/observer_vtproto.pb.go +++ b/model/modelpb/observer_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -118,6 +119,24 @@ func (m *Observer) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Observer = sync.Pool{ + New: func() interface{} { + return &Observer{} + }, +} + +func (m *Observer) ResetVT() { + m.Reset() +} +func (m *Observer) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Observer.Put(m) + } +} +func ObserverFromVTPool() *Observer { + return vtprotoPool_Observer.Get().(*Observer) +} func (m *Observer) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/os_vtproto.pb.go b/model/modelpb/os_vtproto.pb.go index aa63ee31..a7a177ad 100644 --- a/model/modelpb/os_vtproto.pb.go +++ b/model/modelpb/os_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -126,6 +127,24 @@ func (m *OS) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_OS = sync.Pool{ + New: func() interface{} { + return &OS{} + }, +} + +func (m *OS) ResetVT() { + m.Reset() +} +func (m *OS) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_OS.Put(m) + } +} +func OSFromVTPool() *OS { + return vtprotoPool_OS.Get().(*OS) +} func (m *OS) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/process.pb.go b/model/modelpb/process.pb.go index 5053f3f9..b16fec29 100644 --- a/model/modelpb/process.pb.go +++ b/model/modelpb/process.pb.go @@ -139,7 +139,7 @@ type ProcessThread struct { unknownFields protoimpl.UnknownFields Name string `protobuf:"bytes,1,opt,name=name,proto3" json:"name,omitempty"` - Id int32 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` + Id uint32 `protobuf:"varint,2,opt,name=id,proto3" json:"id,omitempty"` } func (x *ProcessThread) Reset() { @@ -181,7 +181,7 @@ func (x *ProcessThread) GetName() string { return "" } -func (x *ProcessThread) GetId() int32 { +func (x *ProcessThread) GetId() uint32 { if x != nil { return x.Id } @@ -209,7 +209,7 @@ var file_process_proto_rawDesc = []byte{ 0x52, 0x03, 0x70, 0x69, 0x64, 0x22, 0x33, 0x0a, 0x0d, 0x50, 0x72, 0x6f, 0x63, 0x65, 0x73, 0x73, 0x54, 0x68, 0x72, 0x65, 0x61, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, - 0x18, 0x02, 0x20, 0x01, 0x28, 0x05, 0x52, 0x02, 0x69, 0x64, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0d, 0x52, 0x02, 0x69, 0x64, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x6c, 0x61, 0x73, 0x74, 0x69, 0x63, 0x2f, 0x61, 0x70, 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x70, 0x62, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, diff --git a/model/modelpb/process_vtproto.pb.go b/model/modelpb/process_vtproto.pb.go index 4e65c711..4d5e40bf 100644 --- a/model/modelpb/process_vtproto.pb.go +++ b/model/modelpb/process_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -211,6 +212,46 @@ func (m *ProcessThread) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Process = sync.Pool{ + New: func() interface{} { + return &Process{} + }, +} + +func (m *Process) ResetVT() { + m.Thread.ReturnToVTPool() + f0 := m.Argv[:0] + m.Reset() + m.Argv = f0 +} +func (m *Process) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Process.Put(m) + } +} +func ProcessFromVTPool() *Process { + return vtprotoPool_Process.Get().(*Process) +} + +var vtprotoPool_ProcessThread = sync.Pool{ + New: func() interface{} { + return &ProcessThread{} + }, +} + +func (m *ProcessThread) ResetVT() { + m.Reset() +} +func (m *ProcessThread) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_ProcessThread.Put(m) + } +} +func ProcessThreadFromVTPool() *ProcessThread { + return vtprotoPool_ProcessThread.Get().(*ProcessThread) +} func (m *Process) SizeVT() (n int) { if m == nil { return 0 @@ -344,7 +385,7 @@ func (m *Process) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Thread == nil { - m.Thread = &ProcessThread{} + m.Thread = ProcessThreadFromVTPool() } if err := m.Thread.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -594,7 +635,7 @@ func (m *ProcessThread) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Id |= int32(b&0x7F) << shift + m.Id |= uint32(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/service_vtproto.pb.go b/model/modelpb/service_vtproto.pb.go index aa228e79..8728172a 100644 --- a/model/modelpb/service_vtproto.pb.go +++ b/model/modelpb/service_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -572,6 +573,144 @@ func (m *ServiceNode) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Service = sync.Pool{ + New: func() interface{} { + return &Service{} + }, +} + +func (m *Service) ResetVT() { + m.Origin.ReturnToVTPool() + m.Target.ReturnToVTPool() + m.Language.ReturnToVTPool() + m.Runtime.ReturnToVTPool() + m.Framework.ReturnToVTPool() + m.Node.ReturnToVTPool() + m.Reset() +} +func (m *Service) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Service.Put(m) + } +} +func ServiceFromVTPool() *Service { + return vtprotoPool_Service.Get().(*Service) +} + +var vtprotoPool_ServiceOrigin = sync.Pool{ + New: func() interface{} { + return &ServiceOrigin{} + }, +} + +func (m *ServiceOrigin) ResetVT() { + m.Reset() +} +func (m *ServiceOrigin) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_ServiceOrigin.Put(m) + } +} +func ServiceOriginFromVTPool() *ServiceOrigin { + return vtprotoPool_ServiceOrigin.Get().(*ServiceOrigin) +} + +var vtprotoPool_ServiceTarget = sync.Pool{ + New: func() interface{} { + return &ServiceTarget{} + }, +} + +func (m *ServiceTarget) ResetVT() { + m.Reset() +} +func (m *ServiceTarget) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_ServiceTarget.Put(m) + } +} +func ServiceTargetFromVTPool() *ServiceTarget { + return vtprotoPool_ServiceTarget.Get().(*ServiceTarget) +} + +var vtprotoPool_Language = sync.Pool{ + New: func() interface{} { + return &Language{} + }, +} + +func (m *Language) ResetVT() { + m.Reset() +} +func (m *Language) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Language.Put(m) + } +} +func LanguageFromVTPool() *Language { + return vtprotoPool_Language.Get().(*Language) +} + +var vtprotoPool_Runtime = sync.Pool{ + New: func() interface{} { + return &Runtime{} + }, +} + +func (m *Runtime) ResetVT() { + m.Reset() +} +func (m *Runtime) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Runtime.Put(m) + } +} +func RuntimeFromVTPool() *Runtime { + return vtprotoPool_Runtime.Get().(*Runtime) +} + +var vtprotoPool_Framework = sync.Pool{ + New: func() interface{} { + return &Framework{} + }, +} + +func (m *Framework) ResetVT() { + m.Reset() +} +func (m *Framework) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Framework.Put(m) + } +} +func FrameworkFromVTPool() *Framework { + return vtprotoPool_Framework.Get().(*Framework) +} + +var vtprotoPool_ServiceNode = sync.Pool{ + New: func() interface{} { + return &ServiceNode{} + }, +} + +func (m *ServiceNode) ResetVT() { + m.Reset() +} +func (m *ServiceNode) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_ServiceNode.Put(m) + } +} +func ServiceNodeFromVTPool() *ServiceNode { + return vtprotoPool_ServiceNode.Get().(*ServiceNode) +} func (m *Service) SizeVT() (n int) { if m == nil { return 0 @@ -785,7 +924,7 @@ func (m *Service) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Origin == nil { - m.Origin = &ServiceOrigin{} + m.Origin = ServiceOriginFromVTPool() } if err := m.Origin.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -821,7 +960,7 @@ func (m *Service) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Target == nil { - m.Target = &ServiceTarget{} + m.Target = ServiceTargetFromVTPool() } if err := m.Target.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -857,7 +996,7 @@ func (m *Service) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Language == nil { - m.Language = &Language{} + m.Language = LanguageFromVTPool() } if err := m.Language.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -893,7 +1032,7 @@ func (m *Service) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Runtime == nil { - m.Runtime = &Runtime{} + m.Runtime = RuntimeFromVTPool() } if err := m.Runtime.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -929,7 +1068,7 @@ func (m *Service) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Framework == nil { - m.Framework = &Framework{} + m.Framework = FrameworkFromVTPool() } if err := m.Framework.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1061,7 +1200,7 @@ func (m *Service) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Node == nil { - m.Node = &ServiceNode{} + m.Node = ServiceNodeFromVTPool() } if err := m.Node.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/session.pb.go b/model/modelpb/session.pb.go index 4470f230..52c2b94b 100644 --- a/model/modelpb/session.pb.go +++ b/model/modelpb/session.pb.go @@ -44,7 +44,7 @@ type Session struct { unknownFields protoimpl.UnknownFields Id string `protobuf:"bytes,1,opt,name=id,proto3" json:"id,omitempty"` - Sequence int64 `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"` + Sequence uint64 `protobuf:"varint,2,opt,name=sequence,proto3" json:"sequence,omitempty"` } func (x *Session) Reset() { @@ -86,7 +86,7 @@ func (x *Session) GetId() string { return "" } -func (x *Session) GetSequence() int64 { +func (x *Session) GetSequence() uint64 { if x != nil { return x.Sequence } @@ -100,7 +100,7 @@ var file_session_proto_rawDesc = []byte{ 0x0e, 0x65, 0x6c, 0x61, 0x73, 0x74, 0x69, 0x63, 0x2e, 0x61, 0x70, 0x6d, 0x2e, 0x76, 0x31, 0x22, 0x35, 0x0a, 0x07, 0x53, 0x65, 0x73, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x0e, 0x0a, 0x02, 0x69, 0x64, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x02, 0x69, 0x64, 0x12, 0x1a, 0x0a, 0x08, 0x73, 0x65, - 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x03, 0x52, 0x08, 0x73, 0x65, + 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x04, 0x52, 0x08, 0x73, 0x65, 0x71, 0x75, 0x65, 0x6e, 0x63, 0x65, 0x42, 0x2b, 0x5a, 0x29, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x6c, 0x61, 0x73, 0x74, 0x69, 0x63, 0x2f, 0x61, 0x70, 0x6d, 0x2d, 0x64, 0x61, 0x74, 0x61, 0x2f, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x2f, 0x6d, 0x6f, 0x64, 0x65, diff --git a/model/modelpb/session_vtproto.pb.go b/model/modelpb/session_vtproto.pb.go index 5ec64d3b..bb03cb9d 100644 --- a/model/modelpb/session_vtproto.pb.go +++ b/model/modelpb/session_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -100,6 +101,24 @@ func (m *Session) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Session = sync.Pool{ + New: func() interface{} { + return &Session{} + }, +} + +func (m *Session) ResetVT() { + m.Reset() +} +func (m *Session) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Session.Put(m) + } +} +func SessionFromVTPool() *Session { + return vtprotoPool_Session.Get().(*Session) +} func (m *Session) SizeVT() (n int) { if m == nil { return 0 @@ -192,7 +211,7 @@ func (m *Session) UnmarshalVT(dAtA []byte) error { } b := dAtA[iNdEx] iNdEx++ - m.Sequence |= int64(b&0x7F) << shift + m.Sequence |= uint64(b&0x7F) << shift if b < 0x80 { break } diff --git a/model/modelpb/source_vtproto.pb.go b/model/modelpb/source_vtproto.pb.go index 1756061d..356008bf 100644 --- a/model/modelpb/source_vtproto.pb.go +++ b/model/modelpb/source_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -183,6 +184,46 @@ func (m *NAT) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Source = sync.Pool{ + New: func() interface{} { + return &Source{} + }, +} + +func (m *Source) ResetVT() { + m.Ip.ReturnToVTPool() + m.Nat.ReturnToVTPool() + m.Reset() +} +func (m *Source) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Source.Put(m) + } +} +func SourceFromVTPool() *Source { + return vtprotoPool_Source.Get().(*Source) +} + +var vtprotoPool_NAT = sync.Pool{ + New: func() interface{} { + return &NAT{} + }, +} + +func (m *NAT) ResetVT() { + m.Ip.ReturnToVTPool() + m.Reset() +} +func (m *NAT) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_NAT.Put(m) + } +} +func NATFromVTPool() *NAT { + return vtprotoPool_NAT.Get().(*NAT) +} func (m *Source) SizeVT() (n int) { if m == nil { return 0 @@ -281,7 +322,7 @@ func (m *Source) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Ip == nil { - m.Ip = &IP{} + m.Ip = IPFromVTPool() } if err := m.Ip.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -317,7 +358,7 @@ func (m *Source) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Nat == nil { - m.Nat = &NAT{} + m.Nat = NATFromVTPool() } if err := m.Nat.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -455,7 +496,7 @@ func (m *NAT) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Ip == nil { - m.Ip = &IP{} + m.Ip = IPFromVTPool() } if err := m.Ip.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/span_vtproto.pb.go b/model/modelpb/span_vtproto.pb.go index ff587d35..cd1990a8 100644 --- a/model/modelpb/span_vtproto.pb.go +++ b/model/modelpb/span_vtproto.pb.go @@ -26,6 +26,7 @@ import ( fmt "fmt" io "io" math "math" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -569,6 +570,112 @@ func (m *SpanLink) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Span = sync.Pool{ + New: func() interface{} { + return &Span{} + }, +} + +func (m *Span) ResetVT() { + m.Message.ReturnToVTPool() + m.Composite.ReturnToVTPool() + m.DestinationService.ReturnToVTPool() + m.Db.ReturnToVTPool() + for _, mm := range m.Stacktrace { + mm.ResetVT() + } + for _, mm := range m.Links { + mm.ResetVT() + } + m.SelfTime.ReturnToVTPool() + m.Reset() +} +func (m *Span) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Span.Put(m) + } +} +func SpanFromVTPool() *Span { + return vtprotoPool_Span.Get().(*Span) +} + +var vtprotoPool_DB = sync.Pool{ + New: func() interface{} { + return &DB{} + }, +} + +func (m *DB) ResetVT() { + m.Reset() +} +func (m *DB) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_DB.Put(m) + } +} +func DBFromVTPool() *DB { + return vtprotoPool_DB.Get().(*DB) +} + +var vtprotoPool_DestinationService = sync.Pool{ + New: func() interface{} { + return &DestinationService{} + }, +} + +func (m *DestinationService) ResetVT() { + m.ResponseTime.ReturnToVTPool() + m.Reset() +} +func (m *DestinationService) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_DestinationService.Put(m) + } +} +func DestinationServiceFromVTPool() *DestinationService { + return vtprotoPool_DestinationService.Get().(*DestinationService) +} + +var vtprotoPool_Composite = sync.Pool{ + New: func() interface{} { + return &Composite{} + }, +} + +func (m *Composite) ResetVT() { + m.Reset() +} +func (m *Composite) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Composite.Put(m) + } +} +func CompositeFromVTPool() *Composite { + return vtprotoPool_Composite.Get().(*Composite) +} + +var vtprotoPool_SpanLink = sync.Pool{ + New: func() interface{} { + return &SpanLink{} + }, +} + +func (m *SpanLink) ResetVT() { + m.Reset() +} +func (m *SpanLink) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_SpanLink.Put(m) + } +} +func SpanLinkFromVTPool() *SpanLink { + return vtprotoPool_SpanLink.Get().(*SpanLink) +} func (m *Span) SizeVT() (n int) { if m == nil { return 0 @@ -796,7 +903,7 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Message == nil { - m.Message = &Message{} + m.Message = MessageFromVTPool() } if err := m.Message.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -832,7 +939,7 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Composite == nil { - m.Composite = &Composite{} + m.Composite = CompositeFromVTPool() } if err := m.Composite.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -868,7 +975,7 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.DestinationService == nil { - m.DestinationService = &DestinationService{} + m.DestinationService = DestinationServiceFromVTPool() } if err := m.DestinationService.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -904,7 +1011,7 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Db == nil { - m.Db = &DB{} + m.Db = DBFromVTPool() } if err := m.Db.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1152,7 +1259,14 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Stacktrace = append(m.Stacktrace, &StacktraceFrame{}) + if len(m.Stacktrace) == cap(m.Stacktrace) { + m.Stacktrace = append(m.Stacktrace, &StacktraceFrame{}) + } else { + m.Stacktrace = m.Stacktrace[:len(m.Stacktrace)+1] + if m.Stacktrace[len(m.Stacktrace)-1] == nil { + m.Stacktrace[len(m.Stacktrace)-1] = &StacktraceFrame{} + } + } if err := m.Stacktrace[len(m.Stacktrace)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1186,7 +1300,14 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Links = append(m.Links, &SpanLink{}) + if len(m.Links) == cap(m.Links) { + m.Links = append(m.Links, &SpanLink{}) + } else { + m.Links = m.Links[:len(m.Links)+1] + if m.Links[len(m.Links)-1] == nil { + m.Links[len(m.Links)-1] = &SpanLink{} + } + } if err := m.Links[len(m.Links)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1221,7 +1342,7 @@ func (m *Span) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.SelfTime == nil { - m.SelfTime = &AggregatedDuration{} + m.SelfTime = AggregatedDurationFromVTPool() } if err := m.SelfTime.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1646,7 +1767,7 @@ func (m *DestinationService) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.ResponseTime == nil { - m.ResponseTime = &AggregatedDuration{} + m.ResponseTime = AggregatedDurationFromVTPool() } if err := m.ResponseTime.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/stacktrace_vtproto.pb.go b/model/modelpb/stacktrace_vtproto.pb.go index ae1e3dc8..66bc3c28 100644 --- a/model/modelpb/stacktrace_vtproto.pb.go +++ b/model/modelpb/stacktrace_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -364,6 +365,51 @@ func (m *Original) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_StacktraceFrame = sync.Pool{ + New: func() interface{} { + return &StacktraceFrame{} + }, +} + +func (m *StacktraceFrame) ResetVT() { + for _, mm := range m.Vars { + mm.ResetVT() + } + m.Original.ReturnToVTPool() + f0 := m.PreContext[:0] + f1 := m.PostContext[:0] + m.Reset() + m.PreContext = f0 + m.PostContext = f1 +} +func (m *StacktraceFrame) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_StacktraceFrame.Put(m) + } +} +func StacktraceFrameFromVTPool() *StacktraceFrame { + return vtprotoPool_StacktraceFrame.Get().(*StacktraceFrame) +} + +var vtprotoPool_Original = sync.Pool{ + New: func() interface{} { + return &Original{} + }, +} + +func (m *Original) ResetVT() { + m.Reset() +} +func (m *Original) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Original.Put(m) + } +} +func OriginalFromVTPool() *Original { + return vtprotoPool_Original.Get().(*Original) +} func (m *StacktraceFrame) SizeVT() (n int) { if m == nil { return 0 @@ -532,7 +578,14 @@ func (m *StacktraceFrame) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Vars = append(m.Vars, &KeyValue{}) + if len(m.Vars) == cap(m.Vars) { + m.Vars = append(m.Vars, &KeyValue{}) + } else { + m.Vars = m.Vars[:len(m.Vars)+1] + if m.Vars[len(m.Vars)-1] == nil { + m.Vars[len(m.Vars)-1] = &KeyValue{} + } + } if err := m.Vars[len(m.Vars)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -831,7 +884,7 @@ func (m *StacktraceFrame) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Original == nil { - m.Original = &Original{} + m.Original = OriginalFromVTPool() } if err := m.Original.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/trace_vtproto.pb.go b/model/modelpb/trace_vtproto.pb.go index 31a052ad..6ed871cb 100644 --- a/model/modelpb/trace_vtproto.pb.go +++ b/model/modelpb/trace_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -94,6 +95,24 @@ func (m *Trace) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Trace = sync.Pool{ + New: func() interface{} { + return &Trace{} + }, +} + +func (m *Trace) ResetVT() { + m.Reset() +} +func (m *Trace) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Trace.Put(m) + } +} +func TraceFromVTPool() *Trace { + return vtprotoPool_Trace.Get().(*Trace) +} func (m *Trace) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/transaction_vtproto.pb.go b/model/modelpb/transaction_vtproto.pb.go index ada053b9..eeedffb1 100644 --- a/model/modelpb/transaction_vtproto.pb.go +++ b/model/modelpb/transaction_vtproto.pb.go @@ -26,6 +26,7 @@ import ( fmt "fmt" io "io" math "math" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -505,6 +506,93 @@ func (m *DroppedSpanStats) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_Transaction = sync.Pool{ + New: func() interface{} { + return &Transaction{} + }, +} + +func (m *Transaction) ResetVT() { + m.SpanCount.ReturnToVTPool() + m.UserExperience.ReturnToVTPool() + for _, mm := range m.Custom { + mm.ResetVT() + } + m.Message.ReturnToVTPool() + m.DurationHistogram.ReturnToVTPool() + for _, mm := range m.DroppedSpansStats { + mm.ResetVT() + } + m.DurationSummary.ReturnToVTPool() + m.Reset() +} +func (m *Transaction) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_Transaction.Put(m) + } +} +func TransactionFromVTPool() *Transaction { + return vtprotoPool_Transaction.Get().(*Transaction) +} + +var vtprotoPool_SpanCount = sync.Pool{ + New: func() interface{} { + return &SpanCount{} + }, +} + +func (m *SpanCount) ResetVT() { + m.Reset() +} +func (m *SpanCount) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_SpanCount.Put(m) + } +} +func SpanCountFromVTPool() *SpanCount { + return vtprotoPool_SpanCount.Get().(*SpanCount) +} + +var vtprotoPool_TransactionMark = sync.Pool{ + New: func() interface{} { + return &TransactionMark{} + }, +} + +func (m *TransactionMark) ResetVT() { + m.Reset() +} +func (m *TransactionMark) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_TransactionMark.Put(m) + } +} +func TransactionMarkFromVTPool() *TransactionMark { + return vtprotoPool_TransactionMark.Get().(*TransactionMark) +} + +var vtprotoPool_DroppedSpanStats = sync.Pool{ + New: func() interface{} { + return &DroppedSpanStats{} + }, +} + +func (m *DroppedSpanStats) ResetVT() { + m.Duration.ReturnToVTPool() + m.Reset() +} +func (m *DroppedSpanStats) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_DroppedSpanStats.Put(m) + } +} +func DroppedSpanStatsFromVTPool() *DroppedSpanStats { + return vtprotoPool_DroppedSpanStats.Get().(*DroppedSpanStats) +} func (m *Transaction) SizeVT() (n int) { if m == nil { return 0 @@ -708,7 +796,7 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.SpanCount == nil { - m.SpanCount = &SpanCount{} + m.SpanCount = SpanCountFromVTPool() } if err := m.SpanCount.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -744,7 +832,7 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.UserExperience == nil { - m.UserExperience = &UserExperience{} + m.UserExperience = UserExperienceFromVTPool() } if err := m.UserExperience.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -779,7 +867,14 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.Custom = append(m.Custom, &KeyValue{}) + if len(m.Custom) == cap(m.Custom) { + m.Custom = append(m.Custom, &KeyValue{}) + } else { + m.Custom = m.Custom[:len(m.Custom)+1] + if m.Custom[len(m.Custom)-1] == nil { + m.Custom[len(m.Custom)-1] = &KeyValue{} + } + } if err := m.Custom[len(m.Custom)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -943,7 +1038,7 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Message == nil { - m.Message = &Message{} + m.Message = MessageFromVTPool() } if err := m.Message.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1107,7 +1202,7 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.DurationHistogram == nil { - m.DurationHistogram = &Histogram{} + m.DurationHistogram = HistogramFromVTPool() } if err := m.DurationHistogram.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1142,7 +1237,14 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { if postIndex > l { return io.ErrUnexpectedEOF } - m.DroppedSpansStats = append(m.DroppedSpansStats, &DroppedSpanStats{}) + if len(m.DroppedSpansStats) == cap(m.DroppedSpansStats) { + m.DroppedSpansStats = append(m.DroppedSpansStats, &DroppedSpanStats{}) + } else { + m.DroppedSpansStats = m.DroppedSpansStats[:len(m.DroppedSpansStats)+1] + if m.DroppedSpansStats[len(m.DroppedSpansStats)-1] == nil { + m.DroppedSpansStats[len(m.DroppedSpansStats)-1] = &DroppedSpanStats{} + } + } if err := m.DroppedSpansStats[len(m.DroppedSpansStats)-1].UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err } @@ -1177,7 +1279,7 @@ func (m *Transaction) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.DurationSummary == nil { - m.DurationSummary = &SummaryMetric{} + m.DurationSummary = SummaryMetricFromVTPool() } if err := m.DurationSummary.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err @@ -1691,7 +1793,7 @@ func (m *DroppedSpanStats) UnmarshalVT(dAtA []byte) error { return io.ErrUnexpectedEOF } if m.Duration == nil { - m.Duration = &AggregatedDuration{} + m.Duration = AggregatedDurationFromVTPool() } if err := m.Duration.UnmarshalVT(dAtA[iNdEx:postIndex]); err != nil { return err diff --git a/model/modelpb/url_vtproto.pb.go b/model/modelpb/url_vtproto.pb.go index e141ad47..74161d31 100644 --- a/model/modelpb/url_vtproto.pb.go +++ b/model/modelpb/url_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -148,6 +149,24 @@ func (m *URL) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_URL = sync.Pool{ + New: func() interface{} { + return &URL{} + }, +} + +func (m *URL) ResetVT() { + m.Reset() +} +func (m *URL) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_URL.Put(m) + } +} +func URLFromVTPool() *URL { + return vtprotoPool_URL.Get().(*URL) +} func (m *URL) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/user_vtproto.pb.go b/model/modelpb/user_vtproto.pb.go index 375e199f..309f5f71 100644 --- a/model/modelpb/user_vtproto.pb.go +++ b/model/modelpb/user_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -118,6 +119,24 @@ func (m *User) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_User = sync.Pool{ + New: func() interface{} { + return &User{} + }, +} + +func (m *User) ResetVT() { + m.Reset() +} +func (m *User) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_User.Put(m) + } +} +func UserFromVTPool() *User { + return vtprotoPool_User.Get().(*User) +} func (m *User) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/modelpb/useragent_vtproto.pb.go b/model/modelpb/useragent_vtproto.pb.go index f7c7fef0..756002ae 100644 --- a/model/modelpb/useragent_vtproto.pb.go +++ b/model/modelpb/useragent_vtproto.pb.go @@ -24,6 +24,7 @@ package modelpb import ( fmt "fmt" io "io" + sync "sync" proto "google.golang.org/protobuf/proto" protoimpl "google.golang.org/protobuf/runtime/protoimpl" @@ -102,6 +103,24 @@ func (m *UserAgent) MarshalToSizedBufferVT(dAtA []byte) (int, error) { return len(dAtA) - i, nil } +var vtprotoPool_UserAgent = sync.Pool{ + New: func() interface{} { + return &UserAgent{} + }, +} + +func (m *UserAgent) ResetVT() { + m.Reset() +} +func (m *UserAgent) ReturnToVTPool() { + if m != nil { + m.ResetVT() + vtprotoPool_UserAgent.Put(m) + } +} +func UserAgentFromVTPool() *UserAgent { + return vtprotoPool_UserAgent.Get().(*UserAgent) +} func (m *UserAgent) SizeVT() (n int) { if m == nil { return 0 diff --git a/model/proto/event.proto b/model/proto/event.proto index 42ba4c1a..203850e1 100644 --- a/model/proto/event.proto +++ b/model/proto/event.proto @@ -36,7 +36,7 @@ message Event { SummaryMetric success_count = 7; google.protobuf.Duration duration = 8; - int64 severity = 9; + uint64 severity = 9; google.protobuf.Timestamp received = 10; } diff --git a/model/proto/experience.proto b/model/proto/experience.proto index 02747c0e..da69691e 100644 --- a/model/proto/experience.proto +++ b/model/proto/experience.proto @@ -29,7 +29,7 @@ message UserExperience { } message LongtaskMetrics { - int64 count = 1; + uint64 count = 1; double sum = 2; double max = 3; } diff --git a/model/proto/http.proto b/model/proto/http.proto index 1abcc9cb..76a30e71 100644 --- a/model/proto/http.proto +++ b/model/proto/http.proto @@ -45,8 +45,8 @@ message HTTPResponse { repeated HTTPHeader headers = 1; optional bool finished = 2; optional bool headers_sent = 3; - optional int64 transfer_size = 4; - optional int64 encoded_body_size = 5; - optional int64 decoded_body_size = 6; - int32 status_code = 7; + optional uint64 transfer_size = 4; + optional uint64 encoded_body_size = 5; + optional uint64 decoded_body_size = 6; + uint32 status_code = 7; } diff --git a/model/proto/log.proto b/model/proto/log.proto index a1bd4f56..8b0e9263 100644 --- a/model/proto/log.proto +++ b/model/proto/log.proto @@ -34,5 +34,5 @@ message LogOrigin { message LogOriginFile { string name = 1; - int32 line = 2; + uint32 line = 2; } diff --git a/model/proto/message.proto b/model/proto/message.proto index 948b1da6..f94273cd 100644 --- a/model/proto/message.proto +++ b/model/proto/message.proto @@ -26,7 +26,7 @@ option go_package = "github.com/elastic/apm-data/model/modelpb"; message Message { string body = 1; repeated HTTPHeader headers = 2; - optional int64 age_millis = 3; + optional uint64 age_millis = 3; string queue_name = 4; string routing_key = 5; } diff --git a/model/proto/metricset.proto b/model/proto/metricset.proto index 1736b490..60429982 100644 --- a/model/proto/metricset.proto +++ b/model/proto/metricset.proto @@ -27,7 +27,7 @@ message Metricset { string name = 1; string interval = 2; repeated MetricsetSample samples = 3; - int64 doc_count = 4; + uint64 doc_count = 4; } enum MetricType { @@ -49,15 +49,15 @@ message MetricsetSample { message Histogram { repeated double values = 1; - repeated int64 counts = 2; + repeated uint64 counts = 2; } message SummaryMetric { - int64 count = 1; + uint64 count = 1; double sum = 2; } message AggregatedDuration { - int64 count = 1; + uint64 count = 1; google.protobuf.Duration sum = 2; } diff --git a/model/proto/process.proto b/model/proto/process.proto index 27edbbcf..31c625c2 100644 --- a/model/proto/process.proto +++ b/model/proto/process.proto @@ -33,5 +33,5 @@ message Process { message ProcessThread { string name = 1; - int32 id = 2; + uint32 id = 2; } diff --git a/model/proto/session.proto b/model/proto/session.proto index 189ad98c..99cb4c76 100644 --- a/model/proto/session.proto +++ b/model/proto/session.proto @@ -23,5 +23,5 @@ option go_package = "github.com/elastic/apm-data/model/modelpb"; message Session { string id = 1; - int64 sequence = 2; + uint64 sequence = 2; } diff --git a/tools/generate-modelpb.sh b/tools/generate-modelpb.sh index 5d3bd3bf..842af953 100755 --- a/tools/generate-modelpb.sh +++ b/tools/generate-modelpb.sh @@ -2,4 +2,13 @@ TOOLS_DIR=$(dirname "$(readlink -f -- "$0")") -PATH="${TOOLS_DIR}/build/bin:${PATH}" protoc --proto_path=./model/proto/ --go_out=. --go_opt=module=github.com/elastic/apm-data --go-vtproto_out=. --go-vtproto_opt=features=marshal+unmarshal+size+pool+clone,module=github.com/elastic/apm-data ./model/proto/*.proto +STRUCTS=$(grep '^message' ./model/proto/*.proto | cut -d ' ' -f2) +PROTOC_VT_STRUCTS=$(for s in ${STRUCTS}; do echo --go-vtproto_opt=pool=github.com/elastic/apm-data/model/modelpb.$s ;done) +PATH="${TOOLS_DIR}/build/bin:${PATH}" protoc \ + --proto_path=./model/proto/ \ + --go_out=. \ + --go_opt=module=github.com/elastic/apm-data \ + --go-vtproto_out=. \ + --go-vtproto_opt=features=marshal+unmarshal+size+pool+clone,module=github.com/elastic/apm-data \ + ${PROTOC_VT_STRUCTS} \ + ./model/proto/*.proto