Skip to content

Commit a87502c

Browse files
authored
Add backwards compatibility tests for exponential_histogram (elastic#136809)
1 parent 6f1b507 commit a87502c

File tree

4 files changed

+220
-1
lines changed

4 files changed

+220
-1
lines changed

x-pack/plugin/mapper-exponential-histogram/build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,15 @@ restResources {
2626
dependencies {
2727
api project(":libs:exponential-histogram")
2828
api project(xpackModule('analytics'))
29+
2930
compileOnly project(path: xpackModule('core'))
31+
3032
testImplementation(testArtifact(project(":libs:exponential-histogram")))
33+
3134
yamlRestTestImplementation(testArtifact(project(xpackModule('core'))))
35+
clusterModules(project(xpackModule('analytics'))) //histogram field type
36+
clusterModules(project(xpackModule('mapper-aggregate-metric'))) //aggregate_metric_double field type
37+
clusterModules project(':modules:data-streams')
3238
}
3339

3440
restResources {

x-pack/plugin/mapper-exponential-histogram/src/yamlRestTest/java/org/elasticsearch/xpack/exponentialhistogram/ExponentialHistogramYamlTestSuiteIT.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,12 @@ public static Iterable<Object[]> parameters() throws Exception {
3535
}
3636

3737
@ClassRule
38-
public static ElasticsearchCluster cluster = ElasticsearchCluster.local().module("exponential-histogram").build();
38+
public static ElasticsearchCluster cluster = ElasticsearchCluster.local()
39+
.module("x-pack-aggregate-metric")
40+
.module("x-pack-analytics")
41+
.module("exponential-histogram")
42+
.module("data-streams")
43+
.build();
3944

4045
@Override
4146
protected String getTestRestCluster() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
setup:
2+
# Create an index template for the data stream with aggregate_metric_double field
3+
- do:
4+
indices.put_index_template:
5+
name: test_data_stream_template
6+
body:
7+
index_patterns: ["test-data-stream*"]
8+
data_stream: {}
9+
template:
10+
mappings:
11+
properties:
12+
histo_or_aggregate_metric:
13+
type: aggregate_metric_double
14+
metrics: [min, max, sum, value_count]
15+
default_metric: value_count
16+
17+
# Create the data stream
18+
- do:
19+
indices.create_data_stream:
20+
name: test-data-stream
21+
22+
# Insert a document with aggregate_metric_double value
23+
- do:
24+
index:
25+
index: test-data-stream
26+
refresh: true
27+
body:
28+
'@timestamp': "2023-01-01T00:00:00Z"
29+
histo_or_aggregate_metric:
30+
min: 1.0
31+
max: 10.0
32+
sum: 20.0
33+
value_count: 3
34+
35+
# Update the index template to change the field type to exponential_histogram
36+
- do:
37+
indices.put_index_template:
38+
name: test_data_stream_template
39+
body:
40+
index_patterns: ["test-data-stream*"]
41+
data_stream: {}
42+
template:
43+
mappings:
44+
properties:
45+
histo_or_aggregate_metric:
46+
type: exponential_histogram
47+
48+
# Rollover the data stream to apply the new mapping
49+
- do:
50+
indices.rollover:
51+
alias: test-data-stream
52+
53+
# Insert a document with exponential_histogram value
54+
- do:
55+
index:
56+
index: test-data-stream
57+
refresh: true
58+
body:
59+
'@timestamp': "2023-01-02T00:00:00Z"
60+
histo_or_aggregate_metric:
61+
scale: 1
62+
sum: 100.0
63+
min: 1.0
64+
max: 10.0
65+
zero: { count: 1 }
66+
positive: { indices: [0,1], counts: [2,3] }
67+
negative: { indices: [0], counts: [1] }
68+
69+
---
70+
"Value count aggregation over aggregate_metric_double and exponential_histogram":
71+
- do:
72+
search:
73+
index: test-data-stream
74+
size: 0
75+
body:
76+
aggs:
77+
value_count_metric:
78+
value_count:
79+
field: histo_or_aggregate_metric
80+
- match: { aggregations.value_count_metric.value: 10.0 }
81+
82+
---
83+
"Sum aggregation over aggregate_metric_double and exponential_histogram":
84+
- do:
85+
search:
86+
index: test-data-stream
87+
size: 0
88+
body:
89+
aggs:
90+
sum_metric:
91+
sum:
92+
field: histo_or_aggregate_metric
93+
- match: { aggregations.sum_metric.value: 120.0 }
94+
95+
---
96+
"Average aggregation over aggregate_metric_double and exponential_histogram":
97+
- do:
98+
search:
99+
index: test-data-stream
100+
size: 0
101+
body:
102+
aggs:
103+
avg_metric:
104+
avg:
105+
field: histo_or_aggregate_metric
106+
- match: { aggregations.avg_metric.value: 12.0 }
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
setup:
2+
# Create an index template for the data stream with histogram field
3+
- do:
4+
indices.put_index_template:
5+
name: test_data_stream_template
6+
body:
7+
index_patterns: ["test-data-stream*"]
8+
data_stream: {}
9+
template:
10+
mappings:
11+
properties:
12+
tdigest_or_exp_histo:
13+
type: histogram
14+
15+
# Create the data stream
16+
- do:
17+
indices.create_data_stream:
18+
name: test-data-stream
19+
20+
# Insert a document with T-Digest histogram value
21+
- do:
22+
index:
23+
index: test-data-stream
24+
refresh: true
25+
body:
26+
'@timestamp': "2023-01-01T00:00:00Z"
27+
tdigest_or_exp_histo:
28+
values: [1.0, 2.0, 4.0]
29+
counts: [2, 2, 1]
30+
31+
# Update the index template to change the field type to exponential_histogram
32+
- do:
33+
indices.put_index_template:
34+
name: test_data_stream_template
35+
body:
36+
index_patterns: ["test-data-stream*"]
37+
data_stream: {}
38+
template:
39+
mappings:
40+
properties:
41+
tdigest_or_exp_histo:
42+
type: exponential_histogram
43+
44+
# Rollover the data stream to apply the new mapping
45+
- do:
46+
indices.rollover:
47+
alias: test-data-stream
48+
49+
# Insert a document with exponential_histogram value
50+
- do:
51+
index:
52+
index: test-data-stream
53+
refresh: true
54+
body:
55+
'@timestamp': "2023-01-02T00:00:00Z"
56+
tdigest_or_exp_histo:
57+
scale: 1
58+
sum: 100.0
59+
min: 1.0
60+
max: 10.0
61+
zero: { count: 1 }
62+
positive: { indices: [0,1], counts: [1,2] }
63+
negative: { indices: [0], counts: [1] }
64+
65+
---
66+
"Value count aggregation over aggregate_metric_double and exponential_histogram":
67+
- do:
68+
search:
69+
index: test-data-stream
70+
size: 0
71+
body:
72+
aggs:
73+
value_count_metric:
74+
value_count:
75+
field: tdigest_or_exp_histo
76+
- match: { aggregations.value_count_metric.value: 10.0 }
77+
78+
---
79+
"Sum aggregation over aggregate_metric_double and exponential_histogram":
80+
- do:
81+
search:
82+
index: test-data-stream
83+
size: 0
84+
body:
85+
aggs:
86+
sum_metric:
87+
sum:
88+
field: tdigest_or_exp_histo
89+
- match: { aggregations.sum_metric.value: 110.0 }
90+
91+
---
92+
"Average aggregation over aggregate_metric_double and exponential_histogram":
93+
- do:
94+
search:
95+
index: test-data-stream
96+
size: 0
97+
body:
98+
aggs:
99+
avg_metric:
100+
avg:
101+
field: tdigest_or_exp_histo
102+
- match: { aggregations.avg_metric.value: 11.0 }

0 commit comments

Comments
 (0)