Skip to content

Commit

Permalink
add global labels values test case
Browse files Browse the repository at this point in the history
Add an e2e test for global labels values with multiple events.

A batch of 2 events in input with different labels Values but
same key should produce in output events with all different
Values added to the same key.
  • Loading branch information
endorama committed Aug 14, 2024
1 parent 6c0a6ab commit 57265b3
Showing 1 changed file with 134 additions and 0 deletions.
134 changes: 134 additions & 0 deletions aggregators/aggregator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1242,6 +1242,140 @@ func TestAggregateAndHarvest(t *testing.T) {
runTest(t, input, expected)
})

t.Run("with multiple global labels values", func(t *testing.T) {
input := modelpb.Batch{
{
Event: &modelpb.Event{
Outcome: "success",
Duration: uint64(txnDuration),
},
Transaction: &modelpb.Transaction{
Name: "foo",
Type: "txtype",
RepresentativeCount: 1,
},
Service: &modelpb.Service{Name: "svc"},
Labels: modelpb.Labels{
"baz": &modelpb.LabelValue{Global: true, Values: []string{"asd", "qwe"}},
},
NumericLabels: modelpb.NumericLabels{
"bar": &modelpb.NumericLabelValue{Global: true, Values: []float64{1, 2}},
},
},
{
Event: &modelpb.Event{
Outcome: "success",
Duration: uint64(txnDuration),
},
Transaction: &modelpb.Transaction{
Name: "foo",
Type: "txtype",
RepresentativeCount: 1,
},
Service: &modelpb.Service{Name: "svc"},
Labels: modelpb.Labels{
"baz": &modelpb.LabelValue{Global: true, Values: []string{"rty", "fgh"}},
},
NumericLabels: modelpb.NumericLabels{
"bar": &modelpb.NumericLabelValue{Global: true, Values: []float64{4, 5}},
},
},
}

expected := []*modelpb.APMEvent{
{
Timestamp: modelpb.FromTime(time.Unix(0, 0).UTC()),
Event: &modelpb.Event{
SuccessCount: &modelpb.SummaryMetric{
Count: 1,
Sum: 1,
},
Outcome: "success",
},
Transaction: &modelpb.Transaction{
Name: "foo",
Type: "txtype",
Root: true,
DurationSummary: &modelpb.SummaryMetric{
Count: 1,
Sum: 100351, // Estimate from histogram
},
DurationHistogram: &modelpb.Histogram{
Values: []float64{100351},
Counts: []uint64{1},
},
},
Service: &modelpb.Service{
Name: "svc",
},
Labels: modelpb.Labels{
"baz": &modelpb.LabelValue{Global: true, Values: []string{"asd", "qwe", "rty", "fgh"}},
},
NumericLabels: modelpb.NumericLabels{
"bar": &modelpb.NumericLabelValue{Global: true, Values: []float64{1, 2, 4, 5}},
},
Metricset: &modelpb.Metricset{
Name: "transaction",
DocCount: 1,
Interval: "1s",
},
},
{
Timestamp: modelpb.FromTime(time.Unix(0, 0).UTC()),
Event: &modelpb.Event{},
Service: &modelpb.Service{
Name: "svc",
},
Labels: modelpb.Labels{
"baz": &modelpb.LabelValue{Global: true, Values: []string{"asd", "qwe", "rty", "fgh"}},
},
NumericLabels: modelpb.NumericLabels{
"bar": &modelpb.NumericLabelValue{Global: true, Values: []float64{1, 2, 4, 5}},
},
Metricset: &modelpb.Metricset{
Name: "service_summary",
Interval: "1s",
},
},
{
Timestamp: modelpb.FromTime(time.Unix(0, 0).UTC()),
Event: &modelpb.Event{
SuccessCount: &modelpb.SummaryMetric{
Count: 1,
Sum: 1,
},
},
Transaction: &modelpb.Transaction{
Type: "txtype",
DurationSummary: &modelpb.SummaryMetric{
Count: 1,
Sum: 100351, // Estimate from histogram
},
DurationHistogram: &modelpb.Histogram{
Values: []float64{100351},
Counts: []uint64{1},
},
},
Service: &modelpb.Service{
Name: "svc",
},
Labels: modelpb.Labels{
"baz": &modelpb.LabelValue{Global: true, Values: []string{"asd", "qwe", "rty", "fgh"}},
},
NumericLabels: modelpb.NumericLabels{
"bar": &modelpb.NumericLabelValue{Global: true, Values: []float64{1, 2, 4, 5}},
},
Metricset: &modelpb.Metricset{
Name: "service_transaction",
DocCount: 1,
Interval: "1s",
},
},
}

runTest(t, input, expected)
})

}

func TestHarvestOverflowCount(t *testing.T) {
Expand Down

0 comments on commit 57265b3

Please sign in to comment.