Skip to content

Commit

Permalink
feat: add aggregation_temporality for statsd counters
Browse files Browse the repository at this point in the history
  • Loading branch information
povilasv committed Apr 25, 2023
1 parent d7b8635 commit f83de3c
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 17 deletions.
4 changes: 4 additions & 0 deletions plugins/inputs/statsd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ See the [CONFIGURATION.md][CONFIGURATION.md] for more details.
enable_start_time_field = false
## Enable temporality tag adds temporality=delta or temporality=commulative tag to the metrics.
enable_temporality_tag = false
## Enable aggregation temporality adds temporality=delta or temporality=commulative tag, and
## start_time field, which adds the start time of the metric accumulation.
## You should use this when using OpenTelemetry output.
enable_aggregation_temporality = false

## Percentiles to calculate for timing & histogram stats.
percentiles = [50.0, 90.0, 99.0, 99.9, 99.95, 100.0]
Expand Down
9 changes: 4 additions & 5 deletions plugins/inputs/statsd/sample.conf
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,10 @@
## Reset timings & histograms every interval (default=true)
delete_timings = true

## Enable start_time field, which adds the start time of the metric accumulation
## You should use this together with enable_temporality_tag when using OpenTelemetry output.
enable_start_time_field = false
## Enable temporality tag adds temporality=delta or temporality=commulative tag to the metrics.
enable_temporality_tag = false
## Enable aggregation temporality adds temporality=delta or temporality=commulative tag, and
## start_time field, which adds the start time of the metric accumulation.
## You should use this when using OpenTelemetry output.
enable_aggregation_temporality = false

## Percentiles to calculate for timing & histogram stats.
percentiles = [50.0, 90.0, 99.0, 99.9, 99.95, 100.0]
Expand Down
15 changes: 7 additions & 8 deletions plugins/inputs/statsd/statsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,7 @@ type Statsd struct {
DeleteTimings bool `toml:"delete_timings"`
ConvertNames bool `toml:"convert_names" deprecated:"0.12.0;2.0.0;use 'metric_separator' instead"`

EnableStartTimeField bool `toml:"enable_start_time_field"`
EnableTemporalityTag bool `toml:"enable_temporality_tag"`
EnableAggregationTemporality bool `toml:"enable_aggregation_temporality"`

// MetricSeparator is the separator between parts of the metric name.
MetricSeparator string `toml:"metric_separator"`
Expand Down Expand Up @@ -231,7 +230,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
fields := map[string]interface{}{
defaultFieldName: m.value,
}
if s.EnableStartTimeField {
if s.EnableAggregationTemporality {
fields["start_time"] = s.lastGatherTime.Format(time.RFC3339)
}
acc.AddFields(m.name, fields, m.tags, now)
Expand Down Expand Up @@ -260,7 +259,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
fields[name] = stats.Percentile(float64(percentile))
}
}
if s.EnableStartTimeField {
if s.EnableAggregationTemporality {
fields["start_time"] = s.lastGatherTime.Format(time.RFC3339)
}

Expand All @@ -271,7 +270,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
}

for _, m := range s.gauges {
if s.EnableStartTimeField && m.fields != nil {
if s.EnableAggregationTemporality && m.fields != nil {
m.fields["start_time"] = s.lastGatherTime.Format(time.RFC3339)
}

Expand All @@ -282,7 +281,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
}

for _, m := range s.counters {
if s.EnableStartTimeField && m.fields != nil {
if s.EnableAggregationTemporality && m.fields != nil {
m.fields["start_time"] = s.lastGatherTime.Format(time.RFC3339)
}

Expand All @@ -297,7 +296,7 @@ func (s *Statsd) Gather(acc telegraf.Accumulator) error {
for field, set := range m.fields {
fields[field] = int64(len(set))
}
if s.EnableStartTimeField {
if s.EnableAggregationTemporality {
fields["start_time"] = s.lastGatherTime.Format(time.RFC3339)
}

Expand Down Expand Up @@ -671,7 +670,7 @@ func (s *Statsd) parseStatsdLine(line string) error {
case "c":
m.tags["metric_type"] = "counter"

if s.EnableTemporalityTag {
if s.EnableAggregationTemporality {
if s.DeleteCounters {
m.tags["temporality"] = "delta"
} else {
Expand Down
7 changes: 3 additions & 4 deletions plugins/inputs/statsd/statsd_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2006,10 +2006,9 @@ func TestParse_DeltaCounter(t *testing.T) {
TCPKeepAlive: true,
NumberWorkerThreads: 5,
// Delete Counters causes Delta temporality to be added
DeleteCounters: true,
lastGatherTime: time.Now(),
EnableTemporalityTag: true,
EnableStartTimeField: true,
DeleteCounters: true,
lastGatherTime: time.Now(),
EnableAggregationTemporality: true,
}

acc := &testutil.Accumulator{}
Expand Down

0 comments on commit f83de3c

Please sign in to comment.