Skip to content

Commit 3304416

Browse files
authored
update sampling config get all response to fit elastic standards (#137290)
1 parent f4e89c9 commit 3304416

File tree

2 files changed

+35
-34
lines changed

2 files changed

+35
-34
lines changed

rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/indices.get_all_sample_configuration/10_basic.yml

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ teardown:
2626
indices.get_all_sample_configuration: {}
2727

2828
# Should return an empty array
29-
- length: { $body: 0 }
29+
- length: { configurations: 0 }
3030

3131
---
3232
"Get all sampling configurations with single configuration":
@@ -49,12 +49,12 @@ teardown:
4949
indices.get_all_sample_configuration:
5050
human: true
5151

52-
- length: { $body: 1 }
53-
- match: { 0.index: "test-single-config-index" }
54-
- match: { 0.configuration.rate: 0.5 }
55-
- match: { 0.configuration.max_samples: 100 }
56-
- match: { 0.configuration.max_size: "10mb" }
57-
- match: { 0.configuration.time_to_live: "1h" }
52+
- length: { configurations: 1 }
53+
- match: { configurations.0.index: "test-single-config-index" }
54+
- match: { configurations.0.configuration.rate: 0.5 }
55+
- match: { configurations.0.configuration.max_samples: 100 }
56+
- match: { configurations.0.configuration.max_size: "10mb" }
57+
- match: { configurations.0.configuration.time_to_live: "1h" }
5858

5959
---
6060
"Get all sampling configurations with multiple configurations":
@@ -102,14 +102,14 @@ teardown:
102102
indices.get_all_sample_configuration:
103103
human: true
104104

105-
- length: { $body: 3 }
105+
- length: { configurations: 3 }
106106
# Note: Array order may vary, so we just verify all 3 configurations exist
107-
- is_true: 0.index
108-
- is_true: 0.configuration
109-
- is_true: 1.index
110-
- is_true: 1.configuration
111-
- is_true: 2.index
112-
- is_true: 2.configuration
107+
- is_true: configurations.0.index
108+
- is_true: configurations.0.configuration
109+
- is_true: configurations.1.index
110+
- is_true: configurations.1.configuration
111+
- is_true: configurations.2.index
112+
- is_true: configurations.2.configuration
113113

114114
---
115115
"Get all sampling configurations with mixed indices":
@@ -148,11 +148,11 @@ teardown:
148148
human: true
149149

150150
# Should only return configured indices (2 items)
151-
- length: { $body: 2 }
152-
- is_true: 0.index
153-
- is_true: 0.configuration
154-
- is_true: 1.index
155-
- is_true: 1.configuration
151+
- length: { configurations: 2 }
152+
- is_true: configurations.0.index
153+
- is_true: configurations.0.configuration
154+
- is_true: configurations.1.index
155+
- is_true: configurations.1.configuration
156156

157157
---
158158
"Get all sampling configurations after update":
@@ -174,10 +174,10 @@ teardown:
174174
indices.get_all_sample_configuration:
175175
human: true
176176

177-
- length: { $body: 1 }
178-
- match: { 0.index: "test-update-all-index" }
179-
- match: { 0.configuration.rate: 0.2 }
180-
- match: { 0.configuration.max_samples: 30 }
177+
- length: { configurations: 1 }
178+
- match: { configurations.0.index: "test-update-all-index" }
179+
- match: { configurations.0.configuration.rate: 0.2 }
180+
- match: { configurations.0.configuration.max_samples: 30 }
181181

182182
# Update configuration
183183
- do:
@@ -195,11 +195,11 @@ teardown:
195195
indices.get_all_sample_configuration:
196196
human: true
197197

198-
- length: { $body: 1 }
199-
- match: { 0.index: "test-update-all-index" }
200-
- match: { 0.configuration.rate: 0.9 }
201-
- match: { 0.configuration.max_samples: 150 }
202-
- match: { 0.configuration.max_size: "15mb" }
198+
- length: { configurations: 1 }
199+
- match: { configurations.0.index: "test-update-all-index" }
200+
- match: { configurations.0.configuration.rate: 0.9 }
201+
- match: { configurations.0.configuration.max_samples: 150 }
202+
- match: { configurations.0.configuration.max_size: "15mb" }
203203

204204
---
205205
"Get all sampling configurations after deletion":
@@ -234,7 +234,7 @@ teardown:
234234
indices.get_all_sample_configuration:
235235
human: true
236236

237-
- length: { $body: 2 }
237+
- length: { configurations: 2 }
238238

239239
# Delete one configuration
240240
- do:
@@ -248,7 +248,7 @@ teardown:
248248
indices.get_all_sample_configuration:
249249
human: true
250250

251-
- length: { $body: 1 }
252-
- match: { 0.index: "test-delete-all-index-2" }
253-
- match: { 0.configuration.rate: 0.8 }
254-
- match: { 0.configuration.max_samples: 200 }
251+
- length: { configurations: 1 }
252+
- match: { configurations.0.index: "test-delete-all-index-2" }
253+
- match: { configurations.0.configuration.rate: 0.8 }
254+
- match: { configurations.0.configuration.max_samples: 200 }

server/src/main/java/org/elasticsearch/action/admin/indices/sampling/GetAllSampleConfigurationAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,15 @@ public Iterator<? extends ToXContent> toXContentChunked(ToXContent.Params params
192192
}
193193

194194
private XContentBuilder toXContent(XContentBuilder builder, ToXContent.Params params) throws IOException {
195-
builder.startArray();
195+
builder.startObject().startArray("configurations");
196196
for (Map.Entry<String, SamplingConfiguration> entry : indexToSamplingConfigMap.entrySet()) {
197197
builder.startObject();
198198
builder.field("index", entry.getKey());
199199
builder.field("configuration", entry.getValue());
200200
builder.endObject();
201201
}
202202
builder.endArray();
203+
builder.endObject();
203204
return builder;
204205
}
205206
}

0 commit comments

Comments
 (0)