diff --git a/docs/changelog/141877.yaml b/docs/changelog/141877.yaml new file mode 100644 index 0000000000000..34b0ada90726d --- /dev/null +++ b/docs/changelog/141877.yaml @@ -0,0 +1,5 @@ +area: Mapping +issues: [] +pr: 141877 +summary: Deprecate aggregate metric double default metric configuration +type: enhancement diff --git a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java index 1453386069a5a..5322eef7212e8 100644 --- a/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/test/rest/ESRestTestCase.java @@ -1998,11 +1998,11 @@ protected static CreateIndexResponse createIndex(String name, Settings settings) } protected static CreateIndexResponse createIndex(RestClient client, String name, Settings settings) throws IOException { - return createIndex(client, name, settings, null, null); + return createIndex(client, name, settings, null, null, RequestOptions.DEFAULT); } protected static CreateIndexResponse createIndex(RestClient client, String name, Settings settings, String mapping) throws IOException { - return createIndex(client, name, settings, mapping, null); + return createIndex(client, name, settings, mapping, null, RequestOptions.DEFAULT); } protected static CreateIndexResponse createIndex(String name, Settings settings, String mapping) throws IOException { @@ -2013,9 +2013,30 @@ protected static CreateIndexResponse createIndex(String name, Settings settings, return createIndex(client(), name, settings, mapping, aliases); } + protected static CreateIndexResponse createIndex( + String name, + Settings settings, + String mapping, + String aliases, + RequestOptions requestOptions + ) throws IOException { + return createIndex(client(), name, settings, mapping, aliases, requestOptions); + } + public static CreateIndexResponse createIndex(RestClient client, String name, Settings settings, String mapping, String aliases) throws IOException { - return createIndex(client::performRequest, name, settings, mapping, aliases); + return createIndex(client::performRequest, name, settings, mapping, aliases, RequestOptions.DEFAULT); + } + + public static CreateIndexResponse createIndex( + RestClient client, + String name, + Settings settings, + String mapping, + String aliases, + RequestOptions requestOptions + ) throws IOException { + return createIndex(client::performRequest, name, settings, mapping, aliases, requestOptions); } protected static CreateIndexResponse createIndex( @@ -2024,6 +2045,17 @@ protected static CreateIndexResponse createIndex( Settings settings, String mapping, String aliases + ) throws IOException { + return createIndex(execute, name, settings, mapping, aliases, RequestOptions.DEFAULT); + } + + protected static CreateIndexResponse createIndex( + CheckedFunction execute, + String name, + Settings settings, + String mapping, + String aliases, + RequestOptions requestOptions ) throws IOException { final Request request = newXContentRequest(HttpMethod.PUT, "/" + name, (builder, params) -> { if (settings != null) { @@ -2053,6 +2085,7 @@ protected static CreateIndexResponse createIndex( return builder; }); + request.setOptions(requestOptions); if (settings != null && settings.getAsBoolean(IndexSettings.INDEX_SOFT_DELETES_SETTING.getKey(), true) == false) { expectSoftDeletesWarning(request, name); diff --git a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_mapping.yml b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_mapping.yml index 85858a9c5ed2e..f6ed5b606ea6a 100644 --- a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_mapping.yml +++ b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_mapping.yml @@ -1,5 +1,7 @@ --- setup: + - skip: + features: allowed_warnings - do: cluster.health: wait_for_events: languid @@ -7,6 +9,8 @@ setup: --- "Test metrics-apm.app-* dynamic mapping": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: index: metrics-apm.app.svc1-testing refresh: true diff --git a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_rerouting.yml b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_rerouting.yml index f5f2307570563..8d8bff310eb8e 100644 --- a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_rerouting.yml +++ b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_rerouting.yml @@ -1,5 +1,7 @@ --- setup: + - skip: + features: allowed_warnings - do: cluster.health: wait_for_events: languid @@ -7,6 +9,8 @@ setup: --- "Test metrics-apm.internal-* data stream rerouting": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: index: metrics-apm.internal-testing refresh: true diff --git a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_pipelines.yml b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_pipelines.yml index 339b3b56462ac..a0172a01a7031 100644 --- a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_pipelines.yml +++ b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_pipelines.yml @@ -1,5 +1,7 @@ --- setup: + - skip: + features: [allowed_warnings] - do: cluster.health: wait_for_events: languid @@ -220,6 +222,8 @@ setup: --- "Test logs @custom ingest pipelines": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: refresh: true body: @@ -243,6 +247,8 @@ setup: --- "Test metrics @custom ingest pipelines": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: refresh: true body: @@ -294,6 +300,8 @@ setup: --- "Test traces @custom ingest pipelines": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: refresh: true body: diff --git a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_templates.yml b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_templates.yml index 62b36926d01dc..3669a6ecc3104 100644 --- a/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_templates.yml +++ b/x-pack/plugin/apm-data/src/yamlRestTest/resources/rest-api-spec/test/30_custom_templates.yml @@ -1,10 +1,14 @@ --- setup: + - skip: + features: allowed_warnings - do: cluster.health: wait_for_events: languid - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" cluster.put_component_template: name: "metrics@custom" body: @@ -21,6 +25,8 @@ setup: source: metrics@custom - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" cluster.put_component_template: name: "metrics-apm.app@custom" body: @@ -39,6 +45,8 @@ setup: --- "Test metrics @custom component templates": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create_data_stream: name: metrics-apm.app.svc1-testing - do: @@ -47,6 +55,8 @@ setup: cluster.health: wait_for_events: languid - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.get_field_mapping: index: metrics-apm.app.svc1-testing fields: custom_field* diff --git a/x-pack/plugin/build.gradle b/x-pack/plugin/build.gradle index afe5154717bd4..18070c914e310 100644 --- a/x-pack/plugin/build.gradle +++ b/x-pack/plugin/build.gradle @@ -173,6 +173,11 @@ tasks.named("yamlRestCompatTestTransform").configure( task.skipTest("esql/192_lookup_join_on_aliases/alias-pattern-single", "New SORT warning not in original test") task.skipTest("ml/data_frame_analytics_crud/Test put config with remote source index", "Error message changed") task.skipTest("esql/40_tsdb/PromQL irate on counter field", "We filter out null values now") + // Expected deprecation warning to compat yaml tests: + task.addAllowedWarningRegex("Parameter \\[default_metric\\] is deprecated and will be removed in a future version") + task.skipTest("aggregate-metrics/40_avg_agg/Test avg agg with query", "Default metric cannot be defined, so the query is empty") + task.skipTest("aggregate-metrics/30_sum_agg/Test sum agg with query", "Default metric cannot be defined, so the query is empty") + task.skipTest("aggregate-metrics/50_value_count_agg/Test value_count agg with query", "Default metric cannot be defined, so the query is empty") } ) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java index 42824a553d2bd..c139f5fbd5b1f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/XPackFeatures.java @@ -16,8 +16,13 @@ * Provides the XPack features that this version of the code supports */ public class XPackFeatures implements FeatureSpecification { + + public static final NodeFeature AGGREGATE_METRIC_DOUBLE_DEPRECATED_DEFAULT_METRIC = new NodeFeature( + "aggregate_metric_double.default_metric.deprecated" + ); + @Override public Set getFeatures() { - return Set.of(); + return Set.of(AGGREGATE_METRIC_DOUBLE_DEPRECATED_DEFAULT_METRIC); } } diff --git a/x-pack/plugin/downsample/qa/mixed-cluster/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml b/x-pack/plugin/downsample/qa/mixed-cluster/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml index fd893eb2e5e30..3c2be407af113 100644 --- a/x-pack/plugin/downsample/qa/mixed-cluster/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml +++ b/x-pack/plugin/downsample/qa/mixed-cluster/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml @@ -85,8 +85,11 @@ setup: - requires: cluster_features: ["gte_v8.10.0"] reason: "Downsampling executed using persistent task framework from version 8.10" + test_runner_features: allowed_warnings - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample diff --git a/x-pack/plugin/downsample/qa/rest/build.gradle b/x-pack/plugin/downsample/qa/rest/build.gradle index e3f456495d3ef..01d4d5736529d 100644 --- a/x-pack/plugin/downsample/qa/rest/build.gradle +++ b/x-pack/plugin/downsample/qa/rest/build.gradle @@ -50,3 +50,12 @@ configurations { artifacts { basicRestSpecs(new File(projectDir, "src/yamlRestTest/resources/rest-api-spec/test")) } + +tasks.named("yamlRestCompatTestTransform").configure({ task -> + // Expected deprecation warning to compat yaml tests: + task.addAllowedWarningRegex("Parameter \\[default_metric\\] is deprecated and will be removed in a future version") + task.skipTest("downsample/10_basic/Downsample a downsampled index", "Default metric has been removed") + task.skipTest("downsample/10_basic/Downsample histogram as label", "Default metric has been removed") + task.skipTest("downsample/10_basic/Downsample index", "Default metric has been removed") + task.skipTest("downsample-with-security/10_basic/Downsample index", "Default metric has been removed") +}) diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample-with-security/10_basic.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample-with-security/10_basic.yml index c95bb34732dad..87783a918c86c 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample-with-security/10_basic.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample-with-security/10_basic.yml @@ -295,8 +295,11 @@ setup: - requires: cluster_features: ["gte_v8.13.0"] reason: _tsid hashing introduced in 8.13 + test_runner_features: allowed_warnings - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -355,7 +358,6 @@ setup: - match: { test-downsample.mappings.properties.@timestamp.meta.time_zone: UTC } - match: { test-downsample.mappings.properties.k8s.properties.pod.properties.multi-gauge.type: aggregate_metric_double } - match: { test-downsample.mappings.properties.k8s.properties.pod.properties.multi-gauge.metrics: [ "min", "max", "sum", "value_count" ] } - - match: { test-downsample.mappings.properties.k8s.properties.pod.properties.multi-gauge.default_metric: max } - match: { test-downsample.mappings.properties.k8s.properties.pod.properties.multi-gauge.time_series_metric: gauge } - match: { test-downsample.mappings.properties.k8s.properties.pod.properties.multi-counter.type: long } - match: { test-downsample.mappings.properties.k8s.properties.pod.properties.multi-counter.time_series_metric: counter } diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml index 74e572708cbab..d574c24d8b67c 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/10_basic.yml @@ -2,6 +2,7 @@ setup: - requires: cluster_features: ["gte_v8.5.0"] reason: "rollup renamed to downsample in 8.5.0" + test_runner_features: allowed_warnings - do: indices.create: @@ -305,6 +306,8 @@ setup: reason: _tsid hashing introduced in 8.13 - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -368,7 +371,6 @@ setup: - match: { test-downsample.mappings.properties.@timestamp.meta.time_zone: UTC } - match: { test-downsample.mappings.properties.k8s\.pod\.multi-gauge.type: aggregate_metric_double } - match: { test-downsample.mappings.properties.k8s\.pod\.multi-gauge.metrics: [ "min", "max", "sum", "value_count" ] } - - match: { test-downsample.mappings.properties.k8s\.pod\.multi-gauge.default_metric: max } - match: { test-downsample.mappings.properties.k8s\.pod\.multi-gauge.time_series_metric: gauge } - match: { test-downsample.mappings.properties.k8s\.pod\.multi-counter.type: long } - match: { test-downsample.mappings.properties.k8s\.pod\.multi-counter.time_series_metric: counter } @@ -377,7 +379,6 @@ setup: - match: { test-downsample.mappings.properties.k8s\.pod\.scaled-counter.time_series_metric: counter } - match: { test-downsample.mappings.properties.k8s\.pod\.scaled-gauge.type: aggregate_metric_double } - match: { test-downsample.mappings.properties.k8s\.pod\.scaled-gauge.metrics: [ "min", "max", "sum", "value_count" ] } - - match: { test-downsample.mappings.properties.k8s\.pod\.scaled-gauge.default_metric: max } - match: { test-downsample.mappings.properties.k8s\.pod\.scaled-gauge.time_series_metric: gauge } - match: { test-downsample.mappings.properties.k8s\.pod\.uid.type: keyword } - match: { test-downsample.mappings.properties.k8s\.pod\.uid.time_series_dimension: true } @@ -686,6 +687,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: no-metric-index target_index: test-downsample-no-metric @@ -777,6 +780,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: no-metric-no-label-index target_index: test-downsample-no-metric-no-label @@ -814,6 +819,8 @@ setup: reason: _tsid hashing introduced in 8.13 - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -824,6 +831,8 @@ setup: - is_true: acknowledged - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-downsample target_index: test-downsample-2 @@ -844,7 +853,6 @@ setup: - match: { test-downsample-2.mappings.properties.@timestamp.meta.time_zone: UTC } - match: { test-downsample-2.mappings.properties.k8s\.pod\.multi-gauge.type: aggregate_metric_double } - match: { test-downsample-2.mappings.properties.k8s\.pod\.multi-gauge.metrics: [ "min", "max", "sum", "value_count" ] } - - match: { test-downsample-2.mappings.properties.k8s\.pod\.multi-gauge.default_metric: max } - match: { test-downsample-2.mappings.properties.k8s\.pod\.multi-gauge.time_series_metric: gauge } - match: { test-downsample-2.mappings.properties.k8s\.pod\.multi-counter.type: long } - match: { test-downsample-2.mappings.properties.k8s\.pod\.multi-counter.time_series_metric: counter } @@ -852,7 +860,6 @@ setup: - match: { test-downsample-2.mappings.properties.k8s\.pod\.uid.time_series_dimension: true } - match: { test-downsample-2.mappings.properties.k8s\.pod\.network\.tx.type: aggregate_metric_double } - match: { test-downsample-2.mappings.properties.k8s\.pod\.network\.tx.metrics: [ "min", "max", "sum", "value_count" ] } - - match: { test-downsample-2.mappings.properties.k8s\.pod\.network\.tx.default_metric: max } - match: { test-downsample-2.mappings.properties.k8s\.pod\.network\.tx.time_series_metric: gauge } - do: @@ -891,6 +898,8 @@ setup: - match: { hits.hits.2._source._doc_count: 2 } - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-downsample target_index: test-downsample-3 @@ -907,6 +916,8 @@ setup: reason: "Rollup of rollups introduced in 8.5.0" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -957,6 +968,8 @@ setup: reason: Last value sampling method was added in 9.3 - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample-default @@ -1016,6 +1029,8 @@ setup: reason: _tsid hashing introduced in 8.13 - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-histogram target_index: test-downsample-histogram @@ -1040,7 +1055,6 @@ setup: - match: { test-downsample-histogram.mappings.properties.k8s\.pod\.uid.time_series_dimension: true } - match: { test-downsample-histogram.mappings.properties.k8s\.pod\.network\.tx.type: aggregate_metric_double } - match: { test-downsample-histogram.mappings.properties.k8s\.pod\.network\.tx.metrics: [ "min", "max", "sum", "value_count" ] } - - match: { test-downsample-histogram.mappings.properties.k8s\.pod\.network\.tx.default_metric: max } - match: { test-downsample-histogram.mappings.properties.k8s\.pod\.network\.tx.time_series_metric: gauge } - do: @@ -1173,6 +1187,8 @@ setup: - is_true: acknowledged - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-timestamp target_index: test-downsample-timestamp @@ -1276,6 +1292,8 @@ setup: - is_true: acknowledged - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-timestamp target_index: test-downsample-timestamp @@ -1379,6 +1397,8 @@ setup: - is_true: acknowledged - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-timestamp-daily target_index: test-downsample-timestamp-hourly @@ -1431,6 +1451,8 @@ setup: reason: _tsid hashing introduced in 8.13 - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-object target_index: test-downsample-object @@ -1499,6 +1521,8 @@ setup: reason: _tsid hashing introduced in 8.13 - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-empty-missing target_index: test-downsample-empty-missing @@ -1621,6 +1645,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-label-ignore-above target_index: test-downsample-label-ignore-above @@ -1741,6 +1767,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-empty-dim target_index: test-empty-dim-downsample @@ -1824,6 +1852,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test-empty-dim-routing target_index: test-empty-dim-routing-downsample diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/20_unsupported_aggs.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/20_unsupported_aggs.yml index 13b7ebd1c0f3d..7c88996dbe709 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/20_unsupported_aggs.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/20_unsupported_aggs.yml @@ -2,8 +2,11 @@ setup: - requires: cluster_features: ["gte_v8.5.0"] reason: "downsampling: unsupported aggregations errors added in 8.5.0" + test_runner_features: ["allowed_warnings"] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/30_date_histogram.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/30_date_histogram.yml index 89ec88162ffcd..c270f7b32179e 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/30_date_histogram.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/30_date_histogram.yml @@ -44,7 +44,7 @@ setup: - requires: cluster_features: ["gte_v8.5.0"] reason: "rollup: unsupported aggregations errors added in 8.5.0" - test_runner_features: close_to + test_runner_features: [close_to, allowed_warnings] - do: indices.put_settings: @@ -53,6 +53,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -235,6 +237,7 @@ timezone support - 15m: - requires: cluster_features: ["gte_v8.13.0"] reason: "timezone support added in 8.13" + test_runner_features: "allowed_warnings" - do: bulk: @@ -281,6 +284,8 @@ timezone support - 15m: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -435,6 +440,7 @@ timezone support - 1h: - requires: cluster_features: ["gte_v8.13.0"] reason: "timezone support added in 8.13" + test_runner_features: [ "allowed_warnings" ] - do: bulk: @@ -481,6 +487,8 @@ timezone support - 1h: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -635,6 +643,7 @@ timezone support - 1d: - requires: cluster_features: ["gte_v8.13.0"] reason: "timezone support added in 8.13" + test_runner_features: ["allowed_warnings"] - do: bulk: @@ -674,6 +683,8 @@ timezone support - 1d: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/40_runtime_fields.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/40_runtime_fields.yml index 1106930c648eb..71b8e5bc1c1d7 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/40_runtime_fields.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/40_runtime_fields.yml @@ -3,7 +3,7 @@ - requires: cluster_features: ["gte_v8.13.0"] reason: _tsid hashing introduced in 8.13 - test_runner_features: close_to + test_runner_features: [close_to, allowed_warnings] - do: indices.create: @@ -95,6 +95,8 @@ # Downsample using `1h` fixed interval - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: source target_index: target @@ -165,6 +167,7 @@ - requires: cluster_features: ["gte_v8.13.0"] reason: _tsid hashing introduced in 8.13 + test_runner_features: allowed_warnings - do: indices.create: @@ -246,6 +249,8 @@ # Downsample using `1h` fixed interval - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: source target_index: target @@ -286,6 +291,7 @@ - requires: cluster_features: ["gte_v8.13.0"] reason: _tsid hashing introduced in 8.13 + test_runner_features: allowed_warnings - do: indices.create: @@ -368,6 +374,8 @@ # Downsample using `1h` fixed interval - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: source target_index: target diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/50_auto_date_histogram.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/50_auto_date_histogram.yml index b5b08b84ac678..ce900d892a4fd 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/50_auto_date_histogram.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/50_auto_date_histogram.yml @@ -2,6 +2,7 @@ setup: - requires: cluster_features: ["gte_v8.7.0"] reason: "Downsample GA version 8.7.0" + test_runner_features: [ "allowed_warnings" ] - do: indices.create: @@ -99,6 +100,8 @@ setup: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test1-raw target_index: test1-downsample diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/60_settings.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/60_settings.yml index 3cd58e3fd1c11..7220345cc7312 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/60_settings.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/60_settings.yml @@ -3,6 +3,7 @@ - requires: cluster_features: ["gte_v8.5.0"] reason: "rollup renamed to downsample in 8.5.0" + test_runner_features: allowed_warnings - do: ingest.put_pipeline: @@ -68,6 +69,8 @@ index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -159,6 +162,8 @@ - is_true: acknowledged - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: $datastream-backing-index target_index: downsample-index diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/70_flattened_field_type.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/70_flattened_field_type.yml index 0f586ec0ed669..ac3132c5f5503 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/70_flattened_field_type.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/70_flattened_field_type.yml @@ -1,4 +1,8 @@ --- +setup: + - requires: + test_runner_features: [allowed_warnings] +--- "A flattened label field": - do: indices.create: @@ -64,6 +68,8 @@ index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: source_index target_index: target_index @@ -167,6 +173,8 @@ index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: source_index target_index: target_index @@ -270,6 +278,8 @@ index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: source_index target_index: target_index diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/80_downsample_aggregate.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/80_downsample_aggregate.yml index 991aa3858d8bc..f3e99329c6a39 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/80_downsample_aggregate.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/80_downsample_aggregate.yml @@ -2,8 +2,11 @@ - requires: cluster_features: ["data_stream.downsample.default_aggregate_metric_fix"] reason: "#119696 fixed" + test_runner_features: allowed_warnings - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: @@ -44,12 +47,16 @@ - '{"@timestamp": "2021-04-28T20:00:00Z", "sensor_id": "1", "temperature": {"min": 24.6, "sum": 49.1, "value_count": 2}}' - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.put_settings: index: test body: index.blocks.write: true - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample diff --git a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/90_multi_fields.yml b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/90_multi_fields.yml index c150aa42dbda3..8a31554d460ce 100644 --- a/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/90_multi_fields.yml +++ b/x-pack/plugin/downsample/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/downsample/90_multi_fields.yml @@ -4,7 +4,7 @@ setup: - method: POST path: /{index}/_downsample/{target_index} capabilities: ['downsample.multi_field_fix'] - test_runner_features: [ "capabilities" ] + test_runner_features: [ "capabilities", "allowed_warnings" ] reason: Requires the fix for downsampling multi fields --- @@ -72,6 +72,8 @@ setup: - is_true: acknowledged - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample diff --git a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java index c6cb08b63778b..7539f1d53a8ff 100644 --- a/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java +++ b/x-pack/plugin/downsample/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java @@ -52,6 +52,7 @@ import org.elasticsearch.common.util.concurrent.EsExecutors; import org.elasticsearch.core.TimeValue; import org.elasticsearch.core.Tuple; +import org.elasticsearch.features.FeatureService; import org.elasticsearch.index.Index; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexNotFoundException; @@ -75,6 +76,7 @@ import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xpack.aggregatemetric.mapper.AggregateMetricDoubleFieldMapper; import org.elasticsearch.xpack.core.ClientHelper; +import org.elasticsearch.xpack.core.XPackFeatures; import org.elasticsearch.xpack.core.downsample.DownsampleShardPersistentTaskState; import org.elasticsearch.xpack.core.downsample.DownsampleShardTask; import org.elasticsearch.xpack.core.ilm.LifecycleSettings; @@ -115,6 +117,7 @@ public class TransportDownsampleAction extends AcknowledgedTransportMasterNodeAc private final IndicesService indicesService; private final MasterServiceTaskQueue taskQueue; private final MetadataCreateIndexService metadataCreateIndexService; + private final FeatureService featureService; private final IndexScopedSettings indexScopedSettings; private final PersistentTasksService persistentTasksService; private final DownsampleMetrics downsampleMetrics; @@ -152,6 +155,7 @@ public TransportDownsampleAction( IndicesService indicesService, ClusterService clusterService, TransportService transportService, + FeatureService featureService, ThreadPool threadPool, MetadataCreateIndexService metadataCreateIndexService, ActionFilters actionFilters, @@ -165,6 +169,7 @@ public TransportDownsampleAction( indicesService, clusterService, transportService, + featureService, threadPool, metadataCreateIndexService, actionFilters, @@ -183,6 +188,7 @@ public TransportDownsampleAction( IndicesService indicesService, ClusterService clusterService, TransportService transportService, + FeatureService featureService, ThreadPool threadPool, MetadataCreateIndexService metadataCreateIndexService, ActionFilters actionFilters, @@ -205,6 +211,7 @@ public TransportDownsampleAction( this.client = client; this.indicesService = indicesService; this.metadataCreateIndexService = metadataCreateIndexService; + this.featureService = featureService; this.projectResolver = projectResolver; this.indexScopedSettings = indexScopedSettings; this.taskQueue = taskQueue; @@ -363,7 +370,11 @@ protected void masterOperation( final String mapping; try { - mapping = createDownsampleIndexMapping(request.getDownsampleConfig(), sourceIndexMappings); + boolean isDefaultMetricDeprecated = featureService.clusterHasFeature( + state, + XPackFeatures.AGGREGATE_METRIC_DOUBLE_DEPRECATED_DEFAULT_METRIC + ); + mapping = createDownsampleIndexMapping(request.getDownsampleConfig(), sourceIndexMappings, isDefaultMetricDeprecated); } catch (IOException e) { recordFailureMetrics(startTime); delegate.onFailure(e); @@ -708,8 +719,11 @@ protected ClusterBlockException checkBlock(DownsampleAction.Request request, Clu * @param sourceIndexMappings a map with the source index mapping * @return the mapping of the downsample index */ - public static String createDownsampleIndexMapping(final DownsampleConfig config, final Map sourceIndexMappings) - throws IOException { + public static String createDownsampleIndexMapping( + final DownsampleConfig config, + final Map sourceIndexMappings, + boolean isDefaultMetricDeprecated + ) throws IOException { final String timestampField = config.getTimestampField(); final String dateIntervalType = config.getIntervalType(); @@ -726,7 +740,7 @@ public static String createDownsampleIndexMapping(final DownsampleConfig config, if (timestampField.equals(fieldName)) { updateTimestampField(sourceMapping, updatedMapping, dateIntervalType, dateInterval, timezone); } else if (TimeSeriesFields.isTimeSeriesMetric(sourceMapping)) { - processMetricField(sourceMapping, updatedMapping, config.getSamplingMethodOrDefault()); + processMetricField(sourceMapping, updatedMapping, config.getSamplingMethodOrDefault(), isDefaultMetricDeprecated); } else { copyMapping(sourceMapping, updatedMapping); } @@ -741,7 +755,8 @@ public static String createDownsampleIndexMapping(final DownsampleConfig config, private static void processMetricField( Map sourceMapping, Map updatedMapping, - DownsampleConfig.SamplingMethod samplingMethod + DownsampleConfig.SamplingMethod samplingMethod, + boolean isDefaultMetricDeprecated ) { final TimeSeriesParams.MetricType metricType = TimeSeriesParams.MetricType.fromString( sourceMapping.get(TIME_SERIES_METRIC_PARAM).toString() @@ -754,7 +769,9 @@ private static void processMetricField( updatedMapping.put(TIME_SERIES_METRIC_PARAM, metricType.toString()); updatedMapping.put(FIELD_TYPE, AggregateMetricDoubleFieldMapper.CONTENT_TYPE); updatedMapping.put(AggregateMetricDoubleFieldMapper.Names.METRICS, supportedMetrics.supportedMetrics); - updatedMapping.put(AggregateMetricDoubleFieldMapper.Names.DEFAULT_METRIC, supportedMetrics.defaultMetric); + if (isDefaultMetricDeprecated == false) { + updatedMapping.put(AggregateMetricDoubleFieldMapper.Names.DEFAULT_METRIC, supportedMetrics.defaultMetric); + } } else { copyMapping(sourceMapping, updatedMapping); } diff --git a/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java b/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java index 2ddface80e711..7f6c521edfdaf 100644 --- a/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java +++ b/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java @@ -241,7 +241,6 @@ public void setup() throws IOException { .field("type", "aggregate_metric_double") .field("time_series_metric", "gauge") .array("metrics", new String[] { "min", "max", "sum", "value_count" }) - .field("default_metric", "value_count") .endObject(); mapping.startObject(FIELD_METRIC_LABEL_DOUBLE) .field("type", "double") /* numeric label indexed as a metric */ @@ -262,7 +261,6 @@ public void setup() throws IOException { mapping.startObject(FIELD_LABEL_AGG_METRIC) .field("type", "aggregate_metric_double") .array("metrics", new String[] { "min", "max", "sum", "value_count" }) - .field("default_metric", "value_count") .endObject(); mapping.endObject().endObject().endObject(); diff --git a/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java b/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java index 9ae2f8b047c31..263661a23572e 100644 --- a/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java +++ b/x-pack/plugin/downsample/src/test/java/org/elasticsearch/xpack/downsample/TransportDownsampleActionTests.java @@ -37,6 +37,7 @@ import org.elasticsearch.common.util.concurrent.ThreadContext; import org.elasticsearch.common.xcontent.XContentHelper; import org.elasticsearch.core.TimeValue; +import org.elasticsearch.features.FeatureService; import org.elasticsearch.index.IndexMode; import org.elasticsearch.index.IndexSettings; import org.elasticsearch.index.IndexVersion; @@ -107,6 +108,8 @@ public class TransportDownsampleActionTests extends ESTestCase { private MasterServiceTaskQueue taskQueue; @Mock private MapperService mapperService; + @Mock + private FeatureService featureService; private static final String MAPPING = """ { @@ -144,6 +147,7 @@ public void setUp() throws Exception { indicesService, clusterService, mock(TransportService.class), + featureService, threadPool, mock(MetadataCreateIndexService.class), new ActionFilters(Set.of()), @@ -203,6 +207,7 @@ public void setUp() throws Exception { DocumentMapper documentMapper = mock(DocumentMapper.class); when(documentMapper.mappingSource()).thenReturn(CompressedXContent.fromJSON(MAPPING)); when(mapperService.merge(anyString(), any(CompressedXContent.class), any())).thenReturn(documentMapper); + when(featureService.clusterHasFeature(any(), any())).thenReturn(true); } @After @@ -434,9 +439,11 @@ public void testDownsamplingMapping() throws IOException { Map.of("type", "exponential_histogram", "time_series_metric", "histogram") ) ); + boolean defaultMetricDeprecated = randomBoolean(); String downsampledMappingStr = TransportDownsampleAction.createDownsampleIndexMapping( new DownsampleConfig(new DateHistogramInterval("1h"), null), - sourceMapping + sourceMapping, + defaultMetricDeprecated ); Map downsampledMapping = XContentHelper.convertToMap( new CompressedXContent(downsampledMappingStr).compressedReference(), @@ -467,7 +474,11 @@ public void testDownsamplingMapping() throws IOException { assertThat(downsampledProperties.containsKey("gauge"), equalTo(true)); Map gauge = (Map) downsampledProperties.get("gauge"); assertThat(gauge.get("type"), equalTo("aggregate_metric_double")); - assertThat(gauge.get("default_metric"), equalTo("max")); + if (defaultMetricDeprecated) { + assertThat(gauge.containsKey("default_metric"), equalTo(false)); + } else { + assertThat(gauge.get("default_metric"), equalTo("max")); + } assertThat((List) gauge.get("metrics"), containsInAnyOrder("max", "min", "sum", "value_count")); assertThat(gauge.get("time_series_metric"), equalTo("gauge")); assertThat(downsampledProperties.containsKey("exp_histogram"), equalTo(true)); diff --git a/x-pack/plugin/eql/qa/rest/build.gradle b/x-pack/plugin/eql/qa/rest/build.gradle index 53d6ef8c958d2..be173d528f3a8 100644 --- a/x-pack/plugin/eql/qa/rest/build.gradle +++ b/x-pack/plugin/eql/qa/rest/build.gradle @@ -4,7 +4,7 @@ * 2.0; you may not use this file except in compliance with the Elastic License * 2.0. */ - + apply plugin: 'elasticsearch.internal-test-artifact' apply plugin: 'elasticsearch.internal-java-rest-test' apply plugin: 'elasticsearch.internal-yaml-rest-test' @@ -40,3 +40,8 @@ if (buildParams.inFipsJvm){ tasks.named("javaRestTest").configure{enabled = false } tasks.named("yamlRestTest").configure{enabled = false } } + +tasks.named("yamlRestCompatTestTransform").configure({ task -> + // Expected deprecation warning to compat yaml tests: + task.addAllowedWarningRegex("Parameter \\[default_metric\\] is deprecated and will be removed in a future version") +}) diff --git a/x-pack/plugin/eql/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/eql/40_tsdb.yml b/x-pack/plugin/eql/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/eql/40_tsdb.yml index 1eba314502337..7693562dd1e27 100644 --- a/x-pack/plugin/eql/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/eql/40_tsdb.yml +++ b/x-pack/plugin/eql/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/eql/40_tsdb.yml @@ -1,4 +1,6 @@ setup: + - requires: + test_runner_features: [allowed_warnings] - do: indices.create: index: test1 @@ -61,6 +63,8 @@ setup: - '{"id":8, "@timestamp": "2021-04-28T18:51:03.142Z", "event.category": "network", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}' - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test2 body: @@ -96,6 +100,8 @@ setup: tx: type: long - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: refresh: true index: test2 diff --git a/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java b/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java index 4d5eb78f5bc84..5bfbe13bd016b 100644 --- a/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java +++ b/x-pack/plugin/esql/qa/server/multi-clusters/src/javaRestTest/java/org/elasticsearch/xpack/esql/ccq/MultiClusterSpecIT.java @@ -14,6 +14,7 @@ import org.apache.http.HttpHost; import org.elasticsearch.Version; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.RestClient; import org.elasticsearch.common.settings.Settings; @@ -93,6 +94,21 @@ public class MultiClusterSpecIT extends EsqlSpecTestCase { TEXT_EMBEDDING_FUNCTION.capabilityName() ); + private static final RequestOptions DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER = RequestOptions.DEFAULT.toBuilder() + .setWarningsHandler(warnings -> { + if (warnings.isEmpty()) { + return false; + } else { + for (String warning : warnings) { + if ("Parameter [default_metric] is deprecated and will be removed in a future version".equals(warning) == false) { + return true; + } + } + return false; + } + }) + .build(); + @ParametersFactory(argumentFormatting = "csv-spec:%2$s.%3$s") public static List readScriptSpec() throws Exception { List urls = classpathResources("/*.csv-spec"); @@ -278,6 +294,7 @@ static RestClient twoClients(RestClient localClient, RestClient remoteClient) th && LOOKUP_ENDPOINTS.contains(endpoint) == false) { return bulkClient.performRequest(request); } else { + request.setOptions(DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER); Request[] clones = cloneRequests(request, 2); Response resp1 = remoteClient.performRequest(clones[0]); Response resp2 = localClient.performRequest(clones[1]); @@ -302,6 +319,7 @@ static Request[] cloneRequests(Request orig, int numClones) throws IOException { for (int i = 0; i < clones.length; i++) { clones[i] = new Request(orig.getMethod(), orig.getEndpoint()); clones[i].addParameters(orig.getParameters()); + clones[i].setOptions(orig.getOptions()); } HttpEntity entity = orig.getEntity(); if (entity != null) { diff --git a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java index dbec7c3737da6..effd956ce6e56 100644 --- a/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java +++ b/x-pack/plugin/esql/qa/server/single-node/src/javaRestTest/java/org/elasticsearch/xpack/esql/qa/single_node/RestEsqlIT.java @@ -817,8 +817,7 @@ public void testSuggestedCast() throws IOException { if (type == DataType.AGGREGATE_METRIC_DOUBLE) { additionalProperties += """ , - "metrics": ["max"], - "default_metric": "max" + "metrics": ["max"] """; } createIndex("index-" + type.esType(), null, String.format(Locale.ROOT, """ diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/AllSupportedFieldsTestCase.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/AllSupportedFieldsTestCase.java index 0edf4cdedb507..20a3305d6eb78 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/AllSupportedFieldsTestCase.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/AllSupportedFieldsTestCase.java @@ -14,6 +14,7 @@ import org.elasticsearch.Build; import org.elasticsearch.TransportVersion; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; @@ -91,6 +92,21 @@ */ public class AllSupportedFieldsTestCase extends ESRestTestCase { + private static final RequestOptions DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER = RequestOptions.DEFAULT.toBuilder() + .setWarningsHandler(warnings -> { + if (warnings.isEmpty()) { + return false; + } else { + for (String warning : warnings) { + if ("Parameter [default_metric] is deprecated and will be removed in a future version".equals(warning) == false) { + return true; + } + } + return false; + } + }) + .build(); + @Rule(order = Integer.MIN_VALUE) public ProfileLogger profileLogger = new ProfileLogger(); @@ -829,6 +845,7 @@ protected static void createAllTypesIndex( config.endObject().endObject().endObject(); } Request request = new Request("PUT", indexName); + request.setOptions(DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER); request.setJsonEntity(Strings.toString(config)); client.performRequest(request); } @@ -900,6 +917,7 @@ protected static void createAllTypesDoc(RestClient client, TransportVersion mini doc.endObject(); Request request = new Request("POST", indexName + "/_doc"); request.addParameter("refresh", ""); + request.setOptions(DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER); request.setJsonEntity(Strings.toString(doc)); client.performRequest(request); } diff --git a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java index 3ee919e9bcdc6..476a2adb17751 100644 --- a/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java +++ b/x-pack/plugin/esql/qa/server/src/main/java/org/elasticsearch/xpack/esql/qa/rest/FieldExtractorTestCase.java @@ -11,6 +11,7 @@ import org.apache.http.util.EntityUtils; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.common.Strings; @@ -68,6 +69,20 @@ */ public abstract class FieldExtractorTestCase extends ESRestTestCase { private static final Logger logger = LogManager.getLogger(FieldExtractorTestCase.class); + private static final RequestOptions DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER = RequestOptions.DEFAULT.toBuilder() + .setWarningsHandler(warnings -> { + if (warnings.isEmpty()) { + return false; + } else { + for (String warning : warnings) { + if ("Parameter [default_metric] is deprecated and will be removed in a future version".equals(warning) == false) { + return true; + } + } + return false; + } + }) + .build(); @Rule(order = Integer.MIN_VALUE) public ProfileLogger profileLogger = new ProfileLogger(); @@ -1395,7 +1410,7 @@ public void testTsIndexConflictingTypes() throws IOException { "default_metric": "max" } } - """); + """, null, DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER); ESRestTestCase.createIndex("metrics-long", settings, """ "properties": { "@timestamp": { "type": "date" }, diff --git a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java index d479edd7c80e2..086064367ba66 100644 --- a/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java +++ b/x-pack/plugin/esql/qa/testFixtures/src/main/java/org/elasticsearch/xpack/esql/CsvTestsDataLoader.java @@ -18,6 +18,7 @@ import org.apache.http.impl.client.BasicCredentialsProvider; import org.apache.logging.log4j.core.config.plugins.util.PluginManager; import org.elasticsearch.client.Request; +import org.elasticsearch.client.RequestOptions; import org.elasticsearch.client.Response; import org.elasticsearch.client.ResponseException; import org.elasticsearch.client.RestClient; @@ -202,6 +203,20 @@ public class CsvTestsDataLoader { "histogram_standard_index.csv" ).withSetting("settings-histogram_time_series_index.json"); private static final TestDataset MANY_NUMBERS = new TestDataset("many_numbers"); + private static final RequestOptions DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER = RequestOptions.DEFAULT.toBuilder() + .setWarningsHandler(warnings -> { + if (warnings.isEmpty()) { + return false; + } else { + for (String warning : warnings) { + if ("Parameter [default_metric] is deprecated and will be removed in a future version".equals(warning) == false) { + return true; + } + } + return false; + } + }) + .build(); public static final Map CSV_DATASET_MAP = Map.ofEntries( Map.entry(EMPLOYEES.indexName, EMPLOYEES), @@ -629,7 +644,14 @@ public static void loadDataSetIntoEs( bFloat16ElementTypeSupported, tDigestMetricFieldSupported, (restClient, indexName, indexMapping, indexSettings) -> { - ESRestTestCase.createIndex(restClient, indexName, indexSettings, indexMapping, null); + ESRestTestCase.createIndex( + restClient, + indexName, + indexSettings, + indexMapping, + null, + DEPRECATED_DEFAULT_METRIC_WARNING_HANDLER + ); } ); if (timeSeriesOnly == false) { diff --git a/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/fielddata/LeafAggregateMetricDoubleFieldData.java b/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/fielddata/LeafAggregateMetricDoubleFieldData.java index c11ccd5d4ff2e..daffae11bfa31 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/fielddata/LeafAggregateMetricDoubleFieldData.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/fielddata/LeafAggregateMetricDoubleFieldData.java @@ -20,4 +20,9 @@ public interface LeafAggregateMetricDoubleFieldData extends LeafFieldData { */ SortedNumericDoubleValues getAggregateMetricValues(Metric metric); + /** + * Return the average of an aggregate_metric of double values + */ + SortedNumericDoubleValues getAggregateMetricValues(); + } diff --git a/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapper.java b/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapper.java index b34c07890b1fd..8601514b9f4b4 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapper.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/main/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapper.java @@ -162,11 +162,16 @@ public static final class Builder extends FieldMapper.Builder { */ private final Parameter defaultMetric = new Parameter<>(Names.DEFAULT_METRIC, false, () -> null, (n, c, o) -> { try { + // For testing, now that the default metric is optional, + // it's possible to get the `null` value in tests and this throws an NPE. + if (o == null) { + return null; + } return Metric.valueOf(o.toString()); } catch (IllegalArgumentException e) { - throw new IllegalArgumentException("Metric [" + o.toString() + "] is not supported.", e); + throw new IllegalArgumentException("Metric [" + o + "] is not supported.", e); } - }, m -> toType(m).defaultMetric, XContentBuilder::field, Objects::toString); + }, m -> toType(m).defaultMetric, XContentBuilder::field, Objects::toString).deprecated().acceptsNull(); private final IndexSettings indexSettings; @@ -202,26 +207,6 @@ public AggregateMetricDoubleFieldMapper build(MapperBuilderContext context) { "Adding multifields to [" + CONTENT_TYPE + "] mappers has no effect and will be forbidden in future" ); } - if (defaultMetric.isConfigured() == false) { - // If a single metric is contained, this should be the default - if (metrics.getValue().size() == 1) { - Metric m = metrics.getValue().iterator().next(); - defaultMetric.setValue(m); - } - - if (metrics.getValue().contains(defaultMetric.getValue()) == false) { - throw new IllegalArgumentException( - "Property [" + Names.DEFAULT_METRIC + "] is required for field [" + leafName() + "]." - ); - } - } - - if (metrics.getValue().contains(defaultMetric.getValue()) == false) { - // The default_metric is not defined in the "metrics" field - throw new IllegalArgumentException( - "Default metric [" + defaultMetric.getValue() + "] is not defined in the metrics of field [" + leafName() + "]." - ); - } EnumMap metricMappers = new EnumMap<>(Metric.class); // Instantiate one NumberFieldMapper instance for each metric @@ -264,7 +249,6 @@ public AggregateMetricDoubleFieldMapper build(MapperBuilderContext context) { AggregateMetricDoubleFieldType metricFieldType = new AggregateMetricDoubleFieldType( context.buildFullName(leafName()), timeSeriesMetric.getValue(), - defaultMetric.getValue(), metricFields, meta.getValue() ); @@ -281,36 +265,42 @@ public AggregateMetricDoubleFieldMapper build(MapperBuilderContext context) { public static final class AggregateMetricDoubleFieldType extends SimpleMappedFieldType { private final EnumMap metricFields; - private final Metric defaultMetric; private final MetricType metricType; public AggregateMetricDoubleFieldType( String name, MetricType metricType, - Metric defaultMetric, EnumMap metricFields, Map meta ) { - super(name, metricFields.get(defaultMetric).indexType(), false, meta); + super(name, metricFields.get(derivedDefaultMetric(name, metricFields)).indexType(), false, meta); this.metricType = metricType; - this.defaultMetric = defaultMetric; this.metricFields = metricFields; } - /** - * Return a delegate field type for a given metric sub-field - * @return a field type - */ - private NumberFieldMapper.NumberFieldType delegateFieldType(Metric metric) { - return metricFields.get(metric); + private Metric derivedDefaultMetric() { + return derivedDefaultMetric(name(), metricFields); + } + + private static Metric derivedDefaultMetric(String name, EnumMap metricFields) { + if (metricFields.containsKey(Metric.max)) { + return Metric.max; + } + // We iterate on the metrics to ensure that we have a deterministic order in metrics + for (Metric metric : Metric.values()) { + if (metricFields.containsKey(metric)) { + return metric; + } + } + throw new IllegalStateException("No metric found for aggregate metric field [" + name + "]"); } /** - * Return a delegate field type for the default metric sub-field + * Return a delegate field type which is max if it exists or any other metric. * @return a field type */ private NumberFieldMapper.NumberFieldType delegateFieldType() { - return delegateFieldType(defaultMetric); + return metricFields.get(derivedDefaultMetric()); } @Override @@ -327,10 +317,6 @@ public Map getMetricFields() { return Collections.unmodifiableMap(metricFields); } - Metric getDefaultMetric() { - return defaultMetric; - } - @Override public boolean mayExistInIndex(SearchExecutionContext context) { return delegateFieldType().mayExistInIndex(context); // TODO how does searching actually work here? @@ -372,7 +358,11 @@ public Object valueForDisplay(Object value) { @Override public DocValueFormat docValueFormat(String format, ZoneId timeZone) { - return delegateFieldType().docValueFormat(format, timeZone); + checkNoTimeZone(timeZone); + if (format == null) { + return DocValueFormat.RAW; + } + return new DocValueFormat.Decimal(format); } @Override @@ -439,11 +429,16 @@ public double nextValue() throws IOException { } } + @Override + public SortedNumericDoubleValues getAggregateMetricValues() { + return getAggregateMetricValues(derivedDefaultMetric()); + } + @Override public DocValuesScriptFieldFactory getScriptFieldFactory(String name) { // getAggregateMetricValues returns all metric as doubles, including `value_count` return new DelegateDocValuesField( - new ScriptDocValues.Doubles(new DoublesSupplier(getAggregateMetricValues(defaultMetric))), + new ScriptDocValues.Doubles(new DoublesSupplier(getAggregateMetricValues())), name ); } @@ -475,7 +470,7 @@ public SortField sortField( XFieldComparatorSource.Nested nested, boolean reverse ) { - return new SortedNumericSortField(delegateFieldType().name(), SortField.Type.DOUBLE, reverse); + return new SortedNumericSortField(subfieldName(name(), derivedDefaultMetric()), SortField.Type.DOUBLE, reverse); } @Override @@ -509,7 +504,8 @@ public BlockLoader blockLoader(BlockLoaderContext blContext) { case AMD_MAX -> Metric.max; case AMD_MIN -> Metric.min; case AMD_SUM -> Metric.sum; - case AMD_DEFAULT -> defaultMetric; + case AMD_DEFAULT -> derivedDefaultMetric(); // TODO: temporary until we combine + // https://github.com/elastic/elasticsearch/pull/141331 default -> null; }; if (metric == null) { @@ -583,10 +579,6 @@ public boolean ignoreMalformed() { return ignoreMalformed; } - Metric defaultMetric() { - return defaultMetric; - } - @Override public AggregateMetricDoubleFieldType fieldType() { return (AggregateMetricDoubleFieldType) super.fieldType(); diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedAvgAggregatorTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedAvgAggregatorTests.java index 4d1e0fd2488d9..561f958a2b661 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedAvgAggregatorTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedAvgAggregatorTests.java @@ -128,7 +128,7 @@ private AggregateMetricDoubleFieldType createDefaultFieldType(String fieldName) ); metricFields.put(m, subfield); } - return new AggregateMetricDoubleFieldType(fieldName, null, Metric.sum, metricFields, Map.of()); + return new AggregateMetricDoubleFieldType(fieldName, null, metricFields, Map.of()); } private void testCase(Query query, CheckedConsumer buildIndex, Consumer verify) diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMaxAggregatorTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMaxAggregatorTests.java index 6ece47ee0608a..5439ec601f0f8 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMaxAggregatorTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMaxAggregatorTests.java @@ -128,7 +128,7 @@ private AggregateMetricDoubleFieldType createDefaultFieldType(String fieldName) ); metricFields.put(m, subfield); } - return new AggregateMetricDoubleFieldType(fieldName, null, Metric.min, metricFields, Map.of()); + return new AggregateMetricDoubleFieldType(fieldName, null, metricFields, Map.of()); } private void testCase(Query query, CheckedConsumer buildIndex, Consumer verify) diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMinAggregatorTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMinAggregatorTests.java index 8134430b6153a..f7d40c209b5fa 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMinAggregatorTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedMinAggregatorTests.java @@ -128,7 +128,7 @@ private AggregateMetricDoubleFieldType createDefaultFieldType(String fieldName) ); metricFields.put(m, subfield); } - return new AggregateMetricDoubleFieldType(fieldName, null, Metric.min, metricFields, Map.of()); + return new AggregateMetricDoubleFieldType(fieldName, null, metricFields, Map.of()); } private void testCase(Query query, CheckedConsumer buildIndex, Consumer verify) diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedSumAggregatorTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedSumAggregatorTests.java index 98255b28083a7..f5ba9ef16a377 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedSumAggregatorTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedSumAggregatorTests.java @@ -128,7 +128,7 @@ private AggregateMetricDoubleFieldType createDefaultFieldType(String fieldName) ); metricFields.put(m, subfield); } - return new AggregateMetricDoubleFieldType(fieldName, null, Metric.sum, metricFields, Map.of()); + return new AggregateMetricDoubleFieldType(fieldName, null, metricFields, Map.of()); } private void testCase(Query query, CheckedConsumer buildIndex, Consumer verify) diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedValueCountAggregatorTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedValueCountAggregatorTests.java index ffe2a371d1a3f..82351c0ccf716 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedValueCountAggregatorTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/aggregations/metrics/AggregateMetricBackedValueCountAggregatorTests.java @@ -127,7 +127,7 @@ private AggregateMetricDoubleFieldType createDefaultFieldType(String fieldName) ); metricFields.put(m, subfield); } - return new AggregateMetricDoubleFieldType(fieldName, null, Metric.sum, metricFields, Map.of()); + return new AggregateMetricDoubleFieldType(fieldName, null, metricFields, Map.of()); } private void testCase(Query query, CheckedConsumer buildIndex, Consumer verify) diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapperTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapperTests.java index f3278833afc78..db8703c749b7c 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapperTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldMapperTests.java @@ -52,6 +52,7 @@ import static org.elasticsearch.xpack.aggregatemetric.mapper.AggregateMetricDoubleFieldMapper.Names.IGNORE_MALFORMED; import static org.elasticsearch.xpack.aggregatemetric.mapper.AggregateMetricDoubleFieldMapper.Names.METRICS; +import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.hamcrest.Matchers.notNullValue; @@ -70,7 +71,7 @@ protected Collection getPlugins() { @Override protected void minimalMapping(XContentBuilder b) throws IOException { - b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "min", "max", "value_count" }).field(DEFAULT_METRIC, "max"); + b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "min", "max", "value_count" }); } @Override @@ -80,13 +81,11 @@ protected void registerParameters(ParameterChecker checker) throws IOException { })); checker.registerConflictCheck(METRICS_FIELD, fieldMapping(this::minimalMapping), fieldMapping(b -> { - b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "min", "max" }).field(DEFAULT_METRIC, "max"); + b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "min", "max" }); })); checker.registerConflictCheck(METRICS_FIELD, fieldMapping(this::minimalMapping), fieldMapping(b -> { - b.field("type", CONTENT_TYPE) - .field(METRICS_FIELD, new String[] { "min", "max", "value_count", "sum" }) - .field(DEFAULT_METRIC, "min"); + b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "min", "max", "value_count", "sum" }); })); } @@ -110,6 +109,11 @@ protected boolean supportsStoredFields() { return false; } + @Override + protected String[] getParseMaximalWarnings() { + return new String[] { "Parameter [default_metric] is deprecated and will be removed in a future version" }; + } + /** * Test parsing field mapping and adding simple field */ @@ -290,10 +294,10 @@ public void testCheckMinMaxValue() throws Exception { private void randomMapping(XContentBuilder b, int randomNumber) throws IOException { b.field("type", CONTENT_TYPE); switch (randomNumber) { - case 0 -> b.field(METRICS_FIELD, new String[] { "min" }).field(DEFAULT_METRIC, "min"); - case 1 -> b.field(METRICS_FIELD, new String[] { "max" }).field(DEFAULT_METRIC, "max"); - case 2 -> b.field(METRICS_FIELD, new String[] { "value_count" }).field(DEFAULT_METRIC, "value_count"); - case 3 -> b.field(METRICS_FIELD, new String[] { "sum" }).field(DEFAULT_METRIC, "sum"); + case 0 -> b.field(METRICS_FIELD, new String[] { "min" }); + case 1 -> b.field(METRICS_FIELD, new String[] { "max" }); + case 2 -> b.field(METRICS_FIELD, new String[] { "value_count" }); + case 3 -> b.field(METRICS_FIELD, new String[] { "sum" }); } } @@ -340,82 +344,7 @@ public void testExplicitDefaultMetric() throws Exception { b -> b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "value_count", "sum" }).field(DEFAULT_METRIC, "sum") ) ); - - Mapper fieldMapper = mapper.mappers().getMapper("field"); - assertThat(fieldMapper, instanceOf(AggregateMetricDoubleFieldMapper.class)); - assertEquals(Metric.sum, ((AggregateMetricDoubleFieldMapper) fieldMapper).defaultMetric()); - } - - /** - * Test the default_metric when not set explicitly. When only a single metric is contained, this is set as the default - */ - public void testImplicitDefaultMetricSingleMetric() throws Exception { - DocumentMapper mapper = createDocumentMapper( - fieldMapping(b -> b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "value_count" })) - ); - - Mapper fieldMapper = mapper.mappers().getMapper("field"); - assertThat(fieldMapper, instanceOf(AggregateMetricDoubleFieldMapper.class)); - assertEquals(Metric.value_count, ((AggregateMetricDoubleFieldMapper) fieldMapper).defaultMetric); - } - - /** - * Test the default_metric when not set explicitly, by default we have set it to be the max. - */ - public void testImplicitDefaultMetric() throws Exception { - DocumentMapper mapper = createDocumentMapper(fieldMapping(this::minimalMapping)); - Mapper fieldMapper = mapper.mappers().getMapper("field"); - assertThat(fieldMapper, instanceOf(AggregateMetricDoubleFieldMapper.class)); - assertEquals(Metric.max, ((AggregateMetricDoubleFieldMapper) fieldMapper).defaultMetric); - } - - /** - * Test the default_metric when not set explicitly. When more than one metrics are contained - * and max is not one of them, an exception should be thrown. - */ - public void testMissingDefaultMetric() { - Exception e = expectThrows( - MapperParsingException.class, - () -> createDocumentMapper( - fieldMapping(b -> b.field("type", CONTENT_TYPE).field(METRICS_FIELD, new String[] { "value_count", "sum" })) - ) - ); - assertThat(e.getMessage(), containsString("Property [default_metric] is required for field [field].")); - } - - /** - * Test setting an invalid value for the default_metric. An exception must be thrown - */ - public void testInvalidDefaultMetric() { - Exception e = expectThrows( - MapperParsingException.class, - () -> createDocumentMapper( - fieldMapping( - b -> b.field("type", CONTENT_TYPE) - .field(METRICS_FIELD, new String[] { "value_count", "sum" }) - .field(DEFAULT_METRIC, "invalid_metric") - ) - ) - ); - assertThat(e.getMessage(), containsString("Metric [invalid_metric] is not supported.")); - } - - /** - * Test setting a value for the default_metric that is not contained in the "metrics" field. - * An exception must be thrown - */ - public void testUndefinedDefaultMetric() { - Exception e = expectThrows( - MapperParsingException.class, - () -> createDocumentMapper( - fieldMapping( - b -> b.field("type", CONTENT_TYPE) - .field(METRICS_FIELD, new String[] { "value_count", "sum" }) - .field(DEFAULT_METRIC, "min") - ) - ) - ); - assertThat(e.getMessage(), containsString("Default metric [min] is not defined in the metrics of field [field].")); + assertParseMaximalWarnings(); } /** @@ -428,7 +357,6 @@ public void testParseNestedValue() throws Exception { .startObject("subfield") .field("type", CONTENT_TYPE) .field(METRICS_FIELD, new String[] { "min", "max", "sum", "value_count" }) - .field(DEFAULT_METRIC, "max") .endObject() .endObject() ) @@ -457,9 +385,7 @@ public void testParseNestedValue() throws Exception { public void testNoSubFieldsIterated() throws IOException { Metric[] values = Metric.values(); List subset = randomSubsetOf(randomIntBetween(1, values.length), values); - DocumentMapper mapper = createDocumentMapper( - fieldMapping(b -> b.field("type", CONTENT_TYPE).field(METRICS_FIELD, subset).field(DEFAULT_METRIC, subset.get(0))) - ); + DocumentMapper mapper = createDocumentMapper(fieldMapping(b -> b.field("type", CONTENT_TYPE).field(METRICS_FIELD, subset))); Iterator iterator = mapper.mappers().getMapper("field").iterator(); assertFalse(iterator.hasNext()); } @@ -479,8 +405,10 @@ public void testFieldCaps() throws IOException { protected void assertExistsQuery(MappedFieldType fieldType, Query query, LuceneDocument fields) { assertThat(query, Matchers.instanceOf(FieldExistsQuery.class)); FieldExistsQuery fieldExistsQuery = (FieldExistsQuery) query; - String defaultMetric = ((AggregateMetricDoubleFieldMapper.AggregateMetricDoubleFieldType) fieldType).getDefaultMetric().name(); - assertEquals("field." + defaultMetric, fieldExistsQuery.getField()); + assertThat( + fieldExistsQuery.getField(), + anyOf(equalTo("field.min"), equalTo("field.max"), equalTo("field.sum"), equalTo("field.value_count")) + ); assertNoFieldNamesField(fields); } @@ -546,12 +474,7 @@ protected IngestScriptSupport ingestScriptSupport() { public void testArrayValueSyntheticSource() throws Exception { DocumentMapper mapper = createSytheticSourceMapperService( - fieldMapping( - b -> b.field("type", CONTENT_TYPE) - .array("metrics", "min", "max") - .field("default_metric", "min") - .field("ignore_malformed", "true") - ) + fieldMapping(b -> b.field("type", CONTENT_TYPE).array("metrics", "min", "max").field("ignore_malformed", "true")) ).documentMapper(); var randomString = randomAlphaOfLength(10); @@ -615,7 +538,7 @@ private Map randomAggregateMetric() { private void mapping(XContentBuilder b) throws IOException { String[] metrics = storedMetrics.stream().map(Metric::toString).toArray(String[]::new); - b.field("type", CONTENT_TYPE).array(METRICS_FIELD, metrics).field(DEFAULT_METRIC, metrics[0]); + b.field("type", CONTENT_TYPE).array(METRICS_FIELD, metrics); if (malformedExample) { b.field(IGNORE_MALFORMED, true); } diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldTypeTests.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldTypeTests.java index 1e39a01e83d14..4e063bb546b2d 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldTypeTests.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/AggregateMetricDoubleFieldTypeTests.java @@ -47,7 +47,7 @@ public class AggregateMetricDoubleFieldTypeTests extends FieldTypeTestCase { - protected AggregateMetricDoubleFieldType createDefaultFieldType(String name, Map meta, Metric defaultMetric) { + protected AggregateMetricDoubleFieldType createDefaultFieldType(String name, Map meta) { EnumMap metricFields = new EnumMap<>(Metric.class); for (Metric m : List.of(Metric.min, Metric.max)) { String subfieldName = subfieldName(name, m); @@ -57,45 +57,45 @@ protected AggregateMetricDoubleFieldType createDefaultFieldType(String name, Map ); metricFields.put(m, subfield); } - return new AggregateMetricDoubleFieldType(name, null, defaultMetric, metricFields, meta); + return new AggregateMetricDoubleFieldType(name, null, metricFields, meta); } public void testTermQuery() { - final MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap(), Metric.max); + final MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap()); Query query = fieldType.termQuery(55.2, MOCK_CONTEXT); assertThat(query, equalTo(DoubleField.newRangeQuery("foo.max", 55.2, 55.2))); } public void testTermsQuery() { - final MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap(), Metric.max); + final MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap()); Query query = fieldType.termsQuery(asList(55.2, 500.3), MOCK_CONTEXT); assertThat(query, equalTo(DoublePoint.newSetQuery("foo.max", 55.2, 500.3))); } public void testRangeQuery() { - final MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap(), Metric.max); + final MappedFieldType fieldType = createDefaultFieldType("foo", Collections.emptyMap()); Query query = fieldType.rangeQuery(10.1, 100.1, true, true, null, null, null, MOCK_CONTEXT); assertThat(query, instanceOf(IndexOrDocValuesQuery.class)); } public void testFetchSourceValueWithOneMetric() throws IOException { - final MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap(), Metric.min); + final MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap()); final double min = 45.8; final Map metric = Collections.singletonMap("min", min); assertEquals(List.of(metric), fetchSourceValue(fieldType, metric)); } public void testFetchSourceValueWithMultipleMetrics() throws IOException { - final MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap(), Metric.max); + final MappedFieldType fieldType = createDefaultFieldType("field", Collections.emptyMap()); final double max = 45.8; final double min = 14.2; final Map metric = Map.of("min", min, "max", max); assertEquals(List.of(metric), fetchSourceValue(fieldType, metric)); } - /** Tests that aggregate_metric_double uses the default_metric subfield's doc-values as values in scripts */ + /** Tests that aggregate_metric_double uses the average subfield's doc-values as values in scripts */ public void testUsedInScript() throws IOException { - final MappedFieldType mappedFieldType = createDefaultFieldType("field", Collections.emptyMap(), Metric.max); + final MappedFieldType mappedFieldType = createDefaultFieldType("field", Collections.emptyMap()); try (Directory directory = newDirectory(); RandomIndexWriter iw = new RandomIndexWriter(random(), directory)) { iw.addDocument( List.of( diff --git a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/datageneration/AggregateMetricDoubleDataSourceHandler.java b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/datageneration/AggregateMetricDoubleDataSourceHandler.java index 08678a3b18850..1184c16e59485 100644 --- a/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/datageneration/AggregateMetricDoubleDataSourceHandler.java +++ b/x-pack/plugin/mapper-aggregate-metric/src/test/java/org/elasticsearch/xpack/aggregatemetric/mapper/datageneration/AggregateMetricDoubleDataSourceHandler.java @@ -50,7 +50,6 @@ public DataSourceResponse.LeafMappingParametersGenerator handle(DataSourceReques ); map.put("metrics", metrics.stream().map(Enum::toString).toList()); - map.put("default_metric", metrics.get(ESTestCase.randomIntBetween(0, metrics.size() - 1))); if (ESTestCase.randomBoolean()) { map.put("ignore_malformed", ESTestCase.randomBoolean()); diff --git a/x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_tests.yml b/x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_tests.yml index 5c20ee7bad129..ae7739154c452 100644 --- a/x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_tests.yml +++ b/x-pack/plugin/otel-data/src/yamlRestTest/resources/rest-api-spec/test/20_metrics_tests.yml @@ -1,5 +1,7 @@ --- setup: + - requires: + test_runner_features: [allowed_warnings] - do: cluster.health: wait_for_events: languid @@ -194,6 +196,8 @@ IP dimensions: --- "Dynamic templates": - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" bulk: index: metrics-generic.otel-default refresh: true diff --git a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java index aa1cabe17161a..132f2c075d3d8 100644 --- a/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java +++ b/x-pack/plugin/sql/qa/server/src/main/java/org/elasticsearch/xpack/sql/qa/rest/RestSqlTestCase.java @@ -1285,8 +1285,7 @@ private void createTsdb2() throws IOException { }, "agg_metric": { "type": "aggregate_metric_double", - "metrics": ["max"], - "default_metric": "max" + "metrics": ["max"] }, "k8s": { "properties": { diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/100_synthetic_source.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/100_synthetic_source.yml index 3723f6cd4d450..2d5fac9f5ab60 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/100_synthetic_source.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/100_synthetic_source.yml @@ -2,14 +2,13 @@ setup: - requires: cluster_features: [ "mapper.source.mode_from_index_setting" ] reason: "Source mode configured through index setting" + test_runner_features: [ allowed_warnings ] --- aggregate_metric_double: - - requires: - cluster_features: ["gte_v8.5.0"] - reason: synthetic source support added in 8.5.0 - - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: @@ -62,6 +61,8 @@ aggregate_metric_double: --- aggregate_metric_double with ignore_malformed: - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/10_basic.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/10_basic.yml index 2487235a2383e..5f4243652bf9d 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/10_basic.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/10_basic.yml @@ -1,10 +1,11 @@ +setup: + - requires: + test_runner_features: [ allowed_warnings ] --- "Test exists query on aggregate metric field": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: aggregate_metric_test body: @@ -57,11 +58,9 @@ --- "Test term query on aggregate metric field": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: @@ -133,11 +132,9 @@ --- "Test range query on aggregate metric field": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: @@ -210,11 +207,9 @@ --- "Sort": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: @@ -293,10 +288,9 @@ --- "Test fields api": - - requires: - cluster_features: "gte_v8.4.0" - reason: "Breaking change introduced in 8.4.0" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: @@ -353,11 +347,11 @@ --- "deprecated use of multi-fields": - requires: - cluster_features: ["gte_v8.14.0"] - reason: "deprecation added in 8.14" test_runner_features: warnings - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" warnings: - "Adding multifields to [aggregate_metric_double] mappers has no effect and will be forbidden in future" indices.create: @@ -367,3 +361,19 @@ properties: aggregated: { "type": "aggregate_metric_double", "metrics": ["max"], "default_metric": "max", "fields": {"keyword": {"type": "keyword"}} } +--- +"deprecated use of default metric": + - requires: + test_runner_features: warnings + - do: + warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" + indices.create: + index: test + body: + mappings: + properties: + metric: + type: aggregate_metric_double + metrics: [ min, max, sum, value_count ] + default_metric: max diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/110_field_caps.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/110_field_caps.yml index 98a4d74b8d3e5..58813982aa323 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/110_field_caps.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/110_field_caps.yml @@ -1,9 +1,10 @@ setup: - requires: - cluster_features: ["gte_v8.5.0"] - reason: metric params only on time series indices introduced in 8.5.0 + test_runner_features: [ allowed_warnings ] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test_rollup body: @@ -65,6 +66,8 @@ setup: time_series_metric: gauge - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test_aggregate_metric body: @@ -77,10 +80,6 @@ setup: --- aggregate_metric on standard index: - - requires: - cluster_features: ["gte_v8.5.0"] - reason: aggregate_metric_double field caps changed in 8.5.0 - - do: field_caps: index: test_aggregate_metric @@ -92,10 +91,6 @@ aggregate_metric on standard index: --- aggregate_metric on standard index conflict with double: - - requires: - cluster_features: ["gte_v8.5.0"] - reason: aggregate_metric_double field caps changed in 8.5.0 - - do: indices.create: index: test_double @@ -120,10 +115,6 @@ aggregate_metric on standard index conflict with double: --- # Test field_caps on a rollup index field caps on rollup indices: - - requires: - cluster_features: ["gte_v8.5.0"] - reason: metric params only on time series indices introduced in 8.5.0 - - do: field_caps: index: test_rollup @@ -143,10 +134,6 @@ field caps on rollup indices: --- # Test field_caps on time-series index (mix of raw and rollup indices) field caps on time series indices: - - requires: - cluster_features: ["gte_v8.5.0"] - reason: metric params only on time series indices introduced in 8.5.0 - - do: field_caps: index: [ test_time_series, test_rollup ] @@ -174,10 +161,6 @@ field caps on time series indices: --- # Test field_caps on mixed standard and time-series (mix of raw and rollup) indices field caps on all indices: - - requires: - cluster_features: ["gte_v8.5.0"] - reason: metric params only on time series indices introduced in 8.5.0 - - do: field_caps: index: [ test_time_series, test_rollup, test_non_time_series ] diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/20_min_max_agg.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/20_min_max_agg.yml index 88a0eb017fabe..57e1314302e07 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/20_min_max_agg.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/20_min_max_agg.yml @@ -3,7 +3,11 @@ ############################################################################################################### setup: + - requires: + test_runner_features: [ allowed_warnings ] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: aggregate_metric_test body: @@ -31,10 +35,6 @@ setup: - '{"metric": {"min": -100, "max": -40} }' --- "Test min_max aggs": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test @@ -55,10 +55,6 @@ setup: --- "Test min_max aggs with query": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/30_sum_agg.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/30_sum_agg.yml index 24323b46c4ed9..577ff1beae0ed 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/30_sum_agg.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/30_sum_agg.yml @@ -1,5 +1,9 @@ setup: + - requires: + test_runner_features: [ allowed_warnings ] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: aggregate_metric_test body: @@ -7,7 +11,7 @@ setup: properties: metric: type: aggregate_metric_double - metrics: [sum, value_count] + metrics: [sum, value_count, max] # temporarily add max so it can use it for filtering default_metric: value_count - do: @@ -16,21 +20,17 @@ setup: refresh: true body: - '{"index": {}}' - - '{"metric": {"sum": 10000.45, "value_count": 100} }' + - '{"metric": {"sum": 10000.45, "value_count": 100, "max": 100} }' - '{"index": {}}' - - '{"metric": {"sum": 60, "value_count": 20} }' + - '{"metric": {"sum": 60, "value_count": 20, "max": 20} }' - '{"index": {}}' - - '{"metric": {"sum": -400.50, "value_count": 1000} }' + - '{"metric": {"sum": -400.50, "value_count": 1000, "max": 1000} }' - '{"index": {}}' - - '{"metric": {"sum": 1, "value_count": 20} }' + - '{"metric": {"sum": 1, "value_count": 20, "max": 20} }' - '{"index": {}}' - - '{"metric": {"sum": -100, "value_count": 40} }' + - '{"metric": {"sum": -100, "value_count": 40, "max": 40} }' --- "Test sum agg": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test @@ -46,10 +46,6 @@ setup: --- "Test sum agg with query": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/40_avg_agg.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/40_avg_agg.yml index e378dae829bd3..c3c8cdd9c83c1 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/40_avg_agg.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/40_avg_agg.yml @@ -1,5 +1,9 @@ setup: + - requires: + test_runner_features: [ allowed_warnings ] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: aggregate_metric_test body: @@ -7,7 +11,7 @@ setup: properties: metric: type: aggregate_metric_double - metrics: [sum, value_count] + metrics: [sum, value_count, max] default_metric: value_count - do: @@ -16,21 +20,17 @@ setup: refresh: true body: - '{"index": {}}' - - '{"metric": {"sum": 10000, "value_count": 100} }' + - '{"metric": {"sum": 10000, "value_count": 100, "max": 100} }' - '{"index": {}}' - - '{"metric": {"sum": 60, "value_count": 20} }' + - '{"metric": {"sum": 60, "value_count": 20, "max": 20} }' - '{"index": {}}' - - '{"metric": {"sum": -400, "value_count": 780} }' + - '{"metric": {"sum": -400, "value_count": 780, "max": 780} }' - '{"index": {}}' - - '{"metric": {"sum": 40, "value_count": 20} }' + - '{"metric": {"sum": 40, "value_count": 20, "max": 20} }' - '{"index": {}}' - - '{"metric": {"sum": -100, "value_count": 40} }' + - '{"metric": {"sum": -100, "value_count": 40, "max": 40} }' --- "Test avg agg": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test @@ -46,10 +46,6 @@ setup: --- "Test avg agg with query": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/50_value_count_agg.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/50_value_count_agg.yml index 7c58379d90b72..46629c78efdea 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/50_value_count_agg.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/50_value_count_agg.yml @@ -1,5 +1,9 @@ setup: + - requires: + test_runner_features: [ allowed_warnings ] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: aggregate_metric_test body: @@ -7,7 +11,7 @@ setup: properties: metric: type: aggregate_metric_double - metrics: [sum, value_count] + metrics: [sum, value_count, max] default_metric: value_count - do: @@ -16,21 +20,17 @@ setup: refresh: true body: - '{"index": {}}' - - '{"metric": {"sum": 10000, "value_count": 100} }' + - '{"metric": {"sum": 10000, "value_count": 100, "max": 100} }' - '{"index": {}}' - - '{"metric": {"sum": 60, "value_count": 20} }' + - '{"metric": {"sum": 60, "value_count": 20, "max": 20} }' - '{"index": {}}' - - '{"metric": {"sum": -400, "value_count": 780} }' + - '{"metric": {"sum": -400, "value_count": 780, "max": 780} }' - '{"index": {}}' - - '{"metric": {"sum": 40, "value_count": 20} }' + - '{"metric": {"sum": 40, "value_count": 20, "max": 20} }' - '{"index": {}}' - - '{"metric": {"sum": -100, "value_count": 40} }' + - '{"metric": {"sum": -100, "value_count": 40, "max": 40} }' --- "Test value_count agg": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test @@ -46,10 +46,6 @@ setup: --- "Test value_count agg with query": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: aggregate_metric_test diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/80_raw_agg_metric_aggs.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/80_raw_agg_metric_aggs.yml index 84207778d0ff7..e2ea85ad8e748 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/80_raw_agg_metric_aggs.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/80_raw_agg_metric_aggs.yml @@ -4,8 +4,12 @@ ############################################################################################################### setup: + - requires: + test_runner_features: [ allowed_warnings ] # Setup aggregate index with field metric of type aggregate_metric_double - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test_metric_aggregate body: @@ -58,10 +62,6 @@ setup: --- "Test mixed aggregations": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: test_metric_* @@ -93,10 +93,6 @@ setup: --- "Test mixed aggregations with query": - - requires: - cluster_features: ["gte_v7.11.0"] - reason: "Aggregate metric fields have been added in 7.11" - - do: search: index: test_metric_* diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/90_tsdb_mappings.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/90_tsdb_mappings.yml index f350a5b6163a5..745b5b3e6372c 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/90_tsdb_mappings.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/aggregate-metrics/90_tsdb_mappings.yml @@ -1,9 +1,10 @@ aggregate_double_metric with time series mappings: - requires: - cluster_features: ["gte_v7.16.0"] - reason: introduced in 7.16.0 + test_runner_features: [ allowed_warnings ] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test_index body: @@ -38,10 +39,6 @@ aggregate_double_metric with time series mappings: --- aggregate_double_metric with wrong time series mappings: - - requires: - cluster_features: ["gte_v7.16.0"] - reason: introduced in 7.16.0 - - do: catch: /Unknown value \[histogram\] for field \[time_series_metric\] \- accepted values are \[gauge\]/ indices.create: @@ -78,10 +75,6 @@ aggregate_double_metric with wrong time series mappings: --- "Field caps with tsdb": - - requires: - cluster_features: ["gte_v8.8.0"] - reason: "Field caps fix in 8.9" - - do: indices.create: index: tsdb-fieldcap diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/160_union_types.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/160_union_types.yml index bfd460b541a42..567748fd64aff 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/160_union_types.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/160_union_types.yml @@ -6,7 +6,7 @@ setup: parameters: [method, path, parameters, capabilities] capabilities: [union_types, union_types_remove_fields, casting_operator] reason: "Union types and casting operator introduced in 8.15.0" - test_runner_features: [capabilities, allowed_warnings_regex, warnings_regex] + test_runner_features: [capabilities, allowed_warnings_regex, warnings_regex, allowed_warnings] - do: indices.create: @@ -917,6 +917,8 @@ suggested_type: reason: "date and date_nanos should no longer produce suggested_cast column" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: metrics_1 body: diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_base_conversion.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_base_conversion.yml index e0a36a9dcef17..92a1a1149671f 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_base_conversion.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/240_base_conversion.yml @@ -1,6 +1,6 @@ setup: - requires: - test_runner_features: [ capabilities, allowed_warnings_regex, contains, warnings_regex ] + test_runner_features: [ capabilities, allowed_warnings_regex, contains, warnings_regex, allowed_warnings ] capabilities: - method: POST path: /_query @@ -154,6 +154,8 @@ setup: # Aggregate data types ─ https://www.elastic.co/docs/reference/elasticsearch/mapping-reference/field-data-types#aggregated-data-types - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: aggregate_family body: diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_tsdb.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_tsdb.yml index 6ab9ef38232e5..8fc92e6f2b9cb 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_tsdb.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_tsdb.yml @@ -1,6 +1,6 @@ setup: - requires: - test_runner_features: allowed_warnings_regex + test_runner_features: [allowed_warnings_regex, allowed_warnings] - do: indices.create: index: test @@ -61,6 +61,8 @@ setup: - '{"@timestamp": "2021-04-28T18:51:03.142Z", "metricset": "pod", "k8s": {"pod": {"name": "dog", "uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9", "ip": "10.10.55.3", "network": {"tx": 1434595272, "rx": 530605511}}}}' - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test2 body: @@ -105,6 +107,8 @@ setup: - '{"@timestamp": "2021-04-28T18:50:44.467Z", "dim": "B", "agg_metric": {"max": 17, "min": -5, "sum": 33, "value_count": 9}}' - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test3 body: @@ -145,6 +149,8 @@ setup: - '{"@timestamp": "2021-04-28T19:51:04.467Z", "k8s": {"pod": {"uid":"df3145b3-0563-4d3b-a0f7-897eb2876ea9"}}}' - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test4 body: @@ -865,15 +871,16 @@ error on rename timestamp: - match: { error.reason: '/(verification_exception:\ )?Found\ 1\ problem\nline\ 3:13:\ \[rate\(k8s.pod.network.tx\)\]\ requires\ the\ \[@timestamp\]\ field,\ which\ was\ either\ not\ present\ in\ the\ source\ index,\ or\ has\ been\ dropped\ or\ renamed/' } --- -Stats using min as default metric for aggregate metric double: +Stats using default metric for aggregate metric double: - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, cluster_features] + cluster_features: ["aggregate_metric_double.default_metric.deprecated"] capabilities: - method: POST path: /_query parameters: [] capabilities: [aggregate_metric_double_default_metric] - reason: "Default metric" + reason: "Using max as the default metric was added in 9.4" - do: allowed_warnings_regex: - "No limit defined, adding default limit of \\[.*\\]" @@ -891,7 +898,7 @@ Stats using min as default metric for aggregate metric double: - match: {columns.2.type: "double"} - match: {values.0.0: 17.0} - match: {values.0.1: -3.0} - - match: {values.0.2: 2.62467} + - match: {values.0.2: 6.54896} --- PromQL rate on counter field: diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_unsupported_types.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_unsupported_types.yml index 6b3aac464b7f4..97ceb6c95f01f 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_unsupported_types.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/40_unsupported_types.yml @@ -2,8 +2,10 @@ setup: - requires: cluster_features: ["gte_v8.11.0"] reason: "ESQL is available in 8.11+" - test_runner_features: allowed_warnings_regex + test_runner_features: [allowed_warnings_regex, allowed_warnings] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: test body: diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/46_downsample.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/46_downsample.yml index da13fd687ce93..05bd60d77f373 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/46_downsample.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/esql/46_downsample.yml @@ -78,7 +78,7 @@ setup: --- "Query stats on downsampled index": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -86,6 +86,8 @@ setup: capabilities: [aggregate_metric_double_v0, dense_vector_agg_metric_double_if_version] reason: "Support for aggregate_metric_double" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -120,7 +122,7 @@ setup: --- "Render stats from downsampled index": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -128,6 +130,8 @@ setup: capabilities: [aggregate_metric_double_v0, dense_vector_agg_metric_double_if_version] reason: "Support for rendering aggregate_metric_doubles" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -150,7 +154,7 @@ setup: --- "Stats from downsampled and non-downsampled index simultaneously": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -159,6 +163,8 @@ setup: reason: "Support for to_aggregate_metric_double function" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -255,7 +261,7 @@ setup: --- "Stats from downsampled and non-downsampled index simultaneously with implicit casting": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -264,6 +270,8 @@ setup: reason: "Requires default metric to run TS ... | STATS max(agg_metric)" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -372,7 +380,7 @@ setup: --- "Over time functions from downsampled and non-downsampled indices simultaneously, no grouping": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -381,6 +389,8 @@ setup: reason: "Support for casting aggregate metric double implicitly when present in aggregations" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -494,7 +504,7 @@ setup: --- "Over time functions from downsampled and non-downsampled indices simultaneously, with grouping": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -503,6 +513,8 @@ setup: reason: "Support for casting aggregate metric double implicitly when present in aggregations" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -633,7 +645,7 @@ setup: --- "Sort from multiple indices one with aggregate metric double": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -642,6 +654,8 @@ setup: reason: "Fix sorting for rows comprised of docs from multiple indices where agg metric is missing from some" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample @@ -700,7 +714,7 @@ setup: --- "MV_EXPAND on non-MV aggregate metric double": - requires: - test_runner_features: [capabilities] + test_runner_features: [capabilities, allowed_warnings] capabilities: - method: POST path: /_query @@ -709,6 +723,8 @@ setup: reason: "Have MV_EXPAND not error out when applied to aggregate_metric_doubles (is a no-op)" - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.downsample: index: test target_index: test-downsample diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/exponential_histogram/30_aggregate_metric_aggregations_compatibility.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/exponential_histogram/30_aggregate_metric_aggregations_compatibility.yml index bbe169c633863..02614adcd54f5 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/exponential_histogram/30_aggregate_metric_aggregations_compatibility.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/exponential_histogram/30_aggregate_metric_aggregations_compatibility.yml @@ -2,8 +2,11 @@ setup: - requires: cluster_features: [ "mapper.exponential_histogram_type" ] reason: exponential_histogram field type was introduced + test_runner_features: [ allowed_warnings ] # Create an index template for the data stream with aggregate_metric_double field - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.put_index_template: name: test_data_stream_template body: @@ -19,6 +22,8 @@ setup: # Create the data stream - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create_data_stream: name: test-data-stream diff --git a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/transform/preview_transforms.yml b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/transform/preview_transforms.yml index e10852b4c93d6..9e9f7d30d746a 100644 --- a/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/transform/preview_transforms.yml +++ b/x-pack/plugin/src/yamlRestTest/resources/rest-api-spec/test/transform/preview_transforms.yml @@ -1,5 +1,9 @@ setup: + - requires: + test_runner_features: [allowed_warnings] - do: + allowed_warnings: + - "Parameter [default_metric] is deprecated and will be removed in a future version" indices.create: index: airline-data body: diff --git a/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformRestTestCase.java b/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformRestTestCase.java index 1544f25770326..857fc59f65f4e 100644 --- a/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformRestTestCase.java +++ b/x-pack/plugin/transform/qa/single-node-tests/src/javaRestTest/java/org/elasticsearch/xpack/transform/integration/TransformRestTestCase.java @@ -196,7 +196,6 @@ protected void putReviewsIndex(String indexName, String dateType, boolean isData .startObject("stars_stats") .field("type", "aggregate_metric_double") .field("metrics", List.of("min", "max", "sum")) - .field("default_metric", "max") .endObject() .startObject("location") .field("type", "geo_point")