From 35a814fc7acb832eed8c15a73796070593ddc1a6 Mon Sep 17 00:00:00 2001 From: Mohammad Qureshi <47198598+qreshi@users.noreply.github.com> Date: Mon, 24 Jan 2022 11:47:12 -0800 Subject: [PATCH] Add back opendistro prefixed sweeper enabled field to alerting stats response (#283) * Add back opendistro prefixed sweeper enabled to alerting stats response Signed-off-by: Mohammad Qureshi * Rename stats response field variables used in tests Signed-off-by: Mohammad Qureshi --- .../alerting/AlertingRestTestCase.kt | 3 +++ .../alerting/resthandler/MonitorRestApiIT.kt | 25 +++++++++++++------ .../action/node/ScheduledJobsStatsResponse.kt | 2 ++ 3 files changed, 22 insertions(+), 8 deletions(-) diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt b/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt index 7e9f05ded..a49a297aa 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt @@ -90,6 +90,9 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { protected val numberOfNodes = System.getProperty("cluster.number_of_nodes", "1")!!.toInt() protected val isMultiNode = numberOfNodes > 1 + protected val statsResponseOpendistroSweeperEnabledField = "opendistro.scheduled_jobs.enabled" + protected val statsResponseOpenSearchSweeperEnabledField = "plugins.scheduled_jobs.enabled" + override fun xContentRegistry(): NamedXContentRegistry { return NamedXContentRegistry( mutableListOf( diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/MonitorRestApiIT.kt b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/MonitorRestApiIT.kt index 0d0a58f5f..9a523d9ea 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/MonitorRestApiIT.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/MonitorRestApiIT.kt @@ -893,8 +893,7 @@ class MonitorRestApiIT : AlertingRestTestCase() { disableScheduledJob() val responseMap = getAlertingStats() - // assertEquals("Cluster name is incorrect", responseMap["cluster_name"], "alerting_integTestCluster") - assertEquals("Scheduled job is not enabled", false, responseMap[ScheduledJobSettings.SWEEPER_ENABLED.key]) + assertAlertingStatsSweeperEnabled(responseMap, false) assertEquals("Scheduled job index exists but there are no scheduled jobs.", false, responseMap["scheduled_job_index_exists"]) val _nodes = responseMap["_nodes"] as Map assertEquals("Incorrect number of nodes", numberOfNodes, _nodes["total"]) @@ -907,8 +906,7 @@ class MonitorRestApiIT : AlertingRestTestCase() { enableScheduledJob() val responseMap = getAlertingStats() - // assertEquals("Cluster name is incorrect", responseMap["cluster_name"], "alerting_integTestCluster") - assertEquals("Scheduled job is not enabled", true, responseMap[ScheduledJobSettings.SWEEPER_ENABLED.key]) + assertAlertingStatsSweeperEnabled(responseMap, true) assertEquals("Scheduled job index exists but there are no scheduled jobs.", false, responseMap["scheduled_job_index_exists"]) val _nodes = responseMap["_nodes"] as Map assertEquals("Incorrect number of nodes", numberOfNodes, _nodes["total"]) @@ -922,8 +920,7 @@ class MonitorRestApiIT : AlertingRestTestCase() { createRandomMonitor(refresh = true) val responseMap = getAlertingStats() - // assertEquals("Cluster name is incorrect", responseMap["cluster_name"], "alerting_integTestCluster") - assertEquals("Scheduled job is not enabled", true, responseMap[ScheduledJobSettings.SWEEPER_ENABLED.key]) + assertAlertingStatsSweeperEnabled(responseMap, true) assertEquals("Scheduled job index does not exist", true, responseMap["scheduled_job_index_exists"]) assertEquals("Scheduled job index is not yellow", "yellow", responseMap["scheduled_job_index_status"]) assertEquals("Nodes are not on schedule", numberOfNodes, responseMap["nodes_on_schedule"]) @@ -953,8 +950,7 @@ class MonitorRestApiIT : AlertingRestTestCase() { createRandomMonitor(refresh = true) val responseMap = getAlertingStats("/jobs_info") - // assertEquals("Cluster name is incorrect", responseMap["cluster_name"], "alerting_integTestCluster") - assertEquals("Scheduled job is not enabled", true, responseMap[ScheduledJobSettings.SWEEPER_ENABLED.key]) + assertAlertingStatsSweeperEnabled(responseMap, true) assertEquals("Scheduled job index does not exist", true, responseMap["scheduled_job_index_exists"]) assertEquals("Scheduled job index is not yellow", "yellow", responseMap["scheduled_job_index_status"]) assertEquals("Nodes not on schedule", numberOfNodes, responseMap["nodes_on_schedule"]) @@ -1055,4 +1051,17 @@ class MonitorRestApiIT : AlertingRestTestCase() { assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus()) } } + + private fun assertAlertingStatsSweeperEnabled(alertingStatsResponse: Map, expected: Boolean) { + assertEquals( + "Legacy scheduled job enabled field is not set to $expected", + expected, + alertingStatsResponse[statsResponseOpendistroSweeperEnabledField] + ) + assertEquals( + "Scheduled job is not ${if (expected) "enabled" else "disabled"}", + expected, + alertingStatsResponse[statsResponseOpenSearchSweeperEnabledField] + ) + } } diff --git a/core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt b/core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt index d38159254..f8d0a0fca 100644 --- a/core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt +++ b/core/src/main/kotlin/org/opensearch/alerting/core/action/node/ScheduledJobsStatsResponse.kt @@ -28,6 +28,7 @@ package org.opensearch.alerting.core.action.node import org.opensearch.action.FailedNodeException import org.opensearch.action.support.nodes.BaseNodesResponse +import org.opensearch.alerting.core.settings.LegacyOpenDistroScheduledJobSettings import org.opensearch.alerting.core.settings.ScheduledJobSettings import org.opensearch.cluster.ClusterName import org.opensearch.cluster.health.ClusterIndexHealth @@ -77,6 +78,7 @@ class ScheduledJobsStatsResponse : BaseNodesResponse, ToXCont } override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder { + builder.field(LegacyOpenDistroScheduledJobSettings.SWEEPER_ENABLED.key, scheduledJobEnabled) builder.field(ScheduledJobSettings.SWEEPER_ENABLED.key, scheduledJobEnabled) builder.field("scheduled_job_index_exists", indexExists) builder.field("scheduled_job_index_status", indexHealth?.status?.name?.toLowerCase())