Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 18 additions & 10 deletions alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunner.kt
Original file line number Diff line number Diff line change
Expand Up @@ -62,16 +62,24 @@ abstract class MonitorRunner {
throw IllegalStateException("Message content missing in the Destination with id: ${action.destinationId}")
}
if (!dryrun) {
val roles = MonitorRunnerService.getRolesForMonitor(monitor)
withClosableContext(
InjectorContextElement(monitor.id, monitorCtx.settings!!, monitorCtx.threadPool!!.threadContext, roles)
) {
actionOutput[Action.MESSAGE_ID] = getConfigAndSendNotification(
action,
monitorCtx,
actionOutput[Action.SUBJECT],
actionOutput[Action.MESSAGE]!!
)
val client = monitorCtx.client
client!!.threadPool().threadContext.stashContext().use {
withClosableContext(
InjectorContextElement(
monitor.id,
monitorCtx.settings!!,
monitorCtx.threadPool!!.threadContext,
monitor.user?.roles,
monitor.user
)
) {
actionOutput[Action.MESSAGE_ID] = getConfigAndSendNotification(
action,
monitorCtx,
actionOutput[Action.SUBJECT],
actionOutput[Action.MESSAGE]!!
)
}
}
}
ActionRunResult(action.id, action.name, actionOutput, false, MonitorRunnerService.currentTime(), null)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,10 @@ import org.opensearch.action.search.SearchResponse
import org.opensearch.action.support.ActionFilters
import org.opensearch.action.support.HandledTransportAction
import org.opensearch.action.support.WriteRequest.RefreshPolicy
import org.opensearch.alerting.opensearchapi.InjectorContextElement
import org.opensearch.alerting.opensearchapi.addFilter
import org.opensearch.alerting.opensearchapi.suspendUntil
import org.opensearch.alerting.opensearchapi.withClosableContext
import org.opensearch.alerting.settings.AlertingSettings
import org.opensearch.alerting.util.AlertingException
import org.opensearch.client.Client
Expand Down Expand Up @@ -53,6 +55,7 @@ import org.opensearch.rest.RestStatus
import org.opensearch.search.builder.SearchSourceBuilder
import org.opensearch.tasks.Task
import org.opensearch.transport.TransportService
import java.util.UUID

private val scope: CoroutineScope = CoroutineScope(Dispatchers.IO)
/**
Expand All @@ -64,7 +67,7 @@ class TransportDeleteWorkflowAction @Inject constructor(
val client: Client,
actionFilters: ActionFilters,
val clusterService: ClusterService,
settings: Settings,
val settings: Settings,
val xContentRegistry: NamedXContentRegistry
) : HandledTransportAction<ActionRequest, DeleteWorkflowResponse>(
AlertingActions.DELETE_WORKFLOW_ACTION_NAME, transportService, actionFilters, ::DeleteWorkflowRequest
Expand Down Expand Up @@ -149,7 +152,22 @@ class TransportDeleteWorkflowAction @Inject constructor(

val deleteResponse = deleteWorkflow(workflow)
if (deleteDelegateMonitors == true) {
deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE)
if (user == null) {
deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE)
} else {
// Un-stash the context
withClosableContext(
InjectorContextElement(
user.name.plus(UUID.randomUUID().toString()),
settings,
client.threadPool().threadContext,
user.roles,
user
)
) {
deleteMonitors(delegateMonitorIds, RefreshPolicy.IMMEDIATE)
}
}
}
actionListener.onResponse(DeleteWorkflowResponse(deleteResponse.id, deleteResponse.version))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,21 @@ class TransportGetWorkflowAction @Inject constructor(
xContentRegistry, LoggingDeprecationHandler.INSTANCE,
response.sourceAsBytesRef, XContentType.JSON
).use { xcp ->
workflow = ScheduledJob.parse(xcp, response.id, response.version) as Workflow
val compositeMonitor = ScheduledJob.parse(xcp, response.id, response.version)
if (compositeMonitor is Workflow) {
workflow = compositeMonitor
} else {
log.error("Wrong monitor type returned")
actionListener.onFailure(
AlertingException.wrap(
OpenSearchStatusException(
"Workflow not found.",
RestStatus.NOT_FOUND
)
)
)
return
}

// security is enabled and filterby is enabled
if (!checkUserPermissionsWithResource(
Expand Down
Loading