Skip to content

Commit

Permalink
Rename EventParam.Rate and remove unused generateExceptionOnError:
Browse files Browse the repository at this point in the history
  • Loading branch information
stoewer committed May 27, 2024
1 parent a9cb542 commit 67a3a92
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 23 deletions.
36 changes: 16 additions & 20 deletions pkg/tracegen/templated.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,10 @@ type LinkParams struct {
type EventParams struct {
// Generate exception event if status code of the span is >= 400
GenerateExceptionOnError bool `js:"generateExceptionOnError"`
// Rate of exception events per each span
// Count of exception events per each span
ExceptionRate float32 `js:"exceptionRate"`
// Rate of random events per each span
Rate float32 `js:"rate"`
// Count of random events per each span
Count float32 `js:"count"`
// Generate random attributes for this event
RandomAttributes *AttributeParams `js:"randomAttributes"`
}
Expand Down Expand Up @@ -178,10 +178,9 @@ type internalLinkTemplate struct {
}

type internalEventTemplate struct {
count int
generateExceptionOnError bool
exceptionCount int
randomAttributes *AttributeParams
count int
exceptionCount int
randomAttributes *AttributeParams
}

// Traces implements Generator for TemplatedGenerator
Expand Down Expand Up @@ -534,15 +533,14 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat
}
span.attributes = util.MergeMaps(defaults.Attributes, tmpl.Attributes)

eventDefaultsRate := defaults.RandomEvents.Rate
eventDefaultsRate := defaults.RandomEvents.Count
var eventDefaults internalEventTemplate
// if rate is more than 1, use whole integers
if eventDefaultsRate > 1 {
eventDefaults = internalEventTemplate{
generateExceptionOnError: defaults.RandomEvents.GenerateExceptionOnError,
randomAttributes: defaults.RandomEvents.RandomAttributes,
count: int(eventDefaultsRate),
exceptionCount: int(defaults.RandomEvents.ExceptionRate),
randomAttributes: defaults.RandomEvents.RandomAttributes,
count: int(eventDefaultsRate),
exceptionCount: int(defaults.RandomEvents.ExceptionRate),
}
} else {
var count, exeptionCount int
Expand All @@ -556,18 +554,16 @@ func (g *TemplatedGenerator) initializeSpan(idx int, parent *internalSpanTemplat

// if rate is less than one
eventDefaults = internalEventTemplate{
generateExceptionOnError: defaults.RandomEvents.GenerateExceptionOnError,
randomAttributes: defaults.RandomEvents.RandomAttributes,
count: count,
exceptionCount: exeptionCount,
randomAttributes: defaults.RandomEvents.RandomAttributes,
count: count,
exceptionCount: exeptionCount,
}
}

randomEvents := internalEventTemplate{
generateExceptionOnError: tmpl.RandomEvents.GenerateExceptionOnError,
randomAttributes: tmpl.RandomEvents.RandomAttributes,
count: int(tmpl.RandomEvents.Rate),
exceptionCount: int(tmpl.RandomEvents.ExceptionRate),
randomAttributes: tmpl.RandomEvents.RandomAttributes,
count: int(tmpl.RandomEvents.Count),
exceptionCount: int(tmpl.RandomEvents.ExceptionRate),
}

// generate all non-exception events
Expand Down
6 changes: 3 additions & 3 deletions pkg/tracegen/templated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ func TestTemplatedGenerator_EventsLinks(t *testing.T) {
Attributes: map[string]interface{}{"fixed.attr": "some-value"},
RandomAttributes: &AttributeParams{Count: 3},
RandomLinks: &LinkParams{Count: 0.5, RandomAttributes: &AttributeParams{Count: 3}},
RandomEvents: EventParams{GenerateExceptionOnError: true, Rate: 0.5, RandomAttributes: &AttributeParams{Count: 3}},
RandomEvents: EventParams{GenerateExceptionOnError: true, Count: 0.5, RandomAttributes: &AttributeParams{Count: 3}},
},
Spans: []SpanTemplate{
// do not change order of the first one
{Service: "test-service", Name: ptr("only_default")},
{Service: "test-service", Name: ptr("default_and_template"), Events: []Event{{Name: "event-name", RandomAttributes: &AttributeParams{Count: 2}}}, Links: []Link{{Attributes: map[string]interface{}{"link-attr-key": "link-attr-value"}}}},
{Service: "test-service", Name: ptr("default_and_random"), RandomEvents: EventParams{Rate: 2, RandomAttributes: &AttributeParams{Count: 1}}, RandomLinks: &LinkParams{Count: 2, RandomAttributes: &AttributeParams{Count: 1}}},
{Service: "test-service", Name: ptr("default_template_random"), Events: []Event{{Name: "event-name", RandomAttributes: &AttributeParams{Count: 2}}}, Links: []Link{{Attributes: map[string]interface{}{"link-attr-key": "link-attr-value"}}}, RandomEvents: EventParams{Rate: 2, RandomAttributes: &AttributeParams{Count: 1}}, RandomLinks: &LinkParams{Count: 2, RandomAttributes: &AttributeParams{Count: 1}}},
{Service: "test-service", Name: ptr("default_and_random"), RandomEvents: EventParams{Count: 2, RandomAttributes: &AttributeParams{Count: 1}}, RandomLinks: &LinkParams{Count: 2, RandomAttributes: &AttributeParams{Count: 1}}},
{Service: "test-service", Name: ptr("default_template_random"), Events: []Event{{Name: "event-name", RandomAttributes: &AttributeParams{Count: 2}}}, Links: []Link{{Attributes: map[string]interface{}{"link-attr-key": "link-attr-value"}}}, RandomEvents: EventParams{Count: 2, RandomAttributes: &AttributeParams{Count: 1}}, RandomLinks: &LinkParams{Count: 2, RandomAttributes: &AttributeParams{Count: 1}}},
{Service: "test-service", Name: ptr("default_generate_on_error"), Attributes: map[string]interface{}{"http.status_code": 400}},
},
}
Expand Down

0 comments on commit 67a3a92

Please sign in to comment.