diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt index 00faea817..b1be99f12 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/Step.kt @@ -26,10 +26,106 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { return this } - abstract suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step + abstract suspend fun execute(): Step - fun postExecute(logger: Logger): Step { + fun postExecute( + logger: Logger, + indexManagementActionMetrics: IndexManagementActionsMetrics, + step: Step, + startingManagedIndexMetaData: ManagedIndexMetaData, + ): Step { logger.info("Finished executing $name for ${context?.metadata?.index}") + val updatedStepMetaData = step.getUpdatedManagedIndexMetadata(startingManagedIndexMetaData) + when (context?.metadata?.actionMetaData?.name) { + IndexManagementActionsMetrics.ROLLOVER -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.ROLLOVER, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.FORCE_MERGE -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.FORCE_MERGE, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.DELETE -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.DELETE, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.REPLICA_COUNT -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.REPLICA_COUNT, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.TRANSITION -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.TRANSITION, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + IndexManagementActionsMetrics.NOTIFICATION -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.NOTIFICATION, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.CLOSE -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.CLOSE, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.SET_INDEX_PRIORITY -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.SET_INDEX_PRIORITY, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.OPEN -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.OPEN, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.CREATE_ROLLUP -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.CREATE_ROLLUP, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + IndexManagementActionsMetrics.CREATE_TRANSFORM -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.CREATE_TRANSFORM, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.MOVE_SHARD -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.MOVE_SHARD, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.SET_READ_ONLY -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.SET_READ_ONLY, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.SHRINK -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.SHRINK, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.SNAPSHOT -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.SNAPSHOT, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.ALIAS_ACTION -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.ALIAS_ACTION, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + + IndexManagementActionsMetrics.ALLOCATION -> indexManagementActionMetrics.getActionMetrics( + IndexManagementActionsMetrics.ALLOCATION, + ) + ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + else -> { + logger.info( + "Action Metrics is not supported for this action [%s]", + context?.metadata?.actionMetaData?.name, + ) + } + } this.context = null return this } @@ -50,7 +146,8 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { } } - final fun getStartingStepMetaData(metadata: ManagedIndexMetaData): StepMetaData = StepMetaData(name, getStepStartTime(metadata).toEpochMilli(), StepStatus.STARTING) + final fun getStartingStepMetaData(metadata: ManagedIndexMetaData): StepMetaData = + StepMetaData(name, getStepStartTime(metadata).toEpochMilli(), StepStatus.STARTING) enum class StepStatus(val status: String) : Writeable { STARTING("starting"), diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt index 5aca52de4..4576ec5ca 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt @@ -5,13 +5,25 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.AliasActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.AllocationActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.CloseActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.CreateRollupActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.CreateTransformActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.DeleteActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.ForceMergeActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.MoveShardActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.NotificationActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.OpenActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.ReplicaCountActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.RolloverActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.SetIndexPriorityActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.SetReadOnlyActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.ShrinkActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.SnapshotActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.TransitionActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.telemetry.metrics.tags.Tags @@ -23,8 +35,15 @@ abstract class ActionMetrics { .addTag("index_name", context.metadata.index) .addTag("policy_id", context.metadata.policyID) .addTag("node_id", context.clusterService.nodeName ?: "") + .addTag("Index_uuid", context.metadata.indexUuid) return tags } + + abstract fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) } class IndexManagementActionsMetrics private constructor() { @@ -40,6 +59,17 @@ class IndexManagementActionsMetrics private constructor() { const val DELETE = "delete" const val REPLICA_COUNT = "replica_count" const val TRANSITION = "transition" + const val CLOSE = "close" + const val SET_INDEX_PRIORITY = "set_index_priority" + const val OPEN = "open" + const val CREATE_ROLLUP = "create_rollup" + const val CREATE_TRANSFORM = "create_transform" + const val MOVE_SHARD = "move_shard" + const val SET_READ_ONLY = "set_read_only" + const val SHRINK = "shrink" + const val SNAPSHOT = "snapshot" + const val ALIAS_ACTION = "alias_action" + const val ALLOCATION = "allocation" private object HOLDER { val instance = IndexManagementActionsMetrics() @@ -55,6 +85,17 @@ class IndexManagementActionsMetrics private constructor() { DeleteActionMetrics.instance.initializeCounters(metricsRegistry) ReplicaCountActionMetrics.instance.initializeCounters(metricsRegistry) TransitionActionMetrics.instance.initializeCounters(metricsRegistry) + CloseActionMetrics.instance.initializeCounters(metricsRegistry) + SetIndexPriorityActionMetrics.instance.initializeCounters(metricsRegistry) + OpenActionMetrics.instance.initializeCounters(metricsRegistry) + CreateRollupActionMetrics.instance.initializeCounters(metricsRegistry) + CreateTransformActionMetrics.instance.initializeCounters(metricsRegistry) + MoveShardActionMetrics.instance.initializeCounters(metricsRegistry) + SetReadOnlyActionMetrics.instance.initializeCounters(metricsRegistry) + ShrinkActionMetrics.instance.initializeCounters(metricsRegistry) + SnapshotActionMetrics.instance.initializeCounters(metricsRegistry) + AliasActionMetrics.instance.initializeCounters(metricsRegistry) + AllocationActionMetrics.instance.initializeCounters(metricsRegistry) actionMetricsMap = mapOf( ROLLOVER to RolloverActionMetrics.instance, @@ -63,6 +104,17 @@ class IndexManagementActionsMetrics private constructor() { DELETE to DeleteActionMetrics.instance, REPLICA_COUNT to ReplicaCountActionMetrics.instance, TRANSITION to TransitionActionMetrics.instance, + CLOSE to CloseActionMetrics.instance, + SET_INDEX_PRIORITY to SetIndexPriorityActionMetrics.instance, + OPEN to OpenActionMetrics.instance, + CREATE_ROLLUP to CreateRollupActionMetrics.instance, + CREATE_TRANSFORM to CreateTransformActionMetrics.instance, + MOVE_SHARD to MoveShardActionMetrics.instance, + SET_READ_ONLY to SetReadOnlyActionMetrics.instance, + SHRINK to ShrinkActionMetrics.instance, + SNAPSHOT to SnapshotActionMetrics.instance, + ALIAS_ACTION to AliasActionMetrics.instance, + ALLOCATION to AllocationActionMetrics.instance, ) } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AliasActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AliasActionMetrics.kt index f1c8fb14b..5652a292e 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AliasActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AliasActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class AliasActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = AliasActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val aliasActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.ALIAS_ACTION) as AliasActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + aliasActionMetrics.successes.add(1.0, context.let { aliasActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + aliasActionMetrics.failures.add(1.0, context.let { aliasActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + aliasActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { aliasActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AllocationActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AllocationActionMetrics.kt index 54a76c665..363fde91d 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AllocationActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AllocationActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class AllocationActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = AllocationActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val allocationActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.ALLOCATION) as AllocationActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + allocationActionMetrics.successes.add(1.0, context.let { allocationActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + allocationActionMetrics.failures.add(1.0, context.let { allocationActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + allocationActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { allocationActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CloseActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CloseActionMetrics.kt index b2c5f28b8..1f301872d 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CloseActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CloseActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class CloseActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = CloseActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val closeActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.CLOSE) as CloseActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + closeActionMetrics.successes.add(1.0, context.let { closeActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + closeActionMetrics.failures.add(1.0, context.let { closeActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + closeActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { closeActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt index f6149b8c8..9470d562f 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,26 @@ class CreateRollupActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = CreateRollupActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val createRollupActionMetrics = + indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.CREATE_ROLLUP) as CreateRollupActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + createRollupActionMetrics.successes.add(1.0, context.let { createRollupActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + createRollupActionMetrics.failures.add(1.0, context.let { createRollupActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + createRollupActionMetrics.cumulativeLatency.add( + latency.toDouble(), + context.let { createRollupActionMetrics.createTags(it) }, + ) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt index 15dcd2fc7..692139172 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class CreateTransformActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = CreateTransformActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val createTransformActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.CREATE_TRANSFORM) as CreateRollupActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + createTransformActionMetrics.successes.add(1.0, context.let { createTransformActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + createTransformActionMetrics.failures.add(1.0, context.let { createTransformActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + createTransformActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { createTransformActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/DeleteActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/DeleteActionMetrics.kt index 1d4390cb9..b8d236364 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/DeleteActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/DeleteActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class DeleteActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = DeleteActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val deleteActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.DELETE) as DeleteActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + deleteActionMetrics.successes.add(1.0, context.let { deleteActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + deleteActionMetrics.failures.add(1.0, context.let { deleteActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + deleteActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { deleteActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ForceMergeActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ForceMergeActionMetrics.kt index 93f3c2220..5b7858ee1 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ForceMergeActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ForceMergeActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class ForceMergeActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = ForceMergeActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val forceMergeActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.FORCE_MERGE) as ForceMergeActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + forceMergeActionMetrics.successes.add(1.0, context.let { forceMergeActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + forceMergeActionMetrics.failures.add(1.0, context.let { forceMergeActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + forceMergeActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { forceMergeActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/MoveShardActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/MoveShardActionMetrics.kt index 10b35c655..2f86100d9 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/MoveShardActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/MoveShardActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class MoveShardActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = MoveShardActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val moveShardActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.MOVE_SHARD) as MoveShardActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + moveShardActionMetrics.successes.add(1.0, context.let { moveShardActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + moveShardActionMetrics.failures.add(1.0, context.let { moveShardActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + moveShardActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { moveShardActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/NotificationActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/NotificationActionMetrics.kt index c1f897740..0faa9b9fd 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/NotificationActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/NotificationActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class NotificationActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = NotificationActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val notificationActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.NOTIFICATION) as NotificationActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + notificationActionMetrics.successes.add(1.0, context.let { notificationActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + notificationActionMetrics.failures.add(1.0, context.let { notificationActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + notificationActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { notificationActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/OpenActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/OpenActionMetrics.kt index 62e9d3944..ad29a5f8a 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/OpenActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/OpenActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class OpenActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = OpenActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val openActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.OPEN) as OpenActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + openActionMetrics.successes.add(1.0, context.let { openActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + openActionMetrics.failures.add(1.0, context.let { openActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + openActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { openActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ReplicaCountActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ReplicaCountActionMetrics.kt index 82254270e..94e60b892 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ReplicaCountActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ReplicaCountActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class ReplicaCountActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = ReplicaCountActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val replicaCountActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.REPLICA_COUNT) as ReplicaCountActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + replicaCountActionMetrics.successes.add(1.0, context.let { replicaCountActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + replicaCountActionMetrics.failures.add(1.0, context.let { replicaCountActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + replicaCountActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { replicaCountActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/RolloverActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/RolloverActionMetrics.kt index 45c07a73e..3d2965702 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/RolloverActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/RolloverActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class RolloverActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = RolloverActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val rolloverActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.ROLLOVER) as RolloverActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + rolloverActionMetrics.successes.add(1.0, context.let { rolloverActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + rolloverActionMetrics.failures.add(1.0, context.let { rolloverActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + rolloverActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { rolloverActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetIndexPriorityActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetIndexPriorityActionMetrics.kt index a670cfceb..023461829 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetIndexPriorityActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetIndexPriorityActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class SetIndexPriorityActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = SetIndexPriorityActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val setIndexPriorityActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.SET_INDEX_PRIORITY) as SetIndexPriorityActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + setIndexPriorityActionMetrics.successes.add(1.0, context.let { setIndexPriorityActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + setIndexPriorityActionMetrics.failures.add(1.0, context.let { setIndexPriorityActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + setIndexPriorityActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { setIndexPriorityActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetReadOnlyActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetReadOnlyActionMetrics.kt index 5d873eb7e..a3a8b4737 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetReadOnlyActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetReadOnlyActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class SetReadOnlyActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = SetReadOnlyActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val setReadOnlyActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.SET_READ_ONLY) as SetReadOnlyActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + setReadOnlyActionMetrics.successes.add(1.0, context.let { setReadOnlyActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + setReadOnlyActionMetrics.failures.add(1.0, context.let { setReadOnlyActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + setReadOnlyActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { setReadOnlyActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ShrinkActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ShrinkActionMetrics.kt index 3ce21b28a..704feca3c 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ShrinkActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ShrinkActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class ShrinkActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = ShrinkActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val shrinkActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.SHRINK) as ShrinkActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + shrinkActionMetrics.successes.add(1.0, context.let { shrinkActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + shrinkActionMetrics.failures.add(1.0, context.let { shrinkActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + shrinkActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { shrinkActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SnapshotActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SnapshotActionMetrics.kt index 07e8200ea..10d74e195 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SnapshotActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SnapshotActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class SnapshotActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = SnapshotActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val snapshotActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.SNAPSHOT) as SnapshotActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + snapshotActionMetrics.successes.add(1.0, context.let { snapshotActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + snapshotActionMetrics.failures.add(1.0, context.let { snapshotActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + snapshotActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { snapshotActionMetrics.createTags(it) }) + } } diff --git a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/TransitionActionMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/TransitionActionMetrics.kt index 6f17909e6..8049ab25e 100644 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/TransitionActionMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/TransitionActionMetrics.kt @@ -5,8 +5,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.Step.StepStatus import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry @@ -29,4 +32,22 @@ class TransitionActionMetrics private constructor() : ActionMetrics() { private object HOLDER { val instance = TransitionActionMetrics() } + + override fun emitMetrics( + context: StepContext, + indexManagementActionsMetrics: IndexManagementActionsMetrics, + stepMetaData: StepMetaData?, + ) { + val transitionActionMetrics = indexManagementActionsMetrics.getActionMetrics(IndexManagementActionsMetrics.TRANSITION) as TransitionActionMetrics + val stepStatus = stepMetaData?.stepStatus + if (stepStatus == StepStatus.COMPLETED) { + transitionActionMetrics.successes.add(1.0, context.let { transitionActionMetrics.createTags(it) }) + } + if (stepStatus == StepStatus.FAILED) { + transitionActionMetrics.failures.add(1.0, context.let { transitionActionMetrics.createTags(it) }) + } + val endTime = System.currentTimeMillis() + val latency = endTime - (context.metadata.stepMetaData?.startTime ?: endTime) + transitionActionMetrics.cumulativeLatency.add(latency.toDouble(), context.let { transitionActionMetrics.createTags(it) }) + } } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt index 6db0d079a..003a612ce 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt @@ -453,7 +453,8 @@ object ManagedIndexRunner : managedIndexConfig.id, settings, threadPool.threadContext, managedIndexConfig.policy.user, ), ) { - step.preExecute(logger, stepContext.getUpdatedContext(startingManagedIndexMetaData)).execute(indexManagementActionMetrics).postExecute(logger) + step.preExecute(logger, stepContext.getUpdatedContext(startingManagedIndexMetaData)).execute() + .postExecute(logger, indexManagementActionMetrics, step, startingManagedIndexMetaData) } var executedManagedIndexMetaData = startingManagedIndexMetaData.getCompletedManagedIndexMetaData(action, step) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt index 64135ab59..f756fe547 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/alias/AttemptAliasActionsStep.kt @@ -11,7 +11,6 @@ import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.indexmanagement.indexstatemanagement.action.AliasAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -20,7 +19,7 @@ class AttemptAliasActionsStep(private val action: AliasAction) : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt index 135ac31d3..1c42612ba 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/allocation/AttemptAllocationStep.kt @@ -12,7 +12,6 @@ import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.indexstatemanagement.action.AllocationAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -21,7 +20,7 @@ class AttemptAllocationStep(private val action: AllocationAction) : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt index b570366ed..f2a6f29ec 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt @@ -11,7 +11,6 @@ import org.opensearch.action.admin.indices.close.CloseIndexRequest import org.opensearch.action.admin.indices.close.CloseIndexResponse import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.snapshots.SnapshotInProgressException @@ -22,7 +21,7 @@ class AttemptCloseStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index try { @@ -55,7 +54,6 @@ class AttemptCloseStep : Step(name) { } catch (e: Exception) { handleException(indexName, e) } - return this } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt index 2f1e19d2e..fade86dc0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/delete/AttemptDeleteStep.kt @@ -11,8 +11,6 @@ import org.opensearch.action.admin.indices.delete.DeleteIndexRequest import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.DeleteActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.snapshots.SnapshotInProgressException @@ -22,16 +20,10 @@ class AttemptDeleteStep : Step(name) { private val logger = LogManager.getLogger(javaClass) private var stepStatus = StepStatus.STARTING private var info: Map? = null - private lateinit var indexManagementActionsMetrics: IndexManagementActionsMetrics - private lateinit var actionMetrics: DeleteActionMetrics - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index - this.indexManagementActionsMetrics = indexManagementActionMetrics - this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.DELETE) as DeleteActionMetrics - val startTime = System.currentTimeMillis() - try { val response: AcknowledgedResponse = context.client.admin().indices() @@ -58,7 +50,6 @@ class AttemptDeleteStep : Step(name) { } catch (e: Exception) { handleException(indexName, e) } - emitDeleteActionMetrics(startTime) return this } @@ -87,21 +78,6 @@ class AttemptDeleteStep : Step(name) { ) } - private fun emitDeleteActionMetrics(startTime: Long) { - if (stepStatus == StepStatus.COMPLETED) { - actionMetrics.successes.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - if (stepStatus == StepStatus.FAILED) { - actionMetrics.failures.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - addLatency(startTime) - } - private fun addLatency(startTime: Long) { - val endTime = System.currentTimeMillis() - val latency = endTime - startTime - actionMetrics.cumulativeLatency.add(latency.toDouble(), context?.let { actionMetrics.createTags(it) }) - } - override fun isIdempotent() = true companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt index 152fe3489..e17770df6 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt @@ -19,8 +19,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.ForceMergeActi import org.opensearch.indexmanagement.opensearchapi.getUsefulCauseString import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.ForceMergeActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -31,17 +29,13 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam private val logger = LogManager.getLogger(javaClass) private var stepStatus = StepStatus.STARTING private var info: Map? = null - private lateinit var indexManagementActionsMetrics: IndexManagementActionsMetrics - private lateinit var actionMetrics: ForceMergeActionMetrics @Suppress("TooGenericExceptionCaught", "ComplexMethod") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): AttemptCallForceMergeStep { + override suspend fun execute(): AttemptCallForceMergeStep { val context = this.context ?: return this val indexName = context.metadata.index - this.indexManagementActionsMetrics = indexManagementActionMetrics - this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.FORCE_MERGE) as ForceMergeActionMetrics + val startTime = Instant.now().toEpochMilli() try { - val startTime = Instant.now().toEpochMilli() val request = ForceMergeRequest(indexName).maxNumSegments(action.maxNumSegments) var response: ForceMergeResponse? = null var throwable: Throwable? = null @@ -67,10 +61,6 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam if (shadowedResponse?.let { it.status == RestStatus.OK } != false) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to if (shadowedResponse == null) getSuccessfulCallMessage(indexName) else getSuccessMessage(indexName)) - actionMetrics.successes.add( - 1.0, - actionMetrics.createTags(context), - ) } else { // Otherwise the request to force merge encountered some problem stepStatus = StepStatus.FAILED @@ -80,17 +70,12 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam "status" to shadowedResponse.status, "shard_failures" to shadowedResponse.shardFailures.map { it.getUsefulCauseString() }, ) - actionMetrics.failures.add( - 1.0, - actionMetrics.createTags(context), - ) } } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) } catch (e: Exception) { handleException(indexName, e) } - return this } @@ -98,10 +83,6 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam val message = getFailedMessage(indexName) logger.error(message, e) stepStatus = StepStatus.FAILED - actionMetrics.failures.add( - 1.0, - context?.let { actionMetrics.createTags(it) }, - ) val mutableInfo = mutableMapOf("message" to message) val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt index 1d477238e..1f931404b 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptSetReadOnlyStep.kt @@ -14,7 +14,6 @@ import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.indexstatemanagement.action.ForceMergeAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -26,7 +25,7 @@ class AttemptSetReadOnlyStep(private val action: ForceMergeAction) : Step(name) private var info: Map? = null @Suppress("ReturnCount") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val indexSetToReadOnly = setIndexToReadOnly(indexName, context) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt index cacee486e..612739251 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/WaitForForceMergeStep.kt @@ -13,7 +13,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.ForceMergeActi import org.opensearch.indexmanagement.opensearchapi.getUsefulCauseString import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext @@ -27,7 +26,7 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f private var info: Map? = null @Suppress("TooGenericExceptionCaught", "ReturnCount") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): WaitForForceMergeStep { + override suspend fun execute(): WaitForForceMergeStep { val context = this.context ?: return this val indexName = context.metadata.index // Retrieve maxNumSegments value from ActionProperties. If ActionProperties is null, update failed info and return early. diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt index 1aa49ae92..9330691ca 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/indexpriority/AttemptSetIndexPriorityStep.kt @@ -14,7 +14,6 @@ import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -25,7 +24,7 @@ class AttemptSetIndexPriorityStep(private val action: IndexPriorityAction) : Ste private var info: Map? = null @Suppress("TooGenericExceptionCaught") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetaData = context.metadata @@ -52,7 +51,6 @@ class AttemptSetIndexPriorityStep(private val action: IndexPriorityAction) : Ste } catch (e: Exception) { handleException(indexName, e) } - return this } diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt index e294f46be..dfafbdb6a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt @@ -11,8 +11,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.publishLegacyNot import org.opensearch.indexmanagement.indexstatemanagement.util.sendNotification import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.NotificationActionMetrics // Added import for NotificationActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.script.Script @@ -23,15 +21,11 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam private val logger = LogManager.getLogger(javaClass) private var stepStatus = StepStatus.STARTING private var info: Map? = null - private lateinit var indexManagementActionsMetrics: IndexManagementActionsMetrics - private lateinit var actionMetrics: NotificationActionMetrics - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val scriptService = context.scriptService - this.indexManagementActionsMetrics = indexManagementActionMetrics - this.actionMetrics = indexManagementActionMetrics.getActionMetrics("notification") as NotificationActionMetrics try { val compiledMessage = compileTemplate(scriptService, action.messageTemplate, context.metadata) @@ -40,10 +34,6 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam // publish and send throws an error for any invalid responses so its safe to assume if we reach this point it was successful stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSuccessMessage(indexName)) - actionMetrics.successes.add( - 1.0, - actionMetrics.createTags(context), - ) } catch (e: Exception) { handleException(indexName, e) } @@ -59,10 +49,6 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage info = mutableInfo.toMap() - actionMetrics.failures.add( - 1.0, - context?.let { actionMetrics.createTags(it) }, - ) } override fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt index 4be84314e..7f384f845 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/open/AttemptOpenStep.kt @@ -11,7 +11,6 @@ import org.opensearch.action.admin.indices.open.OpenIndexRequest import org.opensearch.action.admin.indices.open.OpenIndexResponse import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -21,7 +20,7 @@ class AttemptOpenStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt index 61b6fe8ce..2560bb208 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readonly/SetReadOnlyStep.kt @@ -13,7 +13,6 @@ import org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -23,7 +22,7 @@ class SetReadOnlyStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt index 68b2815ab..11e634c7a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/readwrite/SetReadWriteStep.kt @@ -13,7 +13,6 @@ import org.opensearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -23,7 +22,7 @@ class SetReadWriteStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index try { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt index b089461f9..470d23453 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/replicacount/AttemptReplicaCountStep.kt @@ -14,8 +14,6 @@ import org.opensearch.common.settings.Settings import org.opensearch.indexmanagement.indexstatemanagement.action.ReplicaCountAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.ReplicaCountActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -25,15 +23,10 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam private var stepStatus = StepStatus.STARTING private var info: Map? = null private val numOfReplicas = action.numOfReplicas - private lateinit var indexManagementActionsMetrics: IndexManagementActionsMetrics - private lateinit var actionMetrics: ReplicaCountActionMetrics - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index - val startTime = System.currentTimeMillis() - this.indexManagementActionsMetrics = indexManagementActionMetrics - this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.REPLICA_COUNT) as ReplicaCountActionMetrics try { val updateSettingsRequest = UpdateSettingsRequest() @@ -57,7 +50,6 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam } catch (e: Exception) { handleException(indexName, numOfReplicas, e) } - emitReplicaCountActionMetrics(startTime) return this } @@ -79,21 +71,6 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam ) } - private fun emitReplicaCountActionMetrics(startTime: Long) { - if (stepStatus == StepStatus.COMPLETED) { - actionMetrics.successes.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - if (stepStatus == StepStatus.FAILED) { - actionMetrics.failures.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - addLatency(startTime) - } - private fun addLatency(startTime: Long) { - val endTime = System.currentTimeMillis() - val latency = endTime - startTime - actionMetrics.cumulativeLatency.add(latency.toDouble(), context?.let { actionMetrics.createTags(it) }) - } - override fun isIdempotent() = true companion object { diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt index f8f1ad791..5ba8be2e3 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt @@ -27,8 +27,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.evaluateConditio import org.opensearch.indexmanagement.opensearchapi.getUsefulCauseString import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.RolloverActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -41,23 +39,17 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null private var newIndex: String? = null // this variable holds the new index name if rollover is successful in this run - private lateinit var indexManagementActionsMetrics: IndexManagementActionsMetrics - private lateinit var actionMetrics: RolloverActionMetrics @Suppress("ComplexMethod", "LongMethod") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val clusterService = context.clusterService val skipRollover = clusterService.state().metadata.index(indexName).getRolloverSkip() - this.indexManagementActionsMetrics = indexManagementActionMetrics - this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.ROLLOVER) as RolloverActionMetrics - val startTime = System.currentTimeMillis() if (skipRollover) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSkipRolloverMessage(indexName)) - emitRolloverMetrics(startTime) return this } @@ -65,7 +57,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { // If the rolloverTarget is null, we would've already updated the failed info from getRolloverTargetOrUpdateInfo and can return early if (rolloverTarget == null) { - emitRolloverMetrics(startTime) return this } @@ -75,23 +66,17 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { // If already rolled over, alias may not get copied over yet copyAlias(clusterService, indexName, context.client, rolloverTarget, context.metadata) - emitRolloverMetrics(startTime) return this } if (!isDataStream && !preCheckIndexAlias(context, rolloverTarget)) { stepStatus = StepStatus.FAILED info = mapOf("message" to getFailedPreCheckMessage(indexName)) - emitRolloverMetrics(startTime) return this } - val statsResponse = getIndexStatsOrUpdateInfo(context) + val statsResponse = getIndexStatsOrUpdateInfo(context) ?: return this // If statsResponse is null we already updated failed info from getIndexStatsOrUpdateInfo and can return early - if (statsResponse == null) { - emitRolloverMetrics(startTime) - return this - } val indexCreationDate = clusterService.state().metadata().index(indexName).creationDate val indexAgeTimeValue = @@ -152,7 +137,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.CONDITION_NOT_MET info = mapOf("message" to getPendingMessage(indexName), "conditions" to conditions) } - emitRolloverMetrics(startTime) return this } @@ -396,18 +380,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { info = mutableInfo.toMap() } - private fun emitRolloverMetrics(startTime: Long) { - if (stepStatus == StepStatus.COMPLETED) { - actionMetrics.successes.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - if (stepStatus == StepStatus.FAILED) { - actionMetrics.failures.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - val endTime = System.currentTimeMillis() - val latency = endTime - startTime - actionMetrics.cumulativeLatency.add(latency.toDouble(), context?.let { actionMetrics.createTags(it) }) - } - override fun isIdempotent(): Boolean = true @Suppress("TooManyFunctions") diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt index 1ddc01a35..ee166ec4a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/AttemptCreateRollupJobStep.kt @@ -20,7 +20,6 @@ import org.opensearch.indexmanagement.rollup.action.index.IndexRollupResponse import org.opensearch.indexmanagement.rollup.action.start.StartRollupAction import org.opensearch.indexmanagement.rollup.action.start.StartRollupRequest import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext @@ -33,7 +32,7 @@ class AttemptCreateRollupJobStep(private val action: RollupAction) : Step(name) private var info: Map? = null private var rollupId: String? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetadata = context.metadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt index c5c0efc94..7bdc1f4be 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollup/WaitForRollupCompletionStep.kt @@ -12,7 +12,6 @@ import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupRequest import org.opensearch.indexmanagement.rollup.action.explain.ExplainRollupResponse import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -23,7 +22,7 @@ class WaitForRollupCompletionStep : Step(name) { private var info: Map? = null private var hasRollupFailed: Boolean? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetadata = context.metadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt index 8e57a264e..e0baae6a0 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/shrink/ShrinkStep.kt @@ -18,7 +18,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.renewShrinkLock import org.opensearch.indexmanagement.indexstatemanagement.util.resetReadOnlyAndRouting import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ShrinkActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.transport.RemoteTransportException @@ -35,7 +34,7 @@ abstract class ShrinkStep( protected var shrinkActionProperties: ShrinkActionProperties? = null @Suppress("ReturnCount") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this try { wrappedExecute(context) diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt index 7561a305c..6e02ad716 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/AttemptSnapshotStep.kt @@ -16,7 +16,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndex import org.opensearch.indexmanagement.opensearchapi.convertToMap import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -38,7 +37,7 @@ class AttemptSnapshotStep(private val action: SnapshotAction) : Step(name) { private var snapshotName: String? = null @Suppress("TooGenericExceptionCaught", "ComplexMethod", "ReturnCount", "LongMethod") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetadata = context.metadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt index e1f6b8868..36157f5c9 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/snapshot/WaitForSnapshotStep.kt @@ -14,7 +14,6 @@ import org.opensearch.cluster.SnapshotsInProgress.State import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -26,7 +25,7 @@ class WaitForSnapshotStep(private val action: SnapshotAction) : Step(name) { private var info: Map? = null @Suppress("ComplexMethod", "ReturnCount") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetadata = context.metadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt index f79cda616..41aa6ff92 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/AttemptCreateTransformJobStep.kt @@ -15,7 +15,6 @@ import org.opensearch.index.engine.VersionConflictEngineException import org.opensearch.indexmanagement.indexstatemanagement.action.TransformAction import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext @@ -36,7 +35,7 @@ class AttemptCreateTransformJobStep( private var info: Map? = null private var transformId: String? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetadata = context.metadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt index ac199b438..8b2085403 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transform/WaitForTransformCompletionStep.kt @@ -9,7 +9,6 @@ import org.apache.logging.log4j.LogManager import org.opensearch.ExceptionsHelper import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -25,7 +24,7 @@ class WaitForTransformCompletionStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val managedIndexMetadata = context.metadata diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt index 8726377df..1bb1865aa 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt @@ -21,8 +21,6 @@ import org.opensearch.indexmanagement.indexstatemanagement.util.hasStatsConditio import org.opensearch.indexmanagement.opensearchapi.getUsefulCauseString import org.opensearch.indexmanagement.opensearchapi.suspendUntil import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.TransitionActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -34,25 +32,19 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) private var stepStatus = StepStatus.STARTING private var policyCompleted: Boolean = false private var info: Map? = null - private lateinit var indexManagementActionsMetrics: IndexManagementActionsMetrics - private lateinit var actionMetrics: TransitionActionMetrics @Suppress("ReturnCount", "ComplexMethod", "LongMethod", "NestedBlockDepth") - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { val context = this.context ?: return this val indexName = context.metadata.index val clusterService = context.clusterService val transitions = action.transitions val indexMetadataProvider = action.indexMetadataProvider - this.indexManagementActionsMetrics = indexManagementActionMetrics - this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.TRANSITION) as TransitionActionMetrics - val startTime = System.currentTimeMillis() try { if (transitions.isEmpty()) { logger.info("$indexName transitions are empty, completing policy") policyCompleted = true stepStatus = StepStatus.COMPLETED - emitTransitionMetrics(startTime) return this } @@ -77,7 +69,6 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) - emitTransitionMetrics(startTime) return this } } @@ -99,7 +90,6 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) "message" to message, "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) - emitTransitionMetrics(startTime) return this } numDocs = statsResponse.primaries.getDocs()?.count ?: 0 @@ -133,7 +123,6 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) } catch (e: Exception) { handleException(indexName, e) } - emitTransitionMetrics(startTime) return this } @@ -189,21 +178,6 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) return -1L } - private fun emitTransitionMetrics(startTime: Long) { - if (stepStatus == StepStatus.COMPLETED) { - actionMetrics.successes.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - if (stepStatus == StepStatus.FAILED) { - actionMetrics.failures.add(1.0, context?.let { actionMetrics.createTags(it) }) - } - addLatency(startTime) - } - private fun addLatency(startTime: Long) { - val endTime = System.currentTimeMillis() - val latency = endTime - startTime - actionMetrics.cumulativeLatency.add(latency.toDouble(), context?.let { actionMetrics.createTags(it) }) - } - override fun isIdempotent() = true companion object { diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt index 08c30df0f..b896ef231 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt @@ -14,7 +14,6 @@ import org.opensearch.core.xcontent.XContentParserUtils import org.opensearch.indexmanagement.spi.indexstatemanagement.Action import org.opensearch.indexmanagement.spi.indexstatemanagement.ActionParser import org.opensearch.indexmanagement.spi.indexstatemanagement.Step -import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -74,7 +73,7 @@ class SampleCustomActionParser : ActionParser() { class SampleCustomStep : Step(name) { private var stepStatus = StepStatus.STARTING - override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(): Step { stepStatus = StepStatus.COMPLETED return this } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt index 35a213cd5..ca05021cb 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt @@ -60,7 +60,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptCloseStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -74,7 +74,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptCloseStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -88,7 +88,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptCloseStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -102,7 +102,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptCloseStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -116,7 +116,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptCloseStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -130,7 +130,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptCloseStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "nested", updatedManagedIndexMetaData.info!!["cause"]) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt index 6acd4c912..e0cc34110 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt @@ -103,7 +103,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptRolloverStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptRolloverStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("message info is not matched", AttemptRolloverStep.getCopyAliasNotAckMessage(oldIndexName, newIndexName), updatedManagedIndexMetaData.info?.get("message")) @@ -129,7 +129,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptRolloverStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptRolloverStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("message info is not matched", AttemptRolloverStep.getFailedCopyAliasMessage(oldIndexName, newIndexName), updatedManagedIndexMetaData.info?.get("message")) @@ -155,7 +155,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptRolloverStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptRolloverStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("message info is not matched", AttemptRolloverStep.getCopyAliasIndexNotFoundMessage(newIndexName), updatedManagedIndexMetaData.info?.get("message")) @@ -181,7 +181,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptRolloverStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = attemptRolloverStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("message info is not matched", AttemptRolloverStep.getCopyAliasRolledOverIndexNotFoundMessage(oldIndexName), updatedManagedIndexMetaData.info?.get("message")) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt index b9431f1a1..a3a70ca6c 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt @@ -18,7 +18,6 @@ import org.opensearch.client.IndicesAdminClient import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.core.action.ActionListener -import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.readonly.SetReadOnlyStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -42,7 +41,7 @@ class SetReadOnlyStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val setReadOnlyStep = SetReadOnlyStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadOnlyStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + setReadOnlyStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -56,7 +55,7 @@ class SetReadOnlyStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val setReadOnlyStep = SetReadOnlyStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadOnlyStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + setReadOnlyStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -70,7 +69,7 @@ class SetReadOnlyStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val setReadOnlyStep = SetReadOnlyStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadOnlyStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + setReadOnlyStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "nested", updatedManagedIndexMetaData.info!!["cause"]) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt index 326349a06..cde5845e5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt @@ -58,7 +58,7 @@ class SetReadWriteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val setReadWriteStep = SetReadWriteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadWriteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + setReadWriteStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = setReadWriteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -72,7 +72,7 @@ class SetReadWriteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val setReadWriteStep = SetReadWriteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadWriteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + setReadWriteStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = setReadWriteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -86,7 +86,7 @@ class SetReadWriteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val setReadWriteStep = SetReadWriteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadWriteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + setReadWriteStep.preExecute(logger, context).execute() val updatedManagedIndexMetaData = setReadWriteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "nested", updatedManagedIndexMetaData.info!!["cause"]) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt index 181d94aa5..8537a3b54 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt @@ -10,7 +10,6 @@ import kotlinx.coroutines.runBlocking import org.opensearch.client.Client import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings -import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.rollup.WaitForRollupCompletionStep import org.opensearch.indexmanagement.rollup.model.RollupMetadata import org.opensearch.indexmanagement.rollup.model.RollupStats @@ -53,7 +52,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { val step = WaitForRollupCompletionStep() runBlocking { - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() } val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt index a6a17f7cb..ae4d394df 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt @@ -20,7 +20,6 @@ import org.opensearch.cluster.SnapshotsInProgress import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.core.action.ActionListener -import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.action.SnapshotAction import org.opensearch.indexmanagement.indexstatemanagement.step.snapshot.WaitForSnapshotStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -51,7 +50,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, emptyActionProperties), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", WaitForSnapshotStep.getFailedActionPropertiesMessage("test", emptyActionProperties), updatedManagedIndexMetaData.info!!["message"]) @@ -63,7 +62,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, nullActionProperties), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", WaitForSnapshotStep.getFailedActionPropertiesMessage("test", nullActionProperties), updatedManagedIndexMetaData.info!!["message"]) @@ -83,7 +82,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get snapshot in progress message", WaitForSnapshotStep.getSnapshotInProgressMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -95,7 +94,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get snapshot in progress message", WaitForSnapshotStep.getSnapshotInProgressMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -107,7 +106,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get snapshot completed message", WaitForSnapshotStep.getSuccessMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -119,7 +118,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get snapshot failed message", WaitForSnapshotStep.getFailedExistsMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -131,7 +130,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get snapshot failed message", WaitForSnapshotStep.getFailedExistsMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -150,7 +149,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get snapshot failed message", WaitForSnapshotStep.getFailedExistsMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -165,7 +164,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "example", updatedManagedIndexMetaData.info!!["cause"]) @@ -180,7 +179,7 @@ class WaitForSnapshotStepTests : OpenSearchTestCase() { val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(WaitForSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) val step = WaitForSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "nested", updatedManagedIndexMetaData.info!!["cause"])