Skip to content

Commit 08997a2

Browse files
authored
apm-data: add event.ingested field to APM documents (#117970) (#119209)
Restore a field originally populated by Fleet final ingest pipeline in all APM documents. --------- Signed-off-by: inge4pres <[email protected]> (cherry picked from commit 78385f3)
1 parent 2853f38 commit 08997a2

File tree

5 files changed

+96
-4
lines changed

5 files changed

+96
-4
lines changed

x-pack/plugin/apm-data/src/main/resources/index-templates/[email protected]

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,4 @@ template:
3030
data_stream.dataset:
3131
type: constant_keyword
3232
value: apm.sampled
33-
event.ingested:
34-
type: date
35-
format: date_time_no_millis
36-
script: "emit(System.currentTimeMillis())"
33+

x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/[email protected]

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,3 +24,13 @@ processors:
2424
target_field: user_agent
2525
ignore_failure: true
2626
ignore_missing: true
27+
- script:
28+
description: Add time when event was ingested (and remove sub-seconds to improve storage efficiency)
29+
tag: truncate-subseconds-event-ingested
30+
ignore_failure: true
31+
source: |-
32+
if (ctx?.event == null) {
33+
ctx.event = [:];
34+
}
35+
36+
ctx.event.ingested = metadata().now.withNano(0).format(DateTimeFormatter.ISO_OFFSET_DATE_TIME);

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

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,3 +26,29 @@ setup:
2626
- length: { hits.hits: 2 }
2727
- match: { hits.hits.0.fields: { "log.level": ["error"] } }
2828
- match: { hits.hits.1.fields: { "log.level": ["warn"] } }
29+
---
30+
"Test logs-apm.error-* setting event.ingested via ingest pipeline":
31+
- requires:
32+
test_runner_features: [is_after]
33+
- do:
34+
bulk:
35+
index: logs-apm.error-event-ingested-testing
36+
refresh: true
37+
body:
38+
# No event.ingested field populated, it gets added
39+
- create: {}
40+
- '{"@timestamp": "2017-06-22", "log": {"level": "error"}, "error": {"log": {"message": "loglevel"}, "exception": [{"message": "exception_used"}]}}'
41+
42+
# event.ingested populated, it is overwritten with current timestamp
43+
- create: {}
44+
- '{"@timestamp": "2017-06-22", "log": {"level": "warn"}, "error": {"log": {"message": "loglevel"}, "exception": [{"message": "exception_used"}]}, "event": {"ingested": "2017-06-22T12:34:56.789123Z"}}'
45+
46+
- is_false: errors
47+
48+
- do:
49+
search:
50+
index: logs-apm.error-event-ingested-testing
51+
body:
52+
fields: ["event.ingested"]
53+
- length: { hits.hits: 2 }
54+
- is_after: { hits.hits.1.fields.event\.ingested.0: "2017-06-22T12:34:56.789Z" }
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
---
2+
setup:
3+
- do:
4+
cluster.health:
5+
wait_for_events: languid
6+
7+
---
8+
"Test metrics-apm.app-* setting event.ingested via ingest pipeline":
9+
- requires:
10+
test_runner_features: [is_after]
11+
- do:
12+
bulk:
13+
index: metrics-apm.app.ingest
14+
refresh: true
15+
body:
16+
# No event.ingested field populated, it gets added
17+
- create: {}
18+
- '{"@timestamp": "2017-06-22"}'
19+
20+
# event.ingested populated, it is overwritten with current timestamp
21+
- create: {}
22+
- '{"@timestamp": "2017-06-22", "event": {"ingested": "2017-06-22T00:00:00.789123Z"}}'
23+
24+
- is_false: errors
25+
26+
- do:
27+
search:
28+
index: metrics-apm.app.ingest
29+
body:
30+
fields: ["event.ingested"]
31+
- length: { hits.hits: 2 }
32+
- is_after: { hits.hits.1.fields.event\.ingested.0: "2017-06-22T00:00:00.000Z" }

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

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,3 +97,30 @@ setup:
9797
- match: { hits.hits.1.fields: null }
9898
- match: { hits.hits.2.fields: {"event.success_count": [1]} }
9999
- match: { hits.hits.3.fields: {"event.success_count": [0]} }
100+
---
101+
"Test traces-apm-* setting event.ingested via ingest pipeline":
102+
- requires:
103+
test_runner_features: [is_after]
104+
- do:
105+
bulk:
106+
index: traces-apm-testing
107+
refresh: true
108+
body:
109+
# No event.ingested field populated, it gets added
110+
- create: {}
111+
- '{"@timestamp": "2017-06-22"}'
112+
113+
# event.ingested populated, it is preserved
114+
- create: {}
115+
- '{"@timestamp": "2017-06-22", "event": {"ingested": "2017-06-22T00:00:00.123456Z"}}'
116+
117+
- is_false: errors
118+
119+
- do:
120+
search:
121+
index: traces-apm-testing
122+
body:
123+
fields: ["event.ingested"]
124+
- length: { hits.hits: 2 }
125+
- is_after: { hits.hits.1.fields.event\.ingested.0: "2017-06-22T00:00:00.000Z" }
126+

0 commit comments

Comments
 (0)