From 28ba8e638f418cace9123972427f7291f93bfa1a Mon Sep 17 00:00:00 2001 From: Saurabh Singh Date: Fri, 25 Mar 2022 09:46:33 -0700 Subject: [PATCH] Fix few ktlint failures. Signed-off-by: Saurabh Singh --- .../alerting/BucketLevelMonitorRunner.kt | 88 +++++++------- .../DocumentReturningMonitorRunner.kt | 114 +++++++++--------- .../org/opensearch/alerting/MonitorRunner.kt | 7 +- .../alerting/MonitorRunnerExecutionContext.kt | 37 +++--- .../alerting/MonitorRunnerService.kt | 3 +- .../alerting/QueryLevelMonitorRunner.kt | 18 +-- .../TransportExecuteMonitorAction.kt | 11 +- 7 files changed, 137 insertions(+), 141 deletions(-) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt index 6e4ba02b6..19d59cb72 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/BucketLevelMonitorRunner.kt @@ -5,16 +5,16 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.apache.logging.log4j.LogManager import org.opensearch.alerting.elasticapi.InjectorContextElement -import org.opensearch.alerting.model.InputRunResults -import org.opensearch.alerting.model.BucketLevelTrigger +import org.opensearch.alerting.model.ActionRunResult import org.opensearch.alerting.model.Alert import org.opensearch.alerting.model.AlertingConfigAccessor -import org.opensearch.alerting.model.ActionRunResult +import org.opensearch.alerting.model.BucketLevelTrigger import org.opensearch.alerting.model.BucketLevelTriggerRunResult +import org.opensearch.alerting.model.InputRunResults import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.model.MonitorRunResult -import org.opensearch.alerting.model.action.ActionExecutionScope import org.opensearch.alerting.model.action.Action +import org.opensearch.alerting.model.action.ActionExecutionScope import org.opensearch.alerting.model.action.AlertCategory import org.opensearch.alerting.model.action.PerAlertActionScope import org.opensearch.alerting.model.action.PerExecutionActionScope @@ -27,11 +27,11 @@ import org.opensearch.alerting.util.isAllowed import org.opensearch.common.Strings import java.time.Instant -object BucketLevelMonitorRunner: MonitorRunner { +object BucketLevelMonitorRunner : MonitorRunner { private val logger = LogManager.getLogger(javaClass) override suspend fun runMonitor(monitor: Monitor, monitorCtx: MonitorRunnerExecutionContext, periodStart: Instant, periodEnd: Instant, dryrun: Boolean): - MonitorRunResult { + MonitorRunResult { val roles = MonitorRunnerService.getRolesForMonitor(monitor) logger.debug("Running monitor: ${monitor.name} with roles: $roles Thread: ${Thread.currentThread().name}") @@ -112,7 +112,7 @@ object BucketLevelMonitorRunner: MonitorRunner { // TODO: Should triggerResult's aggregationResultBucket be a list? If not, getCategorizedAlertsForBucketLevelMonitor can // be refactored to use a map instead val categorizedAlerts = monitorCtx.alertService!!.getCategorizedAlertsForBucketLevelMonitor( - monitor, trigger, currentAlertsForTrigger, triggerResult.aggregationResultBuckets.values.toList() + monitor, trigger, currentAlertsForTrigger, triggerResult.aggregationResultBuckets.values.toList() ).toMutableMap() val dedupedAlerts = categorizedAlerts.getOrDefault(AlertCategory.DEDUPED, emptyList()) var newAlerts = categorizedAlerts.getOrDefault(AlertCategory.NEW, emptyList()) @@ -134,9 +134,9 @@ object BucketLevelMonitorRunner: MonitorRunner { // Store deduped and new Alerts to accumulate across pages if (!nextAlerts.containsKey(trigger.id)) { nextAlerts[trigger.id] = mutableMapOf( - AlertCategory.DEDUPED to mutableListOf(), - AlertCategory.NEW to mutableListOf(), - AlertCategory.COMPLETED to mutableListOf() + AlertCategory.DEDUPED to mutableListOf(), + AlertCategory.NEW to mutableListOf(), + AlertCategory.COMPLETED to mutableListOf() ) } nextAlerts[trigger.id]?.get(AlertCategory.DEDUPED)?.addAll(dedupedAlerts) @@ -158,8 +158,8 @@ object BucketLevelMonitorRunner: MonitorRunner { // Filter ACKNOWLEDGED Alerts from the deduped list so they do not have Actions executed for them. // New Alerts are ignored since they cannot be acknowledged yet. val dedupedAlerts = nextAlerts[trigger.id]?.get(AlertCategory.DEDUPED) - ?.filterNot { it.state == Alert.State.ACKNOWLEDGED }?.toMutableList() - ?: mutableListOf() + ?.filterNot { it.state == Alert.State.ACKNOWLEDGED }?.toMutableList() + ?: mutableListOf() // Update nextAlerts so the filtered DEDUPED Alerts are reflected for PER_ALERT Action execution nextAlerts[trigger.id]?.set(AlertCategory.DEDUPED, dedupedAlerts) val newAlerts = nextAlerts[trigger.id]?.get(AlertCategory.NEW) ?: mutableListOf() @@ -174,11 +174,11 @@ object BucketLevelMonitorRunner: MonitorRunner { val triggerResult = triggerResults[trigger.id]!! val monitorOrTriggerError = monitorResult.error ?: triggerResult.error val shouldDefaultToPerExecution = defaultToPerExecutionAction( - monitorCtx, - monitorId = monitor.id, - triggerId = trigger.id, - totalActionableAlertCount = dedupedAlerts.size + newAlerts.size + completedAlerts.size, - monitorOrTriggerError = monitorOrTriggerError + monitorCtx, + monitorId = monitor.id, + triggerId = trigger.id, + totalActionableAlertCount = dedupedAlerts.size + newAlerts.size + completedAlerts.size, + monitorOrTriggerError = monitorOrTriggerError ) for (action in trigger.actions) { // ActionExecutionPolicy should not be null for Bucket-Level Monitors since it has a default config when not set explicitly @@ -188,7 +188,7 @@ object BucketLevelMonitorRunner: MonitorRunner { val alertsToExecuteActionsFor = nextAlerts[trigger.id]?.get(alertCategory) ?: mutableListOf() for (alert in alertsToExecuteActionsFor) { val actionCtx = getActionContextForAlertCategory( - alertCategory, alert, triggerCtx, monitorOrTriggerError + alertCategory, alert, triggerCtx, monitorOrTriggerError ) // AggregationResultBucket should not be null here val alertBucketKeysHash = alert.aggregationResultBucket!!.getBucketKeysHash() @@ -218,10 +218,10 @@ object BucketLevelMonitorRunner: MonitorRunner { continue val actionCtx = triggerCtx.copy( - dedupedAlerts = dedupedAlerts, - newAlerts = newAlerts, - completedAlerts = completedAlerts, - error = monitorResult.error ?: triggerResult.error + dedupedAlerts = dedupedAlerts, + newAlerts = newAlerts, + completedAlerts = completedAlerts, + error = monitorResult.error ?: triggerResult.error ) val actionResult = this.runAction(action, actionCtx, monitorCtx, dryrun) // If there was an error during trigger execution then the Alerts to be updated are the current Alerts since the state @@ -250,10 +250,10 @@ object BucketLevelMonitorRunner: MonitorRunner { val bucketKeysHash = alert.aggregationResultBucket!!.getBucketKeysHash() val actionResults = triggerResult.actionResultsMap.getOrDefault(bucketKeysHash, emptyMap()) monitorCtx.alertService!!.updateActionResultsForBucketLevelAlert( - alert.copy(lastNotificationTime = MonitorRunnerService.currentTime()), - actionResults, - // TODO: Update BucketLevelTriggerRunResult.alertError() to retrieve error based on the first failed Action - monitorResult.alertError() ?: triggerResult.alertError() + alert.copy(lastNotificationTime = MonitorRunnerService.currentTime()), + actionResults, + // TODO: Update BucketLevelTriggerRunResult.alertError() to retrieve error based on the first failed Action + monitorResult.alertError() ?: triggerResult.alertError() ) } @@ -286,10 +286,10 @@ object BucketLevelMonitorRunner: MonitorRunner { val destinationCtx = monitorCtx.destinationContextFactory!!.getDestinationContext(destination) actionOutput[Action.MESSAGE_ID] = destination.publish( - actionOutput[Action.SUBJECT], - actionOutput[Action.MESSAGE]!!, - destinationCtx, - monitorCtx.hostDenyList + actionOutput[Action.SUBJECT], + actionOutput[Action.MESSAGE]!!, + destinationCtx, + monitorCtx.hostDenyList ) } } @@ -300,17 +300,17 @@ object BucketLevelMonitorRunner: MonitorRunner { } private fun defaultToPerExecutionAction( - monitorCtx: MonitorRunnerExecutionContext, - monitorId: String, - triggerId: String, - totalActionableAlertCount: Int, - monitorOrTriggerError: Exception? + monitorCtx: MonitorRunnerExecutionContext, + monitorId: String, + triggerId: String, + totalActionableAlertCount: Int, + monitorOrTriggerError: Exception? ): Boolean { // If the monitorId or triggerResult has an error, then also default to PER_EXECUTION to communicate the error if (monitorOrTriggerError != null) { logger.debug( - "Trigger [$triggerId] in monitor [$monitorId] encountered an error. Defaulting to " + - "[${ActionExecutionScope.Type.PER_EXECUTION}] for action execution to communicate error." + "Trigger [$triggerId] in monitor [$monitorId] encountered an error. Defaulting to " + + "[${ActionExecutionScope.Type.PER_EXECUTION}] for action execution to communicate error." ) return true } @@ -322,9 +322,9 @@ object BucketLevelMonitorRunner: MonitorRunner { // PER_EXECUTION for less intrusive Actions if (totalActionableAlertCount > monitorCtx.maxActionableAlertCount) { logger.debug( - "The total actionable alerts for trigger [$triggerId] in monitor [$monitorId] is [$totalActionableAlertCount] " + - "which exceeds the maximum of [$(monitorCtx.maxActionableAlertCount)]. Defaulting to [${ActionExecutionScope.Type.PER_EXECUTION}] " + - "for action execution." + "The total actionable alerts for trigger [$triggerId] in monitor [$monitorId] is [$totalActionableAlertCount] " + + "which exceeds the maximum of [$(monitorCtx.maxActionableAlertCount)]. Defaulting to [${ActionExecutionScope.Type.PER_EXECUTION}] " + + "for action execution." ) return true } @@ -333,10 +333,10 @@ object BucketLevelMonitorRunner: MonitorRunner { } private fun getActionContextForAlertCategory( - alertCategory: AlertCategory, - alert: Alert, - ctx: BucketLevelTriggerExecutionContext, - error: Exception? + alertCategory: AlertCategory, + alert: Alert, + ctx: BucketLevelTriggerExecutionContext, + error: Exception? ): BucketLevelTriggerExecutionContext { return when (alertCategory) { AlertCategory.DEDUPED -> diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentReturningMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentReturningMonitorRunner.kt index 40ec26244..989b7ae79 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/DocumentReturningMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/DocumentReturningMonitorRunner.kt @@ -7,8 +7,8 @@ import org.opensearch.action.search.SearchResponse import org.opensearch.action.support.WriteRequest import org.opensearch.alerting.elasticapi.string import org.opensearch.alerting.model.ActionRunResult -import org.opensearch.alerting.model.DocumentLevelTrigger import org.opensearch.alerting.model.DocumentExecutionContext +import org.opensearch.alerting.model.DocumentLevelTrigger import org.opensearch.alerting.model.DocumentLevelTriggerRunResult import org.opensearch.alerting.model.Finding import org.opensearch.alerting.model.Monitor @@ -34,11 +34,11 @@ import java.time.Instant import java.util.UUID import kotlin.collections.HashMap -object DocumentReturningMonitorRunner: MonitorRunner { +object DocumentReturningMonitorRunner : MonitorRunner { private val logger = LogManager.getLogger(javaClass) override suspend fun runMonitor(monitor: Monitor, monitorCtx: MonitorRunnerExecutionContext, periodStart: Instant, periodEnd: Instant, dryrun: Boolean): - MonitorRunResult { + MonitorRunResult { logger.info("Document-level-monitor is running ...") val monitorResult = MonitorRunResult(monitor.name, periodStart, periodEnd) try { @@ -105,13 +105,13 @@ object DocumentReturningMonitorRunner: MonitorRunner { } private fun runForEachDocTrigger( - monitorCtx: MonitorRunnerExecutionContext, - trigger: DocumentLevelTrigger, - monitor: Monitor, - docsToQueries: Map>, - queryIds: List, - queryToDocIds: Map>, - dryrun: Boolean + monitorCtx: MonitorRunnerExecutionContext, + trigger: DocumentLevelTrigger, + monitor: Monitor, + docsToQueries: Map>, + queryIds: List, + queryToDocIds: Map>, + dryrun: Boolean ) { val triggerCtx = DocumentLevelTriggerExecutionContext(monitor, trigger) val triggerResult = monitorCtx.triggerService!!.runDocLevelTrigger(monitor, trigger, triggerCtx, docsToQueries, queryIds) @@ -133,25 +133,25 @@ object DocumentReturningMonitorRunner: MonitorRunner { } fun createFindings( - monitor: Monitor, - monitorCtx: MonitorRunnerExecutionContext, - index: String, - docLevelQuery: DocLevelQuery, - matchingDocIds: Set, - trigger: DocumentLevelTrigger + monitor: Monitor, + monitorCtx: MonitorRunnerExecutionContext, + index: String, + docLevelQuery: DocLevelQuery, + matchingDocIds: Set, + trigger: DocumentLevelTrigger ): String { val finding = Finding( - id = UUID.randomUUID().toString(), - relatedDocId = matchingDocIds.joinToString(","), - monitorId = monitor.id, - monitorName = monitor.name, - index = index, - queryId = docLevelQuery.id, - queryTags = docLevelQuery.tags, - severity = docLevelQuery.severity, - timestamp = Instant.now(), - triggerId = trigger.id, - triggerName = trigger.name + id = UUID.randomUUID().toString(), + relatedDocId = matchingDocIds.joinToString(","), + monitorId = monitor.id, + monitorName = monitor.name, + index = index, + queryId = docLevelQuery.id, + queryTags = docLevelQuery.tags, + severity = docLevelQuery.severity, + timestamp = Instant.now(), + triggerId = trigger.id, + triggerName = trigger.name ) val findingStr = finding.toXContent(XContentBuilder.builder(XContentType.JSON.xContent()), ToXContent.EMPTY_PARAMS).string() @@ -160,8 +160,8 @@ object DocumentReturningMonitorRunner: MonitorRunner { // todo: below is all hardcoded, temp code and added only to test. replace this with proper Findings index lifecycle management. val indexRequest = IndexRequest(".opensearch-alerting-findings") - .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) - .source(findingStr, XContentType.JSON) + .setRefreshPolicy(WriteRequest.RefreshPolicy.IMMEDIATE) + .source(findingStr, XContentType.JSON) monitorCtx.client!!.index(indexRequest).actionGet() return finding.id @@ -207,16 +207,16 @@ object DocumentReturningMonitorRunner: MonitorRunner { */ private fun getMaxSeqNo(monitorCtx: MonitorRunnerExecutionContext, index: String, shard: String): Long { val request: SearchRequest = SearchRequest() - .indices(index) - .preference("_shards:$shard") - .source( - SearchSourceBuilder() - .version(true) - .sort("_seq_no", SortOrder.DESC) - .seqNoAndPrimaryTerm(true) - .query(QueryBuilders.matchAllQuery()) - .size(1) - ) + .indices(index) + .preference("_shards:$shard") + .source( + SearchSourceBuilder() + .version(true) + .sort("_seq_no", SortOrder.DESC) + .seqNoAndPrimaryTerm(true) + .query(QueryBuilders.matchAllQuery()) + .size(1) + ) val response: SearchResponse = monitorCtx.client!!.search(request).actionGet() if (response.status() !== RestStatus.OK) { throw IOException("Failed to get max seq no for shard: $shard") @@ -233,10 +233,10 @@ object DocumentReturningMonitorRunner: MonitorRunner { } private fun runForEachQuery( - monitorCtx: MonitorRunnerExecutionContext, - docExecutionCtx: DocumentExecutionContext, - query: DocLevelQuery, - index: String + monitorCtx: MonitorRunnerExecutionContext, + docExecutionCtx: DocumentExecutionContext, + query: DocLevelQuery, + index: String ): Set { val count: Int = docExecutionCtx.lastRunContext["shards_count"] as Int val matchingDocs = mutableSetOf() @@ -249,12 +249,12 @@ object DocumentReturningMonitorRunner: MonitorRunner { logger.info("MaxSeqNo of shard_$shard is $maxSeqNo") val hits: SearchHits = searchShard( - monitorCtx, - index, - shard, - docExecutionCtx.lastRunContext[shard].toString().toLongOrNull(), - maxSeqNo, - query.query + monitorCtx, + index, + shard, + docExecutionCtx.lastRunContext[shard].toString().toLongOrNull(), + maxSeqNo, + query.query ) logger.info("Search hits for shard_$shard is: ${hits.hits.size}") @@ -279,14 +279,14 @@ object DocumentReturningMonitorRunner: MonitorRunner { boolQueryBuilder.must(QueryBuilders.queryStringQuery(query)) val request: SearchRequest = SearchRequest() - .indices(index) - .preference("_shards:$shard") - .source( - SearchSourceBuilder() - .version(true) - .query(boolQueryBuilder) - .size(10000) // fixme: make this configurable. - ) + .indices(index) + .preference("_shards:$shard") + .source( + SearchSourceBuilder() + .version(true) + .query(boolQueryBuilder) + .size(10000) // fixme: make this configurable. + ) logger.info("Request: $request") val response: SearchResponse = monitorCtx.client!!.search(request).actionGet() if (response.status() !== RestStatus.OK) { diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunner.kt index a8b0395b7..9f1543718 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunner.kt @@ -3,14 +3,13 @@ package org.opensearch.alerting import org.opensearch.alerting.model.ActionRunResult import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.model.MonitorRunResult -import org.opensearch.alerting.model.Trigger +import org.opensearch.alerting.model.action.Action import org.opensearch.alerting.script.TriggerExecutionContext import java.time.Instant -import org.opensearch.alerting.model.action.Action interface MonitorRunner { - suspend fun runMonitor(monitor: Monitor, monitorCtx: MonitorRunnerExecutionContext, periodStart: Instant, periodEnd: Instant, dryRun: Boolean) : MonitorRunResult<*>; + suspend fun runMonitor(monitor: Monitor, monitorCtx: MonitorRunnerExecutionContext, periodStart: Instant, periodEnd: Instant, dryRun: Boolean): MonitorRunResult<*> - suspend fun runAction(action: Action, ctx: TriggerExecutionContext, monitorCtx: MonitorRunnerExecutionContext, dryRun: Boolean): ActionRunResult; + suspend fun runAction(action: Action, ctx: TriggerExecutionContext, monitorCtx: MonitorRunnerExecutionContext, dryRun: Boolean): ActionRunResult } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt index 323501205..354dadca3 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerExecutionContext.kt @@ -15,26 +15,25 @@ import org.opensearch.threadpool.ThreadPool data class MonitorRunnerExecutionContext( - var clusterService: ClusterService? = null, - var client: Client? = null, - var xContentRegistry: NamedXContentRegistry? = null, - var scriptService: ScriptService? = null, - var settings: Settings? = null, - var threadPool: ThreadPool? = null, - var alertIndices: AlertIndices? = null, - var inputService: InputService? = null, - var triggerService: TriggerService? = null, - var alertService: AlertService? = null, + var clusterService: ClusterService? = null, + var client: Client? = null, + var xContentRegistry: NamedXContentRegistry? = null, + var scriptService: ScriptService? = null, + var settings: Settings? = null, + var threadPool: ThreadPool? = null, + var alertIndices: AlertIndices? = null, + var inputService: InputService? = null, + var triggerService: TriggerService? = null, + var alertService: AlertService? = null, - @Volatile var retryPolicy: BackoffPolicy? = null, - @Volatile var moveAlertsRetryPolicy: BackoffPolicy? = null, + @Volatile var retryPolicy: BackoffPolicy? = null, + @Volatile var moveAlertsRetryPolicy: BackoffPolicy? = null, - @Volatile var allowList: List = DestinationSettings.ALLOW_LIST_NONE, - @Volatile var hostDenyList: List = LegacyOpenDistroDestinationSettings.HOST_DENY_LIST_NONE, + @Volatile var allowList: List = DestinationSettings.ALLOW_LIST_NONE, + @Volatile var hostDenyList: List = LegacyOpenDistroDestinationSettings.HOST_DENY_LIST_NONE, - @Volatile var destinationSettings: Map? = null, - @Volatile var destinationContextFactory: DestinationContextFactory? = null, + @Volatile var destinationSettings: Map? = null, + @Volatile var destinationContextFactory: DestinationContextFactory? = null, - @Volatile var maxActionableAlertCount: Long = AlertingSettings.DEFAULT_MAX_ACTIONABLE_ALERT_COUNT -) { -} + @Volatile var maxActionableAlertCount: Long = AlertingSettings.DEFAULT_MAX_ACTIONABLE_ALERT_COUNT +) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt index dc1014df6..4b6f1a896 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt @@ -209,10 +209,9 @@ object MonitorRunnerService : JobRunner, CoroutineScope, AbstractLifecycleCompon } else { QueryLevelMonitorRunner.runMonitor(monitor, monitorCtx, periodStart, periodEnd, dryrun) } - } - //TODO: See if we can move below methods (or few of these) to a common utils + // TODO: See if we can move below methods (or few of these) to a common utils internal fun getRolesForMonitor(monitor: Monitor): List { /* * We need to handle 3 cases: diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/QueryLevelMonitorRunner.kt b/alerting/src/main/kotlin/org/opensearch/alerting/QueryLevelMonitorRunner.kt index 1e26d04e6..98ae74cde 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/QueryLevelMonitorRunner.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/QueryLevelMonitorRunner.kt @@ -5,12 +5,12 @@ import kotlinx.coroutines.runBlocking import kotlinx.coroutines.withContext import org.apache.logging.log4j.LogManager import org.opensearch.alerting.elasticapi.InjectorContextElement -import org.opensearch.alerting.model.QueryLevelTrigger -import org.opensearch.alerting.model.AlertingConfigAccessor import org.opensearch.alerting.model.ActionRunResult import org.opensearch.alerting.model.Alert +import org.opensearch.alerting.model.AlertingConfigAccessor import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.model.MonitorRunResult +import org.opensearch.alerting.model.QueryLevelTrigger import org.opensearch.alerting.model.QueryLevelTriggerRunResult import org.opensearch.alerting.model.action.Action import org.opensearch.alerting.script.QueryLevelTriggerExecutionContext @@ -24,7 +24,7 @@ object QueryLevelMonitorRunner : MonitorRunner { private val logger = LogManager.getLogger(javaClass) override suspend fun runMonitor(monitor: Monitor, monitorCtx: MonitorRunnerExecutionContext, periodStart: Instant, periodEnd: Instant, dryrun: Boolean): - MonitorRunResult { + MonitorRunResult { val roles = MonitorRunnerService.getRolesForMonitor(monitor) logger.debug("Running monitor: ${monitor.name} with roles: $roles Thread: ${Thread.currentThread().name}") @@ -67,8 +67,8 @@ object QueryLevelMonitorRunner : MonitorRunner { } val updatedAlert = monitorCtx.alertService!!.composeQueryLevelAlert( - triggerCtx, triggerResult, - monitorResult.alertError() ?: triggerResult.alertError() + triggerCtx, triggerResult, + monitorResult.alertError() ?: triggerResult.alertError() ) if (updatedAlert != null) updatedAlerts += updatedAlert } @@ -100,10 +100,10 @@ object QueryLevelMonitorRunner : MonitorRunner { val destinationCtx = monitorCtx.destinationContextFactory!!.getDestinationContext(destination) actionOutput[Action.MESSAGE_ID] = destination.publish( - actionOutput[Action.SUBJECT], - actionOutput[Action.MESSAGE]!!, - destinationCtx, - monitorCtx.hostDenyList + actionOutput[Action.SUBJECT], + actionOutput[Action.MESSAGE]!!, + destinationCtx, + monitorCtx.hostDenyList ) } } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteMonitorAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteMonitorAction.kt index 7fc20b038..8813418fa 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteMonitorAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteMonitorAction.kt @@ -22,7 +22,6 @@ import org.opensearch.alerting.action.ExecuteMonitorResponse import org.opensearch.alerting.core.model.ScheduledJob import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.util.AlertingException -import org.opensearch.alerting.util.isBucketLevelMonitor import org.opensearch.client.Client import org.opensearch.common.inject.Inject import org.opensearch.common.xcontent.LoggingDeprecationHandler @@ -39,11 +38,11 @@ import java.time.Instant private val log = LogManager.getLogger(TransportGetMonitorAction::class.java) class TransportExecuteMonitorAction @Inject constructor( - transportService: TransportService, - private val client: Client, - private val runner: MonitorRunnerService, - actionFilters: ActionFilters, - val xContentRegistry: NamedXContentRegistry + transportService: TransportService, + private val client: Client, + private val runner: MonitorRunnerService, + actionFilters: ActionFilters, + val xContentRegistry: NamedXContentRegistry ) : HandledTransportAction ( ExecuteMonitorAction.NAME, transportService, actionFilters, ::ExecuteMonitorRequest ) {