diff --git a/aggregators/aggregator_test.go b/aggregators/aggregator_test.go index 80b7755..fa97983 100644 --- a/aggregators/aggregator_test.go +++ b/aggregators/aggregator_test.go @@ -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) {