Skip to content

Commit 2b0ee91

Browse files
committed
Adapt the Cluster Health API to closed indices (#39364)
This commit adapts the Cluster Health API to support replicated closed indices. In order to do that, it removes the hard coded indices options from the `ClusterHealthRequest` and replaces it with a new `IndicesOptions.lenientExpand()` option. This option will be used by the master node (once it is upgraded to 8.0) to compute the global cluster health using both opened and closed indices information by default. The `expand_wildcards` REST parameter is also documented and tests where added to ensure that a specific expansion type can be used to monitoring the health of a only opened or only closed indices. Since the Cat Indices relies on the Cluster Health API, it has been adapted to report information about closed indices too. Note that the health and number of shards/replicas is only printed out for closed indices that have an index routing table. Closed indices without routing table have the same output as before. Related to #33888
1 parent 6fc3590 commit 2b0ee91

File tree

12 files changed

+641
-47
lines changed

12 files changed

+641
-47
lines changed

rest-api-spec/src/main/resources/rest-api-spec/api/cluster.health.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,12 @@
1212
}
1313
},
1414
"params": {
15+
"expand_wildcards": {
16+
"type" : "enum",
17+
"options" : ["open","closed","none","all"],
18+
"default" : "all",
19+
"description" : "Whether to expand wildcard expression to concrete indices that are open, closed or both."
20+
},
1521
"level": {
1622
"type" : "enum",
1723
"options" : ["cluster","indices","shards"],

rest-api-spec/src/main/resources/rest-api-spec/test/cat.indices/10_basic.yml

Lines changed: 73 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
---
2-
"Test cat indices output":
2+
"Test cat indices output (no indices)":
33

44
- do:
55
cat.indices: {}
66

77
- match:
88
$body: |
99
/^$/
10+
---
11+
"Test cat indices output":
1012

1113
- do:
1214
indices.create:
@@ -47,29 +49,88 @@
4749
(\d\d\d\d\-\d\d\-\d\dT\d\d:\d\d:\d\d.\d\d\dZ) \s*
4850
)
4951
$/
52+
---
53+
"Test cat indices output for closed index (pre 8.0.0)":
54+
- skip:
55+
version: "8.0.0 - "
56+
reason: "closed indices are replicated starting version 8.0"
57+
58+
- do:
59+
indices.create:
60+
index: index-2
61+
body:
62+
settings:
63+
number_of_shards: 3
64+
number_of_replicas: 0
65+
5066
- do:
5167
indices.close:
52-
index: index1
68+
index: index-2
69+
- is_true: acknowledged
70+
71+
- do:
72+
cluster.health:
73+
wait_for_status: green
5374

5475
- do:
5576
cat.indices:
56-
index: index*
77+
index: index-*
5778

5879
- match:
5980
$body: |
60-
/^( \s+
61-
close \s+
62-
index1 \s+
81+
/^( \s+
82+
close \s+
83+
index-2 \s+
6384
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
64-
\s+
65-
\s+
66-
\s+
67-
\s+
68-
\s+
69-
\s*
85+
\s+
86+
\s+
87+
\s+
88+
\s+
89+
\s+
90+
\s*
7091
)
7192
$/
93+
---
94+
"Test cat indices output for closed index":
95+
- skip:
96+
version: " - 7.99.99"
97+
reason: "closed indices are replicated starting version 8.0"
7298

99+
- do:
100+
indices.create:
101+
index: index-2
102+
body:
103+
settings:
104+
number_of_shards: 3
105+
number_of_replicas: 0
106+
107+
- do:
108+
indices.close:
109+
index: index-2
110+
- is_true: acknowledged
111+
112+
- do:
113+
cluster.health:
114+
wait_for_status: green
115+
116+
- do:
117+
cat.indices:
118+
index: index-*
119+
120+
- match:
121+
$body: |
122+
/^(green \s+
123+
close \s+
124+
index-2 \s+
125+
([a-zA-Z0-9=/_+]|[\\\-]){22} \s+
126+
3 \s+
127+
0 \s+
128+
\s+
129+
\s+
130+
\s+
131+
\s*
132+
)
133+
$/
73134
---
74135
"Test cat indices using health status":
75136

rest-api-spec/src/main/resources/rest-api-spec/test/cluster.health/10_basic.yml

Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,150 @@
132132
- is_true: indices
133133
- is_true: indices.test_index.shards
134134

135+
---
136+
"cluster health with closed index (pre 8.0)":
137+
- skip:
138+
version: "8.0.0 - "
139+
reason: "closed indices are replicated starting version 8.0"
140+
141+
- do:
142+
indices.create:
143+
index: index-1
144+
body:
145+
settings:
146+
index:
147+
number_of_replicas: 0
148+
149+
- do:
150+
cluster.health:
151+
wait_for_status: green
152+
- match: { status: green }
153+
154+
- do:
155+
indices.create:
156+
index: index-2
157+
body:
158+
settings:
159+
index:
160+
number_of_replicas: 50
161+
162+
- do:
163+
cluster.health:
164+
wait_for_status: yellow
165+
wait_for_no_relocating_shards: true
166+
- match: { status: yellow }
167+
168+
- do:
169+
cluster.health:
170+
index: index-*
171+
- match: { status: yellow }
172+
173+
- do:
174+
cluster.health:
175+
index: index-1
176+
- match: { status: green }
177+
178+
- do:
179+
cluster.health:
180+
index: index-2
181+
- match: { status: yellow }
182+
183+
- do:
184+
indices.close:
185+
index: index-2
186+
- is_true: acknowledged
187+
188+
# closing the index-2 turns the cluster health back to green
189+
- do:
190+
cluster.health:
191+
wait_for_status: green
192+
- match: { status: green }
193+
194+
- do:
195+
cluster.health:
196+
index: index-*
197+
- match: { status: green }
198+
199+
- do:
200+
cluster.health:
201+
index: index-1
202+
- match: { status: green }
203+
204+
- do:
205+
cluster.health:
206+
index: index-2
207+
- match: { status: green }
135208

209+
---
210+
"cluster health with closed index":
211+
- skip:
212+
version: " - 7.99.99"
213+
reason: "closed indices are replicated starting version 8.0"
214+
215+
- do:
216+
indices.create:
217+
index: index-1
218+
body:
219+
settings:
220+
index:
221+
number_of_replicas: 0
222+
223+
- do:
224+
cluster.health:
225+
wait_for_status: green
226+
- match: { status: green }
227+
228+
- do:
229+
indices.create:
230+
index: index-2
231+
body:
232+
settings:
233+
index:
234+
number_of_replicas: 50
235+
236+
- do:
237+
cluster.health:
238+
wait_for_status: yellow
239+
wait_for_no_relocating_shards: true
240+
- match: { status: yellow }
241+
242+
- do:
243+
cluster.health:
244+
index: index-*
245+
- match: { status: yellow }
246+
247+
- do:
248+
cluster.health:
249+
index: index-1
250+
- match: { status: green }
251+
252+
- do:
253+
cluster.health:
254+
index: index-2
255+
- match: { status: yellow }
256+
257+
# closing the index-2 does not change the cluster health with replicated closed indices
258+
- do:
259+
indices.close:
260+
index: index-2
261+
- is_true: acknowledged
262+
263+
- do:
264+
cluster.health:
265+
wait_for_status: yellow
266+
- match: { status: yellow }
267+
268+
- do:
269+
cluster.health:
270+
index: index-*
271+
- match: { status: yellow }
272+
273+
- do:
274+
cluster.health:
275+
index: index-1
276+
- match: { status: green }
277+
278+
- do:
279+
cluster.health:
280+
index: index-2
281+
- match: { status: yellow }
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
setup:
2+
3+
- do:
4+
indices.create:
5+
index: index-1
6+
body:
7+
settings:
8+
number_of_shards: 1
9+
number_of_replicas: 0
10+
11+
- do:
12+
indices.create:
13+
index: index-2
14+
body:
15+
settings:
16+
number_of_shards: 2
17+
number_of_replicas: 0
18+
19+
- do:
20+
cluster.health:
21+
wait_for_status: green
22+
23+
- do:
24+
indices.close:
25+
index: index-2
26+
27+
- do:
28+
cluster.health:
29+
wait_for_status: green
30+
31+
---
32+
"cluster health with expand_wildcards":
33+
- skip:
34+
version: " - 7.99.99"
35+
reason: "indices options has been introduced in cluster health request starting version 8.0"
36+
37+
- do:
38+
cluster.health:
39+
index: "index-*"
40+
level: indices
41+
expand_wildcards: open
42+
- match: { status: green }
43+
- match: { active_shards: 1 }
44+
- match: { indices.index-1.status: green }
45+
- match: { indices.index-1.active_shards: 1 }
46+
- is_false: indices.index-2
47+
48+
- do:
49+
cluster.health:
50+
index: "index-*"
51+
level: indices
52+
expand_wildcards: closed
53+
- match: { status: green }
54+
- match: { active_shards: 2 }
55+
- is_false: indices.index-1
56+
- match: { indices.index-2.status: green }
57+
- match: { indices.index-2.active_shards: 2 }
58+
59+
- do:
60+
cluster.health:
61+
index: "index-*"
62+
level: indices
63+
expand_wildcards: all
64+
- match: { status: green }
65+
- match: { active_shards: 3 }
66+
- match: { indices.index-1.status: green }
67+
- match: { indices.index-1.active_shards: 1 }
68+
- match: { indices.index-2.status: green }
69+
- match: { indices.index-2.active_shards: 2 }
70+
71+
- do:
72+
cluster.health:
73+
index: "index-*"
74+
level: indices
75+
expand_wildcards: none
76+
- match: { status: green }
77+
- match: { active_shards: 0 }
78+
- is_false: indices.index-1
79+
- is_false: indices.index-2

0 commit comments

Comments
 (0)