Skip to content

Commit 60b9135

Browse files
authored
[otel-data] Add @timestamp as sort field for logs and traces (#114049) (#114125)
* Add @timestamp as sort field for logs and traces * Change order of sort fields * Adapt tests
1 parent 79e662e commit 60b9135

File tree

4 files changed

+42
-19
lines changed

4 files changed

+42
-19
lines changed

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ template:
88
index:
99
mode: logsdb
1010
sort:
11-
field: [ "resource.attributes.host.name" ]
11+
field: [ "resource.attributes.host.name", "@timestamp" ]
1212
mappings:
1313
properties:
1414
attributes:

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ template:
88
index:
99
mode: logsdb
1010
sort:
11-
field: [ "resource.attributes.host.name" ]
11+
field: [ "resource.attributes.host.name", "@timestamp" ]
1212
mappings:
1313
_source:
1414
mode: synthetic

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

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,23 @@ setup:
7070
- match: { hits.hits.0.fields.error\.exception\.type: ["MyException"] }
7171
- match: { hits.hits.0.fields.error\.exception\.message: ["foo"] }
7272
- match: { hits.hits.0.fields.error\.stack_trace: ["Exception in thread \"main\" java.lang.RuntimeException: Test exception\n at com.example.GenerateTrace.methodB(GenerateTrace.java:13)\n at com.example.GenerateTrace.methodA(GenerateTrace.java:9)\n at com.example.GenerateTrace.main(GenerateTrace.java:5)"] }
73+
---
74+
"resource.attributes.host.name @timestamp should be used as sort fields":
75+
- do:
76+
bulk:
77+
index: logs-generic.otel-default
78+
refresh: true
79+
body:
80+
- create: {}
81+
- '{"@timestamp":"2024-07-18T14:49:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "body_text":"error1"}'
82+
- is_false: errors
83+
- do:
84+
indices.get_data_stream:
85+
name: logs-generic.otel-default
86+
- set: { data_streams.0.indices.0.index_name: datastream-backing-index }
87+
- do:
88+
indices.get_settings:
89+
index: $datastream-backing-index
90+
- is_true: $datastream-backing-index
91+
- match: { .$datastream-backing-index.settings.index.sort.field.0: "resource.attributes.host.name" }
92+
- match: { .$datastream-backing-index.settings.index.sort.field.1: "@timestamp" }

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

Lines changed: 20 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,6 @@ setup:
7676
- match: { hits.hits.0._source.links.1.trace_id: "4aaa9f33312b3dbb8b2c2c62bb7abe1a1" }
7777
- match: { hits.hits.0._source.links.1.span_id: "b3b7d1f1f1b4e1e1" }
7878
---
79-
"Default data_stream.type must be traces":
80-
- do:
81-
bulk:
82-
index: traces-generic.otel-default
83-
refresh: true
84-
body:
85-
- create: {}
86-
- '{"@timestamp":"2024-02-18T14:48:33.467654000Z","data_stream":{"dataset":"generic.otel","type":"traces","namespace":"default"},"resource":{"attributes":{"service.name":"OtelSample","telemetry.sdk.language":"dotnet","telemetry.sdk.name":"opentelemetry"}},"name":"foo","trace_id":"7bba9f33312b3dbb8b2c2c62bb7abe2d","span_id":"086e83747d0e381e","kind":"SERVER","status":{"code":"2xx"}}'
87-
- is_false: errors
88-
- do:
89-
search:
90-
index: traces-generic.otel-default
91-
body:
92-
fields: ["data_stream.type"]
93-
- length: { hits.hits: 1 }
94-
- match: { hits.hits.0.fields.data_stream\.type: ["traces"] }
95-
---
9679
Conflicting attribute types:
9780
- do:
9881
bulk:
@@ -117,3 +100,23 @@ Conflicting attribute types:
117100
- length: { hits.hits: 2 }
118101
- match: { hits.hits.0.fields.attributes\.http\.status_code: [200] }
119102
- match: { hits.hits.1._ignored: ["attributes.http.status_code"] }
103+
---
104+
"resource.attributes.host.name @timestamp should be used as sort fields":
105+
- do:
106+
bulk:
107+
index: traces-generic.otel-default
108+
refresh: true
109+
body:
110+
- create: {}
111+
- '{"@timestamp":"2024-07-18T14:49:33.467654000Z","data_stream":{"dataset":"generic.otel","namespace":"default"}, "span_id":"1"}'
112+
- is_false: errors
113+
- do:
114+
indices.get_data_stream:
115+
name: traces-generic.otel-default
116+
- set: { data_streams.0.indices.0.index_name: datastream-backing-index }
117+
- do:
118+
indices.get_settings:
119+
index: $datastream-backing-index
120+
- is_true: $datastream-backing-index
121+
- match: { .$datastream-backing-index.settings.index.sort.field.0: "resource.attributes.host.name" }
122+
- match: { .$datastream-backing-index.settings.index.sort.field.1: "@timestamp" }

0 commit comments

Comments
 (0)