From 7022912e725dba8d67e3db8693f15be303fc0f61 Mon Sep 17 00:00:00 2001 From: Ashish Agrawal Date: Wed, 4 Oct 2023 09:45:24 -0700 Subject: [PATCH] Add logging for execution and indexes of monitors and workflows Signed-off-by: Ashish Agrawal --- .../opensearch/alerting/MonitorRunnerService.kt | 5 +++++ .../transport/TransportExecuteMonitorAction.kt | 4 ++++ .../transport/TransportExecuteWorkflowAction.kt | 4 ++++ .../transport/TransportIndexMonitorAction.kt | 14 ++++++++++++++ 4 files changed, 27 insertions(+) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt index 15ccf482e..ca223f7a0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/MonitorRunnerService.kt @@ -288,10 +288,15 @@ object MonitorRunnerService : JobRunner, CoroutineScope, AbstractLifecycleCompon } if (job is Workflow) { + logger.info("Executing scheduled workflow - id: ${job.id}, periodStart: $periodStart, periodEnd: $periodEnd, dryrun: $dryrun") CompositeWorkflowRunner.runWorkflow(workflow = job, monitorCtx, periodStart, periodEnd, dryrun) } val monitor = job as Monitor val executionId = "${monitor.id}_${LocalDateTime.now(ZoneOffset.UTC)}_${UUID.randomUUID()}" + logger.info( + "Executing scheduled monitor - id: ${monitor.id}, type: ${monitor.monitorType.name}, periodStart: $periodStart, " + + "periodEnd: $periodEnd, dryrun: $dryrun, executionId: $executionId" + ) val runResult = if (monitor.isBucketLevelMonitor()) { BucketLevelMonitorRunner.runMonitor(monitor, monitorCtx, periodStart, periodEnd, dryrun, executionId = executionId) } else if (monitor.isDocLevelMonitor()) { 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 cc1438584..b0de10ff0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteMonitorAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteMonitorAction.kt @@ -75,6 +75,10 @@ class TransportExecuteMonitorAction @Inject constructor( val (periodStart, periodEnd) = monitor.schedule.getPeriodEndingAt(Instant.ofEpochMilli(execMonitorRequest.requestEnd.millis)) try { + log.info( + "Executing monitor from API - id: ${monitor.id}, type: ${monitor.monitorType.name}, " + + "periodStart: $periodStart, periodEnd: $periodEnd, dryrun: ${execMonitorRequest.dryrun}" + ) val monitorRunResult = runner.runJob(monitor, periodStart, periodEnd, execMonitorRequest.dryrun) withContext(Dispatchers.IO) { actionListener.onResponse(ExecuteMonitorResponse(monitorRunResult)) diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteWorkflowAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteWorkflowAction.kt index 425981099..037628e9e 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteWorkflowAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportExecuteWorkflowAction.kt @@ -62,6 +62,10 @@ class TransportExecuteWorkflowAction @Inject constructor( val (periodStart, periodEnd) = workflow.schedule.getPeriodEndingAt(Instant.ofEpochMilli(execWorkflowRequest.requestEnd.millis)) try { + log.info( + "Executing workflow from API - id: ${workflow.id}, periodStart: $periodStart, periodEnd: $periodEnd, " + + "dryrun: ${execWorkflowRequest.dryrun}" + ) val workflowRunResult = MonitorRunnerService.runJob(workflow, periodStart, periodEnd, execWorkflowRequest.dryrun) withContext(Dispatchers.IO, { diff --git a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexMonitorAction.kt b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexMonitorAction.kt index 8669c038d..49743b3f0 100644 --- a/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexMonitorAction.kt +++ b/alerting/src/main/kotlin/org/opensearch/alerting/transport/TransportIndexMonitorAction.kt @@ -486,6 +486,13 @@ class TransportIndexMonitorAction @Inject constructor( .setIfPrimaryTerm(request.primaryTerm) .timeout(indexTimeout) + log.info( + "Creating new monitor: ${request.monitor.toXContentWithUser( + jsonBuilder(), + ToXContent.MapParams(mapOf("with_type" to "true")) + )}" + ) + try { val indexResponse: IndexResponse = client.suspendUntil { client.index(indexRequest, it) } val failureReasons = checkShardsFailure(indexResponse) @@ -648,6 +655,13 @@ class TransportIndexMonitorAction @Inject constructor( .setIfPrimaryTerm(request.primaryTerm) .timeout(indexTimeout) + log.info( + "Updating monitor, ${currentMonitor.id}, from: ${currentMonitor.toXContentWithUser( + jsonBuilder(), + ToXContent.MapParams(mapOf("with_type" to "true")) + )} \n to: ${request.monitor.toXContentWithUser(jsonBuilder(), ToXContent.MapParams(mapOf("with_type" to "true")))}" + ) + try { val indexResponse: IndexResponse = client.suspendUntil { client.index(indexRequest, it) } val failureReasons = checkShardsFailure(indexResponse)