Skip to content

Commit

Permalink
[exporter/datadogexporter] Fix tag slice appending on summary and buc…
Browse files Browse the repository at this point in the history
…ket metrics (#5416)
  • Loading branch information
mx-psi authored Sep 23, 2021
1 parent 8c5231f commit dc00e5e
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -199,10 +199,11 @@ func (t *Translator) getLegacyBuckets(name string, p pdata.HistogramDataPoint, d
fullName := fmt.Sprintf("%s.bucket", name)
for idx, val := range p.BucketCounts() {
lowerBound, upperBound := getBounds(p, idx)
bucketTags := append(tags,
bucketTags := []string{
fmt.Sprintf("lower_bound:%s", formatFloat(lowerBound)),
fmt.Sprintf("upper_bound:%s", formatFloat(upperBound)),
)
}
bucketTags = append(bucketTags, tags...)

count := float64(val)
ts := uint64(p.Timestamp())
Expand Down Expand Up @@ -336,7 +337,8 @@ func (t *Translator) mapSummaryMetrics(name string, slice pdata.SummaryDataPoint
continue
}

quantileTags := append(tags, getQuantileTag(q.Quantile()))
quantileTags := []string{getQuantileTag(q.Quantile())}
quantileTags = append(quantileTags, tags...)
ms = append(ms,
metrics.NewGauge(fullName, ts, q.Value(), quantileTags),
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -483,8 +483,8 @@ func TestMapDeltaHistogramMetrics(t *testing.T) {
}

bucketsAttributeTags := []datadog.Metric{
metrics.NewCount("doubleHist.test.bucket", uint64(ts), 2, []string{"attribute_tag:attribute_value", "lower_bound:-inf", "upper_bound:0"}),
metrics.NewCount("doubleHist.test.bucket", uint64(ts), 18, []string{"attribute_tag:attribute_value", "lower_bound:0", "upper_bound:inf"}),
metrics.NewCount("doubleHist.test.bucket", uint64(ts), 2, []string{"lower_bound:-inf", "upper_bound:0", "attribute_tag:attribute_value"}),
metrics.NewCount("doubleHist.test.bucket", uint64(ts), 18, []string{"lower_bound:0", "upper_bound:inf", "attribute_tag:attribute_value"}),
}

tr.cfg.HistConfig.Mode = histogramModeNoBuckets
Expand Down Expand Up @@ -539,6 +539,29 @@ func TestMapCumulativeHistogramMetrics(t *testing.T) {
)
}

func TestLegacyBucketsTags(t *testing.T) {
// Test that passing the same tags slice doesn't reuse the slice.
cfg := config.MetricsConfig{}
tr := newTranslator(zap.NewNop(), cfg)

tags := make([]string, 0, 10)

pointOne := pdata.NewHistogramDataPoint()
pointOne.SetBucketCounts([]uint64{2, 18})
pointOne.SetExplicitBounds([]float64{0})
pointOne.SetTimestamp(seconds(0))
seriesOne := tr.getLegacyBuckets("test.histogram.one", pointOne, true, tags)

pointTwo := pdata.NewHistogramDataPoint()
pointTwo.SetBucketCounts([]uint64{2, 18})
pointTwo.SetExplicitBounds([]float64{1})
pointTwo.SetTimestamp(seconds(0))
seriesTwo := tr.getLegacyBuckets("test.histogram.two", pointTwo, true, tags)

assert.ElementsMatch(t, seriesOne[0].Tags, []string{"lower_bound:-inf", "upper_bound:0"})
assert.ElementsMatch(t, seriesTwo[0].Tags, []string{"lower_bound:-inf", "upper_bound:1.0"})
}

func TestFormatFloat(t *testing.T) {
tests := []struct {
f float64
Expand Down Expand Up @@ -626,10 +649,10 @@ func TestMapSummaryMetrics(t *testing.T) {
metrics.NewCount("summary.example.sum", uint64(ts), 10_000, []string{"attribute_tag:attribute_value"}),
}
quantilesAttr := []datadog.Metric{
metrics.NewGauge("summary.example.quantile", uint64(ts), 0, []string{"attribute_tag:attribute_value", "quantile:0"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 100, []string{"attribute_tag:attribute_value", "quantile:0.5"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 500, []string{"attribute_tag:attribute_value", "quantile:0.999"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 600, []string{"attribute_tag:attribute_value", "quantile:1.0"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 0, []string{"quantile:0", "attribute_tag:attribute_value"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 100, []string{"quantile:0.5", "attribute_tag:attribute_value"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 500, []string{"quantile:0.999", "attribute_tag:attribute_value"}),
metrics.NewGauge("summary.example.quantile", uint64(ts), 600, []string{"quantile:1.0", "attribute_tag:attribute_value"}),
}
tr = newTranslator([]string{"attribute_tag:attribute_value"}, false)
assert.ElementsMatch(t,
Expand Down

0 comments on commit dc00e5e

Please sign in to comment.