Skip to content

Commit bfd77c9

Browse files
authored
Add _metric_names_hash field to OTel metric mappings (#120952) (#122881)
If metrics that have the same timestamp and dimensions aren't grouped into the same document, ES will consider them to be a duplicate. The _metric_names_hash field will be set by the OTel ES exporter. As it's mapped as a time_series_dimensions, it creates a different _tsid for documents with different sets of metrics. The tradeoff is that if the composition of the metrics grouping changes over time, a different _tsid will be created. That has an impact on the rate aggregation for counters.
1 parent 4d408d4 commit bfd77c9

File tree

3 files changed

+32
-0
lines changed

3 files changed

+32
-0
lines changed

docs/changelog/120952.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 120952
2+
summary: Add `_metric_names_hash` field to OTel metric mappings
3+
area: Data streams
4+
type: bug
5+
issues: []

x-pack/plugin/otel-data/src/main/resources/component-templates/[email protected]

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ template:
1313
type: passthrough
1414
dynamic: true
1515
priority: 10
16+
# workaround for https://github.com/elastic/elasticsearch/issues/99123
17+
_metric_names_hash:
18+
type: keyword
19+
time_series_dimension: true
1620
unit:
1721
type: keyword
1822
time_series_dimension: true

x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_tests.yml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,26 @@ Metrics with different scope names are not duplicates:
305305
metrics:
306306
foo.bar: 42
307307
- is_false: errors
308+
309+
---
310+
Metrics with different metric name hashes are not duplicates:
311+
- do:
312+
bulk:
313+
index: metrics-generic.otel-default
314+
refresh: true
315+
body:
316+
- create: {"dynamic_templates":{"metrics.foo":"counter_long"}}
317+
- "@timestamp": 2024-07-18T14:00:00Z
318+
attributes:
319+
foo: bar
320+
metrics:
321+
foo: 42
322+
_metric_names_hash: a9f37ed7
323+
- create: {"dynamic_templates":{"metrics.bar":"counter_long"}}
324+
- "@timestamp": 2024-07-18T14:00:00Z
325+
attributes:
326+
foo: bar
327+
metrics:
328+
bar: 42
329+
_metric_names_hash: 76b77d1a
330+
- is_false: errors

0 commit comments

Comments
 (0)