From 0c3b6d323cae1a5fc0d847577f44eee6cae542e4 Mon Sep 17 00:00:00 2001 From: David Zane Date: Wed, 4 Jan 2023 14:18:59 -1000 Subject: [PATCH] Use ?verbose query param Signed-off-by: David Zane --- README.md | 4 ++ ...anceanalyzer-rca-3.0.0.0-SNAPSHOT.jar.sha1 | 1 - ...formanceAnalyzerClusterSettingHandler.java | 9 ++- ...erformanceAnalyzerClusterConfigAction.java | 7 +- ...nceAnalyzerClusterSettingHandlerTests.java | 64 ++++++++----------- 5 files changed, 44 insertions(+), 41 deletions(-) delete mode 100644 licenses/performanceanalyzer-rca-3.0.0.0-SNAPSHOT.jar.sha1 diff --git a/README.md b/README.md index 170e376c..181a3a4d 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/licenses/performanceanalyzer-rca-3.0.0.0-SNAPSHOT.jar.sha1 b/licenses/performanceanalyzer-rca-3.0.0.0-SNAPSHOT.jar.sha1 deleted file mode 100644 index d0fb378b..00000000 --- a/licenses/performanceanalyzer-rca-3.0.0.0-SNAPSHOT.jar.sha1 +++ /dev/null @@ -1 +0,0 @@ -5f095985e19dc87f62919f3bf4c2c29beee1006e \ No newline at end of file diff --git a/src/main/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java b/src/main/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java index 860e7e25..bd3bd9e8 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java +++ b/src/main/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java @@ -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; @@ -140,7 +141,11 @@ public void onSettingUpdate(final Integer newSettingValue) { * * @return the current cluster setting value if exists. Initial cluster setting otherwise. */ - public Map getCurrentClusterSettingValue() { + public int getCurrentClusterSettingValue() { + return currentClusterSetting; + } + + public Map getCurrentClusterSettingValueVerbose() { Map statusMap = new LinkedHashMap(); statusMap.put(PA_ENABLED_KEY, getPAStateFromSetting(currentClusterSetting.intValue())); statusMap.put(RCA_ENABLED_KEY, getRcaStateFromSetting(currentClusterSetting.intValue())); diff --git a/src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigAction.java b/src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigAction.java index 01bbeadf..37a3ea1f 100644 --- a/src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigAction.java +++ b/src/main/java/org/opensearch/performanceanalyzer/http_action/config/PerformanceAnalyzerClusterConfigAction.java @@ -160,6 +160,7 @@ public List 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 map = XContentHelper.convertToMap(request.content(), false, XContentType.JSON).v2(); @@ -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, diff --git a/src/test/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandlerTests.java b/src/test/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandlerTests.java index 36962dbb..e89ef446 100644 --- a/src/test/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandlerTests.java +++ b/src/test/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandlerTests.java @@ -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; @@ -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 ALL_ENABLED_CLUSTER = + createStatusMap( + ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE, ENABLED_STATE); + private final Map ALL_DISABLED_CLUSTER = + createStatusMap( + DISABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE); + private final Map MIXED_STATUS_CLUSTER = + createStatusMap( + ENABLED_STATE, ENABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE); + private PerformanceAnalyzerClusterSettingHandler clusterSettingHandler; @Mock private PerformanceAnalyzerController mockPerformanceAnalyzerController; @@ -37,14 +48,9 @@ public void disabledClusterStateTest() { clusterSettingHandler = new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); - Map 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 @@ -54,10 +60,9 @@ public void enabledClusterStateTest() { clusterSettingHandler = new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); - Map 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 @@ -67,14 +72,9 @@ public void paDisabledClusterStateTest() { clusterSettingHandler = new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); - Map 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 @@ -84,23 +84,13 @@ public void updateClusterStateTest() { clusterSettingHandler = new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); - Map statusMap = - createStatusMap( - ENABLED_STATE, - ENABLED_STATE, - DISABLED_STATE, - DISABLED_STATE, - DISABLED_STATE); - Map 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(