Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/main' into copyright
Browse files Browse the repository at this point in the history
  • Loading branch information
Annie Lee committed Dec 21, 2021
2 parents 8cb69db + ea7d526 commit 4c3325e
Show file tree
Hide file tree
Showing 11 changed files with 132 additions and 157 deletions.
2 changes: 2 additions & 0 deletions .github/CODEOWNERS
Validating CODEOWNERS rules …
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# This should match the owning team set up in https://github.com/orgs/opensearch-project/teams
* @opensearch-project/alerting-plugin
6 changes: 3 additions & 3 deletions .github/workflows/multi-node-test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: Multi node test workflow
on:
pull_request:
branches:
- main
- "*"
push:
branches:
- main
- "*"

jobs:
build:
Expand All @@ -32,7 +32,7 @@ jobs:
with:
java-version: 14
- name: Run integration tests with multi node config
run: ./gradlew integTest -PnumNodes=3 -Dopensearch.version=1.2.0-SNAPSHOT
run: ./gradlew integTest -PnumNodes=3 -Dopensearch.version=1.3.0-SNAPSHOT
- name: Pull and Run Docker
run: |
plugin=`ls alerting/build/distributions/*.zip`
Expand Down
122 changes: 0 additions & 122 deletions .github/workflows/release-workflow.yml

This file was deleted.

10 changes: 4 additions & 6 deletions .github/workflows/test-workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,10 @@ name: Test Workflow
on:
pull_request:
branches:
- main
- opendistro-*
- "*"
push:
branches:
- main
- opendistro-*
- "*"

jobs:
build:
Expand All @@ -31,7 +29,7 @@ jobs:


- name: Build and run with Gradle
run: ./gradlew build -Dopensearch.version=1.2.0-SNAPSHOT
run: ./gradlew build -Dopensearch.version=1.3.0-SNAPSHOT

# - name: Create Artifact Path
# run: |
Expand All @@ -50,4 +48,4 @@ jobs:
# path: alerting-artifacts
# Publish to local maven
- name: Publish to Maven Local
run: ./gradlew publishToMavenLocal -Dopensearch.version=1.2.0-SNAPSHOT
run: ./gradlew publishToMavenLocal -Dopensearch.version=1.3.0-SNAPSHOT
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[![Test Workflow](https://github.com/opensearch-project/alerting/workflows/Test%20Workflow/badge.svg)](https://github.com/opendistro-for-elasticsearch/alerting/actions)
[![codecov](https://codecov.io/gh/opendistro-for-elasticsearch/alerting/branch/main/graph/badge.svg)](https://codecov.io/gh/opendistro-for-elasticsearch/alerting)
[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://opendistro.github.io/for-elasticsearch-docs/docs/alerting/api/)
[![Test Workflow](https://github.com/opensearch-project/alerting/workflows/Test%20Workflow/badge.svg)](https://github.com/opensearch-project/alerting/actions)
[![codecov](https://codecov.io/gh/opensearch-project/alerting/branch/main/graph/badge.svg)](https://codecov.io/gh/opensearch-project/alerting)
[![Documentation](https://img.shields.io/badge/api-reference-blue.svg)](https://opensearch.org/docs/latest/monitoring-plugins/alerting/api/)
[![Chat](https://img.shields.io/badge/chat-on%20forums-blue)](https://discuss.opendistrocommunity.dev/c/alerting/)
![PRs welcome!](https://img.shields.io/badge/PRs-welcome!-success)

Expand Down
2 changes: 1 addition & 1 deletion alerting/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ String bwcFilePath = "src/test/resources/bwc"
testClusters {
"${baseName}$i" {
testDistribution = "ARCHIVE"
versions = ["7.10.2","1.2.0-SNAPSHOT"]
versions = ["7.10.2","1.3.0-SNAPSHOT"]
numberOfNodes = 3
plugin(provider(new Callable<RegularFile>(){
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,7 @@ abstract class AlertingRestTestCase : ODFERestTestCase() {
return getMonitor(monitorId = monitorId)
}

@Suppress("UNCHECKED_CAST")
protected fun updateMonitor(monitor: Monitor, refresh: Boolean = false): Monitor {
val response = client().makeRequest(
"PUT", "${monitor.relativeUrl()}?refresh=$refresh",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ class MonitorRestApiIT : AlertingRestTestCase() {
}
}

/* Enable this test case after issue issue#269 is fixed.
/* Enable this test case after checking for disallowed destination during Monitor creation is added in
fun `test creating a monitor with a disallowed destination type fails`() {
try {
// Create a Chime Destination
Expand All @@ -263,7 +263,8 @@ class MonitorRestApiIT : AlertingRestTestCase() {
chime = chime,
slack = null,
customWebhook = null,
email = null)
email = null
)
val chimeDestination = createDestination(destination = destination)
// Remove Chime from the allow_list
Expand All @@ -272,12 +273,13 @@ class MonitorRestApiIT : AlertingRestTestCase() {
.joinToString(prefix = "[", postfix = "]") { string -> "\"$string\"" }
client().updateSettings(DestinationSettings.ALLOW_LIST.key, allowedDestinations)
createMonitor(randomMonitor(triggers = listOf(randomTrigger(destinationId = chimeDestination.id))))
createMonitor(randomQueryLevelMonitor(triggers = listOf(randomQueryLevelTrigger(destinationId = chimeDestination.id))))
fail("Expected 403 Method FORBIDDEN response")
} catch (e: ResponseException) {
assertEquals("Unexpected status", RestStatus.FORBIDDEN, e.response.restStatus())
}
}*/
}
*/

@Throws(Exception::class)
fun `test updating search for a monitor`() {
Expand Down Expand Up @@ -866,23 +868,62 @@ class MonitorRestApiIT : AlertingRestTestCase() {
assertEquals("Scheduled job is not enabled", false, responseMap[ScheduledJobSettings.SWEEPER_ENABLED.key])
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>
assertEquals("Incorrect number of nodes", numberOfNodes, _nodes["total"])
assertEquals("Failed nodes found during monitor stats call", 0, _nodes["failed"])
assertEquals("More than $numberOfNodes successful node", numberOfNodes, _nodes["successful"])
validateAlertingStatsNodeResponse(_nodes)
}

fun `test monitor stats when disabling and re-enabling scheduled jobs with existing monitor`() {
// Enable Monitor jobs
enableScheduledJob()
val monitorId = createMonitor(randomQueryLevelMonitor(enabled = true), refresh = true).id

var alertingStats = getAlertingStats()
assertEquals("Scheduled job is not enabled", true, alertingStats[ScheduledJobSettings.SWEEPER_ENABLED.key])
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"])

val _nodes = alertingStats["_nodes"] as Map<String, Int>
validateAlertingStatsNodeResponse(_nodes)

assertTrue(
"Monitor [$monitorId] was not found scheduled based on the alerting stats response: $alertingStats",
isMonitorScheduled(monitorId, alertingStats)
)

// Disable Monitor jobs
disableScheduledJob()

alertingStats = getAlertingStats()
assertEquals("Scheduled job is still enabled", false, alertingStats[ScheduledJobSettings.SWEEPER_ENABLED.key])
assertFalse(
"Monitor [$monitorId] was still scheduled based on the alerting stats response: $alertingStats",
isMonitorScheduled(monitorId, alertingStats)
)

// Re-enable Monitor jobs
enableScheduledJob()

// Sleep briefly so sweep can reschedule the Monitor
Thread.sleep(2000)

alertingStats = getAlertingStats()
assertEquals("Scheduled job is not enabled", true, alertingStats[ScheduledJobSettings.SWEEPER_ENABLED.key])
assertTrue(
"Monitor [$monitorId] was not re-scheduled based on the alerting stats response: $alertingStats",
isMonitorScheduled(monitorId, alertingStats)
)
}

fun `test monitor stats no jobs`() {
// Disable the Monitor plugin.
// Enable the Monitor plugin.
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])
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>
assertEquals("Incorrect number of nodes", numberOfNodes, _nodes["total"])
assertEquals("Failed nodes found during monitor stats call", 0, _nodes["failed"])
assertEquals("More than $numberOfNodes successful node", numberOfNodes, _nodes["successful"])
validateAlertingStatsNodeResponse(_nodes)
}

fun `test monitor stats jobs`() {
Expand All @@ -898,9 +939,7 @@ class MonitorRestApiIT : AlertingRestTestCase() {
assertEquals("Nodes are not on schedule", numberOfNodes, responseMap["nodes_on_schedule"])

val _nodes = responseMap["_nodes"] as Map<String, Int>
assertEquals("Incorrect number of nodes", numberOfNodes, _nodes["total"])
assertEquals("Failed nodes found during monitor stats call", 0, _nodes["failed"])
assertEquals("More than $numberOfNodes successful node", numberOfNodes, _nodes["successful"])
validateAlertingStatsNodeResponse(_nodes)
}

@Throws(Exception::class)
Expand Down Expand Up @@ -929,9 +968,7 @@ class MonitorRestApiIT : AlertingRestTestCase() {
assertEquals("Nodes not on schedule", numberOfNodes, responseMap["nodes_on_schedule"])

val _nodes = responseMap["_nodes"] as Map<String, Int>
assertEquals("Incorrect number of nodes", numberOfNodes, _nodes["total"])
assertEquals("Failed nodes found during monitor stats call", 0, _nodes["failed"])
assertEquals("More than $numberOfNodes successful node", numberOfNodes, _nodes["successful"])
validateAlertingStatsNodeResponse(_nodes)
}

fun `test monitor stats incorrect metric`() {
Expand Down Expand Up @@ -1024,4 +1061,23 @@ class MonitorRestApiIT : AlertingRestTestCase() {
assertEquals("Unexpected status", RestStatus.BAD_REQUEST, e.response.restStatus())
}
}

private fun validateAlertingStatsNodeResponse(nodesResponse: Map<String, Int>) {
assertEquals("Incorrect number of nodes", numberOfNodes, nodesResponse["total"])
assertEquals("Failed nodes found during monitor stats call", 0, nodesResponse["failed"])
assertEquals("More than $numberOfNodes successful node", numberOfNodes, nodesResponse["successful"])
}

private fun isMonitorScheduled(monitorId: String, alertingStatsResponse: Map<String, Any>): Boolean {
val nodesInfo = alertingStatsResponse["nodes"] as Map<String, Any>
for (nodeId in nodesInfo.keys) {
val nodeInfo = nodesInfo[nodeId] as Map<String, Any>
val jobsInfo = nodeInfo["jobs_info"] as Map<String, Any>
if (jobsInfo.keys.contains(monitorId)) {
return true
}
}

return false
}
}
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ buildscript {
apply from: 'build-tools/repositories.gradle'

ext {
opensearch_version = System.getProperty("opensearch.version", "1.2.0-SNAPSHOT")
opensearch_version = System.getProperty("opensearch.version", "1.3.0-SNAPSHOT")
// 1.0.0 -> 1.0.0.0, and 1.0.0-SNAPSHOT -> 1.0.0.0-SNAPSHOT
opensearch_build = opensearch_version.replaceAll(/(\.\d)([^\d]*)$/, '$1.0$2')
common_utils_version = System.getProperty("common_utils.version", opensearch_build)
Expand Down
Loading

0 comments on commit 4c3325e

Please sign in to comment.