Skip to content

Commit 4d8b9c1

Browse files
Enable downsampling of time series index without any metric field (#95353)
Time series indices require at least one dimension field but do not require any metric field. As a result, for consistency, we align the behaviour of downsampling to allow processing of such indices which include at least a dimension field but do not include any metric field.
1 parent ec2bdee commit 4d8b9c1

File tree

4 files changed

+150
-10
lines changed

4 files changed

+150
-10
lines changed

docs/changelog/95353.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
pr: 95353
2+
summary: Enable downsampling of time series index without any metric field
3+
area: Rollup
4+
type: bug
5+
issues:
6+
- 95352

x-pack/plugin/rollup/qa/rest/src/yamlRestTest/resources/rest-api-spec/test/rollup/10_basic.yml

Lines changed: 141 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -435,8 +435,8 @@ setup:
435435
---
436436
"Downsample no metric index":
437437
- skip:
438-
version: " - 8.4.99"
439-
reason: "rollup renamed to downsample in 8.5.0"
438+
version: " - 8.7.99"
439+
reason: "Downsample of time series index without metric allowed from version 8.8.0"
440440

441441
- do:
442442
indices.create:
@@ -458,6 +458,30 @@ setup:
458458
metricset:
459459
type: keyword
460460
time_series_dimension: true
461+
label:
462+
type: integer
463+
464+
- do:
465+
bulk:
466+
refresh: true
467+
index: no-metric-index
468+
body:
469+
- '{"index": {}}'
470+
- '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod", "label": 10, "unmapped": 10 }'
471+
- '{"index": {}}'
472+
- '{"@timestamp": "2021-04-28T18:50:24.467Z", "metricset": "pod", "label": 20, "unmapped": 20 }'
473+
- '{"index": {}}'
474+
- '{"@timestamp": "2021-04-28T20:50:44.467Z", "metricset": "pod", "label": 30, "unmapped": 30 }'
475+
- '{"index": {}}'
476+
- '{"@timestamp": "2021-04-28T20:51:04.467Z", "metricset": "pod", "label": 40, "unmapped": 40 }'
477+
- '{"index": {}}'
478+
- '{"@timestamp": "2021-04-28T18:50:03.142Z", "metricset": "pod", "label": 100, "unmapped": 100 }'
479+
- '{"index": {}}'
480+
- '{"@timestamp": "2021-04-28T18:50:23.142Z", "metricset": "pod", "label": 200, "unampped": 200 }'
481+
- '{"index": {}}'
482+
- '{"@timestamp": "2021-04-28T19:50:53.142Z", "metricset": "pod", "label": 300, "unmapped": 300 }'
483+
- '{"index": {}}'
484+
- '{"@timestamp": "2021-04-28T19:51:03.142Z", "metricset": "pod", "label": 400, "unmapped": 400 }'
461485

462486
- do:
463487
indices.put_settings:
@@ -466,15 +490,128 @@ setup:
466490
index.blocks.write: true
467491

468492
- do:
469-
catch: /Index \[no-metric-index\] does not contain any metric fields;/
470493
indices.downsample:
471494
index: no-metric-index
472-
target_index: rollup-test
495+
target_index: rollup-test-no-metric
473496
body: >
474497
{
475498
"fixed_interval": "1h"
476499
}
477500
501+
- is_true: acknowledged
502+
503+
- do:
504+
search:
505+
index: rollup-test-no-metric
506+
body:
507+
sort: [ "_tsid", "@timestamp" ]
508+
509+
- length: { hits.hits: 3 }
510+
511+
- match: { hits.hits.0._source._doc_count: 4 }
512+
- match: { hits.hits.0._source.metricset: pod }
513+
- match: { hits.hits.0._source.label: 20 }
514+
- match: { hits.hits.0._source.unmapped: 20 }
515+
- match: { hits.hits.0._source.@timestamp: 2021-04-28T18:00:00.000Z }
516+
517+
- match: { hits.hits.1._source._doc_count: 2 }
518+
- match: { hits.hits.1._source.metricset: pod }
519+
- match: { hits.hits.1._source.label: 400 }
520+
- match: { hits.hits.1._source.unmapped: 400 }
521+
- match: { hits.hits.1._source.@timestamp: 2021-04-28T19:00:00.000Z }
522+
523+
- match: { hits.hits.2._source._doc_count: 2 }
524+
- match: { hits.hits.2._source.metricset: pod }
525+
- match: { hits.hits.2._source.label: 40 }
526+
- match: { hits.hits.2._source.unmapped: 40 }
527+
- match: { hits.hits.2._source.@timestamp: 2021-04-28T20:00:00.000Z }
528+
529+
---
530+
"Downsample no metric no label index":
531+
- skip:
532+
version: " - 8.7.99"
533+
reason: "Downsample of time series index without metric allowed from version 8.8.0"
534+
535+
- do:
536+
indices.create:
537+
index: no-metric-no-label-index
538+
body:
539+
settings:
540+
number_of_shards: 1
541+
number_of_replicas: 0
542+
index:
543+
mode: time_series
544+
routing_path: [metricset]
545+
time_series:
546+
start_time: 2021-04-28T00:00:00Z
547+
end_time: 2021-04-29T00:00:00Z
548+
mappings:
549+
properties:
550+
"@timestamp":
551+
type: date
552+
metricset:
553+
type: keyword
554+
time_series_dimension: true
555+
556+
- do:
557+
bulk:
558+
refresh: true
559+
index: no-metric-no-label-index
560+
body:
561+
- '{"index": {}}'
562+
- '{"@timestamp": "2021-04-28T18:50:04.467Z", "metricset": "pod" }'
563+
- '{"index": {}}'
564+
- '{"@timestamp": "2021-04-28T18:50:24.467Z", "metricset": "pod" }'
565+
- '{"index": {}}'
566+
- '{"@timestamp": "2021-04-28T20:50:44.467Z", "metricset": "pod" }'
567+
- '{"index": {}}'
568+
- '{"@timestamp": "2021-04-28T20:51:04.467Z", "metricset": "pod" }'
569+
- '{"index": {}}'
570+
- '{"@timestamp": "2021-04-28T18:50:03.142Z", "metricset": "pod" }'
571+
- '{"index": {}}'
572+
- '{"@timestamp": "2021-04-28T18:50:23.142Z", "metricset": "pod" }'
573+
- '{"index": {}}'
574+
- '{"@timestamp": "2021-04-28T19:50:53.142Z", "metricset": "pod" }'
575+
- '{"index": {}}'
576+
- '{"@timestamp": "2021-04-28T19:51:03.142Z", "metricset": "pod" }'
577+
578+
- do:
579+
indices.put_settings:
580+
index: no-metric-no-label-index
581+
body:
582+
index.blocks.write: true
583+
584+
- do:
585+
indices.downsample:
586+
index: no-metric-no-label-index
587+
target_index: rollup-test-no-metric-no-label
588+
body: >
589+
{
590+
"fixed_interval": "1h"
591+
}
592+
593+
- is_true: acknowledged
594+
595+
- do:
596+
search:
597+
index: rollup-test-no-metric-no-label
598+
body:
599+
sort: [ "_tsid", "@timestamp" ]
600+
601+
- length: { hits.hits: 3 }
602+
603+
- match: { hits.hits.0._source._doc_count: 4 }
604+
- match: { hits.hits.0._source.metricset: pod }
605+
- match: { hits.hits.0._source.@timestamp: 2021-04-28T18:00:00.000Z }
606+
607+
- match: { hits.hits.1._source._doc_count: 2 }
608+
- match: { hits.hits.1._source.metricset: pod }
609+
- match: { hits.hits.1._source.@timestamp: 2021-04-28T19:00:00.000Z }
610+
611+
- match: { hits.hits.2._source._doc_count: 2 }
612+
- match: { hits.hits.2._source.metricset: pod }
613+
- match: { hits.hits.2._source.@timestamp: 2021-04-28T20:00:00.000Z }
614+
478615
---
479616
"Downsample a downsampled index":
480617
- skip:

x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/downsample/TransportDownsampleAction.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,9 +258,6 @@ protected void masterOperation(
258258
if (dimensionFields.isEmpty()) {
259259
validationException.addValidationError("Index [" + sourceIndexName + "] does not contain any dimension fields");
260260
}
261-
if (metricFields.isEmpty()) {
262-
validationException.addValidationError("Index [" + sourceIndexName + "] does not contain any metric fields");
263-
}
264261

265262
if (validationException.validationErrors().isEmpty() == false) {
266263
listener.onFailure(validationException);

x-pack/plugin/rollup/src/test/java/org/elasticsearch/xpack/downsample/DownsampleActionSingleNodeTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ public void testRollupEmptyIndex() throws IOException {
458458
assertRollupIndex(sourceIndex, rollupIndex, config);
459459
}
460460

461-
public void testCannotRollupIndexWithNoMetrics() {
461+
public void testRollupIndexWithNoMetrics() throws IOException {
462462
// Create a source index that contains no metric fields in its mapping
463463
String sourceIndex = "no-metrics-idx-" + randomAlphaOfLength(5).toLowerCase(Locale.ROOT);
464464
client().admin()
@@ -486,8 +486,8 @@ public void testCannotRollupIndexWithNoMetrics() {
486486

487487
DownsampleConfig config = new DownsampleConfig(randomInterval());
488488
prepareSourceIndex(sourceIndex);
489-
Exception exception = expectThrows(ActionRequestValidationException.class, () -> rollup(sourceIndex, rollupIndex, config));
490-
assertThat(exception.getMessage(), containsString("does not contain any metric fields"));
489+
rollup(sourceIndex, rollupIndex, config);
490+
assertRollupIndex(sourceIndex, rollupIndex, config);
491491
}
492492

493493
public void testCannotRollupWriteableIndex() {

0 commit comments

Comments
 (0)