diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/AlertService.kt b/alerting/src/main/kotlin/org/opensearch/alerting/AlertService.kt index 71b41494e..6b1e848e9 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/AlertService.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/AlertService.kt @@ -97,9 +97,11 @@ class AlertService( return monitor.triggers.associateWith { trigger -> // Default to an empty map if there are no Alerts found for a Trigger to make Alert categorization logic easier - (foundAlerts[trigger.id]?.mapNotNull { alert -> - alert.aggregationResultBucket?.let { it.getBucketKeysHash() to alert } - }?.toMap() ?: mutableMapOf()) as MutableMap + ( + foundAlerts[trigger.id]?.mapNotNull { alert -> + alert.aggregationResultBucket?.let { it.getBucketKeysHash() to alert } + }?.toMap() ?: mutableMapOf() + ) as MutableMap } } @@ -122,38 +124,52 @@ class AlertService( when { actionRunResult == null -> updatedActionExecutionResults.add(actionExecutionResult) actionRunResult.throttled -> - updatedActionExecutionResults.add(actionExecutionResult.copy( - throttledCount = actionExecutionResult.throttledCount + 1)) + updatedActionExecutionResults.add( + actionExecutionResult.copy( + throttledCount = actionExecutionResult.throttledCount + 1 + ) + ) else -> updatedActionExecutionResults.add(actionExecutionResult.copy(lastExecutionTime = actionRunResult.executionTime)) } } // add action execution results which not exist in current alert - updatedActionExecutionResults.addAll(result.actionResults.filter { !currentActionIds.contains(it.key) } - .map { ActionExecutionResult(it.key, it.value.executionTime, if (it.value.throttled) 1 else 0) }) + updatedActionExecutionResults.addAll( + result.actionResults.filter { !currentActionIds.contains(it.key) } + .map { ActionExecutionResult(it.key, it.value.executionTime, if (it.value.throttled) 1 else 0) } + ) } else { - updatedActionExecutionResults.addAll(result.actionResults.map { - ActionExecutionResult(it.key, it.value.executionTime, if (it.value.throttled) 1 else 0) }) + updatedActionExecutionResults.addAll( + result.actionResults.map { + ActionExecutionResult(it.key, it.value.executionTime, if (it.value.throttled) 1 else 0) + } + ) } // Merge the alert's error message to the current alert's history val updatedHistory = currentAlert?.errorHistory.update(alertError) return if (alertError == null && !result.triggered) { - currentAlert?.copy(state = Alert.State.COMPLETED, endTime = currentTime, errorMessage = null, + currentAlert?.copy( + state = Alert.State.COMPLETED, endTime = currentTime, errorMessage = null, errorHistory = updatedHistory, actionExecutionResults = updatedActionExecutionResults, - schemaVersion = IndexUtils.alertIndexSchemaVersion) + schemaVersion = IndexUtils.alertIndexSchemaVersion + ) } else if (alertError == null && currentAlert?.isAcknowledged() == true) { null } else if (currentAlert != null) { val alertState = if (alertError == null) Alert.State.ACTIVE else Alert.State.ERROR - currentAlert.copy(state = alertState, lastNotificationTime = currentTime, errorMessage = alertError?.message, + currentAlert.copy( + state = alertState, lastNotificationTime = currentTime, errorMessage = alertError?.message, errorHistory = updatedHistory, actionExecutionResults = updatedActionExecutionResults, - schemaVersion = IndexUtils.alertIndexSchemaVersion) + schemaVersion = IndexUtils.alertIndexSchemaVersion + ) } else { val alertState = if (alertError == null) Alert.State.ACTIVE else Alert.State.ERROR - Alert(monitor = ctx.monitor, trigger = ctx.trigger, startTime = currentTime, + Alert( + monitor = ctx.monitor, trigger = ctx.trigger, startTime = currentTime, lastNotificationTime = currentTime, state = alertState, errorMessage = alertError?.message, errorHistory = updatedHistory, actionExecutionResults = updatedActionExecutionResults, - schemaVersion = IndexUtils.alertIndexSchemaVersion) + schemaVersion = IndexUtils.alertIndexSchemaVersion + ) } } @@ -172,8 +188,11 @@ class AlertService( when { actionRunResult == null -> updatedActionExecutionResults.add(actionExecutionResult) actionRunResult.throttled -> - updatedActionExecutionResults.add(actionExecutionResult.copy( - throttledCount = actionExecutionResult.throttledCount + 1)) + updatedActionExecutionResults.add( + actionExecutionResult.copy( + throttledCount = actionExecutionResult.throttledCount + 1 + ) + ) else -> updatedActionExecutionResults.add(actionExecutionResult.copy(lastExecutionTime = actionRunResult.executionTime)) } } @@ -221,10 +240,12 @@ class AlertService( } else { // New Alert // TODO: Setting lastNotificationTime is deceiving since the actions haven't run yet, maybe it should be null here - val newAlert = Alert(monitor = monitor, trigger = trigger, startTime = currentTime, + val newAlert = Alert( + monitor = monitor, trigger = trigger, startTime = currentTime, lastNotificationTime = currentTime, state = Alert.State.ACTIVE, errorMessage = null, errorHistory = mutableListOf(), actionExecutionResults = mutableListOf(), - schemaVersion = IndexUtils.alertIndexSchemaVersion, aggregationResultBucket = aggAlertBucket) + schemaVersion = IndexUtils.alertIndexSchemaVersion, aggregationResultBucket = aggAlertBucket + ) newAlerts.add(newAlert) } } @@ -238,8 +259,10 @@ class AlertService( fun convertToCompletedAlerts(currentAlerts: Map?): List { val currentTime = Instant.now() return currentAlerts?.map { - it.value.copy(state = Alert.State.COMPLETED, endTime = currentTime, errorMessage = null, - schemaVersion = IndexUtils.alertIndexSchemaVersion) + it.value.copy( + state = Alert.State.COMPLETED, endTime = currentTime, errorMessage = null, + schemaVersion = IndexUtils.alertIndexSchemaVersion + ) } ?: listOf() } @@ -251,10 +274,12 @@ class AlertService( // spend time reloading the alert and writing it back. when (alert.state) { Alert.State.ACTIVE, Alert.State.ERROR -> { - listOf>(IndexRequest(AlertIndices.ALERT_INDEX) - .routing(alert.monitorId) - .source(alert.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) - .id(if (alert.id != Alert.NO_ID) alert.id else null)) + listOf>( + IndexRequest(AlertIndices.ALERT_INDEX) + .routing(alert.monitorId) + .source(alert.toXContent(XContentFactory.jsonBuilder(), ToXContent.EMPTY_PARAMS)) + .id(if (alert.id != Alert.NO_ID) alert.id else null) + ) } Alert.State.ACKNOWLEDGED, Alert.State.DELETED -> { throw IllegalStateException("Unexpected attempt to save ${alert.state} alert: $alert") @@ -354,8 +379,10 @@ class AlertService( } private fun contentParser(bytesReference: BytesReference): XContentParser { - val xcp = XContentHelper.createParser(xContentRegistry, LoggingDeprecationHandler.INSTANCE, - bytesReference, XContentType.JSON) + val xcp = XContentHelper.createParser( + xContentRegistry, LoggingDeprecationHandler.INSTANCE, + bytesReference, XContentType.JSON + ) XContentParserUtils.ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.nextToken(), xcp) return xcp } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt b/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt index 062c8d937..bab8a5153 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/InputService.kt @@ -55,11 +55,18 @@ class InputService( when (input) { is SearchInput -> { // TODO: Figure out a way to use SearchTemplateRequest without bringing in the entire TransportClient - val searchParams = mapOf("period_start" to periodStart.toEpochMilli(), - "period_end" to periodEnd.toEpochMilli()) + val searchParams = mapOf( + "period_start" to periodStart.toEpochMilli(), + "period_end" to periodEnd.toEpochMilli() + ) AggregationQueryRewriter.rewriteQuery(input.query, prevResult, monitor.triggers) - val searchSource = scriptService.compile(Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, - input.query.toString(), searchParams), TemplateScript.CONTEXT) + val searchSource = scriptService.compile( + Script( + ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, + input.query.toString(), searchParams + ), + TemplateScript.CONTEXT + ) .newInstance(searchParams) .execute() @@ -100,8 +107,13 @@ class InputService( val input = monitor.inputs[0] as SearchInput val searchParams = mapOf("period_start" to periodStart.toEpochMilli(), "period_end" to periodEnd.toEpochMilli()) - val searchSource = scriptService.compile(Script(ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, - input.query.toString(), searchParams), TemplateScript.CONTEXT) + val searchSource = scriptService.compile( + Script( + ScriptType.INLINE, Script.DEFAULT_TEMPLATE_LANG, + input.query.toString(), searchParams + ), + TemplateScript.CONTEXT + ) .newInstance(searchParams) .execute() diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/TriggerService.kt b/alerting/src/main/kotlin/org/opensearch/alerting/TriggerService.kt index 10b3c5f02..bb92ba7ea 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/TriggerService.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/TriggerService.kt @@ -68,8 +68,10 @@ class TriggerService(val scriptService: ScriptService) { return try { val bucketIndices = ((ctx.results[0][Aggregations.AGGREGATIONS_FIELD] as HashMap<*, *>)[trigger.id] as HashMap<*, *>)[BUCKET_INDICES] as List<*> - val parentBucketPath = ((ctx.results[0][Aggregations.AGGREGATIONS_FIELD] as HashMap<*, *>) - .get(trigger.id) as HashMap<*, *>)[PARENT_BUCKET_PATH] as String + val parentBucketPath = ( + (ctx.results[0][Aggregations.AGGREGATIONS_FIELD] as HashMap<*, *>) + .get(trigger.id) as HashMap<*, *> + )[PARENT_BUCKET_PATH] as String val aggregationPath = AggregationPath.parse(parentBucketPath) // TODO test this part by passing sub-aggregation path var parentAgg = (ctx.results[0][Aggregations.AGGREGATIONS_FIELD] as HashMap<*, *>) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregationBuilder.kt b/alerting/src/main/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregationBuilder.kt index d3bb0057e..9962b9d58 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregationBuilder.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/aggregation/bucketselectorext/BucketSelectorExtAggregationBuilder.kt @@ -126,9 +126,11 @@ class BucketSelectorExtAggregationBuilder : if (other == null || javaClass != other.javaClass) return false if (!super.equals(other)) return false val otherCast = other as BucketSelectorExtAggregationBuilder - return (bucketsPathsMap == otherCast.bucketsPathsMap && - script == otherCast.script && - gapPolicy == otherCast.gapPolicy) + return ( + bucketsPathsMap == otherCast.bucketsPathsMap && + script == otherCast.script && + gapPolicy == otherCast.gapPolicy + ) } override fun getWriteableName(): String { @@ -224,21 +226,24 @@ class BucketSelectorExtAggregationBuilder : } if (bucketsPathsMap == null) { throw ParsingException( - parser.tokenLocation, "Missing required field [" + PipelineAggregator.Parser.BUCKETS_PATH.preferredName + - "] for bucket_selector aggregation [" + reducerName + "]" + parser.tokenLocation, + "Missing required field [" + PipelineAggregator.Parser.BUCKETS_PATH.preferredName + + "] for bucket_selector aggregation [" + reducerName + "]" ) } if (script == null) { throw ParsingException( - parser.tokenLocation, "Missing required field [" + Script.SCRIPT_PARSE_FIELD.preferredName + - "] for bucket_selector aggregation [" + reducerName + "]" + parser.tokenLocation, + "Missing required field [" + Script.SCRIPT_PARSE_FIELD.preferredName + + "] for bucket_selector aggregation [" + reducerName + "]" ) } if (parentBucketPath == null) { throw ParsingException( - parser.tokenLocation, "Missing required field [" + PARENT_BUCKET_PATH + - "] for bucket_selector aggregation [" + reducerName + "]" + parser.tokenLocation, + "Missing required field [" + PARENT_BUCKET_PATH + + "] for bucket_selector aggregation [" + reducerName + "]" ) } val factory = BucketSelectorExtAggregationBuilder(reducerName, bucketsPathsMap, script, parentBucketPath, filter) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/AggregationResultBucket.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/AggregationResultBucket.kt index edd772047..e31942c30 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/AggregationResultBucket.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/AggregationResultBucket.kt @@ -67,10 +67,12 @@ data class AggregationResultBucket( ensureExpectedToken(XContentParser.Token.START_OBJECT, xcp.currentToken(), xcp) if (CONFIG_NAME != xcp.currentName()) { - throw ParsingException(xcp.tokenLocation, + throw ParsingException( + xcp.tokenLocation, String.format( Locale.ROOT, "Failed to parse object: expecting token with name [%s] but found [%s]", - CONFIG_NAME, xcp.currentName()) + CONFIG_NAME, xcp.currentName() + ) ) } while (xcp.nextToken() != Token.END_OBJECT) { diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/Alert.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/Alert.kt index 5283a61e9..22ba715e7 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/Alert.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/Alert.kt @@ -31,7 +31,6 @@ import org.opensearch.alerting.elasticapi.instant import org.opensearch.alerting.elasticapi.optionalTimeField import org.opensearch.alerting.elasticapi.optionalUserField import org.opensearch.alerting.util.IndexUtils.Companion.NO_SCHEMA_VERSION -import org.opensearch.commons.authuser.User import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable @@ -40,6 +39,7 @@ import org.opensearch.common.xcontent.ToXContent import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken +import org.opensearch.commons.authuser.User import java.io.IOException import java.time.Instant @@ -81,11 +81,13 @@ data class Alert( errorHistory: List = mutableListOf(), actionExecutionResults: List = mutableListOf(), schemaVersion: Int = NO_SCHEMA_VERSION - ) : this(monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user, + ) : this( + monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user, triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime, lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory, severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion, - aggregationResultBucket = null) + aggregationResultBucket = null + ) constructor( monitor: Monitor, @@ -97,11 +99,13 @@ data class Alert( errorHistory: List = mutableListOf(), actionExecutionResults: List = mutableListOf(), schemaVersion: Int = NO_SCHEMA_VERSION - ) : this(monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user, + ) : this( + monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user, triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime, lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory, severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion, - aggregationResultBucket = null) + aggregationResultBucket = null + ) constructor( monitor: Monitor, @@ -114,11 +118,13 @@ data class Alert( actionExecutionResults: List = mutableListOf(), schemaVersion: Int = NO_SCHEMA_VERSION, aggregationResultBucket: AggregationResultBucket - ) : this(monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user, + ) : this( + monitorId = monitor.id, monitorName = monitor.name, monitorVersion = monitor.version, monitorUser = monitor.user, triggerId = trigger.id, triggerName = trigger.name, state = state, startTime = startTime, lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = errorHistory, severity = trigger.severity, actionExecutionResults = actionExecutionResults, schemaVersion = schemaVersion, - aggregationResultBucket = aggregationResultBucket) + aggregationResultBucket = aggregationResultBucket + ) enum class State { ACTIVE, ACKNOWLEDGED, COMPLETED, ERROR, DELETED @@ -272,13 +278,15 @@ data class Alert( } } - return Alert(id = id, version = version, schemaVersion = schemaVersion, monitorId = requireNotNull(monitorId), + return Alert( + id = id, version = version, schemaVersion = schemaVersion, monitorId = requireNotNull(monitorId), monitorName = requireNotNull(monitorName), monitorVersion = monitorVersion, monitorUser = monitorUser, triggerId = requireNotNull(triggerId), triggerName = requireNotNull(triggerName), state = requireNotNull(state), startTime = requireNotNull(startTime), endTime = endTime, lastNotificationTime = lastNotificationTime, acknowledgedTime = acknowledgedTime, errorMessage = errorMessage, errorHistory = errorHistory, severity = severity, - actionExecutionResults = actionExecutionResults, aggregationResultBucket = aggAlertBucket) + actionExecutionResults = actionExecutionResults, aggregationResultBucket = aggAlertBucket + ) } @JvmStatic diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTrigger.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTrigger.kt index 137715ba7..750a4d7fb 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTrigger.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTrigger.kt @@ -43,7 +43,7 @@ data class BucketLevelTrigger( ) : Trigger { @Throws(IOException::class) - constructor(sin: StreamInput): this( + constructor(sin: StreamInput) : this( sin.readString(), // id sin.readString(), // name sin.readString(), // severity @@ -98,8 +98,10 @@ data class BucketLevelTrigger( const val CONDITION_FIELD = "condition" const val PARENT_BUCKET_PATH = "parentBucketPath" - val XCONTENT_REGISTRY = NamedXContentRegistry.Entry(Trigger::class.java, ParseField(BUCKET_LEVEL_TRIGGER_FIELD), - CheckedFunction { parseInner(it) }) + val XCONTENT_REGISTRY = NamedXContentRegistry.Entry( + Trigger::class.java, ParseField(BUCKET_LEVEL_TRIGGER_FIELD), + CheckedFunction { parseInner(it) } + ) @JvmStatic @Throws(IOException::class) @@ -140,7 +142,8 @@ data class BucketLevelTrigger( name = requireNotNull(name) { "Trigger name is null" }, severity = requireNotNull(severity) { "Trigger severity is null" }, bucketSelector = requireNotNull(bucketSelector) { "Trigger condition is null" }, - actions = requireNotNull(actions) { "Trigger actions are null" }) + actions = requireNotNull(actions) { "Trigger actions are null" } + ) } @JvmStatic diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTriggerRunResult.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTriggerRunResult.kt index 5e05032d2..23c9a4af7 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTriggerRunResult.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/BucketLevelTriggerRunResult.kt @@ -26,7 +26,7 @@ data class BucketLevelTriggerRunResult( @Throws(IOException::class) @Suppress("UNCHECKED_CAST") - constructor(sin: StreamInput): this( + constructor(sin: StreamInput) : this( sin.readString(), sin.readException() as Exception?, // error sin.readMap(StreamInput::readString, ::AggregationResultBucket), @@ -44,7 +44,8 @@ data class BucketLevelTriggerRunResult( override fun writeTo(out: StreamOutput) { super.writeTo(out) out.writeMap(aggregationResultBuckets, StreamOutput::writeString) { - valueOut: StreamOutput, aggResultBucket: AggregationResultBucket -> aggResultBucket.writeTo(valueOut) + valueOut: StreamOutput, aggResultBucket: AggregationResultBucket -> + aggResultBucket.writeTo(valueOut) } out.writeMap(actionResultsMap as Map) } diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/Monitor.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/Monitor.kt index 4cc346070..8fe3e8ce5 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/Monitor.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/Monitor.kt @@ -40,7 +40,6 @@ import org.opensearch.alerting.util.IndexUtils.Companion.NO_SCHEMA_VERSION import org.opensearch.alerting.util._ID import org.opensearch.alerting.util._VERSION import org.opensearch.alerting.util.isBucketLevelMonitor -import org.opensearch.commons.authuser.User import org.opensearch.common.CheckedFunction import org.opensearch.common.ParseField import org.opensearch.common.io.stream.StreamInput @@ -51,6 +50,7 @@ import org.opensearch.common.xcontent.XContentBuilder import org.opensearch.common.xcontent.XContentParser import org.opensearch.common.xcontent.XContentParser.Token import org.opensearch.common.xcontent.XContentParserUtils.ensureExpectedToken +import org.opensearch.commons.authuser.User import java.io.IOException import java.time.Instant import java.util.Locale @@ -112,7 +112,7 @@ data class Monitor( } @Throws(IOException::class) - constructor(sin: StreamInput): this( + constructor(sin: StreamInput) : this( id = sin.readString(), version = sin.readLong(), name = sin.readString(), @@ -219,9 +219,11 @@ data class Monitor( // This is defined here instead of in ScheduledJob to avoid having the ScheduledJob class know about all // the different subclasses and creating circular dependencies - val XCONTENT_REGISTRY = NamedXContentRegistry.Entry(ScheduledJob::class.java, + val XCONTENT_REGISTRY = NamedXContentRegistry.Entry( + ScheduledJob::class.java, ParseField(MONITOR_TYPE), - CheckedFunction { parse(it) }) + CheckedFunction { parse(it) } + ) @JvmStatic @JvmOverloads @@ -284,7 +286,8 @@ data class Monitor( } else if (!enabled) { enabledTime = null } - return Monitor(id, + return Monitor( + id, version, requireNotNull(name) { "Monitor name is null" }, enabled, @@ -296,7 +299,8 @@ data class Monitor( schemaVersion, inputs.toList(), triggers.toList(), - uiMetadata) + uiMetadata + ) } @JvmStatic diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/MonitorRunResult.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/MonitorRunResult.kt index eef9899f7..3d880b225 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/MonitorRunResult.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/MonitorRunResult.kt @@ -27,9 +27,9 @@ package org.opensearch.alerting.model import org.apache.logging.log4j.LogManager +import org.opensearch.OpenSearchException import org.opensearch.alerting.alerts.AlertError import org.opensearch.alerting.elasticapi.optionalTimeField -import org.opensearch.OpenSearchException import org.opensearch.common.io.stream.StreamInput import org.opensearch.common.io.stream.StreamOutput import org.opensearch.common.io.stream.Writeable diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/QueryLevelTrigger.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/QueryLevelTrigger.kt index 442de276a..67cc8c2e0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/QueryLevelTrigger.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/QueryLevelTrigger.kt @@ -44,7 +44,7 @@ data class QueryLevelTrigger( ) : Trigger { @Throws(IOException::class) - constructor(sin: StreamInput): this( + constructor(sin: StreamInput) : this( sin.readString(), // id sin.readString(), // name sin.readString(), // severity @@ -73,8 +73,10 @@ data class QueryLevelTrigger( /** Returns a representation of the trigger suitable for passing into painless and mustache scripts. */ fun asTemplateArg(): Map { - return mapOf(ID_FIELD to id, NAME_FIELD to name, SEVERITY_FIELD to severity, - ACTIONS_FIELD to actions.map { it.asTemplateArg() }) + return mapOf( + ID_FIELD to id, NAME_FIELD to name, SEVERITY_FIELD to severity, + ACTIONS_FIELD to actions.map { it.asTemplateArg() } + ) } @Throws(IOException::class) @@ -91,8 +93,10 @@ data class QueryLevelTrigger( const val CONDITION_FIELD = "condition" const val SCRIPT_FIELD = "script" - val XCONTENT_REGISTRY = NamedXContentRegistry.Entry(Trigger::class.java, ParseField(QUERY_LEVEL_TRIGGER_FIELD), - CheckedFunction { parseInner(it) }) + val XCONTENT_REGISTRY = NamedXContentRegistry.Entry( + Trigger::class.java, ParseField(QUERY_LEVEL_TRIGGER_FIELD), + CheckedFunction { parseInner(it) } + ) /** * This parse method needs to account for both the old and new Trigger format. @@ -173,7 +177,8 @@ data class QueryLevelTrigger( severity = requireNotNull(severity) { "Trigger severity is null" }, condition = requireNotNull(condition) { "Trigger condition is null" }, actions = requireNotNull(actions) { "Trigger actions are null" }, - id = requireNotNull(id) { "Trigger id is null." }) + id = requireNotNull(id) { "Trigger id is null." } + ) } @JvmStatic diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/action/Action.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/action/Action.kt index af3a98ad5..2d7b02733 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/action/Action.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/action/Action.kt @@ -60,7 +60,7 @@ data class Action( } @Throws(IOException::class) - constructor(sin: StreamInput): this( + constructor(sin: StreamInput) : this( sin.readString(), // name sin.readString(), // destinationId sin.readOptionalWriteable(::Script), // subjectTemplate diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/model/action/ActionExecutionScope.kt b/alerting/src/main/kotlin/org/opensearch/alerting/model/action/ActionExecutionScope.kt index 866e07b80..e1dcd1fd5 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/model/action/ActionExecutionScope.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/model/action/ActionExecutionScope.kt @@ -113,7 +113,7 @@ data class PerAlertActionScope( ) : ActionExecutionScope() { @Throws(IOException::class) - constructor(sin: StreamInput): this( + constructor(sin: StreamInput) : this( sin.readSet { si -> si.readEnum(AlertCategory::class.java) } // alertFilter ) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/script/BucketLevelTriggerExecutionContext.kt b/alerting/src/main/kotlin/org/opensearch/alerting/script/BucketLevelTriggerExecutionContext.kt index 9da6b5b75..d79f7d5ea 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/script/BucketLevelTriggerExecutionContext.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/script/BucketLevelTriggerExecutionContext.kt @@ -11,9 +11,9 @@ package org.opensearch.alerting.script +import org.opensearch.alerting.model.Alert import org.opensearch.alerting.model.BucketLevelTrigger import org.opensearch.alerting.model.BucketLevelTriggerRunResult -import org.opensearch.alerting.model.Alert import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.model.MonitorRunResult import java.time.Instant @@ -37,8 +37,10 @@ data class BucketLevelTriggerExecutionContext( dedupedAlerts: List = listOf(), newAlerts: List = listOf(), completedAlerts: List = listOf() - ) : this(monitor, trigger, monitorRunResult.inputResults.results, monitorRunResult.periodStart, monitorRunResult.periodEnd, - dedupedAlerts, newAlerts, completedAlerts, monitorRunResult.scriptContextError(trigger)) + ) : this( + monitor, trigger, monitorRunResult.inputResults.results, monitorRunResult.periodStart, monitorRunResult.periodEnd, + dedupedAlerts, newAlerts, completedAlerts, monitorRunResult.scriptContextError(trigger) + ) /** * Mustache templates need special permissions to reflectively introspect field names. To avoid doing this we diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/script/QueryLevelTriggerExecutionContext.kt b/alerting/src/main/kotlin/org/opensearch/alerting/script/QueryLevelTriggerExecutionContext.kt index 566d503ab..e047da7f5 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/script/QueryLevelTriggerExecutionContext.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/script/QueryLevelTriggerExecutionContext.kt @@ -33,8 +33,10 @@ data class QueryLevelTriggerExecutionContext( trigger: QueryLevelTrigger, monitorRunResult: MonitorRunResult, alert: Alert? = null - ) : this(monitor, trigger, monitorRunResult.inputResults.results, monitorRunResult.periodStart, monitorRunResult.periodEnd, - alert, monitorRunResult.scriptContextError(trigger)) + ) : this( + monitor, trigger, monitorRunResult.inputResults.results, monitorRunResult.periodStart, monitorRunResult.periodEnd, + alert, monitorRunResult.scriptContextError(trigger) + ) /** * Mustache templates need special permissions to reflectively introspect field names. To avoid doing this we diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/script/TriggerExecutionContext.kt b/alerting/src/main/kotlin/org/opensearch/alerting/script/TriggerExecutionContext.kt index 46c447fbc..d5ac7c35a 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/script/TriggerExecutionContext.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/script/TriggerExecutionContext.kt @@ -39,9 +39,11 @@ abstract class TriggerExecutionContext( open val error: Exception? = null ) { - constructor(monitor: Monitor, trigger: Trigger, monitorRunResult: MonitorRunResult<*>): - this(monitor, monitorRunResult.inputResults.results, monitorRunResult.periodStart, - monitorRunResult.periodEnd, monitorRunResult.scriptContextError(trigger)) + constructor(monitor: Monitor, trigger: Trigger, monitorRunResult: MonitorRunResult<*>) : + this( + monitor, monitorRunResult.inputResults.results, monitorRunResult.periodStart, + monitorRunResult.periodEnd, monitorRunResult.scriptContextError(trigger) + ) /** * Mustache templates need special permissions to reflectively introspect field names. To avoid doing this we diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/util/AggregationQueryRewriter.kt b/alerting/src/main/kotlin/org/opensearch/alerting/util/AggregationQueryRewriter.kt index 65966e60b..ad1e62b1a 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/util/AggregationQueryRewriter.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/util/AggregationQueryRewriter.kt @@ -11,10 +11,10 @@ package org.opensearch.alerting.util +import org.opensearch.action.search.SearchResponse import org.opensearch.alerting.model.BucketLevelTrigger import org.opensearch.alerting.model.InputRunResults import org.opensearch.alerting.model.Trigger -import org.opensearch.action.search.SearchResponse import org.opensearch.search.aggregations.AggregationBuilder import org.opensearch.search.aggregations.AggregatorFactories import org.opensearch.search.aggregations.bucket.SingleBucketAggregation diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/ADTestHelpers.kt b/alerting/src/test/kotlin/org/opensearch/alerting/ADTestHelpers.kt index 18204c559..ea7b4d7c2 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/ADTestHelpers.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/ADTestHelpers.kt @@ -514,12 +514,16 @@ fun randomADMonitor( lastUpdateTime: Instant = Instant.now().truncatedTo(ChronoUnit.MILLIS), withMetadata: Boolean = false ): Monitor { - return Monitor(name = name, monitorType = Monitor.MonitorType.QUERY_LEVEL_MONITOR, enabled = enabled, inputs = inputs, + return Monitor( + name = name, monitorType = Monitor.MonitorType.QUERY_LEVEL_MONITOR, enabled = enabled, inputs = inputs, schedule = schedule, triggers = triggers, enabledTime = enabledTime, lastUpdateTime = lastUpdateTime, - user = user, uiMetadata = if (withMetadata) mapOf("foo" to "bar") else mapOf()) + user = user, uiMetadata = if (withMetadata) mapOf("foo" to "bar") else mapOf() + ) } fun randomADUser(backendRole: String = OpenSearchRestTestCase.randomAlphaOfLength(10)): User { - return User(OpenSearchRestTestCase.randomAlphaOfLength(10), listOf(backendRole), - listOf(OpenSearchRestTestCase.randomAlphaOfLength(10), "all_access"), listOf("test_attr=test")) + return User( + OpenSearchRestTestCase.randomAlphaOfLength(10), listOf(backendRole), + listOf(OpenSearchRestTestCase.randomAlphaOfLength(10), "all_access"), listOf("test_attr=test") + ) } diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/AlertServiceTests.kt b/alerting/src/test/kotlin/org/opensearch/alerting/AlertServiceTests.kt index e4c65b1c3..b2dccf921 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/AlertServiceTests.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/AlertServiceTests.kt @@ -11,15 +11,17 @@ package org.opensearch.alerting +import org.junit.Before +import org.mockito.Mockito +import org.opensearch.Version import org.opensearch.alerting.alerts.AlertIndices import org.opensearch.alerting.model.AggregationResultBucket -import org.opensearch.alerting.model.BucketLevelTrigger import org.opensearch.alerting.model.Alert +import org.opensearch.alerting.model.BucketLevelTrigger import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.model.action.AlertCategory import org.opensearch.alerting.settings.AlertingSettings import org.opensearch.alerting.util.getBucketKeysHash -import org.opensearch.Version import org.opensearch.client.Client import org.opensearch.cluster.node.DiscoveryNode import org.opensearch.cluster.service.ClusterService @@ -30,8 +32,6 @@ import org.opensearch.common.xcontent.NamedXContentRegistry import org.opensearch.test.ClusterServiceUtils import org.opensearch.test.OpenSearchTestCase import org.opensearch.threadpool.ThreadPool -import org.junit.Before -import org.mockito.Mockito import java.time.Instant import java.time.temporal.ChronoUnit @@ -77,19 +77,24 @@ class AlertServiceTests : OpenSearchTestCase() { val monitor = randomBucketLevelMonitor(triggers = listOf(trigger)) val currentAlerts = mutableMapOf() - val aggResultBuckets = createAggregationResultBucketsFromBucketKeys(listOf( - listOf("a"), - listOf("b") - )) + val aggResultBuckets = createAggregationResultBucketsFromBucketKeys( + listOf( + listOf("a"), + listOf("b") + ) + ) val categorizedAlerts = alertService.getCategorizedAlertsForBucketLevelMonitor(monitor, trigger, currentAlerts, aggResultBuckets) // Completed Alerts are what remains in currentAlerts after categorization val completedAlerts = currentAlerts.values.toList() assertEquals(listOf(), categorizedAlerts[AlertCategory.DEDUPED]) - assertAlertsExistForBucketKeys(listOf( - listOf("a"), - listOf("b") - ), categorizedAlerts[AlertCategory.NEW] ?: error("New alerts not found")) + assertAlertsExistForBucketKeys( + listOf( + listOf("a"), + listOf("b") + ), + categorizedAlerts[AlertCategory.NEW] ?: error("New alerts not found") + ) assertEquals(listOf(), completedAlerts) } @@ -97,22 +102,30 @@ class AlertServiceTests : OpenSearchTestCase() { val trigger = randomBucketLevelTrigger() val monitor = randomBucketLevelMonitor(triggers = listOf(trigger)) - val currentAlerts = createCurrentAlertsFromBucketKeys(monitor, trigger, listOf( - listOf("a"), - listOf("b") - )) - val aggResultBuckets = createAggregationResultBucketsFromBucketKeys(listOf( - listOf("a"), - listOf("b") - )) + val currentAlerts = createCurrentAlertsFromBucketKeys( + monitor, trigger, + listOf( + listOf("a"), + listOf("b") + ) + ) + val aggResultBuckets = createAggregationResultBucketsFromBucketKeys( + listOf( + listOf("a"), + listOf("b") + ) + ) val categorizedAlerts = alertService.getCategorizedAlertsForBucketLevelMonitor(monitor, trigger, currentAlerts, aggResultBuckets) // Completed Alerts are what remains in currentAlerts after categorization val completedAlerts = currentAlerts.values.toList() - assertAlertsExistForBucketKeys(listOf( - listOf("a"), - listOf("b") - ), categorizedAlerts[AlertCategory.DEDUPED] ?: error("Deduped alerts not found")) + assertAlertsExistForBucketKeys( + listOf( + listOf("a"), + listOf("b") + ), + categorizedAlerts[AlertCategory.DEDUPED] ?: error("Deduped alerts not found") + ) assertEquals(listOf(), categorizedAlerts[AlertCategory.NEW]) assertEquals(listOf(), completedAlerts) } @@ -121,10 +134,13 @@ class AlertServiceTests : OpenSearchTestCase() { val trigger = randomBucketLevelTrigger() val monitor = randomBucketLevelMonitor(triggers = listOf(trigger)) - val currentAlerts = createCurrentAlertsFromBucketKeys(monitor, trigger, listOf( - listOf("a"), - listOf("b") - )) + val currentAlerts = createCurrentAlertsFromBucketKeys( + monitor, trigger, + listOf( + listOf("a"), + listOf("b") + ) + ) val aggResultBuckets = listOf() val categorizedAlerts = alertService.getCategorizedAlertsForBucketLevelMonitor(monitor, trigger, currentAlerts, aggResultBuckets) @@ -132,24 +148,32 @@ class AlertServiceTests : OpenSearchTestCase() { val completedAlerts = currentAlerts.values.toList() assertEquals(listOf(), categorizedAlerts[AlertCategory.DEDUPED]) assertEquals(listOf(), categorizedAlerts[AlertCategory.NEW]) - assertAlertsExistForBucketKeys(listOf( - listOf("a"), - listOf("b") - ), completedAlerts) + assertAlertsExistForBucketKeys( + listOf( + listOf("a"), + listOf("b") + ), + completedAlerts + ) } fun `test getting categorized alerts for bucket-level monitor with de-duped and completed alerts`() { val trigger = randomBucketLevelTrigger() val monitor = randomBucketLevelMonitor(triggers = listOf(trigger)) - val currentAlerts = createCurrentAlertsFromBucketKeys(monitor, trigger, listOf( - listOf("a"), - listOf("b") - )) - val aggResultBuckets = createAggregationResultBucketsFromBucketKeys(listOf( - listOf("b"), - listOf("c") - )) + val currentAlerts = createCurrentAlertsFromBucketKeys( + monitor, trigger, + listOf( + listOf("a"), + listOf("b") + ) + ) + val aggResultBuckets = createAggregationResultBucketsFromBucketKeys( + listOf( + listOf("b"), + listOf("c") + ) + ) val categorizedAlerts = alertService.getCategorizedAlertsForBucketLevelMonitor(monitor, trigger, currentAlerts, aggResultBuckets) // Completed Alerts are what remains in currentAlerts after categorization @@ -166,8 +190,10 @@ class AlertServiceTests : OpenSearchTestCase() { ): MutableMap { return bucketKeysList.map { bucketKeys -> val aggResultBucket = AggregationResultBucket("parent_bucket_path", bucketKeys, mapOf()) - val alert = Alert(monitor, trigger, Instant.now().truncatedTo(ChronoUnit.MILLIS), null, - actionExecutionResults = listOf(randomActionExecutionResult()), aggregationResultBucket = aggResultBucket) + val alert = Alert( + monitor, trigger, Instant.now().truncatedTo(ChronoUnit.MILLIS), null, + actionExecutionResults = listOf(randomActionExecutionResult()), aggregationResultBucket = aggResultBucket + ) aggResultBucket.getBucketKeysHash() to alert }.toMap() as MutableMap } diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt b/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt index 494338737..d39542a02 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/AlertingRestTestCase.kt @@ -96,7 +96,8 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { SearchInput.XCONTENT_REGISTRY, QueryLevelTrigger.XCONTENT_REGISTRY, BucketLevelTrigger.XCONTENT_REGISTRY - ) + SearchModule(Settings.EMPTY, false, emptyList()).namedXContents) + ) + SearchModule(Settings.EMPTY, false, emptyList()).namedXContents + ) } fun Response.asMap(): Map { @@ -572,7 +573,8 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { "properties" : { "test_strict_date_time" : { "type" : "date", "format" : "strict_date_time" } } - """.trimIndent()) + """.trimIndent() + ) } catch (ex: WarningFailureException) { // ignore } diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/action/IndexMonitorResponseTests.kt b/alerting/src/test/kotlin/org/opensearch/alerting/action/IndexMonitorResponseTests.kt index 5a7a9b01f..4d1d138de 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/action/IndexMonitorResponseTests.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/action/IndexMonitorResponseTests.kt @@ -56,7 +56,8 @@ class IndexMonitorResponseTests : OpenSearchTestCase() { schemaVersion = 0, inputs = mutableListOf(), triggers = mutableListOf(), - uiMetadata = mutableMapOf()) + uiMetadata = mutableMapOf() + ) val req = IndexMonitorResponse("1234", 1L, 2L, 0L, RestStatus.OK, monitor) assertNotNull(req) diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/model/AlertTests.kt b/alerting/src/test/kotlin/org/opensearch/alerting/model/AlertTests.kt index 6e2df7dd7..de8f8b98c 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/model/AlertTests.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/model/AlertTests.kt @@ -62,10 +62,14 @@ class AlertTests : OpenSearchTestCase() { assertEquals("Template args start time does not", templateArgs[Alert.START_TIME_FIELD], alert.startTime.toEpochMilli()) assertEquals("Template args last notification time does not match", templateArgs[Alert.LAST_NOTIFICATION_TIME_FIELD], null) assertEquals("Template args severity does not match", templateArgs[Alert.SEVERITY_FIELD], alert.severity) - Assert.assertEquals("Template args bucketKeys do not match", - templateArgs[Alert.BUCKET_KEYS], alert.aggregationResultBucket?.bucketKeys?.joinToString(",")) - Assert.assertEquals("Template args parentBucketPath does not match", - templateArgs[Alert.PARENTS_BUCKET_PATH], alert.aggregationResultBucket?.parentBucketPath) + Assert.assertEquals( + "Template args bucketKeys do not match", + templateArgs[Alert.BUCKET_KEYS], alert.aggregationResultBucket?.bucketKeys?.joinToString(",") + ) + Assert.assertEquals( + "Template args parentBucketPath does not match", + templateArgs[Alert.PARENTS_BUCKET_PATH], alert.aggregationResultBucket?.parentBucketPath + ) } fun `test alert acknowledged`() { diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/model/WriteableTests.kt b/alerting/src/test/kotlin/org/opensearch/alerting/model/WriteableTests.kt index f0c372d2f..fda3bfbc2 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/model/WriteableTests.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/model/WriteableTests.kt @@ -43,9 +43,9 @@ import org.opensearch.alerting.randomEmailGroup import org.opensearch.alerting.randomInputRunResults import org.opensearch.alerting.randomQueryLevelMonitor import org.opensearch.alerting.randomQueryLevelMonitorRunResult -import org.opensearch.alerting.randomThrottle import org.opensearch.alerting.randomQueryLevelTrigger import org.opensearch.alerting.randomQueryLevelTriggerRunResult +import org.opensearch.alerting.randomThrottle import org.opensearch.alerting.randomUser import org.opensearch.alerting.randomUserEmpty import org.opensearch.common.io.stream.BytesStreamOutput diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/model/XContentTests.kt b/alerting/src/test/kotlin/org/opensearch/alerting/model/XContentTests.kt index f3ce396a8..db38de381 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/model/XContentTests.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/model/XContentTests.kt @@ -45,8 +45,8 @@ import org.opensearch.alerting.randomEmailAccount import org.opensearch.alerting.randomEmailGroup import org.opensearch.alerting.randomQueryLevelMonitor import org.opensearch.alerting.randomQueryLevelMonitorWithoutUser -import org.opensearch.alerting.randomThrottle import org.opensearch.alerting.randomQueryLevelTrigger +import org.opensearch.alerting.randomThrottle import org.opensearch.alerting.randomUser import org.opensearch.alerting.randomUserEmpty import org.opensearch.alerting.toJsonString @@ -84,7 +84,8 @@ class XContentTests : OpenSearchTestCase() { val action = randomAction().copy(throttle = null).copy(throttleEnabled = true) val actionString = action.toXContent(builder(), ToXContent.EMPTY_PARAMS).string() assertFailsWith("Action throttle enabled but not set throttle value") { - Action.parse(parser(actionString)) } + Action.parse(parser(actionString)) + } } fun `test throttle parsing`() { 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 274b1a4bb..d9a947c3c 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/MonitorRestApiIT.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/MonitorRestApiIT.kt @@ -43,15 +43,14 @@ import org.opensearch.alerting.makeRequest import org.opensearch.alerting.model.Alert import org.opensearch.alerting.model.Monitor import org.opensearch.alerting.model.QueryLevelTrigger -import org.opensearch.alerting.model.Trigger import org.opensearch.alerting.randomADMonitor import org.opensearch.alerting.randomAction import org.opensearch.alerting.randomAlert import org.opensearch.alerting.randomAnomalyDetector import org.opensearch.alerting.randomAnomalyDetectorWithUser import org.opensearch.alerting.randomQueryLevelMonitor -import org.opensearch.alerting.randomThrottle import org.opensearch.alerting.randomQueryLevelTrigger +import org.opensearch.alerting.randomThrottle import org.opensearch.alerting.settings.AlertingSettings import org.opensearch.client.ResponseException import org.opensearch.client.WarningFailureException diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureMonitorRestApiIT.kt b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureMonitorRestApiIT.kt index ee10bedc4..254659b65 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureMonitorRestApiIT.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/resthandler/SecureMonitorRestApiIT.kt @@ -25,8 +25,8 @@ import org.opensearch.alerting.model.Alert import org.opensearch.alerting.randomAction import org.opensearch.alerting.randomAlert import org.opensearch.alerting.randomQueryLevelMonitor -import org.opensearch.alerting.randomTemplateScript import org.opensearch.alerting.randomQueryLevelTrigger +import org.opensearch.alerting.randomTemplateScript import org.opensearch.client.Response import org.opensearch.client.ResponseException import org.opensearch.client.RestClient @@ -463,7 +463,10 @@ class SecureMonitorRestApiIT : AlertingRestTestCase() { query = SearchSourceBuilder().query(QueryBuilders.matchAllQuery()) ) ) - val monitor = randomQueryLevelMonitor(triggers = listOf(randomQueryLevelTrigger(condition = ALWAYS_RUN, actions = listOf(action))), inputs = inputs) + val monitor = randomQueryLevelMonitor( + triggers = listOf(randomQueryLevelTrigger(condition = ALWAYS_RUN, actions = listOf(action))), + inputs = inputs + ) // Make sure the elevating the permissions fails execute. val adminUser = User("admin", listOf("admin"), listOf("all_access"), listOf()) diff --git a/alerting/src/test/kotlin/org/opensearch/alerting/util/AggregationQueryRewriterTests.kt b/alerting/src/test/kotlin/org/opensearch/alerting/util/AggregationQueryRewriterTests.kt index 8b2d4803b..dd1f3dabf 100644 --- a/alerting/src/test/kotlin/org/opensearch/alerting/util/AggregationQueryRewriterTests.kt +++ b/alerting/src/test/kotlin/org/opensearch/alerting/util/AggregationQueryRewriterTests.kt @@ -11,11 +11,12 @@ package org.opensearch.alerting.util +import org.junit.Assert +import org.opensearch.action.search.SearchResponse import org.opensearch.alerting.model.InputRunResults import org.opensearch.alerting.model.Trigger import org.opensearch.alerting.randomBucketLevelTrigger import org.opensearch.alerting.randomQueryLevelTrigger -import org.opensearch.action.search.SearchResponse import org.opensearch.cluster.ClusterModule import org.opensearch.common.CheckedFunction import org.opensearch.common.ParseField @@ -30,7 +31,6 @@ import org.opensearch.search.aggregations.bucket.composite.TermsValuesSourceBuil import org.opensearch.search.aggregations.bucket.terms.TermsAggregationBuilder import org.opensearch.search.builder.SearchSourceBuilder import org.opensearch.test.OpenSearchTestCase -import org.junit.Assert import java.io.IOException class AggregationQueryRewriterTests : OpenSearchTestCase() {