Skip to content

Commit

Permalink
Add comments.
Browse files Browse the repository at this point in the history
Signed-off-by: Swetha Guptha <[email protected]>
  • Loading branch information
Swetha Guptha committed Oct 4, 2024
1 parent 204ae8c commit f1f60eb
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 106 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,8 @@ public int getIndex() {
/**
* An enumeration of the "core" sections of indices metrics that may be requested
* from the cluster stats endpoint.
*
* When no value is provided for param index_metric, default filter is set to _all.
*/
@PublicApi(since = "3.0.0")
public enum IndexMetric {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,41 +108,40 @@ public RestChannelConsumer prepareRequest(final RestRequest request, final NodeC

public static ClusterStatsRequest fromRequest(final RestRequest request) {
Set<String> metrics = Strings.tokenizeByCommaToSet(request.param("metric", "_all"));
// Value for param index_metric defaults to _all when indices metric or all metrics are requested.
String indicesMetricsDefaultValue = metrics.contains(Metric.INDICES.metricName()) || metrics.contains("_all") ? "_all" : null;
Set<String> indexMetrics = Strings.tokenizeByCommaToSet(request.param("index_metric", indicesMetricsDefaultValue));
String[] nodeIds = request.paramAsStringArray("nodeId", null);

ClusterStatsRequest clusterStatsRequest = new ClusterStatsRequest().nodesIds(nodeIds);
clusterStatsRequest.timeout(request.param("timeout"));
clusterStatsRequest.useAggregatedNodeLevelResponses(true);

if (!metrics.isEmpty()) {
paramValidations(metrics, indexMetrics, request);
final Set<String> metricsRequested = metrics.contains("_all")
? new HashSet<>(METRIC_REQUEST_CONSUMER_MAP.keySet())
: new HashSet<>(metrics);
Set<String> invalidMetrics = validateAndSetRequestedMetrics(metricsRequested, METRIC_REQUEST_CONSUMER_MAP, clusterStatsRequest);
if (!invalidMetrics.isEmpty()) {
clusterStatsRequest.computeAllMetrics(false);

paramValidations(metrics, indexMetrics, request);
final Set<String> metricsRequested = metrics.contains("_all")
? new HashSet<>(METRIC_REQUEST_CONSUMER_MAP.keySet())
: new HashSet<>(metrics);
Set<String> invalidMetrics = validateAndSetRequestedMetrics(metricsRequested, METRIC_REQUEST_CONSUMER_MAP, clusterStatsRequest);
if (!invalidMetrics.isEmpty()) {
throw new IllegalArgumentException(
unrecognizedStrings(request, invalidMetrics, METRIC_REQUEST_CONSUMER_MAP.keySet(), "metric")
);
}
if (metricsRequested.contains(Metric.INDICES.metricName())) {
final Set<String> indexMetricsRequested = indexMetrics.contains("_all")
? INDEX_METRIC_TO_REQUEST_CONSUMER_MAP.keySet()
: new HashSet<>(indexMetrics);
Set<String> invalidIndexMetrics = validateAndSetRequestedMetrics(
indexMetricsRequested,
INDEX_METRIC_TO_REQUEST_CONSUMER_MAP,
clusterStatsRequest
);
if (!invalidIndexMetrics.isEmpty()) {
throw new IllegalArgumentException(
unrecognizedStrings(request, invalidMetrics, METRIC_REQUEST_CONSUMER_MAP.keySet(), "metric")
);
}
if (metricsRequested.contains(Metric.INDICES.metricName())) {
final Set<String> indexMetricsRequested = indexMetrics.contains("_all")
? INDEX_METRIC_TO_REQUEST_CONSUMER_MAP.keySet()
: new HashSet<>(indexMetrics);
Set<String> invalidIndexMetrics = validateAndSetRequestedMetrics(
indexMetricsRequested,
INDEX_METRIC_TO_REQUEST_CONSUMER_MAP,
clusterStatsRequest
unrecognizedStrings(request, invalidIndexMetrics, INDEX_METRIC_TO_REQUEST_CONSUMER_MAP.keySet(), "index metric")
);
if (!invalidIndexMetrics.isEmpty()) {
throw new IllegalArgumentException(
unrecognizedStrings(request, invalidIndexMetrics, INDEX_METRIC_TO_REQUEST_CONSUMER_MAP.keySet(), "index metric")
);
}
}
clusterStatsRequest.computeAllMetrics(false);
}

return clusterStatsRequest;
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ private ClusterStatsNodeResponse createClusterStatsNodeResponse(DiscoveryNode no
null,
null,
null,
null,
null
);
return new ClusterStatsNodeResponse(node, null, nodeInfo, nodeStats, shardStats);
Expand Down

0 comments on commit f1f60eb

Please sign in to comment.