@@ -23,10 +23,13 @@ module RestAPIYAMLTests
23
23
module WipeCluster8
24
24
PRESERVE_ILM_POLICY_IDS = [
25
25
'ilm-history-ilm-policy' , 'slm-history-ilm-policy' , 'watch-history-ilm-policy' ,
26
- 'ml-size-based-ilm-policy' , 'logs' , 'metrics' , 'synthetics' , '7-days-default' ,
27
- '30-days-default' , '90-days-default' , '180-days-default' , '365-days-default' ,
28
- '.fleet-actions-results-ilm-policy' , '.deprecation-indexing-ilm-policy' ,
29
- 'watch-history-ilm-policy-16' , '.monitoring-8-ilm-policy'
26
+ 'watch-history-ilm-policy-16' , 'ml-size-based-ilm-policy' , 'logs' , 'metrics' , 'profiling' ,
27
+ 'synthetics' , '7-days-default' , '30-days-default' , '90-days-default' , '180-days-default' ,
28
+ '365-days-default' , '.fleet-files-ilm-policy' , '.fleet-file-data-ilm-policy' ,
29
+ '.fleet-actions-results-ilm-policy' , '.fleet-file-fromhost-data-ilm-policy' ,
30
+ '.fleet-file-fromhost-meta-ilm-policy' , '.fleet-file-tohost-data-ilm-policy' ,
31
+ '.fleet-file-tohost-meta-ilm-policy' , '.deprecation-indexing-ilm-policy' ,
32
+ '.monitoring-8-ilm-policy' , 'behavioral_analytics-events-default_policy'
30
33
] . freeze
31
34
32
35
PLATINUM_TEMPLATES = [
@@ -37,9 +40,7 @@ module WipeCluster8
37
40
'synthetics' , 'synthetics-settings' , 'synthetics-mappings' ,
38
41
'.snapshot-blob-cache' , '.deprecation-indexing-template' ,
39
42
'.deprecation-indexing-mappings' , '.deprecation-indexing-settings' ,
40
- 'behavioral_analytics-events-mappings' , 'behavioral_analytics-events-settings' ,
41
- 'security-index-template' , 'data-streams-mappings' , 'ecs@dynamic_templates' ,
42
- 'search-acl-filter'
43
+ 'security-index-template' , 'data-streams-mappings' , 'search-acl-filter'
43
44
] . freeze
44
45
45
46
# Wipe Cluster, based on PHP's implementation of ESRestTestCase.java:wipeCluster()
@@ -51,14 +52,21 @@ def self.run(client)
51
52
check_for_unexpectedly_recreated_objects ( client )
52
53
end
53
54
55
+ def self . create_xpack_rest_user ( client )
56
+ client . security . put_user (
57
+ username : 'x_pack_rest_user' ,
58
+ body : { password : 'x-pack-test-password' , roles : [ 'superuser' ] }
59
+ )
60
+ end
61
+
54
62
class << self
55
63
private
56
64
57
65
def wipe_cluster ( client )
58
66
read_plugins ( client )
59
67
if @has_rollups
60
68
wipe_rollup_jobs ( client )
61
- wait_for_pending_rollup_tasks ( client )
69
+ # wait_for_pending_rollup_tasks(client)
62
70
end
63
71
delete_all_slm_policies ( client )
64
72
wipe_searchable_snapshot_indices ( client ) if @has_xpack
@@ -71,12 +79,13 @@ def wipe_cluster(client)
71
79
clear_ml_jobs ( client )
72
80
clear_datafeeds ( client )
73
81
delete_data_frame_analytics ( client )
74
- delete_filters ( client )
75
- clear_transforms ( client )
82
+ clear_ml_filters ( client )
76
83
end
77
84
delete_all_ilm_policies ( client ) if @has_ilm
78
85
delete_all_follow_patterns ( client ) if @has_ccr
79
86
delete_all_node_shutdown_metadata ( client )
87
+ clear_tasks ( client )
88
+ clear_transforms ( client )
80
89
wipe_calendars ( client )
81
90
end
82
91
@@ -86,7 +95,7 @@ def ensure_no_initializing_shards(client)
86
95
87
96
def check_for_unexpectedly_recreated_objects ( client )
88
97
unexpected_ilm_policies = client . ilm . get_lifecycle
89
- unexpected_ilm_policies . reject! { |k , _ | PRESERVE_ILM_POLICY_IDS . include? k }
98
+ unexpected_ilm_policies . reject! { |k , _ | preserve_policy? ( k ) }
90
99
unless unexpected_ilm_policies . empty?
91
100
logger . info (
92
101
"Expected no ILM policies after deletions, but found #{ unexpected_ilm_policies . keys . join ( ',' ) } "
@@ -97,12 +106,12 @@ def check_for_unexpectedly_recreated_objects(client)
97
106
templates = client . indices . get_index_template
98
107
unexpected_templates = templates [ 'index_templates' ] . reject do |t |
99
108
# reject platinum templates
100
- PLATINUM_TEMPLATES . include? t [ 'name' ]
109
+ platinum_template? ( t [ 'name' ] )
101
110
end . map { |t | t [ 'name' ] } # only keep the names
102
111
legacy_templates = client . indices . get_template
103
- unexpected_templates << legacy_templates . keys . reject { |t | PLATINUM_TEMPLATES . include? t }
112
+ unexpected_templates << legacy_templates . keys . reject { |t | platinum_template? ( t ) }
104
113
105
- unless unexpected_templates . empty?
114
+ unless unexpected_templates . reject ( & :empty? ) . empty?
106
115
logger . info (
107
116
"Expected no templates after deletions, but found #{ unexpected_templates . join ( ',' ) } "
108
117
)
@@ -136,19 +145,19 @@ def wipe_rollup_jobs(client)
136
145
137
146
def wait_for_pending_rollup_tasks ( client )
138
147
filter = 'xpack/rollup/job'
148
+ start_time = Time . now . to_i
149
+ count = 0
139
150
loop do
140
151
results = client . cat . tasks ( detailed : true ) . split ( "\n " )
141
- count = 0
142
152
143
- time = Time . now . to_i
144
153
results . each do |task |
145
- next if task . empty?
154
+ next if task . empty? || skippable_task? ( task ) || task . include? ( filter )
146
155
147
- logger . debug ( "Pending task: #{ task } " )
148
- count += 1 if task . include? ( filter )
156
+ count += 1
149
157
end
150
- break unless count . positive? && Time . now . to_i < ( time + 30 )
158
+ break unless count . positive? && Time . now . to_i < ( start_time + 1 )
151
159
end
160
+ logger . debug ( "Waited for #{ count } pending rollup tasks for #{ Time . now . to_i - start_time } s." ) if count . positive?
152
161
end
153
162
154
163
def delete_all_slm_policies ( client )
@@ -229,7 +238,7 @@ def wipe_all_templates(client)
229
238
# Always check for legacy templates
230
239
templates = client . indices . get_template
231
240
templates . each do |name , _ |
232
- next if platinum_template? name
241
+ next if platinum_template? ( name )
233
242
234
243
begin
235
244
client . indices . delete_template ( name : name )
@@ -240,35 +249,51 @@ def wipe_all_templates(client)
240
249
end
241
250
242
251
def platinum_template? ( template )
252
+ return true if template . include? ( '@' )
253
+
243
254
platinum_prefixes = [
244
- '.monitoring' , '.watch' , '.triggered-watches' , '.data-frame' , '.ml-' , '.transform' ,
245
- 'data-streams-mappings' , 'elastic-connectors'
255
+ '.monitoring' , '.watch' , '.triggered-watches' , '.data-frame' , '.ml-' ,
256
+ '.transform' , '.deprecation' , 'data-streams-mappings' , '.fleet' ,
257
+ 'behavioral_analytics-' , 'profiling' , 'elastic-connectors' , 'ilm-history' , '.slm-history'
246
258
] . freeze
247
- platinum_prefixes . map { | a | return true if ( a . include? ( template ) || template . start_with? ( a ) ) }
259
+ return true if template . start_with? ( * platinum_prefixes )
248
260
249
261
PLATINUM_TEMPLATES . include? template
250
262
end
251
263
264
+ def preserve_policy? ( policy )
265
+ PRESERVE_ILM_POLICY_IDS . include? ( policy ) || policy . include? ( '@' )
266
+ end
267
+
252
268
def wait_for_cluster_tasks ( client )
253
- time = Time . now . to_i
269
+ start_time = Time . now . to_i
254
270
count = 0
255
-
256
271
loop do
257
272
results = client . cluster . pending_tasks
258
273
results [ 'tasks' ] . each do |task |
259
- next if task . empty?
274
+ next if task . empty? || skippable_task? ( task )
260
275
261
- logger . debug "Pending cluster task: #{ task } "
262
276
count += 1
263
277
end
264
- break unless count . positive? && Time . now . to_i < ( time + 10 )
278
+ break unless count . positive? && Time . now . to_i < ( start_time + 5 )
279
+ end
280
+ logger . debug ( "Waited for #{ count } pending cluster tasks for #{ Time . now . to_i - start_time } s." ) if count . positive?
281
+ end
282
+
283
+ def skippable_task? ( task )
284
+ names = [ 'health-node' , 'cluster:monitor/tasks/lists' , 'create-index-template-v2' ,
285
+ 'remove-component-template' ]
286
+ if task . is_a? ( String )
287
+ names . select { |n | task . match? n } . any?
288
+ elsif task . is_a? ( Hash )
289
+ names . select { |n | task [ 'source' ] . match? n } . any?
265
290
end
266
291
end
267
292
268
293
def delete_all_ilm_policies ( client )
269
294
policies = client . ilm . get_lifecycle
270
295
policies . each do |policy |
271
- client . ilm . delete_lifecycle ( policy : policy [ 0 ] ) unless PRESERVE_ILM_POLICY_IDS . include? policy [ 0 ]
296
+ client . ilm . delete_lifecycle ( policy : policy [ 0 ] ) unless preserve_policy? ( policy [ 0 ] )
272
297
end
273
298
end
274
299
@@ -294,13 +319,6 @@ def delete_all_follow_patterns(client)
294
319
end
295
320
end
296
321
297
- def create_xpack_rest_user ( client )
298
- client . security . put_user (
299
- username : 'x_pack_rest_user' ,
300
- body : { password : 'x-pack-test-password' , roles : [ 'superuser' ] }
301
- )
302
- end
303
-
304
322
def clear_roles ( client )
305
323
client . security . get_role . each do |role , _ |
306
324
begin ; client . security . delete_role ( name : role ) ; rescue ; end
@@ -376,13 +394,6 @@ def delete_all_node_shutdown_metadata(client)
376
394
end
377
395
end
378
396
379
- def wipe_calendars ( client )
380
- calendars = client . ml . get_calendars ( calendar_id : '_all' ) [ 'calendars' ]
381
- calendars . each do |calendar |
382
- client . ml . delete_calendar ( calendar_id : calendar [ 'calendar_id' ] )
383
- end
384
- end
385
-
386
397
def delete_data_frame_analytics ( client )
387
398
dfs = client . ml . get_data_frame_analytics
388
399
return unless dfs [ 'data_frame_analytics' ]
@@ -392,10 +403,10 @@ def delete_data_frame_analytics(client)
392
403
end
393
404
end
394
405
395
- def delete_filters ( client )
396
- filters = client . ml . get_filters
397
- filters [ 'filters' ] . each do |filter |
398
- client . ml . delete_filter ( filter_id : filter [ 'filter_id '] )
406
+ def wipe_calendars ( client )
407
+ calendars = client . ml . get_calendars ( calendar_id : '_all' ) [ 'calendars' ]
408
+ calendars . each do |calendar |
409
+ client . ml . delete_calendar ( calendar_id : calendar [ 'calendar_id '] )
399
410
end
400
411
end
401
412
end
0 commit comments