Browse Source

x-pack/plugin/otel-data: Fix dynamic template summary and summary_minmax (#113868) (#113889)

<!-- Thank you for your interest in and contributing to Elasticsearch!
There are a few simple things to check before submitting your pull
request that can help with the review process. You should delete these
items from your submission, but they are here to help bring them to your
attention. --> Fix error `failed to parse: class java.lang.String cannot
be cast to class java.util.List (java.lang.String and java.util.List are
in module java.base of loader 'bootstrap')`

(cherry picked from commit f6a5252436cc5f659a6b5ae6e2c8e60c01c27f6b)

Co-authored-by: Elastic Machine <elasticmachine@users.noreply.github.com>
Carson Ip 1 year ago
parent
commit
08efdad65c

+ 2 - 2
x-pack/plugin/otel-data/src/main/resources/component-templates/metrics-otel@mappings.yaml

@@ -43,10 +43,10 @@ template:
       - summary:
           mapping:
             type: aggregate_metric_double
-            metrics: sum, value_count
+            metrics: [sum, value_count]
             default_metric: value_count
       - summary_minmax:
           mapping:
             type: aggregate_metric_double
-            metrics: sum, value_count, min, max
+            metrics: [sum, value_count, min, max]
             default_metric: value_count

+ 1 - 1
x-pack/plugin/otel-data/src/main/resources/resources.yaml

@@ -1,7 +1,7 @@
 # "version" holds the version of the templates and ingest pipelines installed
 # by xpack-plugin otel-data. This must be increased whenever an existing template is
 # changed, in order for it to be updated on Elasticsearch upgrade.
-version: 1
+version: 2
 
 component-templates:
   - otel@mappings

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

@@ -196,3 +196,52 @@ IP dimensions:
       search:
         index: metrics-generic.otel-default
   - length: { hits.hits: 1 }
+---
+"Dynamic templates":
+  - do:
+      bulk:
+        index: metrics-generic.otel-default
+        refresh: true
+        body:
+          - create: {"dynamic_templates":{"metrics.counter_long":"counter_long","metrics.gauge_long":"gauge_long","metrics.counter_double":"counter_double","metrics.gauge_double":"gauge_double","metrics.summary":"summary","metrics.summary_minmax":"summary_minmax","metrics.histogram":"histogram"}}
+          - "@timestamp": 2024-07-18T14:48:33.467654000Z
+            attributes:
+              foo: bar
+            metrics:
+              counter_long: 42
+              gauge_long: 42
+              counter_double: 42.42
+              gauge_double: 42.42
+              summary:
+                sum: 42.42
+                value_count: 42
+              summary_minmax:
+                sum: 42.42
+                value_count: 42
+                min: 0.42
+                max: 4.2
+              histogram:
+                counts: [1,2]
+                values: [42,4242]
+  - is_false: errors
+  - do:
+      search:
+        index: metrics-generic.otel-default
+  - length: { hits.hits: 1 }
+
+  - do:
+      indices.get_data_stream:
+        name: metrics-generic.otel-default
+  - set: { data_streams.0.indices.0.index_name: idx0name }
+
+  - do:
+      indices.get_mapping:
+        index: $idx0name
+        expand_wildcards: hidden
+  - match: { .$idx0name.mappings.properties.metrics.properties.counter_long.type: 'long' }
+  - match: { .$idx0name.mappings.properties.metrics.properties.gauge_long.type: 'long' }
+  - match: { .$idx0name.mappings.properties.metrics.properties.counter_double.type: 'double' }
+  - match: { .$idx0name.mappings.properties.metrics.properties.gauge_double.type: 'double' }
+  - match: { .$idx0name.mappings.properties.metrics.properties.summary.type: 'aggregate_metric_double' }
+  - match: { .$idx0name.mappings.properties.metrics.properties.summary_minmax.type: 'aggregate_metric_double' }
+  - match: { .$idx0name.mappings.properties.metrics.properties.histogram.type: 'histogram' }