Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

x-pack/plugin/apm-data: map some APM fields as flattened and fix error.grouping_name script #103032

Merged
merged 7 commits into from
Dec 16, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions docs/changelog/103032.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
pr: 103032
summary: "x-pack/plugin/apm-data: Map some APM fields as flattened and fix error.grouping_name script"
area: Data streams
type: enhancement
issues: []
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,29 @@ _meta:
template:
mappings:
properties:
# error.*
error.custom:
type: flattened
error.exception.attributes:
type: flattened
error.exception.stacktrace:
type: flattened
error.log.stacktrace:
type: flattened
error.grouping_name:
type: keyword
script: |
def logMessage = params['_source'].error?.log?.message;
if (logMessage != null) {
if (logMessage != null && logMessage != "") {
emit(logMessage);
return;
}
def exception = params['_source'].error?.exception;
if (exception != null && exception.length > 0) {
def exceptionMessage = exception != null && exception.length > 0 ? exception[0]?.message : null;
if (exceptionMessage != null && exceptionMessage != "") {
emit(exception[0].message);
}

# http.*
http.request.body:
type: flattened
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,22 @@ _meta:
template:
mappings:
properties:
# NOTE(axw) processor.event may be either "span" or "transaction".
#
# This field should eventually be removed, and we should end up
# with only spans. Some of those spans may be identified as local
# roots, equivalent in concept to transactions.
processor.event:
type: keyword

# event.*
event.success_count:
type: byte
index: false
span.duration.us:
type: long
transaction.duration.us:
type: long

# http.*
http.request.body:
type: flattened
http.response.transfer_size:
type: long
index: false
Expand All @@ -24,10 +31,22 @@ template:
http.response.decoded_body_size:
type: long
index: false

# span.*
span.duration.us:
type: long
span.representative_count:
type: scaled_float
scaling_factor: 1000
index: false
span.stacktrace:
type: flattened

# transaction.*
transaction.custom:
type: flattened
transaction.duration.us:
type: long
transaction.representative_count:
type: scaled_float
scaling_factor: 1000
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,110 +82,3 @@ setup:
- length: {hits.hits: 1}
- match: {hits.hits.0.fields.event\.success_count: [1]}
- match: {hits.hits.0.fields.span\.duration\.us: [123]}

---
"Test metrics-apm.internal-* data stream rerouting":
- do:
bulk:
index: metrics-apm.internal-testing
refresh: true
body:
- create: {}
- "@timestamp": "2017-06-22"
data_stream.type: metrics
data_stream.dataset: apm.internal
data_stream.namespace: testing
metricset:
name: transaction
- create: {}
- "@timestamp": "2017-06-22"
data_stream.type: metrics
data_stream.dataset: apm.internal
data_stream.namespace: testing
metricset:
name: service_destination
- create: {}
- "@timestamp": "2017-06-22"
data_stream.type: metrics
data_stream.dataset: apm.internal
data_stream.namespace: testing
metricset:
name: app_config # should not be rerouted
- do:
indices.get_data_stream:
name: metrics-apm.transaction.1m-testing
- do:
indices.get_data_stream:
name: metrics-apm.service_destination.1m-testing
- do:
indices.get_data_stream:
name: metrics-apm.internal-testing
- do:
search:
index: metrics-apm*
- length: {hits.hits: 3}
- match: {hits.hits.0._source.data_stream.dataset: "apm.internal"}
- match: {hits.hits.1._source.data_stream.dataset: "apm.service_destination.1m"}
- match: {hits.hits.1._source.metricset.interval: "1m"}
- match: {hits.hits.2._source.data_stream.dataset: "apm.transaction.1m"}
- match: {hits.hits.2._source.metricset.interval: "1m"}

---
"Test metrics-apm.app-* dynamic mapping":
- do:
bulk:
index: metrics-apm.app.svc1-testing
refresh: true
body:
- create: {}
- "@timestamp": "2017-06-22"
data_stream.type: metrics
data_stream.dataset: apm.app.svc1
data_stream.namespace: testing
metricset:
name: app
samples:
- name: double_metric
type: gauge
value: 123
- name: summary_metric
type: summary
value_count: 123
sum: 456.789
- name: histogram_metric
type: histogram
counts: [1, 2, 3]
values: [1.5, 2.5, 3.5]
- set:
items.0.create._index: index
- do:
# Wait for cluster state changes to be applied before
# querying field mappings.
cluster.health:
wait_for_events: languid
- do:
indices.get_field_mapping:
index: metrics-apm.app.svc1-testing
fields: [double_metric, summary_metric, histogram_metric]
- match:
$body:
$index:
mappings:
double_metric:
full_name: double_metric
mapping:
double_metric:
type: double
index: false
summary_metric:
full_name: summary_metric
mapping:
summary_metric:
type: aggregate_metric_double
metrics : [sum, value_count]
default_metric: value_count
histogram_metric:
full_name: histogram_metric
mapping:
histogram_metric:
type: histogram
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
---
setup:
- do:
cluster.health:
wait_for_events: languid

---
"Test logs-apm.error-* error grouping":
- do:
bulk:
index: logs-apm.error-testing
refresh: true
body:
# No error object field
- create: {}
- '{"@timestamp": "2017-06-22"}'

# Empty error object
- create: {}
- '{"@timestamp": "2017-06-22", "error": {}}'

# Empty error.log object
- create: {}
- '{"@timestamp": "2017-06-22", "error": {"log": {}}}'

# Empty error.exception array
- create: {}
- '{"@timestamp": "2017-06-22", "error": {"exception": []}}'

# Empty error.exception object
- create: {}
- '{"@timestamp": "2017-06-22", "error": {"exception": [{}]}}'

# Non-empty error.log.message used
- create: {}
- '{"@timestamp": "2017-06-22", "error": {"log": {"message": "log_used"}, "exception": [{"message": "ignored"}]}}'

# Non-empty error.exception.message used
- create: {}
- '{"@timestamp": "2017-06-22", "error": {"log": {"message": ""}, "exception": [{"message": "exception_used"}]}}'

- is_false: errors

- do:
search:
index: logs-apm.error-testing
body:
fields: ["error.grouping_name"]
- length: { hits.hits: 7 }
- match: { hits.hits.0.fields: null }
- match: { hits.hits.1.fields: null }
- match: { hits.hits.2.fields: null }
- match: { hits.hits.3.fields: null }
- match: { hits.hits.4.fields: null }
- match: { hits.hits.5.fields: {"error.grouping_name": ["log_used"]} }
- match: { hits.hits.6.fields: {"error.grouping_name": ["exception_used"]} }
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
---
setup:
- do:
cluster.health:
wait_for_events: languid

---
"Test traces-apm-* flattened fields":
- do:
bulk:
index: traces-apm-testing
refresh: true
body:
# http.request.body should be mapped as flattened, allowing
# differing types to be used in http.request.body.original.
- create: {}
- '{"@timestamp": "2017-06-22", "http.request.body": {"original": "text"}}'
- create: {}
- '{"@timestamp": "2017-06-22", "http.request.body": {"original": {"field": "value"}}}'

# span.stacktrace is a complex object whose structure may
# change over time, and which is always treated as an object.
# Moreover, stacktraces may contain dynamic "vars" whose
# types may change from one document to the next.
- create: {}
- '{"@timestamp": "2017-06-22", "span.stacktrace": [{"vars": {"a": 123}}]}'
- create: {}
- '{"@timestamp": "2017-06-22", "span.stacktrace": [{"vars": {"a": "b"}}]}'

# transaction.custom is a complex object of fields with
# arbitrary field types that may change from one document
# to the next.
- create: {}
- '{"@timestamp": "2017-06-22", "transaction.custom": {"a": {"b": 123}}}'
- create: {}
- '{"@timestamp": "2017-06-22", "transaction.custom": {"a": "b"}}'

- is_false: errors

- do:
search:
index: traces-apm-testing
body:
fields: ["http.request.body", "span.stacktrace", "transaction.custom"]
- length: { hits.hits: 6 }
- match: { hits.hits.0.fields: {"http.request.body": [{"original": "text"}]} }
- match: { hits.hits.1.fields: {"http.request.body": [{"original": {"field": "value"}}]} }
- match: { hits.hits.2.fields: {"span.stacktrace": [{"vars": {"a": 123}}]} }
- match: { hits.hits.3.fields: {"span.stacktrace": [{"vars": {"a": "b"}}]} }
- match: { hits.hits.4.fields: {"transaction.custom": [{"a": {"b": 123}}]} }
- match: { hits.hits.5.fields: {"transaction.custom": [{"a": "b"}]} }

---
"Test logs-apm.error-* flattened fields":
- do:
bulk:
index: logs-apm.error-testing
refresh: true
body:
# http.request.body has the same requirements as http.request.body
# in traces-apm-* data streams.
- create: {}
- '{"@timestamp": "2017-06-22", "http.request.body": {"original": "text"}}'
- create: {}
- '{"@timestamp": "2017-06-22", "http.request.body": {"original": {"field": "value"}}}'

# error.{exception,log}.stacktrace have the same requirements as span.stacktrace.
- create: {}
- '{"@timestamp": "2017-06-22", "error.exception.stacktrace": [{"vars": {"a": 123}}]}'
- create: {}
- '{"@timestamp": "2017-06-22", "error.exception.stacktrace": [{"vars": {"a": "b"}}]}'
- create: {}
- '{"@timestamp": "2017-06-22", "error.log.stacktrace": [{"vars": {"a": 123}}]}'
- create: {}
- '{"@timestamp": "2017-06-22", "error.log.stacktrace": [{"vars": {"a": "b"}}]}'

# error.exception.attributes is a complex object with arbitrary field types
# that may change from one document to the next.
- create: {}
- '{"@timestamp": "2017-06-22", "error.exception": [{"attributes": {"a": 123}}]}'
- create: {}
- '{"@timestamp": "2017-06-22", "error.exception": [{"attributes": {"a": "b"}}]}'

# error.custom has the same requirements as transaction.custom.
- create: {}
- '{"@timestamp": "2017-06-22", "error.custom": {"a": {"b": 123}}}'
- create: {}
- '{"@timestamp": "2017-06-22", "error.custom": {"a": "b"}}'

- is_false: errors

- do:
search:
index: logs-apm.error-testing
body:
fields: ["http.request.body", "error.log.*", "error.exception.*", "error.custom"]
- length: { hits.hits: 10 }
- match: { hits.hits.0.fields: {"http.request.body": [{"original": "text"}]} }
- match: { hits.hits.1.fields: {"http.request.body": [{"original": {"field": "value"}}]} }
- match: { hits.hits.2.fields: {"error.exception.stacktrace": [{"vars": {"a": 123}}]} }
- match: { hits.hits.3.fields: {"error.exception.stacktrace": [{"vars": {"a": "b"}}]} }
- match: { hits.hits.4.fields: {"error.log.stacktrace": [{"vars": {"a": 123}}]} }
- match: { hits.hits.5.fields: {"error.log.stacktrace": [{"vars": {"a": "b"}}]} }
- match: { hits.hits.6.fields: {"error.exception.attributes": [{"a": 123}]} }
- match: { hits.hits.7.fields: {"error.exception.attributes": [{"a": "b"}]} }
- match: { hits.hits.8.fields: {"error.custom": [{"a": {"b": 123}}]} }
- match: { hits.hits.9.fields: {"error.custom": [{"a": "b"}]} }
Loading