Skip to content

Commit

Permalink
Merge branch 'main' into new-jvm-metics
Browse files Browse the repository at this point in the history
  • Loading branch information
JonasKunz authored Jul 28, 2023
2 parents 38177c8 + 31428f0 commit fd5d81b
Show file tree
Hide file tree
Showing 170 changed files with 2,591 additions and 1,039 deletions.
22 changes: 11 additions & 11 deletions codec/fullevent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent {
Value: []string{"bar"},
},
},
AgeMillis: int64Ptr(2),
AgeMillis: uint64Ptr(2),
QueueName: "queuename",
RoutingKey: "routingkey",
},
Expand Down Expand Up @@ -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",
Expand Down Expand Up @@ -158,7 +158,7 @@ func fullEvent(t *testing.B) *modelpb.APMEvent {
Value: []string{"bar"},
},
},
AgeMillis: int64Ptr(2),
AgeMillis: uint64Ptr(2),
QueueName: "queuename",
RoutingKey: "routingkey",
},
Expand All @@ -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{
{
Expand Down Expand Up @@ -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,
Expand All @@ -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{
Expand Down Expand Up @@ -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",
Expand All @@ -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",
Expand Down
30 changes: 11 additions & 19 deletions codec/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()},
},
Expand All @@ -61,7 +53,7 @@ func uintPtr(i uint32) *uint32 {
return &i
}

func int64Ptr(i int64) *int64 {
func uint64Ptr(i uint64) *uint64 {
return &i
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,8 @@ var (
nullableTypeInt: TypeNameInteger,
"int": TypeNameInteger,
"int64": TypeNameInteger,
"uint": TypeNameInteger,
"uint64": TypeNameInteger,
nullableTypeTimeMicrosUnix: TypeNameInteger,
nullableTypeString: TypeNameString,
"string": TypeNameString,
Expand Down
1 change: 1 addition & 0 deletions input/elasticapm/internal/modeldecoder/generator/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
24 changes: 12 additions & 12 deletions input/elasticapm/internal/modeldecoder/rumv3/decoder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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)
Expand All @@ -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
}
}
Expand Down Expand Up @@ -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() {
Expand All @@ -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
Expand All @@ -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,
}
Expand Down
Loading

0 comments on commit fd5d81b

Please sign in to comment.