Skip to content

Commit

Permalink
remove comments
Browse files Browse the repository at this point in the history
Signed-off-by: Ashish Agrawal <ashisagr@amazon.com>
  • Loading branch information
lezzago committed Apr 18, 2022
1 parent f947a21 commit 1e85df9
Show file tree
Hide file tree
Showing 4 changed files with 2 additions and 121 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,47 +282,6 @@ object BucketLevelMonitorRunner : MonitorRunner() {
return monitorResult.copy(inputResults = firstPageOfInputResults, triggerResults = triggerResults)
}

// override suspend fun runAction(
// action: Action,
// ctx: TriggerExecutionContext,
// monitorCtx: MonitorRunnerExecutionContext,
// dryrun: Boolean
// ): ActionRunResult {
// return try {
// val actionOutput = mutableMapOf<String, String>()
// actionOutput[Action.SUBJECT] = if (action.subjectTemplate != null)
// MonitorRunnerService.compileTemplate(action.subjectTemplate, ctx)
// else ""
// actionOutput[Action.MESSAGE] = MonitorRunnerService.compileTemplate(action.messageTemplate, ctx)
// if (Strings.isNullOrEmpty(actionOutput[Action.MESSAGE])) {
// throw IllegalStateException("Message content missing in the Destination with id: ${action.destinationId}")
// }
// if (!dryrun) {
// withContext(Dispatchers.IO) {
// val destination = AlertingConfigAccessor.getDestinationInfo(
// monitorCtx.client!!,
// monitorCtx.xContentRegistry!!,
// action.destinationId
// )
// if (!destination.isAllowed(monitorCtx.allowList)) {
// throw IllegalStateException("Monitor contains a Destination type that is not allowed: ${destination.type}")
// }
//
// val destinationCtx = monitorCtx.destinationContextFactory!!.getDestinationContext(destination)
// actionOutput[Action.MESSAGE_ID] = destination.publish(
// actionOutput[Action.SUBJECT],
// actionOutput[Action.MESSAGE]!!,
// destinationCtx,
// monitorCtx.hostDenyList
// )
// }
// }
// ActionRunResult(action.id, action.name, actionOutput, false, MonitorRunnerService.currentTime(), null)
// } catch (e: Exception) {
// ActionRunResult(action.id, action.name, mapOf(), false, MonitorRunnerService.currentTime(), e)
// }
// }

private fun defaultToPerExecutionAction(
monitorCtx: MonitorRunnerExecutionContext,
monitorId: String,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@

package org.opensearch.alerting

import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.withContext
import org.apache.logging.log4j.LogManager
import org.opensearch.action.index.IndexRequest
import org.opensearch.action.search.SearchAction
Expand All @@ -17,7 +15,6 @@ import org.opensearch.alerting.alerts.AlertIndices.Companion.FINDING_HISTORY_WRI
import org.opensearch.alerting.core.model.DocLevelMonitorInput
import org.opensearch.alerting.core.model.DocLevelQuery
import org.opensearch.alerting.core.model.ScheduledJob
import org.opensearch.alerting.model.ActionRunResult
import org.opensearch.alerting.model.Alert
import org.opensearch.alerting.model.DocumentExecutionContext
import org.opensearch.alerting.model.DocumentLevelTrigger
Expand All @@ -26,16 +23,12 @@ import org.opensearch.alerting.model.Finding
import org.opensearch.alerting.model.InputRunResults
import org.opensearch.alerting.model.Monitor
import org.opensearch.alerting.model.MonitorRunResult
import org.opensearch.alerting.model.action.Action
import org.opensearch.alerting.opensearchapi.string
import org.opensearch.alerting.script.DocumentLevelTriggerExecutionContext
import org.opensearch.alerting.script.TriggerExecutionContext
import org.opensearch.alerting.util.AlertingException
import org.opensearch.alerting.util.updateMonitor
import org.opensearch.client.Client
import org.opensearch.cluster.routing.ShardRouting
import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.Strings
import org.opensearch.common.bytes.BytesReference
import org.opensearch.common.xcontent.ToXContent
import org.opensearch.common.xcontent.XContentBuilder
Expand All @@ -50,7 +43,7 @@ import org.opensearch.search.builder.SearchSourceBuilder
import org.opensearch.search.sort.SortOrder
import java.io.IOException
import java.time.Instant
import java.util.UUID
import java.util.*
import kotlin.collections.HashMap
import kotlin.math.max

Expand Down Expand Up @@ -280,42 +273,6 @@ object DocumentReturningMonitorRunner : MonitorRunner() {
return finding.id
}

// TODO: Implement action for triggers
override suspend fun runAction(
action: Action,
ctx: TriggerExecutionContext,
monitorCtx: MonitorRunnerExecutionContext,
dryrun: Boolean
): ActionRunResult {
return try {
if (!MonitorRunnerService.isActionActionable(action, (ctx as DocumentLevelTriggerExecutionContext).alert)) {
return ActionRunResult(action.id, action.name, mapOf(), true, null, null)
}
val actionOutput = mutableMapOf<String, String>()
actionOutput[Action.SUBJECT] = if (action.subjectTemplate != null)
MonitorRunnerService.compileTemplate(action.subjectTemplate, ctx)
else ""
actionOutput[Action.MESSAGE] = MonitorRunnerService.compileTemplate(action.messageTemplate, ctx)
if (Strings.isNullOrEmpty(actionOutput[Action.MESSAGE])) {
throw IllegalStateException("Message content missing in the Destination with id: ${action.destinationId}")
}
if (!dryrun) {
withContext(Dispatchers.IO) {
actionOutput[Action.MESSAGE_ID] = getConfigAndSendNotification(
action,
monitorCtx,
actionOutput[Action.SUBJECT],
actionOutput[Action.MESSAGE]!!
)
}
}
ActionRunResult(action.id, action.name, actionOutput, false, MonitorRunnerService.currentTime(), null)
} catch (e: Exception) {
logger.debug("Failed to run action", AlertingException.wrap(e))
ActionRunResult(action.id, action.name, mapOf(), false, MonitorRunnerService.currentTime(), e)
}
}

private fun validate(monitor: Monitor) {
if (monitor.inputs.size > 1) {
throw IOException("Only one input is supported with document-level-monitor.")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ abstract class MonitorRunner {
dryRun: Boolean
): MonitorRunResult<*>

open suspend fun runAction(
suspend fun runAction(
action: Action,
ctx: TriggerExecutionContext,
monitorCtx: MonitorRunnerExecutionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,39 +85,4 @@ object QueryLevelMonitorRunner : MonitorRunner() {
}
return monitorResult.copy(triggerResults = triggerResults)
}
//
// override suspend fun runAction(
// action: Action,
// ctx: TriggerExecutionContext,
// monitorCtx: MonitorRunnerExecutionContext,
// dryrun: Boolean
// ): ActionRunResult {
// return try {
// if (!MonitorRunnerService.isActionActionable(action, (ctx as QueryLevelTriggerExecutionContext).alert)) {
// return ActionRunResult(action.id, action.name, mapOf(), true, null, null)
// }
// val actionOutput = mutableMapOf<String, String>()
// actionOutput[Action.SUBJECT] = if (action.subjectTemplate != null)
// MonitorRunnerService.compileTemplate(action.subjectTemplate, ctx)
// else ""
// actionOutput[Action.MESSAGE] = MonitorRunnerService.compileTemplate(action.messageTemplate, ctx)
// if (Strings.isNullOrEmpty(actionOutput[Action.MESSAGE])) {
// throw IllegalStateException("Message content missing in the Destination with id: ${action.destinationId}")
// }
// if (!dryrun) {
// // TODO: Inject user here so only Destination/Notifications that the user has permissions to are retrieved
// withContext(Dispatchers.IO) {
// actionOutput[Action.MESSAGE_ID] = getConfigAndSendNotification(
// action,
// monitorCtx,
// actionOutput[Action.SUBJECT],
// actionOutput[Action.MESSAGE]!!
// )
// }
// }
// ActionRunResult(action.id, action.name, actionOutput, false, MonitorRunnerService.currentTime(), null)
// } catch (e: Exception) {
// ActionRunResult(action.id, action.name, mapOf(), false, MonitorRunnerService.currentTime(), e)
// }
// }
}

0 comments on commit 1e85df9

Please sign in to comment.