From 2d92b344970668d8a86d2519fabbd61d8bfdc84e Mon Sep 17 00:00:00 2001 From: Surya Sashank Nistala Date: Tue, 16 May 2023 12:33:52 -0700 Subject: [PATCH] fix execution id field in alerts Signed-off-by: Surya Sashank Nistala --- .../commons/alerting/model/Alert.kt | 38 +++++++++---------- .../commons/alerting/TestHelpers.kt | 1 + .../alerting/action/GetAlertsResponseTests.kt | 2 +- 3 files changed, 21 insertions(+), 20 deletions(-) diff --git a/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt b/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt index c965778c..763c541f 100644 --- a/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt +++ b/src/main/kotlin/org/opensearch/commons/alerting/model/Alert.kt @@ -39,7 +39,7 @@ data class Alert( val severity: String, val actionExecutionResults: List, val aggregationResultBucket: AggregationResultBucket? = null, - val workflowExecutionId: String? = null, + val executionId: String? = null, ) : Writeable, ToXContent { init { @@ -54,7 +54,7 @@ data class Alert( state: State = State.ACTIVE, errorMessage: String? = null, schemaVersion: Int = NO_SCHEMA_VERSION, - workflowExecutionId: String, + executionId: String, chainedAlertTrigger: ChainedAlertTrigger, user: User ) : this( @@ -63,7 +63,7 @@ data class Alert( lastNotificationTime = lastNotificationTime, errorMessage = errorMessage, errorHistory = emptyList(), severity = chainedAlertTrigger.severity, actionExecutionResults = emptyList(), schemaVersion = schemaVersion, aggregationResultBucket = null, findingIds = emptyList(), relatedDocIds = emptyList(), - workflowExecutionId = workflowExecutionId + executionId = executionId ) constructor( @@ -76,14 +76,14 @@ data class Alert( errorHistory: List = mutableListOf(), actionExecutionResults: List = mutableListOf(), schemaVersion: Int = NO_SCHEMA_VERSION, - workflowExecutionId: String? = null + executionId: String? = null ) : 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, findingIds = emptyList(), relatedDocIds = emptyList(), - workflowExecutionId = workflowExecutionId + executionId = executionId ) constructor( @@ -97,14 +97,14 @@ data class Alert( actionExecutionResults: List = mutableListOf(), schemaVersion: Int = NO_SCHEMA_VERSION, findingIds: List = emptyList(), - workflowExecutionId: String? = null + executionId: String? = null ) : 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, findingIds = findingIds, relatedDocIds = emptyList(), - workflowExecutionId = workflowExecutionId + executionId = executionId ) constructor( @@ -119,14 +119,14 @@ data class Alert( schemaVersion: Int = NO_SCHEMA_VERSION, aggregationResultBucket: AggregationResultBucket, findingIds: List = emptyList(), - workflowExecutionId: String? = null + executionId: String? = null ) : 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, findingIds = findingIds, relatedDocIds = emptyList(), - workflowExecutionId = workflowExecutionId + executionId = executionId ) constructor( @@ -142,14 +142,14 @@ data class Alert( errorHistory: List = mutableListOf(), actionExecutionResults: List = mutableListOf(), schemaVersion: Int = NO_SCHEMA_VERSION, - workflowExecutionId: String? = null + executionId: String? = null ) : this( id = id, 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, findingIds = findingIds, relatedDocIds = relatedDocIds, - workflowExecutionId = workflowExecutionId + executionId = executionId ) enum class State { @@ -181,7 +181,7 @@ data class Alert( severity = sin.readString(), actionExecutionResults = sin.readList(::ActionExecutionResult), aggregationResultBucket = if (sin.readBoolean()) AggregationResultBucket(sin) else null, - workflowExecutionId = sin.readOptionalString() + executionId = sin.readOptionalString() ) fun isAcknowledged(): Boolean = (state == State.ACKNOWLEDGED) @@ -215,7 +215,7 @@ data class Alert( } else { out.writeBoolean(false) } - out.writeOptionalString(workflowExecutionId) + out.writeOptionalString(executionId) } companion object { @@ -240,7 +240,7 @@ data class Alert( const val ALERT_HISTORY_FIELD = "alert_history" const val SEVERITY_FIELD = "severity" const val ACTION_EXECUTION_RESULTS_FIELD = "action_execution_results" - const val WORKFLOW_EXECUTION_ID_FIELD = "workflow_execution_id" + const val EXECUTION_ID_FIELD = "execution_id" const val BUCKET_KEYS = AggregationResultBucket.BUCKET_KEYS const val PARENTS_BUCKET_PATH = AggregationResultBucket.PARENTS_BUCKET_PATH const val NO_ID = "" @@ -266,7 +266,7 @@ data class Alert( var lastNotificationTime: Instant? = null var acknowledgedTime: Instant? = null var errorMessage: String? = null - var workflowExecutionId: String? = null + var executionId: String? = null val errorHistory: MutableList = mutableListOf() val actionExecutionResults: MutableList = mutableListOf() var aggAlertBucket: AggregationResultBucket? = null @@ -301,7 +301,7 @@ data class Alert( LAST_NOTIFICATION_TIME_FIELD -> lastNotificationTime = xcp.instant() ACKNOWLEDGED_TIME_FIELD -> acknowledgedTime = xcp.instant() ERROR_MESSAGE_FIELD -> errorMessage = xcp.textOrNull() - WORKFLOW_EXECUTION_ID_FIELD -> workflowExecutionId = xcp.textOrNull() + EXECUTION_ID_FIELD -> executionId = xcp.textOrNull() ALERT_HISTORY_FIELD -> { ensureExpectedToken(XContentParser.Token.START_ARRAY, xcp.currentToken(), xcp) while (xcp.nextToken() != XContentParser.Token.END_ARRAY) { @@ -337,7 +337,7 @@ data class Alert( lastNotificationTime = lastNotificationTime, acknowledgedTime = acknowledgedTime, errorMessage = errorMessage, errorHistory = errorHistory, severity = severity, actionExecutionResults = actionExecutionResults, aggregationResultBucket = aggAlertBucket, findingIds = findingIds, - relatedDocIds = relatedDocIds, workflowExecutionId = workflowExecutionId + relatedDocIds = relatedDocIds, executionId = executionId ) } @@ -363,7 +363,7 @@ data class Alert( .field(SCHEMA_VERSION_FIELD, schemaVersion) .field(MONITOR_VERSION_FIELD, monitorVersion) .field(MONITOR_NAME_FIELD, monitorName) - .field(WORKFLOW_EXECUTION_ID_FIELD, workflowExecutionId) + .field(EXECUTION_ID_FIELD, executionId) if (!secure) { builder.optionalUserField(MONITOR_USER_FIELD, monitorUser) @@ -394,7 +394,7 @@ data class Alert( ALERT_VERSION_FIELD to version, END_TIME_FIELD to endTime?.toEpochMilli(), ERROR_MESSAGE_FIELD to errorMessage, - WORKFLOW_EXECUTION_ID_FIELD to workflowExecutionId, + EXECUTION_ID_FIELD to executionId, LAST_NOTIFICATION_TIME_FIELD to lastNotificationTime?.toEpochMilli(), SEVERITY_FIELD to severity, START_TIME_FIELD to startTime.toEpochMilli(), diff --git a/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt b/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt index f8e86965..5e4691b9 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/TestHelpers.kt @@ -492,6 +492,7 @@ fun xContentRegistry(): NamedXContentRegistry { DocLevelMonitorInput.XCONTENT_REGISTRY, QueryLevelTrigger.XCONTENT_REGISTRY, BucketLevelTrigger.XCONTENT_REGISTRY, + ChainedAlertTrigger.XCONTENT_REGISTRY, DocumentLevelTrigger.XCONTENT_REGISTRY ) + SearchModule(Settings.EMPTY, emptyList()).namedXContents ) diff --git a/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsResponseTests.kt b/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsResponseTests.kt index 5d5b2364..f04745d3 100644 --- a/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsResponseTests.kt +++ b/src/test/kotlin/org/opensearch/commons/alerting/action/GetAlertsResponseTests.kt @@ -97,7 +97,7 @@ class GetAlertsResponseTests { var actualXContentString = req.toXContent(builder(), ToXContent.EMPTY_PARAMS).string() val expectedXContentString = "{\"alerts\":[{\"id\":\"id\",\"version\":0,\"monitor_id\":\"monitorId\"," + "\"schema_version\":0,\"monitor_version\":0,\"monitor_name\":\"monitorName\"," + - "\"trigger_id\":\"triggerId\",\"trigger_name\":\"triggerName\"," + + "\"execution_id\":null,\"trigger_id\":\"triggerId\",\"trigger_name\":\"triggerName\"," + "\"finding_ids\":[],\"related_doc_ids\":[],\"state\":\"ACKNOWLEDGED\",\"error_message\":null,\"alert_history\":[]," + "\"severity\":\"severity\",\"action_execution_results\":[],\"start_time\":" + now.toEpochMilli() + ",\"last_notification_time\":null,\"end_time\":null,\"acknowledged_time\":null}],\"totalAlerts\":1}"