Skip to content

Commit 4f9bb9c

Browse files
authored
[exporter/datadog] Add 'exporter.datadogexporter.InferIntervalForDeltaMetrics' feature gate (#42494)
<!--Ex. Fixing a bug - Describe the bug and how this fixes the issue. Ex. Adding a feature - Explain what this achieves.--> #### Description Adds a new `exporter.datadogexporter.InferIntervalForDeltaMetrics` feature gate. This feature gate will set the interval field for OTLP delta metrics when it can be inferred (i.e. when the difference between Timestamp and StartTimestamp is close enough to a whole number of seconds). Relates to [DataDog/opentelemetry-mapping-go/pull/765](DataDog/opentelemetry-mapping-go#765)
1 parent 3e5b6b9 commit 4f9bb9c

File tree

7 files changed

+77
-11
lines changed

7 files changed

+77
-11
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# Use this changelog template to create an entry for release notes.
2+
3+
# One of 'breaking', 'deprecation', 'new_component', 'enhancement', 'bug_fix'
4+
change_type: enhancement
5+
6+
# The name of the component, or a single word describing the area of concern, (e.g. filelogreceiver)
7+
component: datadogexporter
8+
9+
# A brief description of the change. Surround your text with quotes ("") if it needs to start with a backtick (`).
10+
note: Add alpha feature gate 'exporter.datadogexporter.InferIntervalForDeltaMetrics'.
11+
12+
# Mandatory: One or more tracking issues related to the change. You can use the PR number here if no issue exists.
13+
issues: [42494]
14+
15+
# (Optional) One or more lines of additional information to render under the primary note.
16+
# These lines will be padded with 2 spaces and then inserted directly into the document.
17+
# Use pipe (|) for multiline entries.
18+
subtext: |
19+
This feature gate will set the interval for OTLP delta metrics mapped by the exporter when it can infer them.
20+
21+
# If your change doesn't affect end users or the exported elements of any package,
22+
# you should instead start your pull request title with [chore] or use the "Skip Changelog" label.
23+
# Optional: The change log or logs in which this entry should be included.
24+
# e.g. '[user]' or '[user, api]'
25+
# Include 'user' if the change is relevant to end users.
26+
# Include 'api' if there is a change to a library API.
27+
# Default: '[user]'
28+
change_logs: []

exporter/datadogexporter/factory.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,12 @@ var metricExportSerializerClientFeatureGate = featuregate.GlobalRegistry().MustR
7070
featuregate.WithRegisterDescription("When enabled, metric export in datadogexporter uses the serializer exporter from the Datadog Agent."),
7171
)
7272

73+
var inferIntervalDeltaFeatureGate = featuregate.GlobalRegistry().MustRegister(
74+
"exporter.datadogexporter.InferIntervalForDeltaMetrics",
75+
featuregate.StageAlpha,
76+
featuregate.WithRegisterDescription("When enabled, the exporter will infer the metrics interval for OTLP delta sums using a heuristic."),
77+
)
78+
7379
func init() {
7480
log.SetupLogger(log.Disabled(), "off")
7581
}

exporter/datadogexporter/internal/metrics/consumer.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,11 @@ func (c *Consumer) ConsumeTimeSeries(
106106
dims *metrics.Dimensions,
107107
typ metrics.DataType,
108108
timestamp uint64,
109-
_ int64,
109+
interval int64,
110110
value float64,
111111
) {
112112
dt := c.toDataType(typ)
113-
met := NewMetric(dims.Name(), dt, timestamp, value, dims.Tags())
113+
met := NewMetric(dims.Name(), dt, timestamp, interval, value, dims.Tags())
114114
met.SetResources([]datadogV2.MetricResource{
115115
{
116116
Name: datadog.PtrString(dims.Host()),

exporter/datadogexporter/internal/metrics/series.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -34,28 +34,29 @@ func newMetricSeries(name string, ts uint64, value float64, tags []string) datad
3434

3535
// NewMetric creates a new DatadogV2 metric given a name, a type, a Unix nanoseconds timestamp
3636
// a value and a slice of tags
37-
func NewMetric(name string, dt datadogV2.MetricIntakeType, ts uint64, value float64, tags []string) datadogV2.MetricSeries {
37+
func NewMetric(name string, dt datadogV2.MetricIntakeType, ts uint64, interval int64, value float64, tags []string) datadogV2.MetricSeries {
3838
metric := newMetricSeries(name, ts, value, tags)
3939
metric.SetType(dt)
40+
metric.SetInterval(interval)
4041
return metric
4142
}
4243

4344
// NewGauge creates a new DatadogV2 Gauge metric given a name, a Unix nanoseconds timestamp
4445
// a value and a slice of tags
45-
func NewGauge(name string, ts uint64, value float64, tags []string) datadogV2.MetricSeries {
46-
return NewMetric(name, datadogV2.METRICINTAKETYPE_GAUGE, ts, value, tags)
46+
func NewGauge(name string, ts uint64, interval int64, value float64, tags []string) datadogV2.MetricSeries {
47+
return NewMetric(name, datadogV2.METRICINTAKETYPE_GAUGE, ts, interval, value, tags)
4748
}
4849

4950
// NewCount creates a new DatadogV2 count metric given a name, a Unix nanoseconds timestamp
5051
// a value and a slice of tags
51-
func NewCount(name string, ts uint64, value float64, tags []string) datadogV2.MetricSeries {
52-
return NewMetric(name, datadogV2.METRICINTAKETYPE_COUNT, ts, value, tags)
52+
func NewCount(name string, ts uint64, interval int64, value float64, tags []string) datadogV2.MetricSeries {
53+
return NewMetric(name, datadogV2.METRICINTAKETYPE_COUNT, ts, interval, value, tags)
5354
}
5455

5556
// DefaultMetrics creates built-in metrics to report that an exporter is running
5657
func DefaultMetrics(exporterType, hostname string, timestamp uint64, tags []string) []datadogV2.MetricSeries {
5758
metrics := []datadogV2.MetricSeries{
58-
NewGauge(fmt.Sprintf("otel.datadog_exporter.%s.running", exporterType), timestamp, 1.0, tags),
59+
NewGauge(fmt.Sprintf("otel.datadog_exporter.%s.running", exporterType), timestamp, 0, 1.0, tags),
5960
}
6061
for i := range metrics {
6162
metrics[i].SetResources([]datadogV2.MetricResource{
@@ -70,7 +71,7 @@ func DefaultMetrics(exporterType, hostname string, timestamp uint64, tags []stri
7071

7172
// GatewayUsageGauge creates a gauge metric to report if there is a gateway
7273
func GatewayUsageGauge(timestamp uint64, hostname string, tags []string, gatewayUsage *attributes.GatewayUsage) datadogV2.MetricSeries {
73-
series := NewGauge("datadog.otel.gateway", timestamp, gatewayUsage.Gauge(), tags)
74+
series := NewGauge("datadog.otel.gateway", timestamp, 0, gatewayUsage.Gauge(), tags)
7475
series.SetResources([]datadogV2.MetricResource{
7576
{
7677
Name: datadog.PtrString(hostname),

exporter/datadogexporter/internal/metrics/series_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ func TestNewType(t *testing.T) {
3434
value := 2.0
3535
tags := []string{"tag:value"}
3636

37-
gauge := NewGauge(name, ts, value, tags)
37+
gauge := NewGauge(name, ts, 10, value, tags)
3838
assert.Equal(t, datadogV2.METRICINTAKETYPE_GAUGE, gauge.GetType())
3939

40-
count := NewCount(name, ts, value, tags)
40+
count := NewCount(name, ts, 10, value, tags)
4141
assert.Equal(t, datadogV2.METRICINTAKETYPE_COUNT, count.GetType())
4242
}
4343

exporter/datadogexporter/metrics_exporter.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,11 @@ func newMetricsExporter(
7878
options = append(options, otlpmetrics.WithRemapping())
7979
}
8080

81+
if inferIntervalDeltaFeatureGate.IsEnabled() {
82+
params.Logger.Info("Metrics interval will be inferred for OTLP delta metrics with a set StartTimestamp.")
83+
options = append(options, otlpmetrics.WithInferDeltaInterval())
84+
}
85+
8186
tr, err := otlpmetrics.NewTranslator(params.TelemetrySettings, attrsTranslator, options...)
8287
if err != nil {
8388
return nil, err

exporter/datadogexporter/metrics_exporter_test.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,48 +191,55 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) {
191191
"metric": "int.gauge",
192192
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(222)}},
193193
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
194+
"interval": float64(0),
194195
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
195196
"tags": []any{"env:dev"},
196197
},
197198
map[string]any{
198199
"metric": "otel.system.filesystem.utilization",
199200
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
200201
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
202+
"interval": float64(0),
201203
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
202204
"tags": []any{"env:dev"},
203205
},
204206
map[string]any{
205207
"metric": "double.histogram.bucket",
206208
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(2)}},
207209
"type": float64(datadogV2.METRICINTAKETYPE_COUNT),
210+
"interval": float64(0),
208211
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
209212
"tags": []any{"lower_bound:-inf", "upper_bound:0", "env:dev"},
210213
},
211214
map[string]any{
212215
"metric": "double.histogram.bucket",
213216
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(18)}},
214217
"type": float64(datadogV2.METRICINTAKETYPE_COUNT),
218+
"interval": float64(0),
215219
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
216220
"tags": []any{"lower_bound:0", "upper_bound:inf", "env:dev"},
217221
},
218222
map[string]any{
219223
"metric": "system.disk.in_use",
220224
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
221225
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
226+
"interval": float64(0),
222227
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
223228
"tags": []any{"env:dev"},
224229
},
225230
map[string]any{
226231
"metric": "datadog.otel.gateway",
227232
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(0)}},
228233
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
234+
"interval": float64(0),
229235
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
230236
"tags": []any{"version:latest", "command:otelcol"},
231237
},
232238
map[string]any{
233239
"metric": "otel.datadog_exporter.metrics.running",
234240
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(1)}},
235241
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
242+
"interval": float64(0),
236243
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
237244
"tags": []any{"version:latest", "command:otelcol"},
238245
},
@@ -256,48 +263,55 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) {
256263
"metric": "int.gauge",
257264
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(222)}},
258265
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
266+
"interval": float64(0),
259267
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
260268
"tags": []any{"env:new_env"},
261269
},
262270
map[string]any{
263271
"metric": "otel.system.filesystem.utilization",
264272
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
265273
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
274+
"interval": float64(0),
266275
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
267276
"tags": []any{"env:new_env"},
268277
},
269278
map[string]any{
270279
"metric": "double.histogram.bucket",
271280
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(2)}},
272281
"type": float64(datadogV2.METRICINTAKETYPE_COUNT),
282+
"interval": float64(0),
273283
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
274284
"tags": []any{"lower_bound:-inf", "upper_bound:0", "env:new_env"},
275285
},
276286
map[string]any{
277287
"metric": "double.histogram.bucket",
278288
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(18)}},
279289
"type": float64(datadogV2.METRICINTAKETYPE_COUNT),
290+
"interval": float64(0),
280291
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
281292
"tags": []any{"lower_bound:0", "upper_bound:inf", "env:new_env"},
282293
},
283294
map[string]any{
284295
"metric": "system.disk.in_use",
285296
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
286297
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
298+
"interval": float64(0),
287299
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
288300
"tags": []any{"env:new_env"},
289301
},
290302
map[string]any{
291303
"metric": "datadog.otel.gateway",
292304
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(0)}},
293305
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
306+
"interval": float64(0),
294307
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
295308
"tags": []any{"version:latest", "command:otelcol"},
296309
},
297310
map[string]any{
298311
"metric": "otel.datadog_exporter.metrics.running",
299312
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(1)}},
300313
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
314+
"interval": float64(0),
301315
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
302316
"tags": []any{"version:latest", "command:otelcol"},
303317
},
@@ -318,34 +332,39 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) {
318332
"metric": "int.gauge",
319333
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(222)}},
320334
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
335+
"interval": float64(0),
321336
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
322337
"tags": []any{"env:dev"},
323338
},
324339
map[string]any{
325340
"metric": "otel.system.filesystem.utilization",
326341
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
327342
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
343+
"interval": float64(0),
328344
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
329345
"tags": []any{"env:dev"},
330346
},
331347
map[string]any{
332348
"metric": "system.disk.in_use",
333349
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
334350
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
351+
"interval": float64(0),
335352
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
336353
"tags": []any{"env:dev"},
337354
},
338355
map[string]any{
339356
"metric": "datadog.otel.gateway",
340357
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(0)}},
341358
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
359+
"interval": float64(0),
342360
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
343361
"tags": []any{"version:latest", "command:otelcol"},
344362
},
345363
map[string]any{
346364
"metric": "otel.datadog_exporter.metrics.running",
347365
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(1)}},
348366
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
367+
"interval": float64(0),
349368
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
350369
"tags": []any{"version:latest", "command:otelcol"},
351370
},
@@ -384,48 +403,55 @@ func Test_metricsExporter_PushMetricsData(t *testing.T) {
384403
"metric": "int.gauge",
385404
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(222)}},
386405
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
406+
"interval": float64(0),
387407
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
388408
"tags": []any{"env:dev", "key1:value1", "key2:value2"},
389409
},
390410
map[string]any{
391411
"metric": "otel.system.filesystem.utilization",
392412
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
393413
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
414+
"interval": float64(0),
394415
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
395416
"tags": []any{"env:dev", "key1:value1", "key2:value2"},
396417
},
397418
map[string]any{
398419
"metric": "double.histogram.bucket",
399420
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(2)}},
400421
"type": float64(datadogV2.METRICINTAKETYPE_COUNT),
422+
"interval": float64(0),
401423
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
402424
"tags": []any{"lower_bound:-inf", "upper_bound:0", "env:dev", "key1:value1", "key2:value2"},
403425
},
404426
map[string]any{
405427
"metric": "double.histogram.bucket",
406428
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(18)}},
407429
"type": float64(datadogV2.METRICINTAKETYPE_COUNT),
430+
"interval": float64(0),
408431
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
409432
"tags": []any{"lower_bound:0", "upper_bound:inf", "env:dev", "key1:value1", "key2:value2"},
410433
},
411434
map[string]any{
412435
"metric": "system.disk.in_use",
413436
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(333)}},
414437
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
438+
"interval": float64(0),
415439
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
416440
"tags": []any{"env:dev", "key1:value1", "key2:value2"},
417441
},
418442
map[string]any{
419443
"metric": "datadog.otel.gateway",
420444
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(0)}},
421445
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
446+
"interval": float64(0),
422447
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
423448
"tags": []any{"version:latest", "command:otelcol", "key1:value1", "key2:value2"},
424449
},
425450
map[string]any{
426451
"metric": "otel.datadog_exporter.metrics.running",
427452
"points": []any{map[string]any{"timestamp": float64(0), "value": float64(1)}},
428453
"type": float64(datadogV2.METRICINTAKETYPE_GAUGE),
454+
"interval": float64(0),
429455
"resources": []any{map[string]any{"name": "test-host", "type": "host"}},
430456
"tags": []any{"version:latest", "command:otelcol", "key1:value1", "key2:value2"},
431457
},

0 commit comments

Comments
 (0)