Skip to content

Commit

Permalink
Use ?verbose query param
Browse files Browse the repository at this point in the history
Signed-off-by: David Zane <[email protected]>
  • Loading branch information
dzane17 committed Jan 5, 2023
1 parent cc389ad commit 0c3b6d3
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 41 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ GET localhost:9200/_plugins/_performanceanalyzer/config
GET localhost:9200/_plugins/_performanceanalyzer/cluster/config
{"currentPerformanceAnalyzerClusterState":9,"shardsPerCollection":0,"batchMetricsRetentionPeriodMinutes":7}
GET localhost:9200/_plugins/_performanceanalyzer/cluster/config?verbose
{"currentPerformanceAnalyzerClusterState":{"PerformanceAnalyzerEnabled":false,"RcaEnabled":false,"LoggingEnabled":false,"BatchMetricsEnabled":false,"ThreadContentionMonitoringEnabled":false},"shardsPerCollection":0,"batchMetricsRetentionPeriodMinutes":7
```

The default retention period is 7 minutes. However, the cluster owner can adjust this by setting `batch-metrics-retention-period-minutes` in performance-analyzer.properties (note, setting this value will require a restart so that the cluster can read the new value upon startup). The value must be between 1 and 60 minutes (inclusive) — the range is capped like so in order to prevent excessive data retention on the cluster, which would eat up a lot of storage.
Expand Down
1 change: 0 additions & 1 deletion licenses/performanceanalyzer-rca-3.0.0.0-SNAPSHOT.jar.sha1

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@
package org.opensearch.performanceanalyzer.config.setting.handler;


import java.util.*;
import java.util.LinkedHashMap;
import java.util.Map;
import org.opensearch.performanceanalyzer.config.PerformanceAnalyzerController;
import org.opensearch.performanceanalyzer.config.setting.ClusterSettingListener;
import org.opensearch.performanceanalyzer.config.setting.ClusterSettingsManager;
Expand Down Expand Up @@ -140,7 +141,11 @@ public void onSettingUpdate(final Integer newSettingValue) {
*
* @return the current cluster setting value if exists. Initial cluster setting otherwise.
*/
public Map<String, Boolean> getCurrentClusterSettingValue() {
public int getCurrentClusterSettingValue() {
return currentClusterSetting;
}

public Map<String, Boolean> getCurrentClusterSettingValueVerbose() {
Map<String, Boolean> statusMap = new LinkedHashMap<String, Boolean>();
statusMap.put(PA_ENABLED_KEY, getPAStateFromSetting(currentClusterSetting.intValue()));
statusMap.put(RCA_ENABLED_KEY, getRcaStateFromSetting(currentClusterSetting.intValue()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ public List<ReplacedRoute> replacedRoutes() {
@Override
protected RestChannelConsumer prepareRequest(final RestRequest request, final NodeClient client)
throws IOException {
request.param("verbose");
if (request.method() == RestRequest.Method.POST && request.content().length() > 0) {
Map<String, Object> map =
XContentHelper.convertToMap(request.content(), false, XContentType.JSON).v2();
Expand Down Expand Up @@ -200,7 +201,11 @@ protected RestChannelConsumer prepareRequest(final RestRequest request, final No
try {
XContentBuilder builder = channel.newBuilder();
builder.startObject();
builder.field(CURRENT, clusterSettingHandler.getCurrentClusterSettingValue());
builder.field(
CURRENT,
request.paramAsBoolean("verbose", false)
? clusterSettingHandler.getCurrentClusterSettingValueVerbose()
: clusterSettingHandler.getCurrentClusterSettingValue());
builder.field(SHARDS_PER_COLLECTION, nodeStatsSettingHandler.getNodeStatsSetting());
builder.field(
BATCH_METRICS_RETENTION_PERIOD_MINUTES,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
import static org.mockito.MockitoAnnotations.initMocks;
import static org.powermock.api.mockito.PowerMockito.when;

import java.util.*;
import java.util.LinkedHashMap;
import java.util.Map;
import org.junit.Before;
import org.junit.Test;
import org.mockito.Mock;
Expand All @@ -20,6 +21,16 @@ public class PerformanceAnalyzerClusterSettingHandlerTests {
private static final Boolean DISABLED_STATE = Boolean.FALSE;
private static final Boolean ENABLED_STATE = Boolean.TRUE;

private final Map<String, Boolean> ALL_ENABLED_CLUSTER =
createStatusMap(
ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE);
private final Map<String, Boolean> ALL_DISABLED_CLUSTER =
createStatusMap(
DISABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE);
private final Map<String, Boolean> MIXED_STATUS_CLUSTER =
createStatusMap(
ENABLED_STATE, ENABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE);

private PerformanceAnalyzerClusterSettingHandler clusterSettingHandler;

@Mock private PerformanceAnalyzerController mockPerformanceAnalyzerController;
Expand All @@ -37,14 +48,9 @@ public void disabledClusterStateTest() {
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
Map<String, Boolean> statusMap =
createStatusMap(
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE);
assertEquals(statusMap, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(
ALL_DISABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose());
}

@Test
Expand All @@ -54,10 +60,9 @@ public void enabledClusterStateTest() {
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
Map<String, Boolean> statusMap =
createStatusMap(
ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE);
assertEquals(statusMap, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(31, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(
ALL_ENABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose());
}

@Test
Expand All @@ -67,14 +72,9 @@ public void paDisabledClusterStateTest() {
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
Map<String, Boolean> statusMap =
createStatusMap(
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE);
assertEquals(statusMap, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(
ALL_DISABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose());
}

@Test
Expand All @@ -84,23 +84,13 @@ public void updateClusterStateTest() {
clusterSettingHandler =
new PerformanceAnalyzerClusterSettingHandler(
mockPerformanceAnalyzerController, mockClusterSettingsManager);
Map<String, Boolean> statusMap =
createStatusMap(
ENABLED_STATE,
ENABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE);
Map<String, Boolean> statusMap2 =
createStatusMap(
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE,
DISABLED_STATE);
assertEquals(statusMap, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(3, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(
MIXED_STATUS_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose());
clusterSettingHandler.onSettingUpdate(0);
assertEquals(statusMap2, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue());
assertEquals(
ALL_DISABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose());
}

private void setControllerValues(
Expand Down

0 comments on commit 0c3b6d3

Please sign in to comment.