Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions .chloggen/anup_statsd_receiver_distribution_support.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Use this changelog template to create an entry for release notes.

# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
change_type: enhancement

# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
component: receiver/statsdreceiver

# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
note: "Add support for distribution type metrics in the statsdreceiver."

# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
issues: [24768]

# (Optional) One or more lines of additional information to render under the primary note.
# These lines will be padded with 2 spaces and then inserted directly into the document.
# Use pipe (|) for multiline entries.
subtext:

# If your change doesn't affect end users or the exported elements of any package,
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
# Optional: The change log or logs in which this entry should be included.
# e.g. '[user]' or '[user, api]'
# Include 'user' if the change is relevant to end users.
# Include 'api' if there is a change to a library API.
# Default: '[user]'
change_logs: [user]
10 changes: 9 additions & 1 deletion receiver/statsdreceiver/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ The Following settings are optional:
- `timer_histogram_mapping:`(default value is below): Specify what OTLP type to convert received timing/histogram data to.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unfortunately this field name is now misleading since it's a mapping for timers, histograms, and distributions. At least, the description should be updated

Specify what OTLP type to convert received timing/histogram/distribution data to.



`"statsd_type"` specifies received Statsd data type. Possible values for this setting are `"timing"`, `"timer"` and `"histogram"`.
`"statsd_type"` specifies received Statsd data type. Possible values for this setting are `"timing"`, `"timer"`, `"histogram"` and `"distribution"`.

`"observer_type"` specifies OTLP data type to convert to. We support `"gauge"`, `"summary"`, and `"histogram"`. For `"gauge"`, it does not perform any aggregation.
For `"summary`, the statsD receiver will aggregate to one OTLP summary metric for one metric description (the same metric name with the same tags). It will send percentile 0, 10, 50, 90, 95, 100 to the downstream. The `"histogram"` setting selects an [auto-scaling exponential histogram configured with only a maximum size](https://github.com/lightstep/go-expohisto#readme), as shown in the example below.
Expand All @@ -61,6 +61,10 @@ receivers:
observer_type: "histogram"
histogram:
max_size: 100
- statsd_type: "distribution"
observer_type: "histogram"
histogram:
max_size: 50
```

The full list of settings exposed for this receiver are documented [here](./config.go)
Expand Down Expand Up @@ -138,6 +142,10 @@ receivers:
observer_type: "histogram"
histogram:
max_size: 50
- statsd_type: "distribution"
observer_type: "histogram"
histogram:
max_size: 50
- statsd_type: "timing"
observer_type: "summary"

Expand Down
2 changes: 1 addition & 1 deletion receiver/statsdreceiver/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (c *Config) Validate() error {
}

switch eachMap.StatsdType {
case protocol.TimingTypeName, protocol.TimingAltTypeName, protocol.HistogramTypeName:
case protocol.TimingTypeName, protocol.TimingAltTypeName, protocol.HistogramTypeName, protocol.DistributionTypeName:
// do nothing
case protocol.CounterTypeName, protocol.GaugeTypeName:
fallthrough
Expand Down
7 changes: 7 additions & 0 deletions receiver/statsdreceiver/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,13 @@ func TestLoadConfig(t *testing.T) {
MaxSize: 170,
},
},
{
StatsdType: "distribution",
ObserverType: "histogram",
Histogram: protocol.HistogramConfig{
MaxSize: 170,
},
},
},
},
},
Expand Down
2 changes: 1 addition & 1 deletion receiver/statsdreceiver/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ const (
)

var (
defaultTimerHistogramMapping = []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}}
defaultTimerHistogramMapping = []protocol.TimerHistogramMapping{{StatsdType: "timer", ObserverType: "gauge"}, {StatsdType: "histogram", ObserverType: "gauge"}, {StatsdType: "distribution", ObserverType: "gauge"}}
)

// NewFactory creates a factory for the StatsD receiver.
Expand Down
32 changes: 18 additions & 14 deletions receiver/statsdreceiver/internal/protocol/statsd_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,16 +33,18 @@ type (
const (
tagMetricType = "metric_type"

CounterType MetricType = "c"
GaugeType MetricType = "g"
HistogramType MetricType = "h"
TimingType MetricType = "ms"

CounterTypeName TypeName = "counter"
GaugeTypeName TypeName = "gauge"
HistogramTypeName TypeName = "histogram"
TimingTypeName TypeName = "timing"
TimingAltTypeName TypeName = "timer"
CounterType MetricType = "c"
GaugeType MetricType = "g"
HistogramType MetricType = "h"
TimingType MetricType = "ms"
DistributionType MetricType = "d"

CounterTypeName TypeName = "counter"
GaugeTypeName TypeName = "gauge"
HistogramTypeName TypeName = "histogram"
TimingTypeName TypeName = "timing"
TimingAltTypeName TypeName = "timer"
DistributionTypeName TypeName = "distribution"

GaugeObserver ObserverType = "gauge"
SummaryObserver ObserverType = "summary"
Expand Down Expand Up @@ -143,6 +145,8 @@ func (t MetricType) FullName() TypeName {
return TimingTypeName
case HistogramType:
return HistogramTypeName
case DistributionType:
return DistributionTypeName
}
return TypeName(fmt.Sprintf("unknown(%s)", t))
}
Expand All @@ -162,7 +166,7 @@ func (p *StatsDParser) Initialize(enableMetricType bool, isMonotonicCounter bool
// Note: validation occurs in ("../".Config).validate()
for _, eachMap := range sendTimerHistogram {
switch eachMap.StatsdType {
case HistogramTypeName:
case HistogramTypeName, DistributionTypeName:
p.histogramEvents.method = eachMap.ObserverType
p.histogramEvents.histogramConfig = expoHistogramConfig(eachMap.Histogram)
case TimingTypeName, TimingAltTypeName:
Expand Down Expand Up @@ -255,7 +259,7 @@ var timeNowFunc = time.Now

func (p *StatsDParser) observerCategoryFor(t MetricType) ObserverCategory {
switch t {
case HistogramType:
case HistogramType, DistributionType:
return p.histogramEvents
case TimingType:
return p.timerEvents
Expand Down Expand Up @@ -301,7 +305,7 @@ func (p *StatsDParser) Aggregate(line string, addr net.Addr) error {
point.SetIntValue(point.IntValue() + parsedMetric.counterValue())
}

case TimingType, HistogramType:
case TimingType, HistogramType, DistributionType:
category := p.observerCategoryFor(parsedMetric.description.metricType)
switch category.method {
case GaugeObserver:
Expand Down Expand Up @@ -372,7 +376,7 @@ func parseMessageToMetric(line string, enableMetricType bool) (statsDMetric, err

inType := MetricType(parts[1])
switch inType {
case CounterType, GaugeType, HistogramType, TimingType:
case CounterType, GaugeType, HistogramType, TimingType, DistributionType:
result.description.metricType = inType
default:
return result, fmt.Errorf("unsupported metric type: %s", inType)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,17 @@ func Test_ParseMessageToMetricWithMetricType(t *testing.T) {
[]string{"metric_type"},
[]string{"histogram"}),
},
{
name: "int distribution",
input: "test.metric:42|d",
wantMetric: testStatsDMetric(
"test.metric",
42,
false,
"d", 0,
[]string{"metric_type"},
[]string{"distribution"}),
},
}

for _, tt := range tests {
Expand Down Expand Up @@ -632,12 +643,14 @@ func TestStatsDParser_Aggregate(t *testing.T) {
},
},
{
name: "counter and gauge: 2 timings and 2 histograms",
name: "counter and gauge: 2 timings and 2 histograms and 2 distribution",
input: []string{
"statsdTestMetric1:500|ms|#mykey:myvalue",
"statsdTestMetric1:400|h|#mykey:myvalue",
"statsdTestMetric1:300|ms|#mykey:myvalue",
"statsdTestMetric1:10|h|@0.1|#mykey:myvalue",
"statsdTestMetric1:100|d|#mykey:myvalue",
"statsdTestMetric1:200|d|#mykey:myvalue",
},
expectedGauges: map[statsDMetricDescription]pmetric.ScopeMetrics{},
expectedCounters: map[statsDMetricDescription]pmetric.ScopeMetrics{},
Expand All @@ -646,6 +659,8 @@ func TestStatsDParser_Aggregate(t *testing.T) {
buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 400, false, "h", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),
buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 300, false, "ms", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),
buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 10, false, "h", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),
buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 100, false, "d", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),
buildGaugeMetric(testStatsDMetric("statsdTestMetric1", 200, false, "d", 0, []string{"mykey"}, []string{"myvalue"}), time.Unix(711, 0)),
},
},
}
Expand Down Expand Up @@ -933,6 +948,30 @@ func TestStatsDParser_AggregateTimerWithSummary(t *testing.T) {
},
},
},
{
name: "distribution",
input: []string{
"statsdTestMetric1:1|d|#mykey:myvalue",
"statsdTestMetric2:2|d|#mykey:myvalue",
"statsdTestMetric1:1|d|#mykey:myvalue",
"statsdTestMetric1:10|d|#mykey:myvalue",
"statsdTestMetric1:20|d|#mykey:myvalue",
"statsdTestMetric2:5|d|#mykey:myvalue",
"statsdTestMetric2:10|d|#mykey:myvalue",
},
expectedSummaries: map[statsDMetricDescription]summaryMetric{
testDescription("statsdTestMetric1", "d",
[]string{"mykey"}, []string{"myvalue"}): {
points: []float64{1, 1, 10, 20},
weights: []float64{1, 1, 1, 1},
},
testDescription("statsdTestMetric2", "d",
[]string{"mykey"}, []string{"myvalue"}): {
points: []float64{2, 5, 10},
weights: []float64{1, 1, 1},
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down Expand Up @@ -1319,6 +1358,33 @@ func TestStatsDParser_AggregateTimerWithHistogram(t *testing.T) {
}(),
mapping: normalMapping,
},
{
name: "one_each_distribution",
input: []string{
"expohisto:1|d|#mykey:myvalue",
"expohisto:0|d|#mykey:myvalue",
"expohisto:-1|d|#mykey:myvalue",
},
expected: func() pmetric.Metrics {
data, dp := newPoint()
dp.SetCount(3)
dp.SetSum(0)
dp.SetMin(-1)
dp.SetMax(1)
dp.SetZeroCount(1)
dp.SetScale(logarithm.MaxScale)
dp.Positive().SetOffset(-1)
dp.Negative().SetOffset(-1)
dp.Positive().BucketCounts().FromRaw([]uint64{
1,
})
dp.Negative().BucketCounts().FromRaw([]uint64{
1,
})
return data
}(),
mapping: normalMapping,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
4 changes: 4 additions & 0 deletions receiver/statsdreceiver/testdata/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,7 @@ statsd/receiver_settings:
observer_type: "histogram"
histogram:
max_size: 170
- statsd_type: "distribution"
observer_type: "histogram"
histogram:
max_size: 170