From eb8e9a2c0aaa8e660d7f665b371bde824c90cf75 Mon Sep 17 00:00:00 2001 From: David Z <38449481+dzane17@users.noreply.github.com> Date: Tue, 10 Jan 2023 12:30:54 -1000 Subject: [PATCH] Cluster config api return verbose PA status (#342) * Cluster config api return verbose PA status Signed-off-by: David Zane (cherry picked from commit 1f35eebbc9b25d46eb2b81463be7e2ba4e7bfc91) --- README.md | 4 ++ ...formanceAnalyzerClusterSettingHandler.java | 20 ++++++++++ ...erformanceAnalyzerClusterConfigAction.java | 7 +++- ...nceAnalyzerClusterSettingHandlerTests.java | 37 +++++++++++++++++++ 4 files changed, 67 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index eb1345b9..6ad819e0 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},"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/src/main/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java b/src/main/java/org/opensearch/performanceanalyzer/config/setting/handler/PerformanceAnalyzerClusterSettingHandler.java index 9b4ac29b..6e0ae5b5 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 @@ -27,6 +27,8 @@ package org.opensearch.performanceanalyzer.config.setting.handler; +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; @@ -51,6 +53,11 @@ public class PerformanceAnalyzerClusterSettingHandler implements ClusterSettingL PerformanceAnalyzerClusterSettings.PerformanceAnalyzerFeatureBits.BATCH_METRICS_BIT .ordinal(); + static final String PA_ENABLED_KEY = "PerformanceAnalyzerEnabled"; + static final String RCA_ENABLED_KEY = "RcaEnabled"; + static final String LOGGING_ENABLED_KEY = "LoggingEnabled"; + static final String BATCH_METRICS_ENABLED_KEY = "BatchMetricsEnabled"; + private final PerformanceAnalyzerController controller; private final ClusterSettingsManager clusterSettingsManager; @@ -139,6 +146,19 @@ 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())); + statusMap.put( + LOGGING_ENABLED_KEY, getLoggingStateFromSetting(currentClusterSetting.intValue())); + statusMap.put( + BATCH_METRICS_ENABLED_KEY, + getBatchMetricsStateFromSetting(currentClusterSetting.intValue())); + + return statusMap; + } + /** * Gets the cluster settings from the controller. * 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 8320cbac..476bb999 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 @@ -171,6 +171,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(); @@ -208,7 +209,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 3eb637ef..b59d4c11 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 @@ -30,6 +30,8 @@ import static org.mockito.MockitoAnnotations.initMocks; import static org.powermock.api.mockito.PowerMockito.when; +import java.util.LinkedHashMap; +import java.util.Map; import org.junit.Before; import org.junit.Test; import org.mockito.Mock; @@ -40,6 +42,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); + private final Map ALL_DISABLED_CLUSTER = + createStatusMap( + DISABLED_STATE, DISABLED_STATE, DISABLED_STATE, DISABLED_STATE); + private final Map MIXED_STATUS_CLUSTER = + createStatusMap( + ENABLED_STATE, ENABLED_STATE, DISABLED_STATE, DISABLED_STATE); + private PerformanceAnalyzerClusterSettingHandler clusterSettingHandler; @Mock private PerformanceAnalyzerController mockPerformanceAnalyzerController; @@ -57,6 +69,8 @@ public void disabledClusterStateTest() { new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue()); + assertEquals( + ALL_DISABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose()); } @Test @@ -66,6 +80,8 @@ public void enabledClusterStateTest() { new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); assertEquals(15, clusterSettingHandler.getCurrentClusterSettingValue()); + assertEquals( + ALL_ENABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose()); } @Test @@ -75,6 +91,8 @@ public void paDisabledClusterStateTest() { new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue()); + assertEquals( + ALL_DISABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose()); } @Test @@ -84,8 +102,12 @@ public void updateClusterStateTest() { new PerformanceAnalyzerClusterSettingHandler( mockPerformanceAnalyzerController, mockClusterSettingsManager); assertEquals(3, clusterSettingHandler.getCurrentClusterSettingValue()); + assertEquals( + MIXED_STATUS_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose()); clusterSettingHandler.onSettingUpdate(0); assertEquals(0, clusterSettingHandler.getCurrentClusterSettingValue()); + assertEquals( + ALL_DISABLED_CLUSTER, clusterSettingHandler.getCurrentClusterSettingValueVerbose()); } private void setControllerValues( @@ -100,4 +122,19 @@ private void setControllerValues( when(mockPerformanceAnalyzerController.isBatchMetricsEnabled()) .thenReturn(batchMetricsEnabled); } + + private Map createStatusMap( + final Boolean paEnabled, + final Boolean rcaEnabled, + final Boolean loggingEnabled, + final Boolean batchMetricsEnabled { + Map statusMap = new LinkedHashMap(); + statusMap.put(PerformanceAnalyzerClusterSettingHandler.PA_ENABLED_KEY, paEnabled); + statusMap.put(PerformanceAnalyzerClusterSettingHandler.RCA_ENABLED_KEY, rcaEnabled); + statusMap.put(PerformanceAnalyzerClusterSettingHandler.LOGGING_ENABLED_KEY, loggingEnabled); + statusMap.put( + PerformanceAnalyzerClusterSettingHandler.BATCH_METRICS_ENABLED_KEY, + batchMetricsEnabled); + return statusMap; + } }