From dcc463ed93d0755d125464c0d0a02544e1a213fc Mon Sep 17 00:00:00 2001 From: Jennie Pham Date: Tue, 16 Jan 2024 13:13:59 -0600 Subject: [PATCH] fix template example, rename defaults --- examples/template/template.js | 8 ++++---- pkg/tracegen/templated.go | 30 +++++++++++++++--------------- pkg/tracegen/templated_test.go | 4 ++-- 3 files changed, 21 insertions(+), 21 deletions(-) diff --git a/examples/template/template.js b/examples/template/template.js index 9039557..c36855f 100644 --- a/examples/template/template.js +++ b/examples/template/template.js @@ -22,8 +22,8 @@ const traceDefaults = { attributeSemantics: tracing.SEMANTICS_HTTP, attributes: {"one": "three"}, randomAttributes: {count: 2, cardinality: 5}, - eventDefaults: {generateExceptionOnError: true, count: 1.0, randomAttributes: {count: 2, cardinality: 3}}, - linkDefaults: {linkToPreviousSpanIndex: true, count: 1.0, randomAttributes: {count: 2, cardinality: 3}}, + randomEvents: {generateExceptionOnError: true, rate: 1.0, randomAttributes: {count: 2, cardinality: 3}}, + randomLinks: {rate: 1.0, randomAttributes: {count: 2, cardinality: 3}}, } const traceTemplates = [ @@ -71,8 +71,8 @@ const traceTemplates = [ {service: "shop-backend", attributes: {"http.status_code": 403}}, {service: "shop-backend", name: "authenticate", attributes: {"http.request.header.accept": ["application/json"]}}, {service: "auth-service", name: "authenticate", attributes: {"http.status_code": 403}}, - {service: "cart-service", name: "checkout", randomEvents: {exceptionCount: 1, count: 2, randomAttributes: {count: 5, cardinality: 2}}}, - {service: "billing-service", name: "payment", randomLinks: {linkToPreviousSpanIndex: true, count: 2, randomAttributes: {count: 3, cardinality: 2}}} + {service: "cart-service", name: "checkout", randomEvents: {exceptionRate: 1, rate: 2, randomAttributes: {count: 5, cardinality: 2}}}, + {service: "billing-service", name: "payment", randomLinks: {rate: 2, randomAttributes: {count: 3, cardinality: 2}}} ] }, ] diff --git a/pkg/tracegen/templated.go b/pkg/tracegen/templated.go index 43031d0..4e75dac 100644 --- a/pkg/tracegen/templated.go +++ b/pkg/tracegen/templated.go @@ -52,9 +52,9 @@ type SpanDefaults struct { // RandomAttributes random attributes generated for each span. RandomAttributes *AttributeParams `js:"randomAttributes"` // Random events generated for each span - EventDefaults EventParams `js:"eventDefaults"` + RandomEvents EventParams `js:"randomEvents"` // Random links generated for each span - LinkDefaults LinkParams `js:"linkDefaults"` + RandomLinks LinkParams `js:"randomLinks"` } // SpanTemplate parameters that define how a span is created. @@ -130,9 +130,8 @@ type EventParams struct { } type internalLinkParams struct { - LinkToPreviousSpanIndex bool - Count int - RandomAttributes *AttributeParams + Count int + RandomAttributes *AttributeParams } type internalEventParams struct { @@ -319,6 +318,7 @@ func (g *TemplatedGenerator) generateSpan(scopeSpans ptrace.ScopeSpans, tmpl *in exceptionEvent := generateExceptionEvent() event := span.Events().AppendEmpty() event.SetName(exceptionEvent.Name) + event.SetTimestamp(pcommon.NewTimestampFromTime(end)) for k, v := range exceptionEvent.Attributes { _ = event.Attributes().PutEmpty(k).FromRaw(v) } @@ -524,15 +524,15 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat } span.attributes = util.MergeMaps(defaults.Attributes, tmpl.Attributes) - eventDefaultsRate := defaults.EventDefaults.Rate + eventDefaultsRate := defaults.RandomEvents.Rate var eventDefaults internalEventParams // if rate is more than 1, use whole integers if eventDefaultsRate > 1 { eventDefaults = internalEventParams{ - GenerateExceptionOnError: defaults.EventDefaults.GenerateExceptionOnError, - RandomAttributes: defaults.EventDefaults.RandomAttributes, + GenerateExceptionOnError: defaults.RandomEvents.GenerateExceptionOnError, + RandomAttributes: defaults.RandomEvents.RandomAttributes, Count: int(eventDefaultsRate), - ExceptionCount: int(defaults.EventDefaults.ExceptionRate), + ExceptionCount: int(defaults.RandomEvents.ExceptionRate), } } else { var count, exeptionCount int @@ -546,8 +546,8 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat // if rate is less than one eventDefaults = internalEventParams{ - GenerateExceptionOnError: defaults.EventDefaults.GenerateExceptionOnError, - RandomAttributes: defaults.EventDefaults.RandomAttributes, + GenerateExceptionOnError: defaults.RandomEvents.GenerateExceptionOnError, + RandomAttributes: defaults.RandomEvents.RandomAttributes, Count: count, ExceptionCount: exeptionCount, } @@ -564,18 +564,18 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat span.events = g.initializeEvents(tmpl.Events, randomEvents, eventDefaults) // need span status to determine if an exception event should occur - span.generateExceptionEvents = defaults.EventDefaults.GenerateExceptionOnError + span.generateExceptionEvents = defaults.RandomEvents.GenerateExceptionOnError - linkDefaultsRate := defaults.LinkDefaults.Rate + linkDefaultsRate := defaults.RandomLinks.Rate var linkDefaults internalLinkParams if linkDefaultsRate > 1 { linkDefaults = internalLinkParams{ - RandomAttributes: defaults.LinkDefaults.RandomAttributes, + RandomAttributes: defaults.RandomLinks.RandomAttributes, Count: int(linkDefaultsRate), } } else if rand.Float32() < linkDefaultsRate { linkDefaults = internalLinkParams{ - RandomAttributes: defaults.LinkDefaults.RandomAttributes, + RandomAttributes: defaults.RandomLinks.RandomAttributes, Count: 1, } } diff --git a/pkg/tracegen/templated_test.go b/pkg/tracegen/templated_test.go index ed1e54c..66b7425 100644 --- a/pkg/tracegen/templated_test.go +++ b/pkg/tracegen/templated_test.go @@ -58,8 +58,8 @@ func TestTemplatedGenerator_EventsLinks(t *testing.T) { Defaults: SpanDefaults{ Attributes: map[string]interface{}{"fixed.attr": "some-value"}, RandomAttributes: &AttributeParams{Count: 3}, - LinkDefaults: LinkParams{Rate: 0.5, RandomAttributes: &AttributeParams{Count: 3}}, - EventDefaults: EventParams{GenerateExceptionOnError: true, Rate: 0.5, RandomAttributes: &AttributeParams{Count: 3}}, + RandomLinks: LinkParams{Rate: 1, RandomAttributes: &AttributeParams{Count: 3}}, + RandomEvents: EventParams{GenerateExceptionOnError: true, Rate: 1, RandomAttributes: &AttributeParams{Count: 3}}, }, Spans: []SpanTemplate{ // do not change order of the first one