Skip to content

Commit 7c5da21

Browse files
SwethaGupthaakolarkunnu
authored andcommitted
URI path filtering support in cluster stats API (opensearch-project#15938)
* URI path filtering support in cluster stats API Signed-off-by: Swetha Guptha <[email protected]>
1 parent df5be8b commit 7c5da21

File tree

14 files changed

+1483
-116
lines changed

14 files changed

+1483
-116
lines changed

Diff for: CHANGELOG.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,8 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
2626
- Add _list/shards API as paginated alternate to _cat/shards ([#14641](https://github.com/opensearch-project/OpenSearch/pull/14641))
2727
- Latency and Memory allocation improvements to Multi Term Aggregation queries ([#14993](https://github.com/opensearch-project/OpenSearch/pull/14993))
2828
- Flat object field use IndexOrDocValuesQuery to optimize query ([#14383](https://github.com/opensearch-project/OpenSearch/issues/14383))
29-
- Add method to return dynamic SecureTransportParameters from SecureTransportSettingsProvider interface ([#16387](https://github.com/opensearch-project/OpenSearch/pull/16387)
29+
- Add method to return dynamic SecureTransportParameters from SecureTransportSettingsProvider interface ([#16387](https://github.com/opensearch-project/OpenSearch/pull/16387))
30+
- URI path filtering support in cluster stats API ([#15938](https://github.com/opensearch-project/OpenSearch/pull/15938))
3031
- [Star Tree - Search] Add support for metric aggregations with/without term query ([15289](https://github.com/opensearch-project/OpenSearch/pull/15289))
3132

3233
### Dependencies
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* SPDX-License-Identifier: Apache-2.0
3+
*
4+
* The OpenSearch Contributors require contributions made to
5+
* this file be licensed under the Apache-2.0 license or a
6+
* compatible open source license.
7+
*/
8+
9+
package org.opensearch.upgrades;
10+
11+
import org.opensearch.Version;
12+
import org.opensearch.client.Request;
13+
import org.opensearch.client.Response;
14+
15+
import java.io.IOException;
16+
import java.util.Collections;
17+
import java.util.List;
18+
import java.util.Map;
19+
20+
public class ClusterStatsIT extends AbstractRollingTestCase {
21+
22+
private final List<String> nodeStatsMetrics = List.of("os", "process", "jvm", "fs", "plugins", "ingest", "network_types", "discovery_types", "packaging_types");
23+
24+
private final List<String> indicesStatsMetrics = List.of("shards", "docs", "store", "fielddata", "query_cache", "completion", "segments", "analysis", "mappings");
25+
26+
public void testClusterStats() throws IOException {
27+
Response response = client().performRequest(new Request("GET", "/_cluster/stats"));
28+
validateClusterStatsWithFilterResponse(response, nodeStatsMetrics, indicesStatsMetrics);
29+
if (AbstractRollingTestCase.UPGRADE_FROM_VERSION.onOrAfter(Version.V_3_0_0) || (
30+
CLUSTER_TYPE == ClusterType.UPGRADED && Version.CURRENT.onOrAfter(Version.V_3_0_0))) {
31+
response = client().performRequest(new Request("GET", "/_cluster/stats/os/nodes/_all"));
32+
validateClusterStatsWithFilterResponse(response, List.of("os"), Collections.emptyList());
33+
response = client().performRequest(new Request("GET", "/_cluster/stats/indices/mappings/nodes/_all"));
34+
validateClusterStatsWithFilterResponse(response, Collections.emptyList(), List.of("mappings"));
35+
response = client().performRequest(new Request("GET", "/_cluster/stats/os,indices/mappings/nodes/_all"));
36+
validateClusterStatsWithFilterResponse(response, List.of("os"), List.of("mappings"));
37+
}
38+
}
39+
40+
private void validateClusterStatsWithFilterResponse(Response response, List<String> requestedNodesStatsMetrics, List<String> requestedIndicesStatsMetrics) throws IOException {
41+
assertEquals(200, response.getStatusLine().getStatusCode());
42+
Map<String, Object> entity = entityAsMap(response);
43+
if (requestedNodesStatsMetrics != null && !requestedNodesStatsMetrics.isEmpty()) {
44+
assertTrue(entity.containsKey("nodes"));
45+
Map<?, ?> nodesStats = (Map<?, ?>) entity.get("nodes");
46+
for (String metric : nodeStatsMetrics) {
47+
if (requestedNodesStatsMetrics.contains(metric)) {
48+
assertTrue(nodesStats.containsKey(metric));
49+
} else {
50+
assertFalse(nodesStats.containsKey(metric));
51+
}
52+
}
53+
}
54+
55+
if (requestedIndicesStatsMetrics != null && !requestedIndicesStatsMetrics.isEmpty()) {
56+
assertTrue(entity.containsKey("indices"));
57+
Map<?, ?> indicesStats = (Map<?, ?>) entity.get("indices");
58+
for (String metric : indicesStatsMetrics) {
59+
if (requestedIndicesStatsMetrics.contains(metric)) {
60+
assertTrue(indicesStats.containsKey(metric));
61+
} else {
62+
assertFalse(indicesStats.containsKey(metric));
63+
}
64+
}
65+
}
66+
}
67+
}

0 commit comments

Comments
 (0)