From faefe32444f9130fb2552bc522243dbd339c24dd Mon Sep 17 00:00:00 2001 From: Ruben van Staden Date: Fri, 10 Jan 2025 14:46:11 -0500 Subject: [PATCH 1/2] plugin: add representative count to apm-data --- .../ingest-pipelines/traces-apm@pipeline.yaml | 6 ++--- .../rest-api-spec/test/20_traces_ingest.yml | 22 +++++++++++++++---- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml b/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml index f79c07ff40ac0..f41d7a4072cb5 100644 --- a/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml +++ b/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml @@ -30,10 +30,10 @@ processors: field: ["event.duration"] ignore_failure: true ignore_missing: true -- set: +- script: if: ctx.event?.outcome == 'success' - field: event.success_count - value: 1 + source: | + ctx.event.success_count = ctx[ctx.processor?.event].representative_count; - set: if: ctx.event?.outcome == 'failure' field: event.success_count diff --git a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_traces_ingest.yml b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_traces_ingest.yml index ea7f948abf0b8..a5786dc168dd5 100644 --- a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_traces_ingest.yml +++ b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_traces_ingest.yml @@ -80,7 +80,20 @@ setup: - '{"@timestamp": "2017-06-22", "event": {"outcome": "unknown"}}' - create: {} - - '{"@timestamp": "2017-06-22", "event": {"outcome": "success"}}' + - '{ + "@timestamp": "2017-06-22", + "processor": {"event": "transaction"}, + "event": {"outcome": "success"}, + "transaction": {"representative_count": 2} + }' + + - create: {} + - '{ + "@timestamp": "2017-06-22", + "processor": {"event": "span"}, + "event": {"outcome": "success"}, + "span": {"representative_count": 3} + }' - create: {} - '{"@timestamp": "2017-06-22", "event": {"outcome": "failure"}}' @@ -92,8 +105,9 @@ setup: index: traces-apm-testing body: fields: ["event.success_count"] - - length: { hits.hits: 4 } + - length: { hits.hits: 5 } - match: { hits.hits.0.fields: null } - match: { hits.hits.1.fields: null } - - match: { hits.hits.2.fields: {"event.success_count": [1]} } - - match: { hits.hits.3.fields: {"event.success_count": [0]} } + - match: { hits.hits.2.fields: {"event.success_count": [2]} } + - match: { hits.hits.3.fields: {"event.success_count": [3]} } + - match: { hits.hits.4.fields: {"event.success_count": [0]} } From 953a14106ab74411dbd9c4f2f07862652d390cd3 Mon Sep 17 00:00:00 2001 From: Ruben van Staden Date: Fri, 10 Jan 2025 16:52:18 -0500 Subject: [PATCH 2/2] add reviewer comments --- .../main/resources/ingest-pipelines/traces-apm@pipeline.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml b/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml index f41d7a4072cb5..0433aabfbccc3 100644 --- a/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml +++ b/x-pack/plugin/apm-data/src/main/resources/ingest-pipelines/traces-apm@pipeline.yaml @@ -33,7 +33,7 @@ processors: - script: if: ctx.event?.outcome == 'success' source: | - ctx.event.success_count = ctx[ctx.processor?.event].representative_count; + ctx.event.success_count = ctx[ctx.processor?.event]?.representative_count; - set: if: ctx.event?.outcome == 'failure' field: event.success_count