Skip to content

Commit

Permalink
Add back opendistro prefixed sweeper enabled field to alerting stats …
Browse files Browse the repository at this point in the history
…response (opensearch-project#283)

* Add back opendistro prefixed sweeper enabled to alerting stats response

Signed-off-by: Mohammad Qureshi <[email protected]>

* Rename stats response field variables used in tests

Signed-off-by: Mohammad Qureshi <[email protected]>
  • Loading branch information
qreshi committed Jan 24, 2022
1 parent 0b1d08e commit cb2c28b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -902,8 +902,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<String, Int>
validateAlertingStatsNodeResponse(_nodes)
Expand All @@ -915,7 +914,7 @@ class MonitorRestApiIT : AlertingRestTestCase() {
val monitorId = createMonitor(randomQueryLevelMonitor(enabled = true), refresh = true).id

var alertingStats = getAlertingStats()
assertEquals("Scheduled job is not enabled", true, alertingStats[ScheduledJobSettings.SWEEPER_ENABLED.key])
assertAlertingStatsSweeperEnabled(alertingStats, true)
assertEquals("Scheduled job index does not exist", true, alertingStats["scheduled_job_index_exists"])
assertEquals("Scheduled job index is not yellow", "yellow", alertingStats["scheduled_job_index_status"])
assertEquals("Nodes are not on schedule", numberOfNodes, alertingStats["nodes_on_schedule"])
Expand All @@ -932,7 +931,7 @@ class MonitorRestApiIT : AlertingRestTestCase() {
disableScheduledJob()

alertingStats = getAlertingStats()
assertEquals("Scheduled job is still enabled", false, alertingStats[ScheduledJobSettings.SWEEPER_ENABLED.key])
assertAlertingStatsSweeperEnabled(alertingStats, false)
assertFalse(
"Monitor [$monitorId] was still scheduled based on the alerting stats response: $alertingStats",
isMonitorScheduled(monitorId, alertingStats)
Expand All @@ -945,7 +944,7 @@ class MonitorRestApiIT : AlertingRestTestCase() {
Thread.sleep(2000)

alertingStats = getAlertingStats()
assertEquals("Scheduled job is not enabled", true, alertingStats[ScheduledJobSettings.SWEEPER_ENABLED.key])
assertAlertingStatsSweeperEnabled(alertingStats, true)
assertTrue(
"Monitor [$monitorId] was not re-scheduled based on the alerting stats response: $alertingStats",
isMonitorScheduled(monitorId, alertingStats)
Expand All @@ -957,8 +956,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<String, Int>
validateAlertingStatsNodeResponse(_nodes)
Expand All @@ -970,8 +968,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"])
Expand Down Expand Up @@ -999,8 +996,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"])
Expand Down Expand Up @@ -1118,4 +1114,17 @@ class MonitorRestApiIT : AlertingRestTestCase() {

return false
}

private fun assertAlertingStatsSweeperEnabled(alertingStatsResponse: Map<String, Any>, 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]
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -77,6 +78,7 @@ class ScheduledJobsStatsResponse : BaseNodesResponse<ScheduledJobStats>, 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())
Expand Down

0 comments on commit cb2c28b

Please sign in to comment.