Skip to content

Commit

Permalink
Fix StatsD drop metrics tags when using summary as observer_type (#3440)
Browse files Browse the repository at this point in the history
  • Loading branch information
gavindoudou authored Jun 1, 2021
1 parent 53ccd18 commit db5d994
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 16 deletions.
21 changes: 10 additions & 11 deletions receiver/statsdreceiver/protocol/metric_translator.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,29 +61,28 @@ func buildGaugeMetric(parsedMetric statsDMetric, timeNow time.Time) pdata.Instru
}

func buildSummaryMetric(summaryMetric summaryMetric) pdata.InstrumentationLibraryMetrics {
dp := pdata.NewSummaryDataPoint()
ilm := pdata.NewInstrumentationLibraryMetrics()
nm := ilm.Metrics().AppendEmpty()
nm.SetName(summaryMetric.name)
nm.SetDataType(pdata.MetricDataTypeSummary)

dp := nm.Summary().DataPoints().AppendEmpty()
dp.SetCount(uint64(len(summaryMetric.summaryPoints)))
sum, _ := stats.Sum(summaryMetric.summaryPoints)
dp.SetSum(sum)
dp.SetTimestamp(pdata.TimestampFromTime(summaryMetric.timeNow))
for i, key := range summaryMetric.labelKeys {
dp.LabelsMap().Insert(key, summaryMetric.labelValues[i])
}

quantile := []float64{0, 10, 50, 90, 95, 100}
for _, v := range quantile {
eachQuantile := pdata.NewValueAtQuantile()
eachQuantile := dp.QuantileValues().AppendEmpty()
eachQuantile.SetQuantile(v)
eachQuantileValue, _ := stats.PercentileNearestRank(summaryMetric.summaryPoints, v)
eachQuantile.SetValue(eachQuantileValue)
dp.QuantileValues().Append(eachQuantile)
}

nm := pdata.NewMetric()
nm.SetName(summaryMetric.name)
nm.SetDataType(pdata.MetricDataTypeSummary)
nm.Summary().DataPoints().Append(dp)

ilm := pdata.NewInstrumentationLibraryMetrics()
ilm.Metrics().Append(nm)

return ilm

}
6 changes: 4 additions & 2 deletions receiver/statsdreceiver/protocol/metric_translator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,14 +95,16 @@ func TestBuildSummaryMetric(t *testing.T) {
expectedMetric.Metrics().At(0).Summary().DataPoints().At(0).SetSum(21)
expectedMetric.Metrics().At(0).Summary().DataPoints().At(0).SetCount(6)
expectedMetric.Metrics().At(0).Summary().DataPoints().At(0).SetTimestamp(pdata.TimestampFromTime(timeNow))
for i, key := range oneSummaryMetric.labelKeys {
expectedMetric.Metrics().At(0).Summary().DataPoints().At(0).LabelsMap().Insert(key, oneSummaryMetric.labelValues[i])
}
quantile := []float64{0, 10, 50, 90, 95, 100}
value := []float64{1, 1, 3, 6, 6, 6}
for int, v := range quantile {
eachQuantile := pdata.NewValueAtQuantile()
eachQuantile := expectedMetric.Metrics().At(0).Summary().DataPoints().At(0).QuantileValues().AppendEmpty()
eachQuantile.SetQuantile(v)
eachQuantileValue := value[int]
eachQuantile.SetValue(eachQuantileValue)
expectedMetric.Metrics().At(0).Summary().DataPoints().At(0).QuantileValues().Append(eachQuantile)
}

assert.Equal(t, metric, expectedMetric)
Expand Down
6 changes: 3 additions & 3 deletions receiver/statsdreceiver/protocol/statsd_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,15 +108,15 @@ func (p *StatsDParser) GetMetrics() pdata.Metrics {
rm := metrics.ResourceMetrics().AppendEmpty()

for _, metric := range p.gauges {
rm.InstrumentationLibraryMetrics().Append(metric)
metric.CopyTo(rm.InstrumentationLibraryMetrics().AppendEmpty())
}

for _, metric := range p.counters {
rm.InstrumentationLibraryMetrics().Append(metric)
metric.CopyTo(rm.InstrumentationLibraryMetrics().AppendEmpty())
}

for _, metric := range p.timersAndDistributions {
rm.InstrumentationLibraryMetrics().Append(metric)
metric.CopyTo(rm.InstrumentationLibraryMetrics().AppendEmpty())
}

for _, summaryMetric := range p.summaries {
Expand Down

0 comments on commit db5d994

Please sign in to comment.