Skip to content

Commit caa029f

Browse files
authored
Fixing data stream support in random sampling (#137271)
1 parent 3304416 commit caa029f

File tree

11 files changed

+875
-6
lines changed

11 files changed

+875
-6
lines changed
Lines changed: 288 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,288 @@
1+
---
2+
"Test get sample for basic sample config":
3+
- requires:
4+
cluster_features: [ "random_sampling" ]
5+
reason: requires feature 'random_sampling' to get random samples
6+
7+
- do:
8+
indices.put_index_template:
9+
name: my-template1
10+
body:
11+
index_patterns: [sample_test]
12+
template:
13+
settings:
14+
index.number_of_shards: 1
15+
index.number_of_replicas: 0
16+
mappings:
17+
dynamic: strict
18+
properties:
19+
animal:
20+
type: text
21+
foo:
22+
type: text
23+
data_stream: {}
24+
25+
- do:
26+
indices.create_data_stream:
27+
name: sample_test
28+
- is_true: acknowledged
29+
30+
- do:
31+
indices.rollover:
32+
alias: sample_test
33+
wait_for_active_shards: 1
34+
- match: { rolled_over: true }
35+
36+
- do:
37+
indices.put_sample_configuration:
38+
index: sample_test
39+
body:
40+
rate: 1.0
41+
max_samples: 100
42+
43+
- do:
44+
indices.get_sample:
45+
index: sample_test
46+
- match: { sample: [] }
47+
48+
- do:
49+
bulk:
50+
refresh: true
51+
body:
52+
- '{"index": {"_index": "sample_test"}}'
53+
- '{"animal": "dog", "foo": "bar"}'
54+
- '{"index": {"_index": "sample_test"}}'
55+
- '{"animal": "cat", "foo": "baz"}'
56+
57+
- do:
58+
indices.get_sample:
59+
index: sample_test
60+
- length: { sample: 2 }
61+
- match: { sample.0.index: "sample_test" }
62+
- match: { sample.0.source.animal: "dog" }
63+
- match: { sample.0.source.foo: "bar" }
64+
- match: { sample.1.source.animal: "cat" }
65+
- match: { sample.1.source.foo: "baz" }
66+
67+
---
68+
"Test get sample for conditional sample config":
69+
- requires:
70+
cluster_features: [ "random_sampling" ]
71+
reason: requires feature 'random_sampling' to get random samples
72+
73+
- do:
74+
indices.put_index_template:
75+
name: my-template1
76+
body:
77+
index_patterns: [sample_test]
78+
template:
79+
settings:
80+
index.number_of_shards: 1
81+
index.number_of_replicas: 0
82+
mappings:
83+
dynamic: strict
84+
properties:
85+
animal:
86+
type: text
87+
foo:
88+
type: text
89+
data_stream: {}
90+
91+
- do:
92+
indices.create_data_stream:
93+
name: sample_test
94+
- is_true: acknowledged
95+
96+
- do:
97+
indices.rollover:
98+
alias: sample_test
99+
wait_for_active_shards: 1
100+
- match: { rolled_over: true }
101+
102+
- do:
103+
indices.put_sample_configuration:
104+
index: sample_test
105+
body:
106+
rate: 1.0
107+
max_samples: 100
108+
if: "ctx?.animal == 'dog'"
109+
110+
- do:
111+
indices.get_sample:
112+
index: sample_test
113+
- match: { sample: [] }
114+
115+
- do:
116+
bulk:
117+
refresh: true
118+
body:
119+
- '{"index": {"_index": "sample_test"}}'
120+
- '{"animal": "dog", "foo": "bar"}'
121+
- '{"index": {"_index": "sample_test"}}'
122+
- '{"animal": "cat", "foo": "baz"}'
123+
124+
- do:
125+
indices.get_sample:
126+
index: sample_test
127+
- length: { sample: 1 }
128+
- match: { sample.0.index: "sample_test" }
129+
- match: { sample.0.source.animal: "dog" }
130+
- match: { sample.0.source.foo: "bar" }
131+
132+
---
133+
"Test that deleting sample config deletes sample":
134+
- requires:
135+
cluster_features: [ "random_sampling" ]
136+
reason: requires feature 'random_sampling' to get random samples
137+
138+
- do:
139+
indices.put_index_template:
140+
name: my-template1
141+
body:
142+
index_patterns: [sample_test]
143+
template:
144+
settings:
145+
index.number_of_shards: 1
146+
index.number_of_replicas: 0
147+
mappings:
148+
dynamic: strict
149+
properties:
150+
animal:
151+
type: text
152+
foo:
153+
type: text
154+
data_stream: {}
155+
156+
- do:
157+
indices.create_data_stream:
158+
name: sample_test
159+
- is_true: acknowledged
160+
161+
- do:
162+
indices.rollover:
163+
alias: sample_test
164+
wait_for_active_shards: 1
165+
- match: { rolled_over: true }
166+
167+
- do:
168+
indices.put_sample_configuration:
169+
index: sample_test
170+
body:
171+
rate: 1.0
172+
max_samples: 100
173+
174+
- do:
175+
indices.get_sample:
176+
index: sample_test
177+
- match: { sample: [] }
178+
179+
- do:
180+
bulk:
181+
refresh: true
182+
body:
183+
- '{"index": {"_index": "sample_test"}}'
184+
- '{"animal": "dog", "foo": "bar"}'
185+
186+
- do:
187+
indices.get_sample:
188+
index: sample_test
189+
- length: { sample: 1 }
190+
191+
- do:
192+
indices.delete_sample_configuration:
193+
index: sample_test
194+
195+
- do:
196+
indices.get_sample:
197+
index: sample_test
198+
catch: missing
199+
200+
---
201+
"Test that deleting index deletes sample":
202+
- requires:
203+
cluster_features: [ "random_sampling" ]
204+
reason: requires feature 'random_sampling' to get random samples
205+
206+
- do:
207+
indices.put_index_template:
208+
name: my-template1
209+
body:
210+
index_patterns: [sample_test]
211+
template:
212+
settings:
213+
index.number_of_shards: 1
214+
index.number_of_replicas: 0
215+
mappings:
216+
dynamic: strict
217+
properties:
218+
animal:
219+
type: text
220+
foo:
221+
type: text
222+
data_stream: {}
223+
224+
- do:
225+
indices.create_data_stream:
226+
name: sample_test
227+
- is_true: acknowledged
228+
229+
- do:
230+
indices.rollover:
231+
alias: sample_test
232+
wait_for_active_shards: 1
233+
- match: { rolled_over: true }
234+
235+
- do:
236+
indices.put_sample_configuration:
237+
index: sample_test
238+
body:
239+
rate: 1.0
240+
max_samples: 100
241+
242+
- do:
243+
indices.get_sample:
244+
index: sample_test
245+
- match: { sample: [] }
246+
247+
- do:
248+
bulk:
249+
refresh: true
250+
body:
251+
- '{"index": {"_index": "sample_test"}}'
252+
- '{"animal": "dog", "foo": "bar"}'
253+
- '{"index": {"_index": "sample_test"}}'
254+
- '{"animal": "cat", "foo": "baz"}'
255+
256+
- do:
257+
indices.get_sample:
258+
index: sample_test
259+
- length: { sample: 2 }
260+
261+
- do:
262+
indices.delete_data_stream:
263+
name: sample_test
264+
- is_true: acknowledged
265+
266+
- do:
267+
indices.get_sample_configuration:
268+
index: sample_test
269+
catch: missing
270+
271+
- do:
272+
indices.get_sample:
273+
index: sample_test
274+
catch: missing
275+
276+
---
277+
teardown:
278+
- requires:
279+
cluster_features: [ "random_sampling" ]
280+
reason: requires feature 'random_sampling' to get random samples
281+
282+
- do:
283+
indices.delete_data_stream:
284+
name: sample_test*
285+
286+
- do:
287+
indices.get_all_sample_configuration: {}
288+
- length: { $body: 0 }

0 commit comments

Comments
 (0)