From 83d53d5d2bc181e1d3de2e7854446290d3ca7383 Mon Sep 17 00:00:00 2001 From: harycash Date: Tue, 11 Jun 2024 12:50:26 +0530 Subject: [PATCH 01/14] Initial integration of TelemetryAwarePlugin to ISM Signed-off-by: harycash --- .../indexmanagement/IndexManagementPlugin.kt | 28 ++++++++-------- .../IndexManagementActionsMetrics.kt | 33 +++++++++++++++++++ 2 files changed, 46 insertions(+), 15 deletions(-) create mode 100644 src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt index 3a67de075..c536c7881 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt @@ -41,15 +41,7 @@ import org.opensearch.indexmanagement.controlcenter.notification.filter.IndexOpe import org.opensearch.indexmanagement.controlcenter.notification.resthandler.RestDeleteLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.resthandler.RestGetLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.resthandler.RestIndexLRONConfigAction -import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService -import org.opensearch.indexmanagement.indexstatemanagement.ExtensionStatusChecker -import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser -import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider -import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementHistory -import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexCoordinator -import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner -import org.opensearch.indexmanagement.indexstatemanagement.PluginVersionSweepCoordinator -import org.opensearch.indexmanagement.indexstatemanagement.SkipExecution +import org.opensearch.indexmanagement.indexstatemanagement.* import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestAddPolicyAction @@ -179,15 +171,13 @@ import org.opensearch.jobscheduler.spi.JobSchedulerExtension import org.opensearch.jobscheduler.spi.ScheduledJobParser import org.opensearch.jobscheduler.spi.ScheduledJobRunner import org.opensearch.monitor.jvm.JvmService -import org.opensearch.plugins.ActionPlugin -import org.opensearch.plugins.ExtensiblePlugin -import org.opensearch.plugins.NetworkPlugin -import org.opensearch.plugins.Plugin -import org.opensearch.plugins.SystemIndexPlugin +import org.opensearch.plugins.* import org.opensearch.repositories.RepositoriesService import org.opensearch.rest.RestController import org.opensearch.rest.RestHandler import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.tracing.Tracer import org.opensearch.threadpool.ThreadPool import org.opensearch.transport.RemoteClusterService import org.opensearch.transport.TransportInterceptor @@ -196,7 +186,8 @@ import org.opensearch.watcher.ResourceWatcherService import java.util.function.Supplier @Suppress("TooManyFunctions") -class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin, ExtensiblePlugin, SystemIndexPlugin, Plugin() { +class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin, ExtensiblePlugin, SystemIndexPlugin, + TelemetryAwarePlugin, Plugin() { private val logger = LogManager.getLogger(javaClass) lateinit var indexManagementIndices: IndexManagementIndices lateinit var actionValidation: ActionValidation @@ -210,6 +201,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin private val extensions = mutableSetOf() private val extensionCheckerMap = mutableMapOf() lateinit var indexOperationActionFilter: IndexOperationActionFilter + private lateinit var metricsRegistry: MetricsRegistry companion object { const val PLUGINS_BASE_URI = "/_plugins" @@ -374,8 +366,11 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin namedWriteableRegistry: NamedWriteableRegistry, indexNameExpressionResolver: IndexNameExpressionResolver, repositoriesServiceSupplier: Supplier, + tracer: Tracer, + metricsRegistry: MetricsRegistry, ): Collection { val settings = environment.settings() + this.metricsRegistry = metricsRegistry this.clusterService = clusterService QueryShardContextFactory.init( client, @@ -385,6 +380,8 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin namedWriteableRegistry, environment, ) + + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) rollupInterceptor = RollupInterceptor(clusterService, settings, indexNameExpressionResolver) val jvmService = JvmService(environment.settings()) val transformRunner = @@ -453,6 +450,7 @@ class IndexManagementPlugin : JobSchedulerExtension, NetworkPlugin, ActionPlugin .registerThreadPool(threadPool) .registerExtensionChecker(extensionChecker) .registerIndexMetadataProvider(indexMetadataProvider) + .registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) val managedIndexCoordinator = ManagedIndexCoordinator( diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt new file mode 100644 index 000000000..df3458f2b --- /dev/null +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt @@ -0,0 +1,33 @@ +package org.opensearch.indexmanagement.indexstatemanagement + +import org.opensearch.indexmanagement.indexstatemanagement.actionmetrics.RolloverActionMetrics +import org.opensearch.telemetry.metrics.MetricsRegistry + +abstract class ActionMetrics { + abstract val actionName: String +} + +class IndexManagementActionsMetrics private constructor() { + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var actionMetricsMap: Map + + fun initialize(metricsRegistry: MetricsRegistry) { + this.metricsRegistry = metricsRegistry + actionMetricsMap = mapOf( + "rollover" to RolloverActionMetrics(metricsRegistry), + // Add other action metrics here + ) + } + + fun getActionMetrics(actionName: String): ActionMetrics? { + return actionMetricsMap[actionName] + } + + companion object { + val instance: IndexManagementActionsMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = IndexManagementActionsMetrics() + } +} From 681d015cd457372ab5cee88fdf21d2640a27abdc Mon Sep 17 00:00:00 2001 From: harycash Date: Wed, 12 Jun 2024 22:55:53 +0530 Subject: [PATCH 02/14] Initial integration of TelemetryAwarePlugin to ISM Signed-off-by: harycash --- .../metrics}/IndexManagementActionsMetrics.kt | 9 ++++--- .../actionmetrics/RolloverActionMetrics.kt | 24 +++++++++++++++++++ .../indexmanagement/IndexManagementPlugin.kt | 18 ++++++++++++-- .../ManagedIndexRunner.kt | 9 ++++++- .../step/rollover/AttemptRolloverStep.kt | 15 +++++++++++- 5 files changed, 68 insertions(+), 7 deletions(-) rename {src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement => spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics}/IndexManagementActionsMetrics.kt (71%) create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/RolloverActionMetrics.kt diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt similarity index 71% rename from src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt rename to spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt index df3458f2b..def480ab7 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/IndexManagementActionsMetrics.kt +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/IndexManagementActionsMetrics.kt @@ -1,6 +1,6 @@ -package org.opensearch.indexmanagement.indexstatemanagement +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics -import org.opensearch.indexmanagement.indexstatemanagement.actionmetrics.RolloverActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.RolloverActionMetrics import org.opensearch.telemetry.metrics.MetricsRegistry abstract class ActionMetrics { @@ -13,8 +13,11 @@ class IndexManagementActionsMetrics private constructor() { fun initialize(metricsRegistry: MetricsRegistry) { this.metricsRegistry = metricsRegistry + + RolloverActionMetrics.instance.initializeCounters(metricsRegistry, "rollover") + actionMetricsMap = mapOf( - "rollover" to RolloverActionMetrics(metricsRegistry), + "rollover" to RolloverActionMetrics.instance, // Add other action metrics here ) } 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 new file mode 100644 index 000000000..48e67b0d7 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/RolloverActionMetrics.kt @@ -0,0 +1,24 @@ +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class RolloverActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = "rollover_action" + lateinit var successes: Counter + lateinit var failures: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry, actionName: String) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Rollover Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Rollover Action Failures", "count") + } + + companion object { + val instance: RolloverActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = RolloverActionMetrics() + } +} diff --git a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt index c536c7881..7660d48e1 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/IndexManagementPlugin.kt @@ -41,7 +41,15 @@ import org.opensearch.indexmanagement.controlcenter.notification.filter.IndexOpe import org.opensearch.indexmanagement.controlcenter.notification.resthandler.RestDeleteLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.resthandler.RestGetLRONConfigAction import org.opensearch.indexmanagement.controlcenter.notification.resthandler.RestIndexLRONConfigAction -import org.opensearch.indexmanagement.indexstatemanagement.* +import org.opensearch.indexmanagement.indexstatemanagement.DefaultIndexMetadataService +import org.opensearch.indexmanagement.indexstatemanagement.ExtensionStatusChecker +import org.opensearch.indexmanagement.indexstatemanagement.ISMActionsParser +import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider +import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementHistory +import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexCoordinator +import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner +import org.opensearch.indexmanagement.indexstatemanagement.PluginVersionSweepCoordinator +import org.opensearch.indexmanagement.indexstatemanagement.SkipExecution import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexConfig import org.opensearch.indexmanagement.indexstatemanagement.model.Policy import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestAddPolicyAction @@ -137,6 +145,7 @@ import org.opensearch.indexmanagement.snapshotmanagement.settings.SnapshotManage import org.opensearch.indexmanagement.spi.IndexManagementExtension import org.opensearch.indexmanagement.spi.indexstatemanagement.IndexMetadataService import org.opensearch.indexmanagement.spi.indexstatemanagement.StatusChecker +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.transform.TargetIndexMappingService import org.opensearch.indexmanagement.transform.TransformRunner @@ -171,7 +180,12 @@ import org.opensearch.jobscheduler.spi.JobSchedulerExtension import org.opensearch.jobscheduler.spi.ScheduledJobParser import org.opensearch.jobscheduler.spi.ScheduledJobRunner import org.opensearch.monitor.jvm.JvmService -import org.opensearch.plugins.* +import org.opensearch.plugins.ActionPlugin +import org.opensearch.plugins.ExtensiblePlugin +import org.opensearch.plugins.NetworkPlugin +import org.opensearch.plugins.Plugin +import org.opensearch.plugins.SystemIndexPlugin +import org.opensearch.plugins.TelemetryAwarePlugin import org.opensearch.repositories.RepositoriesService import org.opensearch.rest.RestController import org.opensearch.rest.RestHandler diff --git a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt index ea7ed3765..6db0d079a 100644 --- a/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt +++ b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/ManagedIndexRunner.kt @@ -86,6 +86,7 @@ import org.opensearch.indexmanagement.opensearchapi.withClosableContext import org.opensearch.indexmanagement.spi.indexstatemanagement.Action import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.Validate +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.PolicyRetryInfoMetaData @@ -121,6 +122,7 @@ object ManagedIndexRunner : private lateinit var skipExecFlag: SkipExecution private lateinit var threadPool: ThreadPool private lateinit var extensionStatusChecker: ExtensionStatusChecker + lateinit var indexManagementActionMetrics: IndexManagementActionsMetrics private lateinit var indexMetadataProvider: IndexMetadataProvider private var indexStateManagementEnabled: Boolean = DEFAULT_ISM_ENABLED private var validationServiceEnabled: Boolean = DEFAULT_ACTION_VALIDATION_ENABLED @@ -221,6 +223,11 @@ object ManagedIndexRunner : return this } + fun registerIndexManagementActionMetrics(indexManagementActionsMetrics: IndexManagementActionsMetrics): Any { + this.indexManagementActionMetrics = indexManagementActionsMetrics + return this + } + override fun runJob(job: ScheduledJobParameter, context: JobExecutionContext) { if (job !is ManagedIndexConfig) { throw IllegalArgumentException("Invalid job type, found ${job.javaClass.simpleName} with id: ${context.jobId}") @@ -446,7 +453,7 @@ object ManagedIndexRunner : managedIndexConfig.id, settings, threadPool.threadContext, managedIndexConfig.policy.user, ), ) { - step.preExecute(logger, stepContext.getUpdatedContext(startingManagedIndexMetaData)).execute().postExecute(logger) + step.preExecute(logger, stepContext.getUpdatedContext(startingManagedIndexMetaData)).execute(indexManagementActionMetrics).postExecute(logger) } var executedManagedIndexMetaData = startingManagedIndexMetaData.getCompletedManagedIndexMetaData(action, step) 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 5b7d455d5..fb8f40d56 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,9 +27,12 @@ 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 +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -39,13 +42,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(): Step { + override suspend fun execute(indexManagementActionsMetrics: IndexManagementActionsMetrics): 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 = indexManagementActionsMetrics + this.actionMetrics = indexManagementActionsMetrics.getActionMetrics("rollover") as RolloverActionMetrics if (skipRollover) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSkipRolloverMessage(indexName)) @@ -68,6 +75,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { if (!isDataStream && !preCheckIndexAlias(context, rolloverTarget)) { stepStatus = StepStatus.FAILED info = mapOf("message" to getFailedPreCheckMessage(indexName)) + actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context.metadata.index).addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName)) return this } @@ -155,6 +163,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) + actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context.metadata.index).addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName)) } return rolloverTarget to isDataStreamIndex @@ -211,6 +220,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) + actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context.metadata.index).addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName)) } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) } catch (e: Exception) { @@ -310,6 +320,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), if (conditions != null) "conditions" to conditions else null, ).toMap() + actionMetrics.successes.add(1.0, Tags.create().addTag("index_name", context?.metadata?.index).addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName)) return } @@ -337,6 +348,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { val aliasRes: AcknowledgedResponse = client.admin().indices().suspendUntil { aliases(aliasReq, it) } if (aliasRes.isAcknowledged) { stepStatus = StepStatus.COMPLETED + actionMetrics.successes.add(1.0, Tags.create().addTag("index_name", context?.metadata?.index).addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName)) info = listOfNotNull( "message" to getSuccessCopyAliasMessage(indexName, rolledOverIndexName), @@ -344,6 +356,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { ).toMap() } else { stepStatus = StepStatus.FAILED + actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context?.metadata?.index).addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName)) info = listOfNotNull( "message" to getCopyAliasNotAckMessage(indexName, rolledOverIndexName), From c3b2846d0eb859f9fa9cad067bb150bf742c81a6 Mon Sep 17 00:00:00 2001 From: harycash Date: Thu, 13 Jun 2024 10:33:22 +0530 Subject: [PATCH 03/14] Initial integration of TelemetryAwarePlugin to ISM with Rollover Step Integration Signed-off-by: harycash --- .../indexstatemanagement/Step.kt | 3 ++- .../step/alias/AttemptAliasActionsStep.kt | 3 ++- .../step/allocation/AttemptAllocationStep.kt | 3 ++- .../step/close/AttemptCloseStep.kt | 3 ++- .../step/delete/AttemptDeleteStep.kt | 3 ++- .../forcemerge/AttemptCallForceMergeStep.kt | 3 ++- .../step/forcemerge/AttemptSetReadOnlyStep.kt | 3 ++- .../step/forcemerge/WaitForForceMergeStep.kt | 3 ++- .../AttemptSetIndexPriorityStep.kt | 3 ++- .../notification/AttemptNotificationStep.kt | 3 ++- .../step/open/AttemptOpenStep.kt | 3 ++- .../step/readonly/SetReadOnlyStep.kt | 3 ++- .../step/readwrite/SetReadWriteStep.kt | 3 ++- .../replicacount/AttemptReplicaCountStep.kt | 3 ++- .../step/rollup/AttemptCreateRollupJobStep.kt | 3 ++- .../rollup/WaitForRollupCompletionStep.kt | 3 ++- .../step/shrink/ShrinkStep.kt | 3 ++- .../step/snapshot/AttemptSnapshotStep.kt | 3 ++- .../step/snapshot/WaitForSnapshotStep.kt | 3 ++- .../AttemptCreateTransformJobStep.kt | 3 ++- .../WaitForTransformCompletionStep.kt | 3 ++- .../step/transition/AttemptTransitionStep.kt | 3 ++- .../extension/SampleCustomActionParser.kt | 3 ++- .../step/AttemptCloseStepTests.kt | 13 ++++++------ .../step/AttemptDeleteStepTests.kt | 9 ++++---- .../step/AttemptOpenStepTests.kt | 7 ++++--- .../step/AttemptRolloverStepTests.kt | 9 ++++---- .../step/AttemptSetIndexPriorityStepTests.kt | 9 ++++---- .../step/AttemptSetReplicaCountStepTests.kt | 7 ++++--- .../step/AttemptSnapshotStepTests.kt | 15 ++++++------- .../step/AttemptTransitionStepTests.kt | 7 ++++--- .../step/SetReadOnlyStepTests.kt | 7 ++++--- .../step/SetReadWriteStepTests.kt | 7 ++++--- .../step/WaitForRollupCompletionStepTests.kt | 3 ++- .../step/WaitForSnapshotStepTests.kt | 21 ++++++++++--------- .../WaitForTransformCompletionStepTests.kt | 3 ++- 36 files changed, 111 insertions(+), 75 deletions(-) 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 8de821936..00faea817 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 @@ -9,6 +9,7 @@ import org.apache.logging.log4j.Logger import org.opensearch.core.common.io.stream.StreamInput import org.opensearch.core.common.io.stream.StreamOutput import org.opensearch.core.common.io.stream.Writeable +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 +26,7 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { return this } - abstract suspend fun execute(): Step + abstract suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step fun postExecute(logger: Logger): Step { logger.info("Finished executing $name for ${context?.metadata?.index}") 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 f756fe547..64135ab59 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,6 +11,7 @@ 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 @@ -19,7 +20,7 @@ class AttemptAliasActionsStep(private val action: AliasAction) : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 1c42612ba..135ac31d3 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,6 +12,7 @@ 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 @@ -20,7 +21,7 @@ class AttemptAllocationStep(private val action: AllocationAction) : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 5e4b01fdd..b570366ed 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,6 +11,7 @@ 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 @@ -21,7 +22,7 @@ class AttemptCloseStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { val context = this.context ?: return this val indexName = context.metadata.index try { 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 bbbc390d3..30cfab0dc 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,6 +11,7 @@ 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.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.snapshots.SnapshotInProgressException @@ -21,7 +22,7 @@ class AttemptDeleteStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { val context = this.context ?: return this val indexName = context.metadata.index try { 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 3ff796e55..564bc4e23 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,6 +19,7 @@ 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.StepMetaData @@ -31,7 +32,7 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam private var info: Map? = null @Suppress("TooGenericExceptionCaught", "ComplexMethod") - override suspend fun execute(): AttemptCallForceMergeStep { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): AttemptCallForceMergeStep { val context = this.context ?: return this val indexName = context.metadata.index try { 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 1f931404b..1d477238e 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,6 +14,7 @@ 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 @@ -25,7 +26,7 @@ class AttemptSetReadOnlyStep(private val action: ForceMergeAction) : Step(name) private var info: Map? = null @Suppress("ReturnCount") - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 612739251..cacee486e 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,6 +13,7 @@ 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 @@ -26,7 +27,7 @@ class WaitForForceMergeStep(private val action: ForceMergeAction) : Step(name, f private var info: Map? = null @Suppress("TooGenericExceptionCaught", "ReturnCount") - override suspend fun execute(): WaitForForceMergeStep { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 09aaa5b0b..1aa49ae92 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,6 +14,7 @@ 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 @@ -24,7 +25,7 @@ class AttemptSetIndexPriorityStep(private val action: IndexPriorityAction) : Ste private var info: Map? = null @Suppress("TooGenericExceptionCaught") - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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/notification/AttemptNotificationStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt index 04cdd2bc0..4cc119806 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,6 +11,7 @@ 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.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.script.Script @@ -22,7 +23,7 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { val context = this.context ?: return this val indexName = context.metadata.index val scriptService = context.scriptService 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 7f384f845..4be84314e 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,6 +11,7 @@ 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 @@ -20,7 +21,7 @@ class AttemptOpenStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 2560bb208..61b6fe8ce 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,6 +13,7 @@ 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 @@ -22,7 +23,7 @@ class SetReadOnlyStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 11e634c7a..68b2815ab 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,6 +13,7 @@ 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 @@ -22,7 +23,7 @@ class SetReadWriteStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 68eccae8f..856711675 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,6 +14,7 @@ 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.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -24,7 +25,7 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam private var info: Map? = null private val numOfReplicas = action.numOfReplicas - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { val context = this.context ?: return this val indexName = context.metadata.index try { 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 ee166ec4a..1ddc01a35 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,6 +20,7 @@ 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 @@ -32,7 +33,7 @@ class AttemptCreateRollupJobStep(private val action: RollupAction) : Step(name) private var info: Map? = null private var rollupId: String? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 7bdc1f4be..c5c0efc94 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,6 +12,7 @@ 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 @@ -22,7 +23,7 @@ class WaitForRollupCompletionStep : Step(name) { private var info: Map? = null private var hasRollupFailed: Boolean? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 e0baae6a0..8e57a264e 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,6 +18,7 @@ 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 @@ -34,7 +35,7 @@ abstract class ShrinkStep( protected var shrinkActionProperties: ShrinkActionProperties? = null @Suppress("ReturnCount") - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 6e02ad716..7561a305c 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,6 +16,7 @@ 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 @@ -37,7 +38,7 @@ class AttemptSnapshotStep(private val action: SnapshotAction) : Step(name) { private var snapshotName: String? = null @Suppress("TooGenericExceptionCaught", "ComplexMethod", "ReturnCount", "LongMethod") - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 36157f5c9..e1f6b8868 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,6 +14,7 @@ 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 @@ -25,7 +26,7 @@ class WaitForSnapshotStep(private val action: SnapshotAction) : Step(name) { private var info: Map? = null @Suppress("ComplexMethod", "ReturnCount") - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 41aa6ff92..f79cda616 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,6 +15,7 @@ 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 @@ -35,7 +36,7 @@ class AttemptCreateTransformJobStep( private var info: Map? = null private var transformId: String? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 8b2085403..ac199b438 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,6 +9,7 @@ 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 @@ -24,7 +25,7 @@ class WaitForTransformCompletionStep : Step(name) { private var stepStatus = StepStatus.STARTING private var info: Map? = null - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 cd12916cd..7dc74e693 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,6 +21,7 @@ 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.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.transport.RemoteTransportException @@ -34,7 +35,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) private var info: Map? = null @Suppress("ReturnCount", "ComplexMethod", "LongMethod", "NestedBlockDepth") - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): Step { val context = this.context ?: return this val indexName = context.metadata.index val clusterService = context.clusterService 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 b896ef231..08c30df0f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/extension/SampleCustomActionParser.kt @@ -14,6 +14,7 @@ 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 @@ -73,7 +74,7 @@ class SampleCustomActionParser : ActionParser() { class SampleCustomStep : Step(name) { private var stepStatus = StepStatus.STARTING - override suspend fun execute(): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 a7e2851e6..f0ce7dfcf 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt @@ -18,6 +18,7 @@ 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.close.AttemptCloseStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -43,7 +44,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() + attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -57,7 +58,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() + attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -71,7 +72,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() + attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -85,7 +86,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() + attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -99,7 +100,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() + attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -113,7 +114,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() + attemptCloseStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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/AttemptDeleteStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt index 4dcd6e2f1..e3a23c09a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt @@ -18,6 +18,7 @@ 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.delete.AttemptDeleteStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -41,7 +42,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute() + attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -55,7 +56,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute() + attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -69,7 +70,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute() + attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) @@ -84,7 +85,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute() + attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt index c0797e3d9..a06e54a4f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt @@ -18,6 +18,7 @@ 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.open.AttemptOpenStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -41,7 +42,7 @@ class AttemptOpenStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptOpenStep = AttemptOpenStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptOpenStep.preExecute(logger, context).execute() + attemptOpenStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptOpenStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -55,7 +56,7 @@ class AttemptOpenStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptOpenStep = AttemptOpenStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptOpenStep.preExecute(logger, context).execute() + attemptOpenStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptOpenStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -69,7 +70,7 @@ class AttemptOpenStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptOpenStep = AttemptOpenStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptOpenStep.preExecute(logger, context).execute() + attemptOpenStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptOpenStep.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 69f674f12..beabc39d6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt @@ -24,6 +24,7 @@ import org.opensearch.cluster.service.ClusterService import org.opensearch.common.settings.Settings import org.opensearch.core.action.ActionListener import org.opensearch.index.IndexNotFoundException +import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverAction import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep @@ -83,7 +84,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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")) @@ -108,7 +109,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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")) @@ -133,7 +134,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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")) @@ -158,7 +159,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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/AttemptSetIndexPriorityStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt index 6842b4dc4..cb580b9d4 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt @@ -18,6 +18,7 @@ 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.action.IndexPriorityAction import org.opensearch.indexmanagement.indexstatemanagement.step.indexpriority.AttemptSetIndexPriorityStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -43,7 +44,7 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute() + attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -58,7 +59,7 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute() + attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -73,7 +74,7 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute() + attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) @@ -89,7 +90,7 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute() + attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt index 30f2e6639..4b29d594a 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt @@ -18,6 +18,7 @@ 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.action.ReplicaCountAction import org.opensearch.indexmanagement.indexstatemanagement.step.replicacount.AttemptReplicaCountStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -43,7 +44,7 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val replicaCountStep = AttemptReplicaCountStep(replicaCountAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - replicaCountStep.preExecute(logger, context).execute() + replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -58,7 +59,7 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val replicaCountStep = AttemptReplicaCountStep(replicaCountAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - replicaCountStep.preExecute(logger, context).execute() + replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -73,7 +74,7 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) val replicaCountStep = AttemptReplicaCountStep(replicaCountAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - replicaCountStep.preExecute(logger, context).execute() + replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = replicaCountStep.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/AttemptSnapshotStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt index 2cc7040db..8024993dd 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt @@ -22,6 +22,7 @@ import org.opensearch.common.settings.ClusterSettings import org.opensearch.common.settings.Settings import org.opensearch.core.action.ActionListener import org.opensearch.core.rest.RestStatus +import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.randomSnapshotActionConfig import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.SNAPSHOT_DENY_LIST import org.opensearch.indexmanagement.indexstatemanagement.step.snapshot.AttemptSnapshotStep @@ -60,7 +61,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -69,7 +70,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -78,7 +79,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -90,7 +91,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -103,7 +104,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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 failed concurrent message", AttemptSnapshotStep.getFailedConcurrentSnapshotMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -116,7 +117,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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 failed concurrent message", AttemptSnapshotStep.getFailedConcurrentSnapshotMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -129,7 +130,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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", "some error", updatedManagedIndexMetaData.info!!["cause"]) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt index 496c4f3b4..d5900eb4d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt @@ -28,6 +28,7 @@ import org.opensearch.core.action.ActionListener import org.opensearch.core.rest.RestStatus import org.opensearch.index.shard.DocsStats import org.opensearch.indexmanagement.indexstatemanagement.IndexMetadataProvider +import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.action.TransitionsAction import org.opensearch.indexmanagement.indexstatemanagement.model.Conditions import org.opensearch.indexmanagement.indexstatemanagement.model.Transition @@ -87,7 +88,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val transitionsAction = TransitionsAction(listOf(Transition("some_state", Conditions(docCount = 5L))), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) val context = StepContext(managedIndexMetadata, clusterService, client, null, null, scriptService, settings, lockService) - attemptTransitionStep.preExecute(logger, context).execute() + attemptTransitionStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptTransitionStep.getUpdatedManagedIndexMetadata(managedIndexMetadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get correct failed message", AttemptTransitionStep.getFailedStatsMessage(indexName), updatedManagedIndexMetaData.info!!["message"]) @@ -105,7 +106,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val transitionsAction = TransitionsAction(listOf(Transition("some_state", Conditions(docCount = 5L))), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) val context = StepContext(managedIndexMetadata, clusterService, client, null, null, scriptService, settings, lockService) - attemptTransitionStep.preExecute(logger, context).execute() + attemptTransitionStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptTransitionStep.getUpdatedManagedIndexMetadata(managedIndexMetadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "example", updatedManagedIndexMetaData.info!!["cause"]) @@ -123,7 +124,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val transitionsAction = TransitionsAction(listOf(Transition("some_state", Conditions(docCount = 5L))), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) val context = StepContext(managedIndexMetadata, clusterService, client, null, null, scriptService, settings, lockService) - attemptTransitionStep.preExecute(logger, context).execute() + attemptTransitionStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptTransitionStep.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/SetReadOnlyStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt index a3a70ca6c..b9431f1a1 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt @@ -18,6 +18,7 @@ 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 @@ -41,7 +42,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() + setReadOnlyStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -55,7 +56,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() + setReadOnlyStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -69,7 +70,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() + setReadOnlyStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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 77211adde..03c03818d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt @@ -18,6 +18,7 @@ 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.readwrite.SetReadWriteStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -41,7 +42,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() + setReadWriteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = setReadWriteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -55,7 +56,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() + setReadWriteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = setReadWriteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -69,7 +70,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() + setReadWriteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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 8537a3b54..181d94aa5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForRollupCompletionStepTests.kt @@ -10,6 +10,7 @@ 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 @@ -52,7 +53,7 @@ class WaitForRollupCompletionStepTests : OpenSearchTestCase() { val step = WaitForRollupCompletionStep() runBlocking { - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) } 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 ae4d394df..a6a17f7cb 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForSnapshotStepTests.kt @@ -20,6 +20,7 @@ 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 @@ -50,7 +51,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -62,7 +63,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -82,7 +83,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -94,7 +95,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -106,7 +107,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -118,7 +119,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -130,7 +131,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -149,7 +150,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -164,7 +165,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) @@ -179,7 +180,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() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) 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"]) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt index bbd0bc99e..8f945cf26 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt @@ -10,6 +10,7 @@ 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.transform.AttemptCreateTransformJobStep import org.opensearch.indexmanagement.indexstatemanagement.step.transform.WaitForTransformCompletionStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -71,7 +72,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { val step = WaitForTransformCompletionStep() runBlocking { - step.preExecute(logger, context).execute() + step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) } val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) From 9eaf83a605f3e88bfbc9c9ff9d741fd177e83bf1 Mon Sep 17 00:00:00 2001 From: harycash Date: Thu, 13 Jun 2024 11:14:13 +0530 Subject: [PATCH 04/14] Initial integration of TelemetryAwarePlugin to ISM with Rollover Step Integration Signed-off-by: harycash --- .../step/rollover/AttemptRolloverStep.kt | 36 +++++++++++++++---- 1 file changed, 30 insertions(+), 6 deletions(-) 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 fb8f40d56..16c5c64d2 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 @@ -75,7 +75,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { if (!isDataStream && !preCheckIndexAlias(context, rolloverTarget)) { stepStatus = StepStatus.FAILED info = mapOf("message" to getFailedPreCheckMessage(indexName)) - actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context.metadata.index).addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName)) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) return this } @@ -163,7 +167,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) - actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context.metadata.index).addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName)) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } return rolloverTarget to isDataStreamIndex @@ -220,7 +228,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) - actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context.metadata.index).addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName)) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) } catch (e: Exception) { @@ -320,7 +332,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), if (conditions != null) "conditions" to conditions else null, ).toMap() - actionMetrics.successes.add(1.0, Tags.create().addTag("index_name", context?.metadata?.index).addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName)) + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) return } @@ -348,7 +364,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { val aliasRes: AcknowledgedResponse = client.admin().indices().suspendUntil { aliases(aliasReq, it) } if (aliasRes.isAcknowledged) { stepStatus = StepStatus.COMPLETED - actionMetrics.successes.add(1.0, Tags.create().addTag("index_name", context?.metadata?.index).addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName)) + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) info = listOfNotNull( "message" to getSuccessCopyAliasMessage(indexName, rolledOverIndexName), @@ -356,7 +376,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { ).toMap() } else { stepStatus = StepStatus.FAILED - actionMetrics.failures.add(1.0, Tags.create().addTag("index_name", context?.metadata?.index).addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName)) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) info = listOfNotNull( "message" to getCopyAliasNotAckMessage(indexName, rolledOverIndexName), From 0c55243b31666ff1a0b06f2ad4e63ec9c400247f Mon Sep 17 00:00:00 2001 From: harycash Date: Thu, 20 Jun 2024 14:05:04 +0530 Subject: [PATCH 05/14] Additional actions metrics with requested changes from previous commit Signed-off-by: harycash --- .../metrics/IndexManagementActionsMetrics.kt | 43 ++++++++++++++----- .../actionmetrics/DeleteActionMetrics.kt | 25 +++++++++++ .../actionmetrics/ForceMergeActionMetrics.kt | 26 +++++++++++ .../NotificationActionMetrics.kt | 25 +++++++++++ .../ReplicaCountActionMetrics.kt | 25 +++++++++++ .../actionmetrics/RolloverActionMetrics.kt | 5 ++- .../actionmetrics/TransitionActionMetrics.kt | 25 +++++++++++ .../step/delete/AttemptDeleteStep.kt | 27 +++++++++--- .../forcemerge/AttemptCallForceMergeStep.kt | 21 +++++++++ .../notification/AttemptNotificationStep.kt | 17 ++++++++ .../replicacount/AttemptReplicaCountStep.kt | 21 +++++++++ .../step/rollover/AttemptRolloverStep.kt | 31 +++++++++++-- .../step/transition/AttemptTransitionStep.kt | 37 ++++++++++++++++ 13 files changed, 307 insertions(+), 21 deletions(-) create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/DeleteActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ForceMergeActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/NotificationActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ReplicaCountActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/TransitionActionMetrics.kt 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 def480ab7..52a93b4f5 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 @@ -1,6 +1,11 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics +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.NotificationActionMetrics +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.TransitionActionMetrics import org.opensearch.telemetry.metrics.MetricsRegistry abstract class ActionMetrics { @@ -11,26 +16,42 @@ class IndexManagementActionsMetrics private constructor() { private lateinit var metricsRegistry: MetricsRegistry private lateinit var actionMetricsMap: Map + companion object { + val instance: IndexManagementActionsMetrics by lazy { HOLDER.instance } + + const val ROLLOVER = "rollover" + const val NOTIFICATION = "notification" + const val FORCE_MERGE = "force_merge" + const val DELETE = "delete" + const val REPLICA_COUNT = "replica_count" + const val TRANSITION = "transition" + + private object HOLDER { + val instance = IndexManagementActionsMetrics() + } + } + fun initialize(metricsRegistry: MetricsRegistry) { this.metricsRegistry = metricsRegistry - RolloverActionMetrics.instance.initializeCounters(metricsRegistry, "rollover") + RolloverActionMetrics.instance.initializeCounters(metricsRegistry) + NotificationActionMetrics.instance.initializeCounters(metricsRegistry) + ForceMergeActionMetrics.instance.initializeCounters(metricsRegistry) + DeleteActionMetrics.instance.initializeCounters(metricsRegistry) + ReplicaCountActionMetrics.instance.initializeCounters(metricsRegistry) + TransitionActionMetrics.instance.initializeCounters(metricsRegistry) actionMetricsMap = mapOf( - "rollover" to RolloverActionMetrics.instance, - // Add other action metrics here + ROLLOVER to RolloverActionMetrics.instance, + NOTIFICATION to NotificationActionMetrics.instance, + FORCE_MERGE to ForceMergeActionMetrics.instance, + DELETE to DeleteActionMetrics.instance, + REPLICA_COUNT to ReplicaCountActionMetrics.instance, + TRANSITION to TransitionActionMetrics.instance, ) } fun getActionMetrics(actionName: String): ActionMetrics? { return actionMetricsMap[actionName] } - - companion object { - val instance: IndexManagementActionsMetrics by lazy { HOLDER.instance } - } - - private object HOLDER { - val instance = IndexManagementActionsMetrics() - } } 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 new file mode 100644 index 000000000..eb7da58f7 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/DeleteActionMetrics.kt @@ -0,0 +1,25 @@ +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class DeleteActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.DELETE + lateinit var successes: Counter + lateinit var failures: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Delete Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Delete Action Failures", "count") + } + + companion object { + val instance: DeleteActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = DeleteActionMetrics() + } +} 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 new file mode 100644 index 000000000..ddddc0817 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ForceMergeActionMetrics.kt @@ -0,0 +1,26 @@ +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class ForceMergeActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.FORCE_MERGE + lateinit var successes: Counter + lateinit var failures: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = + metricsRegistry.createCounter("${actionName}_successes", "Force Merge Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Force Merge Action Failures", "count") + } + + companion object { + val instance: ForceMergeActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = ForceMergeActionMetrics() + } +} 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 new file mode 100644 index 000000000..b43c18888 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/NotificationActionMetrics.kt @@ -0,0 +1,25 @@ +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class NotificationActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.NOTIFICATION + lateinit var successes: Counter + lateinit var failures: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Notification Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Notification Action Failures", "count") + } + + companion object { + val instance: NotificationActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = NotificationActionMetrics() + } +} 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 new file mode 100644 index 000000000..f46ee9f71 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ReplicaCountActionMetrics.kt @@ -0,0 +1,25 @@ +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class ReplicaCountActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.REPLICA_COUNT + lateinit var successes: Counter + lateinit var failures: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Replica Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Replica Action Failures", "count") + } + + companion object { + val instance: ReplicaCountActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = ReplicaCountActionMetrics() + } +} 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 48e67b0d7..5ed3a1401 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 @@ -1,15 +1,16 @@ package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry class RolloverActionMetrics private constructor() : ActionMetrics() { - override val actionName: String = "rollover_action" + override val actionName: String = IndexManagementActionsMetrics.ROLLOVER lateinit var successes: Counter lateinit var failures: Counter - fun initializeCounters(metricsRegistry: MetricsRegistry, actionName: String) { + fun initializeCounters(metricsRegistry: MetricsRegistry) { successes = metricsRegistry.createCounter("${actionName}_successes", "Rollover Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Rollover Action Failures", "count") } 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 new file mode 100644 index 000000000..dde8e2ac8 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/TransitionActionMetrics.kt @@ -0,0 +1,25 @@ +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class TransitionActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.TRANSITION + lateinit var successes: Counter + lateinit var failures: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Transition Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Transition Action Failures", "count") + } + + companion object { + val instance: TransitionActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = TransitionActionMetrics() + } +} 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 30cfab0dc..a5c367641 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 @@ -1,8 +1,3 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - package org.opensearch.indexmanagement.indexstatemanagement.step.delete import org.apache.logging.log4j.LogManager @@ -12,19 +7,26 @@ 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 +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException 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 { val context = this.context ?: return this val indexName = context.metadata.index + this.indexManagementActionsMetrics = indexManagementActionMetrics + this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.DELETE) as DeleteActionMetrics + try { val response: AcknowledgedResponse = context.client.admin().indices() @@ -33,11 +35,21 @@ class AttemptDeleteStep : Step(name) { if (response.isAcknowledged) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSuccessMessage(indexName)) + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } else { val message = getFailedMessage(indexName) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } } catch (e: RemoteTransportException) { val cause = ExceptionsHelper.unwrapCause(e) @@ -66,6 +78,11 @@ class AttemptDeleteStep : Step(name) { val message = getFailedMessage(indexName) logger.error(message, e) stepStatus = StepStatus.FAILED + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) 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/AttemptCallForceMergeStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/forcemerge/AttemptCallForceMergeStep.kt index 564bc4e23..61b1002ca 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 @@ -20,9 +20,11 @@ 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 +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -30,11 +32,15 @@ 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 { val context = this.context ?: return this val indexName = context.metadata.index + this.indexManagementActionsMetrics = indexManagementActionMetrics + this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.FORCE_MERGE) as ForceMergeActionMetrics try { val startTime = Instant.now().toEpochMilli() val request = ForceMergeRequest(indexName).maxNumSegments(action.maxNumSegments) @@ -62,6 +68,11 @@ 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, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } else { // Otherwise the request to force merge encountered some problem stepStatus = StepStatus.FAILED @@ -71,6 +82,11 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam "status" to shadowedResponse.status, "shard_failures" to shadowedResponse.shardFailures.map { it.getUsefulCauseString() }, ) + actionMetrics.failures.add( // Changed from actionMetrics to indexManagementActionMetrics + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) @@ -85,6 +101,11 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam val message = getFailedMessage(indexName) logger.error(message, e) stepStatus = StepStatus.FAILED + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) 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/notification/AttemptNotificationStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/notification/AttemptNotificationStep.kt index 4cc119806..12925c7b5 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 @@ -12,21 +12,28 @@ 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 import org.opensearch.script.ScriptService import org.opensearch.script.TemplateScript +import org.opensearch.telemetry.metrics.tags.Tags class AttemptNotificationStep(private val action: NotificationAction) : 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: NotificationActionMetrics override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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) action.destination?.buildLegacyBaseMessage(null, compiledMessage)?.publishLegacyNotification(context.client) @@ -34,6 +41,11 @@ 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, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } catch (e: Exception) { handleException(indexName, e) } @@ -49,6 +61,11 @@ 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, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) } override fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData { 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 856711675..dfcd13d4c 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 @@ -15,8 +15,10 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.ReplicaCountAc 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.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(name) { @@ -24,10 +26,14 @@ 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 { val context = this.context ?: return this val indexName = context.metadata.index + this.indexManagementActionsMetrics = indexManagementActionMetrics + this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.REPLICA_COUNT) as ReplicaCountActionMetrics try { val updateSettingsRequest = UpdateSettingsRequest() @@ -40,11 +46,21 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam if (response.isAcknowledged) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSuccessMessage(indexName, numOfReplicas)) + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } else { val message = getFailedMessage(indexName, numOfReplicas) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } } catch (e: RemoteTransportException) { handleException(indexName, numOfReplicas, ExceptionsHelper.unwrapCause(e) as Exception) @@ -59,6 +75,11 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam val message = getFailedMessage(indexName, numOfReplicas) logger.error(message, e) stepStatus = StepStatus.FAILED + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) 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/rollover/AttemptRolloverStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/rollover/AttemptRolloverStep.kt index 16c5c64d2..dcb4d8ea5 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 @@ -46,13 +46,13 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { private lateinit var actionMetrics: RolloverActionMetrics @Suppress("ComplexMethod", "LongMethod") - override suspend fun execute(indexManagementActionsMetrics: IndexManagementActionsMetrics): Step { + override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 = indexManagementActionsMetrics - this.actionMetrics = indexManagementActionsMetrics.getActionMetrics("rollover") as RolloverActionMetrics + this.indexManagementActionsMetrics = indexManagementActionMetrics + this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.ROLLOVER) as RolloverActionMetrics if (skipRollover) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSkipRolloverMessage(indexName)) @@ -142,6 +142,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { ) executeRollover(context, rolloverTarget, isDataStream, conditions) copyAlias(clusterService, indexName, context.client, rolloverTarget, context.metadata) + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } else { stepStatus = StepStatus.CONDITION_NOT_MET info = mapOf("message" to getPendingMessage(indexName), "conditions" to conditions) @@ -276,6 +281,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, if (conditions.isEmpty()) null else "conditions" to conditions, // don't show empty conditions object if no conditions specified ).toMap() + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } else { val message = when { @@ -291,6 +301,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, if (conditions.isEmpty()) null else "conditions" to conditions, // don't show empty conditions object if no conditions specified ).toMap() + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) @@ -395,6 +410,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to getCopyAliasIndexNotFoundMessage(rolledOverIndexName), if (conditions != null) "conditions" to conditions else null, ).toMap() + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) } catch (e: Exception) { handleException(indexName, e, getFailedCopyAliasMessage(indexName, rolledOverIndexName), conditions) } @@ -413,6 +433,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { private fun handleException(indexName: String, e: Exception, message: String = getFailedMessage(indexName), conditions: Any? = null) { logger.error(message, e) stepStatus = StepStatus.FAILED + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) val mutableInfo: MutableMap = 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/transition/AttemptTransitionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt index 7dc74e693..3b3434d94 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 @@ -22,8 +22,10 @@ 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.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -33,6 +35,8 @@ 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 { @@ -41,11 +45,19 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) val clusterService = context.clusterService val transitions = action.transitions val indexMetadataProvider = action.indexMetadataProvider + this.indexManagementActionsMetrics = indexManagementActionMetrics + this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.TRANSITION) as TransitionActionMetrics + try { if (transitions.isEmpty()) { logger.info("$indexName transitions are empty, completing policy") policyCompleted = true stepStatus = StepStatus.COMPLETED + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) return this } @@ -70,6 +82,11 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) return this } } @@ -91,6 +108,11 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) "message" to message, "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) return this } numDocs = statsResponse.primaries.getDocs()?.count ?: 0 @@ -114,9 +136,19 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) ) stepStatus = StepStatus.COMPLETED message = getSuccessMessage(indexName, stateName) + actionMetrics.successes.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } else { stepStatus = StepStatus.CONDITION_NOT_MET message = getEvaluatingMessage(indexName) + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + ) } info = mapOf("message" to message) } catch (e: RemoteTransportException) { @@ -132,6 +164,11 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) val message = getFailedMessage(indexName) logger.error(message, e) stepStatus = StepStatus.FAILED + actionMetrics.failures.add( + 1.0, + Tags.create().addTag("index_name", context?.metadata?.index) + .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + ) val mutableInfo = mutableMapOf("message" to message) val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage From 6d9488fdb5d8b83b184c173594410dfc7fe2f4b2 Mon Sep 17 00:00:00 2001 From: harycash Date: Tue, 25 Jun 2024 00:42:23 +0530 Subject: [PATCH 06/14] Fixed Build Issues Signed-off-by: harycash --- .../step/rollover/AttemptRolloverStep.kt | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) 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 dcb4d8ea5..d3c2330ae 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 @@ -331,22 +331,18 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { rolloverTarget: String, metadata: ManagedIndexMetaData, ) { - if (!action.copyAlias) return - - // Try to preserve the rollover conditions + if (!action.copyAlias) return // Try to preserve the rollover conditions val conditions = info?.get("conditions") ?: context?.metadata?.info?.get("conditions") val rolledOverIndexName = newIndex ?: metadata.rolledOverIndexName - if (rolledOverIndexName == null) { - // Only in rare case when the program shut down unexpectedly before rolledOverIndexName is set or metadata corrupted + if (rolledOverIndexName == null) { // Only in rare case when the program shut down unexpectedly before rolledOverIndexName is set or metadata corrupted // ISM cannot auto recover from this case, so the status is COMPLETED logger.error("$indexName rolled over but cannot find the rolledOverIndexName to copy aliases to") stepStatus = StepStatus.COMPLETED - info = - listOfNotNull( - "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), - if (conditions != null) "conditions" to conditions else null, - ).toMap() + info = listOfNotNull( + "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), + if (conditions != null) "conditions" to conditions else null, + ).toMap() actionMetrics.successes.add( 1.0, Tags.create().addTag("index_name", context?.metadata?.index) From c60a3520341168905979ccf97f93b14d6e7b60da Mon Sep 17 00:00:00 2001 From: harycash Date: Tue, 25 Jun 2024 01:03:37 +0530 Subject: [PATCH 07/14] Fixed Build Issues Signed-off-by: harycash --- .../metrics/IndexManagementActionsMetrics.kt | 5 +++++ .../metrics/actionmetrics/DeleteActionMetrics.kt | 5 +++++ .../metrics/actionmetrics/ForceMergeActionMetrics.kt | 5 +++++ .../metrics/actionmetrics/NotificationActionMetrics.kt | 5 +++++ .../metrics/actionmetrics/ReplicaCountActionMetrics.kt | 5 +++++ .../metrics/actionmetrics/RolloverActionMetrics.kt | 5 +++++ .../metrics/actionmetrics/TransitionActionMetrics.kt | 5 +++++ .../indexstatemanagement/step/delete/AttemptDeleteStep.kt | 5 +++++ .../step/rollover/AttemptRolloverStep.kt | 1 - 9 files changed, 40 insertions(+), 1 deletion(-) 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 52a93b4f5..307019ef2 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.DeleteActionMetrics 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 eb7da58f7..bd5bb0e84 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics 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 ddddc0817..e1bd6df88 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics 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 b43c18888..091de4178 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics 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 f46ee9f71..093112828 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics 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 5ed3a1401..da0e2d5e9 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics 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 dde8e2ac8..cebd44c13 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics 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 a5c367641..ac5fc75a0 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 @@ -1,3 +1,8 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + package org.opensearch.indexmanagement.indexstatemanagement.step.delete import org.apache.logging.log4j.LogManager 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 d3c2330ae..79ea23084 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 @@ -333,7 +333,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { ) { if (!action.copyAlias) return // Try to preserve the rollover conditions val conditions = info?.get("conditions") ?: context?.metadata?.info?.get("conditions") - val rolledOverIndexName = newIndex ?: metadata.rolledOverIndexName if (rolledOverIndexName == null) { // Only in rare case when the program shut down unexpectedly before rolledOverIndexName is set or metadata corrupted // ISM cannot auto recover from this case, so the status is COMPLETED From 96736b9631f5071b54d87f91bb0f5d3c0f6a6e2d Mon Sep 17 00:00:00 2001 From: harycash Date: Wed, 26 Jun 2024 19:38:19 +0530 Subject: [PATCH 08/14] Fixed Build Issues, Added new metric : Cumulative Latency Signed-off-by: harycash --- .../metrics/IndexManagementActionsMetrics.kt | 10 +++ .../actionmetrics/DeleteActionMetrics.kt | 2 + .../actionmetrics/ForceMergeActionMetrics.kt | 5 +- .../NotificationActionMetrics.kt | 2 + .../ReplicaCountActionMetrics.kt | 2 + .../actionmetrics/RolloverActionMetrics.kt | 2 + .../actionmetrics/TransitionActionMetrics.kt | 2 + .../step/delete/AttemptDeleteStep.kt | 34 ++++---- .../forcemerge/AttemptCallForceMergeStep.kt | 12 +-- .../notification/AttemptNotificationStep.kt | 7 +- .../replicacount/AttemptReplicaCountStep.kt | 34 ++++---- .../step/rollover/AttemptRolloverStep.kt | 86 ++++++------------- .../step/transition/AttemptTransitionStep.kt | 53 +++++------- .../step/AttemptCloseStepTests.kt | 16 ++++ .../step/AttemptDeleteStepTests.kt | 25 ++++++ .../step/AttemptOpenStepTests.kt | 15 ++++ .../step/AttemptRolloverStepTests.kt | 23 +++++ .../step/AttemptSetIndexPriorityStepTests.kt | 16 ++++ .../step/AttemptSetReplicaCountStepTests.kt | 25 ++++++ .../step/AttemptTransitionStepTests.kt | 20 +++++ .../step/SetReadWriteStepTests.kt | 16 ++++ 21 files changed, 266 insertions(+), 141 deletions(-) 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 307019ef2..5aca52de4 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 @@ -11,10 +11,20 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmet 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.TransitionActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags abstract class ActionMetrics { abstract val actionName: String + + fun createTags(context: StepContext): Tags { + val tags = Tags.create() + .addTag("index_name", context.metadata.index) + .addTag("policy_id", context.metadata.policyID) + .addTag("node_id", context.clusterService.nodeName ?: "") + return tags + } } class IndexManagementActionsMetrics private constructor() { 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 bd5bb0e84..1d4390cb9 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 @@ -14,10 +14,12 @@ class DeleteActionMetrics private constructor() : ActionMetrics() { override val actionName: String = IndexManagementActionsMetrics.DELETE lateinit var successes: Counter lateinit var failures: Counter + lateinit var cumulativeLatency: Counter fun initializeCounters(metricsRegistry: MetricsRegistry) { successes = metricsRegistry.createCounter("${actionName}_successes", "Delete Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Delete Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Delete Action", "milliseconds") } companion object { 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 e1bd6df88..93f3c2220 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 @@ -14,11 +14,12 @@ class ForceMergeActionMetrics private constructor() : ActionMetrics() { override val actionName: String = IndexManagementActionsMetrics.FORCE_MERGE lateinit var successes: Counter lateinit var failures: Counter + lateinit var cumulativeLatency: Counter fun initializeCounters(metricsRegistry: MetricsRegistry) { - successes = - metricsRegistry.createCounter("${actionName}_successes", "Force Merge Action Successes", "count") + successes = metricsRegistry.createCounter("${actionName}_successes", "Force Merge Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Force Merge Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Force Merge Action", "milliseconds") } companion object { 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 091de4178..c1f897740 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 @@ -14,10 +14,12 @@ class NotificationActionMetrics private constructor() : ActionMetrics() { override val actionName: String = IndexManagementActionsMetrics.NOTIFICATION lateinit var successes: Counter lateinit var failures: Counter + lateinit var cumulativeLatency: Counter fun initializeCounters(metricsRegistry: MetricsRegistry) { successes = metricsRegistry.createCounter("${actionName}_successes", "Notification Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Notification Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Notification Action", "milliseconds") } companion object { 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 093112828..82254270e 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 @@ -14,10 +14,12 @@ class ReplicaCountActionMetrics private constructor() : ActionMetrics() { override val actionName: String = IndexManagementActionsMetrics.REPLICA_COUNT lateinit var successes: Counter lateinit var failures: Counter + lateinit var cumulativeLatency: Counter fun initializeCounters(metricsRegistry: MetricsRegistry) { successes = metricsRegistry.createCounter("${actionName}_successes", "Replica Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Replica Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Replica Count Action", "milliseconds") } companion object { 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 da0e2d5e9..45c07a73e 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 @@ -14,10 +14,12 @@ class RolloverActionMetrics private constructor() : ActionMetrics() { override val actionName: String = IndexManagementActionsMetrics.ROLLOVER lateinit var successes: Counter lateinit var failures: Counter + lateinit var cumulativeLatency: Counter fun initializeCounters(metricsRegistry: MetricsRegistry) { successes = metricsRegistry.createCounter("${actionName}_successes", "Rollover Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Rollover Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Rollover Actions", "milliseconds") } companion object { 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 cebd44c13..6f17909e6 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 @@ -14,10 +14,12 @@ class TransitionActionMetrics private constructor() : ActionMetrics() { override val actionName: String = IndexManagementActionsMetrics.TRANSITION lateinit var successes: Counter lateinit var failures: Counter + lateinit var cumulativeLatency: Counter fun initializeCounters(metricsRegistry: MetricsRegistry) { successes = metricsRegistry.createCounter("${actionName}_successes", "Transition Action Successes", "count") failures = metricsRegistry.createCounter("${actionName}_failures", "Transition Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Transition Actions", "milliseconds") } companion object { 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 ac5fc75a0..2f1e19d2e 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 @@ -16,7 +16,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmet import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.snapshots.SnapshotInProgressException -import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException class AttemptDeleteStep : Step(name) { @@ -31,6 +30,7 @@ class AttemptDeleteStep : Step(name) { val indexName = context.metadata.index this.indexManagementActionsMetrics = indexManagementActionMetrics this.actionMetrics = indexManagementActionMetrics.getActionMetrics(IndexManagementActionsMetrics.DELETE) as DeleteActionMetrics + val startTime = System.currentTimeMillis() try { val response: AcknowledgedResponse = @@ -40,21 +40,11 @@ class AttemptDeleteStep : Step(name) { if (response.isAcknowledged) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSuccessMessage(indexName)) - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } else { val message = getFailedMessage(indexName) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } } catch (e: RemoteTransportException) { val cause = ExceptionsHelper.unwrapCause(e) @@ -68,7 +58,7 @@ class AttemptDeleteStep : Step(name) { } catch (e: Exception) { handleException(indexName, e) } - + emitDeleteActionMetrics(startTime) return this } @@ -83,11 +73,6 @@ class AttemptDeleteStep : Step(name) { val message = getFailedMessage(indexName) logger.error(message, e) stepStatus = StepStatus.FAILED - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) val mutableInfo = mutableMapOf("message" to message) val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage @@ -102,6 +87,21 @@ 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 61b1002ca..152fe3489 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 @@ -24,7 +24,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmet import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -70,8 +69,7 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam info = mapOf("message" to if (shadowedResponse == null) getSuccessfulCallMessage(indexName) else getSuccessMessage(indexName)) actionMetrics.successes.add( 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + actionMetrics.createTags(context), ) } else { // Otherwise the request to force merge encountered some problem @@ -82,10 +80,9 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam "status" to shadowedResponse.status, "shard_failures" to shadowedResponse.shardFailures.map { it.getUsefulCauseString() }, ) - actionMetrics.failures.add( // Changed from actionMetrics to indexManagementActionMetrics + actionMetrics.failures.add( 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + actionMetrics.createTags(context), ) } } catch (e: RemoteTransportException) { @@ -103,8 +100,7 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam stepStatus = StepStatus.FAILED actionMetrics.failures.add( 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + context?.let { actionMetrics.createTags(it) }, ) val mutableInfo = mutableMapOf("message" to message) val errorMessage = e.message 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 12925c7b5..e294f46be 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 @@ -18,7 +18,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaDat import org.opensearch.script.Script import org.opensearch.script.ScriptService import org.opensearch.script.TemplateScript -import org.opensearch.telemetry.metrics.tags.Tags class AttemptNotificationStep(private val action: NotificationAction) : Step(name) { private val logger = LogManager.getLogger(javaClass) @@ -43,8 +42,7 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam info = mapOf("message" to getSuccessMessage(indexName)) actionMetrics.successes.add( 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), + actionMetrics.createTags(context), ) } catch (e: Exception) { handleException(indexName, e) @@ -63,8 +61,7 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam info = mutableInfo.toMap() actionMetrics.failures.add( 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), + context?.let { actionMetrics.createTags(it) }, ) } 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 dfcd13d4c..b089461f9 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 @@ -18,7 +18,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexMana 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.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(name) { @@ -32,6 +31,7 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam override suspend fun execute(indexManagementActionMetrics: IndexManagementActionsMetrics): 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 { @@ -46,28 +46,18 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam if (response.isAcknowledged) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSuccessMessage(indexName, numOfReplicas)) - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } else { val message = getFailedMessage(indexName, numOfReplicas) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } } catch (e: RemoteTransportException) { handleException(indexName, numOfReplicas, ExceptionsHelper.unwrapCause(e) as Exception) } catch (e: Exception) { handleException(indexName, numOfReplicas, e) } - + emitReplicaCountActionMetrics(startTime) return this } @@ -75,11 +65,6 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam val message = getFailedMessage(indexName, numOfReplicas) logger.error(message, e) stepStatus = StepStatus.FAILED - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) val mutableInfo = mutableMapOf("message" to message) val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage @@ -94,6 +79,21 @@ 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 79ea23084..f8f1ad791 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 @@ -32,7 +32,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmet import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData -import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -53,15 +52,22 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { 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 } val (rolloverTarget, isDataStream) = getRolloverTargetOrUpdateInfo(context) // If the rolloverTarget is null, we would've already updated the failed info from getRolloverTargetOrUpdateInfo and can return early - rolloverTarget ?: return this + + if (rolloverTarget == null) { + emitRolloverMetrics(startTime) + return this + } if (clusterService.state().metadata.index(indexName).rolloverInfos.containsKey(rolloverTarget)) { stepStatus = StepStatus.COMPLETED @@ -69,23 +75,23 @@ 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)) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) + emitRolloverMetrics(startTime) return this } val statsResponse = getIndexStatsOrUpdateInfo(context) // If statsResponse is null we already updated failed info from getIndexStatsOrUpdateInfo and can return early - statsResponse ?: return this + if (statsResponse == null) { + emitRolloverMetrics(startTime) + return this + } val indexCreationDate = clusterService.state().metadata().index(indexName).creationDate val indexAgeTimeValue = @@ -142,16 +148,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { ) executeRollover(context, rolloverTarget, isDataStream, conditions) copyAlias(clusterService, indexName, context.client, rolloverTarget, context.metadata) - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } else { stepStatus = StepStatus.CONDITION_NOT_MET info = mapOf("message" to getPendingMessage(indexName), "conditions" to conditions) } - + emitRolloverMetrics(startTime) return this } @@ -172,11 +173,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } return rolloverTarget to isDataStreamIndex @@ -233,11 +229,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) } catch (e: Exception) { @@ -281,11 +272,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, if (conditions.isEmpty()) null else "conditions" to conditions, // don't show empty conditions object if no conditions specified ).toMap() - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } else { val message = when { @@ -301,11 +287,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to message, if (conditions.isEmpty()) null else "conditions" to conditions, // don't show empty conditions object if no conditions specified ).toMap() - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } } catch (e: RemoteTransportException) { handleException(indexName, ExceptionsHelper.unwrapCause(e) as Exception) @@ -342,11 +323,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), if (conditions != null) "conditions" to conditions else null, ).toMap() - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) return } @@ -374,11 +350,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { val aliasRes: AcknowledgedResponse = client.admin().indices().suspendUntil { aliases(aliasReq, it) } if (aliasRes.isAcknowledged) { stepStatus = StepStatus.COMPLETED - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) info = listOfNotNull( "message" to getSuccessCopyAliasMessage(indexName, rolledOverIndexName), @@ -386,11 +357,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { ).toMap() } else { stepStatus = StepStatus.FAILED - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) info = listOfNotNull( "message" to getCopyAliasNotAckMessage(indexName, rolledOverIndexName), @@ -405,11 +371,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { "message" to getCopyAliasIndexNotFoundMessage(rolledOverIndexName), if (conditions != null) "conditions" to conditions else null, ).toMap() - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) } catch (e: Exception) { handleException(indexName, e, getFailedCopyAliasMessage(indexName, rolledOverIndexName), conditions) } @@ -428,11 +389,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { private fun handleException(indexName: String, e: Exception, message: String = getFailedMessage(indexName), conditions: Any? = null) { logger.error(message, e) stepStatus = StepStatus.FAILED - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) val mutableInfo: MutableMap = mutableMapOf("message" to message) val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage @@ -440,6 +396,18 @@ 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/transition/AttemptTransitionStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/transition/AttemptTransitionStep.kt index 3b3434d94..8726377df 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 @@ -25,7 +25,6 @@ import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexMana 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.telemetry.metrics.tags.Tags import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -47,17 +46,13 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) 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 - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) + emitTransitionMetrics(startTime) return this } @@ -82,11 +77,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) logger.warn(message) stepStatus = StepStatus.FAILED info = mapOf("message" to message) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) + emitTransitionMetrics(startTime) return this } } @@ -108,11 +99,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) "message" to message, "shard_failures" to statsResponse.shardFailures.map { it.getUsefulCauseString() }, ) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) + emitTransitionMetrics(startTime) return this } numDocs = statsResponse.primaries.getDocs()?.count ?: 0 @@ -136,19 +123,9 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) ) stepStatus = StepStatus.COMPLETED message = getSuccessMessage(indexName, stateName) - actionMetrics.successes.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } else { stepStatus = StepStatus.CONDITION_NOT_MET message = getEvaluatingMessage(indexName) - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context.metadata.index) - .addTag("policy_id", context.metadata.policyID).addTag("node_id", context.clusterService.nodeName), - ) } info = mapOf("message" to message) } catch (e: RemoteTransportException) { @@ -156,7 +133,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) } catch (e: Exception) { handleException(indexName, e) } - + emitTransitionMetrics(startTime) return this } @@ -164,11 +141,6 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) val message = getFailedMessage(indexName) logger.error(message, e) stepStatus = StepStatus.FAILED - actionMetrics.failures.add( - 1.0, - Tags.create().addTag("index_name", context?.metadata?.index) - .addTag("policy_id", context?.metadata?.policyID).addTag("node_id", context?.clusterService?.nodeName), - ) val mutableInfo = mutableMapOf("message" to message) val errorMessage = e.message if (errorMessage != null) mutableInfo["cause"] = errorMessage @@ -217,6 +189,21 @@ 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/step/AttemptCloseStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt index f0ce7dfcf..35a213cd5 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt @@ -11,6 +11,8 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString import org.opensearch.action.admin.indices.close.CloseIndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -21,11 +23,14 @@ import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.close.AttemptCloseStep 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.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService import org.opensearch.snapshots.SnapshotInProgressException +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException import kotlin.IllegalArgumentException @@ -35,6 +40,17 @@ class AttemptCloseStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + } fun `test close step sets step status to completed when successful`() { val closeIndexResponse = CloseIndexResponse(true, true, listOf()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt index e3a23c09a..33909f296 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt @@ -8,8 +8,12 @@ package org.opensearch.indexmanagement.indexstatemanagement.step import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito.doAnswer import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient @@ -21,11 +25,16 @@ import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.delete.AttemptDeleteStep 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.StepContext import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService import org.opensearch.snapshots.SnapshotInProgressException +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase class AttemptDeleteStepTests : OpenSearchTestCase() { @@ -33,6 +42,19 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var deleteActionMetrics: DeleteActionMetrics + + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + deleteActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.DELETE) as DeleteActionMetrics + } fun `test delete step sets step status to completed when successful`() { val acknowledgedResponse = AcknowledgedResponse(true) @@ -45,6 +67,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(deleteActionMetrics.successes).add(eq(1.0), any()) } } @@ -59,6 +82,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(deleteActionMetrics.failures).add(eq(1.0), any()) } } @@ -74,6 +98,7 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(deleteActionMetrics.failures).add(eq(1.0), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt index a06e54a4f..3619fb211 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt @@ -11,6 +11,8 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString import org.opensearch.action.admin.indices.open.OpenIndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -21,10 +23,13 @@ import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.open.AttemptOpenStep 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.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -33,7 +38,17 @@ class AttemptOpenStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + } fun `test open step sets step status to failed when not acknowledged`() { val openIndexResponse = OpenIndexResponse(false, false) val client = getClient(getAdminClient(getIndicesAdminClient(openIndexResponse, null))) 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 beabc39d6..6acd4c912 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt @@ -9,9 +9,12 @@ import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doAnswer import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before +import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.opensearch.action.admin.indices.rollover.RolloverResponse import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient @@ -29,10 +32,15 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.RolloverAction import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.AttemptRolloverStep 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.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase class AttemptRolloverStepTests : OpenSearchTestCase() { @@ -43,9 +51,20 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { private val oldIndexName = "old_index" private val newIndexName = "new_index" val alias = "alias" + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var rolloverActionMetrics: RolloverActionMetrics @Before fun setup() { + // Setup metrics + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + rolloverActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.ROLLOVER) as RolloverActionMetrics + // mock rollover target val clusterState: ClusterState = mock() val metadata: Metadata = mock() @@ -88,6 +107,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { 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")) + verify(rolloverActionMetrics.failures).add(eq(1.0), any()) } } @@ -113,6 +133,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { 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")) + verify(rolloverActionMetrics.failures).add(eq(1.0), any()) } } @@ -138,6 +159,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { 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")) + verify(rolloverActionMetrics.failures).add(eq(1.0), any()) } } @@ -163,6 +185,7 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { 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")) + verify(rolloverActionMetrics.successes).add(eq(1.0), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt index cb580b9d4..40902668e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt @@ -11,6 +11,8 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -22,10 +24,13 @@ import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityAction import org.opensearch.indexmanagement.indexstatemanagement.step.indexpriority.AttemptSetIndexPriorityStep 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.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -34,6 +39,17 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + } fun `test set priority step sets step status to completed when successful`() { val acknowledgedResponse = AcknowledgedResponse(true) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt index 4b29d594a..3ed19636d 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt @@ -8,8 +8,12 @@ package org.opensearch.indexmanagement.indexstatemanagement.step import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.mockito.Mockito.doAnswer import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient @@ -22,10 +26,15 @@ import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.action.ReplicaCountAction import org.opensearch.indexmanagement.indexstatemanagement.step.replicacount.AttemptReplicaCountStep 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.StepContext import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -34,7 +43,20 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var replicaCountActionMetrics: ReplicaCountActionMetrics + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + replicaCountActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.REPLICA_COUNT) as ReplicaCountActionMetrics + } fun `test replica step sets step status to failed when not acknowledged`() { val replicaCountResponse = AcknowledgedResponse(false) val client = getClient(getAdminClient(getIndicesAdminClient(replicaCountResponse, null))) @@ -47,6 +69,7 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(replicaCountActionMetrics.failures).add(eq(1.0), any()) } } @@ -62,6 +85,7 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(replicaCountActionMetrics.failures).add(eq(1.0), any()) } } @@ -78,6 +102,7 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { val updatedManagedIndexMetaData = replicaCountStep.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"]) + verify(replicaCountActionMetrics.failures).add(eq(1.0), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt index d5900eb4d..2a236b093 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt @@ -9,9 +9,12 @@ import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doAnswer import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before +import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.opensearch.action.admin.indices.rollover.RolloverInfo import org.opensearch.action.admin.indices.stats.CommonStats import org.opensearch.action.admin.indices.stats.IndicesStatsResponse @@ -35,11 +38,16 @@ import org.opensearch.indexmanagement.indexstatemanagement.model.Transition import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings import org.opensearch.indexmanagement.indexstatemanagement.step.transition.AttemptTransitionStep 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.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException import java.time.Instant @@ -47,6 +55,8 @@ import java.time.Instant class AttemptTransitionStepTests : OpenSearchTestCase() { private val indexName: String = "test" private val indexUUID: String = "indexUuid" + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var transitionActionMetrics: TransitionActionMetrics @Suppress("UNCHECKED_CAST") private val indexMetadata: IndexMetadata = @@ -71,6 +81,13 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { @Before fun `setup settings`() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + transitionActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.TRANSITION) as TransitionActionMetrics whenever(clusterService.clusterSettings).doReturn(ClusterSettings(Settings.EMPTY, setOf(ManagedIndexSettings.RESTRICTED_INDEX_PATTERN))) } @@ -92,6 +109,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val updatedManagedIndexMetaData = attemptTransitionStep.getUpdatedManagedIndexMetadata(managedIndexMetadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get correct failed message", AttemptTransitionStep.getFailedStatsMessage(indexName), updatedManagedIndexMetaData.info!!["message"]) + verify(transitionActionMetrics.failures).add(eq(1.0), any()) } } @@ -110,6 +128,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val updatedManagedIndexMetaData = attemptTransitionStep.getUpdatedManagedIndexMetadata(managedIndexMetadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "example", updatedManagedIndexMetaData.info!!["cause"]) + verify(transitionActionMetrics.failures).add(eq(1.0), any()) } } @@ -128,6 +147,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val updatedManagedIndexMetaData = attemptTransitionStep.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"]) + verify(transitionActionMetrics.failures).add(eq(1.0), any()) } } 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 03c03818d..326349a06 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt @@ -11,6 +11,8 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -21,10 +23,13 @@ import org.opensearch.core.action.ActionListener import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.readwrite.SetReadWriteStep 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.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -33,6 +38,17 @@ class SetReadWriteStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + } fun `test read write step sets step status to failed when not acknowledged`() { val setReadWriteResponse = AcknowledgedResponse(false) From 55ff6dd6ce7b574abf93a897dae6f10a5a948e84 Mon Sep 17 00:00:00 2001 From: harycash Date: Mon, 1 Jul 2024 12:03:44 +0530 Subject: [PATCH 09/14] Fixed Build Issues, Added new metric : Cumulative Latency Signed-off-by: harycash --- .../actionmetrics/AliasActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/AllocationActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/CloseActionMetrics.kt | 32 +++++++++++++++++++ .../CreateRollupActionMetrics.kt | 32 +++++++++++++++++++ .../CreateTransformActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/MoveShardActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/OpenActionMetrics.kt | 32 +++++++++++++++++++ .../SetIndexPriorityActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/SetReadOnlyActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/ShrinkActionMetrics.kt | 32 +++++++++++++++++++ .../actionmetrics/SnapshotActionMetrics.kt | 32 +++++++++++++++++++ 11 files changed, 352 insertions(+) create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AliasActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AllocationActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CloseActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/MoveShardActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/OpenActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetIndexPriorityActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetReadOnlyActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ShrinkActionMetrics.kt create mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SnapshotActionMetrics.kt 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 new file mode 100644 index 000000000..f1c8fb14b --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AliasActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class AliasActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.ALIAS_ACTION + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Alias Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Alias Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Alias Actions", "milliseconds") + } + + companion object { + val instance: AliasActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = AliasActionMetrics() + } +} 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 new file mode 100644 index 000000000..54a76c665 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/AllocationActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class AllocationActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.ALLOCATION + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Allocation Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Allocation Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Allocation Actions", "milliseconds") + } + + companion object { + val instance: AllocationActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = AllocationActionMetrics() + } +} 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 new file mode 100644 index 000000000..b2c5f28b8 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CloseActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class CloseActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.CLOSE + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Close Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Close Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Close Actions", "milliseconds") + } + + companion object { + val instance: CloseActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = CloseActionMetrics() + } +} 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 new file mode 100644 index 000000000..f6149b8c8 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class CreateRollupActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.CREATE_ROLLUP + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Create Rollup Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Create Rollup Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Create Rollup Actions", "milliseconds") + } + + companion object { + val instance: CreateRollupActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = CreateRollupActionMetrics() + } +} 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 new file mode 100644 index 000000000..15dcd2fc7 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class CreateTransformActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.CREATE_TRANSFORM + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Create Transform Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Create Transform Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Create Transform Actions", "milliseconds") + } + + companion object { + val instance: CreateTransformActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = CreateTransformActionMetrics() + } +} 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 new file mode 100644 index 000000000..10b35c655 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/MoveShardActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class MoveShardActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.MOVE_SHARD + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Move Shard Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Move Shard Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Move Shard Actions", "milliseconds") + } + + companion object { + val instance: MoveShardActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = MoveShardActionMetrics() + } +} 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 new file mode 100644 index 000000000..62e9d3944 --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/OpenActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class OpenActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.OPEN + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Open Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Open Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Open Actions", "milliseconds") + } + + companion object { + val instance: OpenActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = OpenActionMetrics() + } +} 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 new file mode 100644 index 000000000..a670cfceb --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetIndexPriorityActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class SetIndexPriorityActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.SET_INDEX_PRIORITY + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Set Index Priority Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Set Index Priority Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Set Index Priority Actions", "milliseconds") + } + + companion object { + val instance: SetIndexPriorityActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = SetIndexPriorityActionMetrics() + } +} 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 new file mode 100644 index 000000000..5d873eb7e --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SetReadOnlyActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class SetReadOnlyActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.SET_READ_ONLY + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Set Read Only Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Set Read Only Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Set Read Only Actions", "milliseconds") + } + + companion object { + val instance: SetReadOnlyActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = SetReadOnlyActionMetrics() + } +} 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 new file mode 100644 index 000000000..3ce21b28a --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/ShrinkActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class ShrinkActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.SHRINK + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Shrink Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Shrink Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Shrink Actions", "milliseconds") + } + + companion object { + val instance: ShrinkActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = ShrinkActionMetrics() + } +} 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 new file mode 100644 index 000000000..07e8200ea --- /dev/null +++ b/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/SnapshotActionMetrics.kt @@ -0,0 +1,32 @@ +/* + * Copyright OpenSearch Contributors + * SPDX-License-Identifier: Apache-2.0 + */ + +package org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics + +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.ActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry + +class SnapshotActionMetrics private constructor() : ActionMetrics() { + override val actionName: String = IndexManagementActionsMetrics.SNAPSHOT + lateinit var successes: Counter + lateinit var failures: Counter + lateinit var cumulativeLatency: Counter + + fun initializeCounters(metricsRegistry: MetricsRegistry) { + successes = metricsRegistry.createCounter("${actionName}_successes", "Snapshot Action Successes", "count") + failures = metricsRegistry.createCounter("${actionName}_failures", "Snapshot Action Failures", "count") + cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Snapshot Actions", "milliseconds") + } + + companion object { + val instance: SnapshotActionMetrics by lazy { HOLDER.instance } + } + + private object HOLDER { + val instance = SnapshotActionMetrics() + } +} From ec440d2de15e38750302fe286a1fde46fd31e5f9 Mon Sep 17 00:00:00 2001 From: harycash Date: Mon, 1 Jul 2024 20:51:19 +0530 Subject: [PATCH 10/14] Requested Changes and Addition of Metrics to all the remaining Actions Signed-off-by: harycash --- .../indexstatemanagement/Step.kt | 103 +++++++++++++++++- .../metrics/IndexManagementActionsMetrics.kt | 52 +++++++++ .../actionmetrics/AliasActionMetrics.kt | 21 ++++ .../actionmetrics/AllocationActionMetrics.kt | 21 ++++ .../actionmetrics/CloseActionMetrics.kt | 21 ++++ .../CreateRollupActionMetrics.kt | 25 +++++ .../CreateTransformActionMetrics.kt | 21 ++++ .../actionmetrics/DeleteActionMetrics.kt | 21 ++++ .../actionmetrics/ForceMergeActionMetrics.kt | 21 ++++ .../actionmetrics/MoveShardActionMetrics.kt | 21 ++++ .../NotificationActionMetrics.kt | 21 ++++ .../actionmetrics/OpenActionMetrics.kt | 21 ++++ .../ReplicaCountActionMetrics.kt | 21 ++++ .../actionmetrics/RolloverActionMetrics.kt | 21 ++++ .../SetIndexPriorityActionMetrics.kt | 21 ++++ .../actionmetrics/SetReadOnlyActionMetrics.kt | 21 ++++ .../actionmetrics/ShrinkActionMetrics.kt | 21 ++++ .../actionmetrics/SnapshotActionMetrics.kt | 21 ++++ .../actionmetrics/TransitionActionMetrics.kt | 21 ++++ .../ManagedIndexRunner.kt | 3 +- .../step/alias/AttemptAliasActionsStep.kt | 3 +- .../step/allocation/AttemptAllocationStep.kt | 3 +- .../step/close/AttemptCloseStep.kt | 4 +- .../step/delete/AttemptDeleteStep.kt | 26 +---- .../forcemerge/AttemptCallForceMergeStep.kt | 23 +--- .../step/forcemerge/AttemptSetReadOnlyStep.kt | 3 +- .../step/forcemerge/WaitForForceMergeStep.kt | 3 +- .../AttemptSetIndexPriorityStep.kt | 4 +- .../notification/AttemptNotificationStep.kt | 16 +-- .../step/open/AttemptOpenStep.kt | 3 +- .../step/readonly/SetReadOnlyStep.kt | 3 +- .../step/readwrite/SetReadWriteStep.kt | 3 +- .../replicacount/AttemptReplicaCountStep.kt | 25 +---- .../step/rollover/AttemptRolloverStep.kt | 32 +----- .../step/rollup/AttemptCreateRollupJobStep.kt | 3 +- .../rollup/WaitForRollupCompletionStep.kt | 3 +- .../step/shrink/ShrinkStep.kt | 3 +- .../step/snapshot/AttemptSnapshotStep.kt | 3 +- .../step/snapshot/WaitForSnapshotStep.kt | 3 +- .../AttemptCreateTransformJobStep.kt | 3 +- .../WaitForTransformCompletionStep.kt | 3 +- .../step/transition/AttemptTransitionStep.kt | 28 +---- .../extension/SampleCustomActionParser.kt | 3 +- .../step/AttemptCloseStepTests.kt | 12 +- .../step/AttemptRolloverStepTests.kt | 8 +- .../step/SetReadOnlyStepTests.kt | 7 +- .../step/SetReadWriteStepTests.kt | 6 +- .../step/WaitForRollupCompletionStepTests.kt | 3 +- .../step/WaitForSnapshotStepTests.kt | 21 ++-- 49 files changed, 567 insertions(+), 212 deletions(-) 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"]) From f0c9cb4ca0f930db3d9e4cab866684be5589cc09 Mon Sep 17 00:00:00 2001 From: harycash Date: Wed, 3 Jul 2024 14:16:05 +0530 Subject: [PATCH 11/14] Updates on Action Metrics Signed-off-by: harycash --- .../indexstatemanagement/Step.kt | 11 +--- .../metrics/IndexManagementActionsMetrics.kt | 8 --- .../CreateRollupActionMetrics.kt | 57 ------------------- .../CreateTransformActionMetrics.kt | 53 ----------------- .../step/close/AttemptCloseStep.kt | 1 + .../step/delete/AttemptDeleteStep.kt | 1 + .../forcemerge/AttemptCallForceMergeStep.kt | 3 +- .../AttemptSetIndexPriorityStep.kt | 1 + .../notification/AttemptNotificationStep.kt | 1 - .../replicacount/AttemptReplicaCountStep.kt | 1 + .../step/rollover/AttemptRolloverStep.kt | 20 ++++--- .../step/transition/AttemptTransitionStep.kt | 1 + .../step/AttemptCloseStepTests.kt | 30 +++++++--- .../step/AttemptDeleteStepTests.kt | 21 ++++--- .../step/AttemptOpenStepTests.kt | 23 ++++++-- .../step/AttemptRolloverStepTests.kt | 18 +++--- .../step/AttemptSetIndexPriorityStepTests.kt | 21 ++++--- .../step/AttemptSetReplicaCountStepTests.kt | 26 +++++---- .../step/AttemptSnapshotStepTests.kt | 39 ++++++++++--- .../step/AttemptTransitionStepTests.kt | 15 ++--- .../step/SetReadOnlyStepTests.kt | 40 +++++++++++-- .../WaitForTransformCompletionStepTests.kt | 3 +- 22 files changed, 182 insertions(+), 212 deletions(-) delete mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt delete mode 100644 spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt 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 b1be99f12..ce347ac1a 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 @@ -72,7 +72,7 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) IndexManagementActionsMetrics.SET_INDEX_PRIORITY -> indexManagementActionMetrics.getActionMetrics( - IndexManagementActionsMetrics.SET_INDEX_PRIORITY, + IndexManagementActionsMetrics.SET_INDEX_PRIORITY, // problem in test ) ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) @@ -81,15 +81,6 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { ) ?.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, ) 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 4576ec5ca..8dc8345b2 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 @@ -8,8 +8,6 @@ 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 @@ -62,8 +60,6 @@ class IndexManagementActionsMetrics private constructor() { 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" @@ -88,8 +84,6 @@ class IndexManagementActionsMetrics private constructor() { 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) @@ -107,8 +101,6 @@ class IndexManagementActionsMetrics private constructor() { 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, 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 deleted file mode 100644 index 9470d562f..000000000 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateRollupActionMetrics.kt +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -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 - -class CreateRollupActionMetrics private constructor() : ActionMetrics() { - override val actionName: String = IndexManagementActionsMetrics.CREATE_ROLLUP - lateinit var successes: Counter - lateinit var failures: Counter - lateinit var cumulativeLatency: Counter - - fun initializeCounters(metricsRegistry: MetricsRegistry) { - successes = metricsRegistry.createCounter("${actionName}_successes", "Create Rollup Action Successes", "count") - failures = metricsRegistry.createCounter("${actionName}_failures", "Create Rollup Action Failures", "count") - cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Create Rollup Actions", "milliseconds") - } - - companion object { - val instance: CreateRollupActionMetrics by lazy { HOLDER.instance } - } - - 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 deleted file mode 100644 index 692139172..000000000 --- a/spi/src/main/kotlin/org.opensearch.indexmanagement.spi/indexstatemanagement/metrics/actionmetrics/CreateTransformActionMetrics.kt +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright OpenSearch Contributors - * SPDX-License-Identifier: Apache-2.0 - */ - -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 - -class CreateTransformActionMetrics private constructor() : ActionMetrics() { - override val actionName: String = IndexManagementActionsMetrics.CREATE_TRANSFORM - lateinit var successes: Counter - lateinit var failures: Counter - lateinit var cumulativeLatency: Counter - - fun initializeCounters(metricsRegistry: MetricsRegistry) { - successes = metricsRegistry.createCounter("${actionName}_successes", "Create Transform Action Successes", "count") - failures = metricsRegistry.createCounter("${actionName}_failures", "Create Transform Action Failures", "count") - cumulativeLatency = metricsRegistry.createCounter("${actionName}_cumulative_latency", "Cumulative Latency of Create Transform Actions", "milliseconds") - } - - companion object { - val instance: CreateTransformActionMetrics by lazy { HOLDER.instance } - } - - 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/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt b/src/main/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/close/AttemptCloseStep.kt index f2a6f29ec..5e4b01fdd 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 @@ -54,6 +54,7 @@ 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 fade86dc0..bbbc390d3 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 @@ -50,6 +50,7 @@ class AttemptDeleteStep : Step(name) { } catch (e: Exception) { handleException(indexName, e) } + return this } 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 e17770df6..3ff796e55 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 @@ -34,8 +34,8 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam override suspend fun execute(): AttemptCallForceMergeStep { val context = this.context ?: return this val indexName = context.metadata.index - 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 @@ -76,6 +76,7 @@ class AttemptCallForceMergeStep(private val action: ForceMergeAction) : Step(nam } catch (e: Exception) { handleException(indexName, e) } + return this } 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 9330691ca..09aaa5b0b 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 @@ -51,6 +51,7 @@ 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 dfafbdb6a..04cdd2bc0 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 @@ -26,7 +26,6 @@ class AttemptNotificationStep(private val action: NotificationAction) : Step(nam val context = this.context ?: return this val indexName = context.metadata.index val scriptService = context.scriptService - try { val compiledMessage = compileTemplate(scriptService, action.messageTemplate, context.metadata) action.destination?.buildLegacyBaseMessage(null, compiledMessage)?.publishLegacyNotification(context.client) 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 470d23453..68eccae8f 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 @@ -50,6 +50,7 @@ class AttemptReplicaCountStep(private val action: ReplicaCountAction) : Step(nam } catch (e: Exception) { handleException(indexName, numOfReplicas, e) } + return this } 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 5ba8be2e3..f01c33e1b 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 @@ -46,7 +46,6 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { val indexName = context.metadata.index val clusterService = context.clusterService val skipRollover = clusterService.state().metadata.index(indexName).getRolloverSkip() - if (skipRollover) { stepStatus = StepStatus.COMPLETED info = mapOf("message" to getSkipRolloverMessage(indexName)) @@ -55,10 +54,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { val (rolloverTarget, isDataStream) = getRolloverTargetOrUpdateInfo(context) // If the rolloverTarget is null, we would've already updated the failed info from getRolloverTargetOrUpdateInfo and can return early - - if (rolloverTarget == null) { - return this - } + rolloverTarget ?: return this if (clusterService.state().metadata.index(indexName).rolloverInfos.containsKey(rolloverTarget)) { stepStatus = StepStatus.COMPLETED @@ -75,8 +71,9 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { return this } - val statsResponse = getIndexStatsOrUpdateInfo(context) ?: return this + val statsResponse = getIndexStatsOrUpdateInfo(context) // If statsResponse is null we already updated failed info from getIndexStatsOrUpdateInfo and can return early + statsResponse ?: return this val indexCreationDate = clusterService.state().metadata().index(indexName).creationDate val indexAgeTimeValue = @@ -137,6 +134,7 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { stepStatus = StepStatus.CONDITION_NOT_MET info = mapOf("message" to getPendingMessage(indexName), "conditions" to conditions) } + return this } @@ -296,16 +294,22 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { rolloverTarget: String, metadata: ManagedIndexMetaData, ) { - if (!action.copyAlias) return // Try to preserve the rollover conditions + if (!action.copyAlias) return + + // Try to preserve the rollover conditions val conditions = info?.get("conditions") ?: context?.metadata?.info?.get("conditions") + val rolledOverIndexName = newIndex ?: metadata.rolledOverIndexName - if (rolledOverIndexName == null) { // Only in rare case when the program shut down unexpectedly before rolledOverIndexName is set or metadata corrupted + if (rolledOverIndexName == null) { + // Only in rare case when the program shut down unexpectedly before rolledOverIndexName is set or metadata corrupted // ISM cannot auto recover from this case, so the status is COMPLETED logger.error("$indexName rolled over but cannot find the rolledOverIndexName to copy aliases to") stepStatus = StepStatus.COMPLETED info = listOfNotNull( + "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), if (conditions != null) "conditions" to conditions else null, + ).toMap() return } 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 1bb1865aa..cd12916cd 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 @@ -123,6 +123,7 @@ class AttemptTransitionStep(private val action: TransitionsAction) : Step(name) } catch (e: Exception) { handleException(indexName, e) } + 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 ca05021cb..09fc4af00 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptCloseStepTests.kt @@ -9,10 +9,12 @@ import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doAnswer import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.opensearch.action.admin.indices.close.CloseIndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -24,6 +26,8 @@ import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.close.AttemptCloseStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.CloseActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService @@ -31,8 +35,10 @@ import org.opensearch.script.ScriptService import org.opensearch.snapshots.SnapshotInProgressException import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException +import java.time.Instant import kotlin.IllegalArgumentException class AttemptCloseStepTests : OpenSearchTestCase() { @@ -41,6 +47,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) private lateinit var metricsRegistry: MetricsRegistry + private lateinit var closeActionMetrics: CloseActionMetrics @Before fun setup() { @@ -50,6 +57,7 @@ class AttemptCloseStepTests : OpenSearchTestCase() { } IndexManagementActionsMetrics.instance.initialize(metricsRegistry) ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + closeActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.CLOSE) as CloseActionMetrics } fun `test close step sets step status to completed when successful`() { @@ -57,12 +65,13 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(closeIndexResponse, null))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("close", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute() + attemptCloseStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptCloseStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(closeActionMetrics.successes).add(eq(1.0), any()) } } @@ -71,12 +80,13 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(closeIndexResponse, null))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("close", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute() + attemptCloseStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptCloseStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(closeActionMetrics.failures).add(eq(1.0), any()) } } @@ -85,12 +95,13 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("close", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute() + attemptCloseStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptCloseStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(closeActionMetrics.failures).add(eq(1.0), any()) } } @@ -102,7 +113,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() + attemptCloseStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptCloseStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptCloseStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -127,13 +138,14 @@ class AttemptCloseStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("close", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptCloseStep = AttemptCloseStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptCloseStep.preExecute(logger, context).execute() + attemptCloseStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptCloseStep, managedIndexMetaData) 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"]) + verify(closeActionMetrics.failures).add(eq(1.0), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt index 33909f296..2f99551ab 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptDeleteStepTests.kt @@ -27,6 +27,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.step.delete.AttemptDe 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.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService @@ -36,6 +37,7 @@ import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase +import java.time.Instant class AttemptDeleteStepTests : OpenSearchTestCase() { private val clusterService: ClusterService = mock() @@ -61,10 +63,13 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(acknowledgedResponse, null))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData( + "test", "indexUuid", "policy_id", null, null, null, null, null, null, null, + ActionMetaData("delete", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null, + ) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptDeleteStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptDeleteStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) verify(deleteActionMetrics.successes).add(eq(1.0), any()) @@ -76,10 +81,10 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(acknowledgedResponse, null))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("delete", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptDeleteStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptDeleteStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) verify(deleteActionMetrics.failures).add(eq(1.0), any()) @@ -91,10 +96,10 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("delete", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptDeleteStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptDeleteStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) @@ -107,10 +112,10 @@ class AttemptDeleteStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("delete", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptDeleteStep = AttemptDeleteStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptDeleteStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptDeleteStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptDeleteStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptDeleteStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not CONDITION_NOT_MET", Step.StepStatus.CONDITION_NOT_MET, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt index 3619fb211..b0986c7ad 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptOpenStepTests.kt @@ -9,10 +9,12 @@ import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doAnswer import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.opensearch.action.admin.indices.open.OpenIndexResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -24,14 +26,18 @@ import org.opensearch.indexmanagement.indexstatemanagement.ManagedIndexRunner import org.opensearch.indexmanagement.indexstatemanagement.step.open.AttemptOpenStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.OpenActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException +import java.time.Instant class AttemptOpenStepTests : OpenSearchTestCase() { private val clusterService: ClusterService = mock() @@ -39,6 +45,7 @@ class AttemptOpenStepTests : OpenSearchTestCase() { private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) private lateinit var metricsRegistry: MetricsRegistry + private lateinit var openActionMetrics: OpenActionMetrics @Before fun setup() { @@ -48,18 +55,20 @@ class AttemptOpenStepTests : OpenSearchTestCase() { } IndexManagementActionsMetrics.instance.initialize(metricsRegistry) ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + openActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.OPEN) as OpenActionMetrics } fun `test open step sets step status to failed when not acknowledged`() { val openIndexResponse = OpenIndexResponse(false, false) val client = getClient(getAdminClient(getIndicesAdminClient(openIndexResponse, null))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("open", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptOpenStep = AttemptOpenStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptOpenStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptOpenStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptOpenStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptOpenStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(openActionMetrics.failures).add(eq(1.0), any()) } } @@ -68,12 +77,13 @@ class AttemptOpenStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("open", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptOpenStep = AttemptOpenStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptOpenStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptOpenStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptOpenStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptOpenStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(openActionMetrics.failures).add(eq(1.0), any()) } } @@ -82,13 +92,14 @@ class AttemptOpenStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("open", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptOpenStep = AttemptOpenStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptOpenStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptOpenStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptOpenStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptOpenStep.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"]) + verify(openActionMetrics.failures).add(eq(1.0), any()) } } 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 e0cc34110..b720614d6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptRolloverStepTests.kt @@ -34,6 +34,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.step.rollover.Attempt 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.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService @@ -42,6 +43,7 @@ import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase +import java.time.Instant class AttemptRolloverStepTests : OpenSearchTestCase() { private val clusterService: ClusterService = mock() @@ -98,12 +100,12 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { oldIndexName, "indexUuid", "policy_id", null, null, null, null, null, null, - null, null, null, + null, ActionMetaData("rollover", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null, rolledOverIndexName = newIndexName, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptRolloverStep, managedIndexMetaData) 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")) @@ -124,12 +126,12 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { oldIndexName, "indexUuid", "policy_id", null, null, null, null, null, null, - null, null, null, + null, ActionMetaData("rollover", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null, rolledOverIndexName = newIndexName, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptRolloverStep, managedIndexMetaData) 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")) @@ -150,12 +152,12 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { oldIndexName, "indexUuid", "policy_id", null, null, null, null, null, null, - null, null, null, + null, ActionMetaData("rollover", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null, rolledOverIndexName = newIndexName, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptRolloverStep, managedIndexMetaData) 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")) @@ -176,12 +178,12 @@ class AttemptRolloverStepTests : OpenSearchTestCase() { oldIndexName, "indexUuid", "policy_id", null, null, null, null, null, null, - null, null, null, + null, ActionMetaData("rollover", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null, rolledOverIndexName = null, ) val attemptRolloverStep = AttemptRolloverStep(rolloverAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptRolloverStep.preExecute(logger, context).execute() + attemptRolloverStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptRolloverStep, managedIndexMetaData) 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/AttemptSetIndexPriorityStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt index 40902668e..a2437a67f 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetIndexPriorityStepTests.kt @@ -25,6 +25,8 @@ import org.opensearch.indexmanagement.indexstatemanagement.action.IndexPriorityA import org.opensearch.indexmanagement.indexstatemanagement.step.indexpriority.AttemptSetIndexPriorityStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.SetIndexPriorityActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService @@ -33,6 +35,7 @@ import org.opensearch.telemetry.metrics.Counter import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException +import java.time.Instant class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { private val clusterService: ClusterService = mock() @@ -40,6 +43,7 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) private lateinit var metricsRegistry: MetricsRegistry + private lateinit var setIndexPriorityActionMetrics: SetIndexPriorityActionMetrics @Before fun setup() { @@ -49,6 +53,7 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { } IndexManagementActionsMetrics.instance.initialize(metricsRegistry) ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + setIndexPriorityActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.SET_INDEX_PRIORITY) as SetIndexPriorityActionMetrics } fun `test set priority step sets step status to completed when successful`() { @@ -57,10 +62,10 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { runBlocking { val indexPriorityAction = IndexPriorityAction(50, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_index_priority", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptSetPriorityStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptSetPriorityStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -72,10 +77,10 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { runBlocking { val indexPriorityAction = IndexPriorityAction(50, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_index_priority", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptSetPriorityStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptSetPriorityStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) } @@ -87,10 +92,10 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { runBlocking { val indexPriorityAction = IndexPriorityAction(50, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_index_priority", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptSetPriorityStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptSetPriorityStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) @@ -103,10 +108,10 @@ class AttemptSetIndexPriorityStepTests : OpenSearchTestCase() { runBlocking { val indexPriorityAction = IndexPriorityAction(50, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_index_priority", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val attemptSetPriorityStep = AttemptSetIndexPriorityStep(indexPriorityAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - attemptSetPriorityStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptSetPriorityStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptSetPriorityStep, managedIndexMetaData) val updatedManagedIndexMetaData = attemptSetPriorityStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) logger.info(updatedManagedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt index 3ed19636d..825695fe3 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSetReplicaCountStepTests.kt @@ -28,6 +28,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.step.replicacount.Att 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.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService @@ -37,6 +38,7 @@ import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException +import java.time.Instant class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { private val clusterService: ClusterService = mock() @@ -63,11 +65,11 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { runBlocking { val replicaCountAction = ReplicaCountAction(2, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) - val replicaCountStep = AttemptReplicaCountStep(replicaCountAction) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("replica_count", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) + val attemptReplicaCountStep = AttemptReplicaCountStep(replicaCountAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) - val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) + attemptReplicaCountStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptReplicaCountStep, managedIndexMetaData) + val updatedManagedIndexMetaData = attemptReplicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) verify(replicaCountActionMetrics.failures).add(eq(1.0), any()) } @@ -79,11 +81,11 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { runBlocking { val replicaCountAction = ReplicaCountAction(2, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) - val replicaCountStep = AttemptReplicaCountStep(replicaCountAction) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("replica_count", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) + val attemptReplicaCountStep = AttemptReplicaCountStep(replicaCountAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) - val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) + attemptReplicaCountStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptReplicaCountStep, managedIndexMetaData) + val updatedManagedIndexMetaData = attemptReplicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) verify(replicaCountActionMetrics.failures).add(eq(1.0), any()) } @@ -95,11 +97,11 @@ class AttemptSetReplicaCountStepTests : OpenSearchTestCase() { runBlocking { val replicaCountAction = ReplicaCountAction(2, 0) - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) - val replicaCountStep = AttemptReplicaCountStep(replicaCountAction) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("replica_count", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) + val attemptReplicaCountStep = AttemptReplicaCountStep(replicaCountAction) val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - replicaCountStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) - val updatedManagedIndexMetaData = replicaCountStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) + attemptReplicaCountStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptReplicaCountStep, managedIndexMetaData) + val updatedManagedIndexMetaData = attemptReplicaCountStep.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"]) verify(replicaCountActionMetrics.failures).add(eq(1.0), any()) diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt index 8024993dd..34f9c4fa6 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptSnapshotStepTests.kt @@ -10,9 +10,13 @@ import com.nhaarman.mockitokotlin2.doAnswer import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.eq import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking import org.junit.Before +import org.mockito.ArgumentMatchers +import org.mockito.ArgumentMatchers.anyString +import org.mockito.Mockito import org.opensearch.action.admin.cluster.snapshots.create.CreateSnapshotResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -27,6 +31,8 @@ import org.opensearch.indexmanagement.indexstatemanagement.randomSnapshotActionC import org.opensearch.indexmanagement.indexstatemanagement.settings.ManagedIndexSettings.Companion.SNAPSHOT_DENY_LIST import org.opensearch.indexmanagement.indexstatemanagement.step.snapshot.AttemptSnapshotStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.SnapshotActionMetrics import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionProperties import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData @@ -36,6 +42,9 @@ import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService import org.opensearch.script.TemplateScript import org.opensearch.snapshots.ConcurrentSnapshotExecutionException +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -44,13 +53,22 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val snapshotAction = randomSnapshotActionConfig("repo", "snapshot-name") - private val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData(AttemptSnapshotStep.name, 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) + private val metadata = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("snapshot", 1, 0, false, 0, null, ActionProperties(snapshotName = "snapshot-name")), null, null, null) private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var snapshotActionMetrics: SnapshotActionMetrics @Before fun settings() { whenever(clusterService.clusterSettings).doReturn(ClusterSettings(Settings.EMPTY, setOf(SNAPSHOT_DENY_LIST))) whenever(scriptService.compile(any(), eq(TemplateScript.CONTEXT))).doReturn(MockTemplateScript.Factory("snapshot-name")) + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + snapshotActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.SNAPSHOT) as SnapshotActionMetrics } fun `test snapshot response when block`() { @@ -61,27 +79,30 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, step, metadata) val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(snapshotActionMetrics.successes).add(ArgumentMatchers.eq(1.0), any()) } whenever(response.status()).doReturn(RestStatus.OK) runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, step, metadata) val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not COMPLETED", Step.StepStatus.COMPLETED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(snapshotActionMetrics.successes, Mockito.times(2)).add(ArgumentMatchers.eq(1.0), any()) } whenever(response.status()).doReturn(RestStatus.INTERNAL_SERVER_ERROR) runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, step, metadata) val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(snapshotActionMetrics.failures).add(ArgumentMatchers.eq(1.0), any()) } } @@ -91,10 +112,11 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, step, metadata) 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"]) + verify(snapshotActionMetrics.failures).add(ArgumentMatchers.eq(1.0), any()) } } @@ -104,7 +126,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(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 failed concurrent message", AttemptSnapshotStep.getFailedConcurrentSnapshotMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -117,7 +139,7 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(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 failed concurrent message", AttemptSnapshotStep.getFailedConcurrentSnapshotMessage("test"), updatedManagedIndexMetaData.info!!["message"]) @@ -130,10 +152,11 @@ class AttemptSnapshotStepTests : OpenSearchTestCase() { runBlocking { val step = AttemptSnapshotStep(snapshotAction) val context = StepContext(metadata, clusterService, client, null, null, scriptService, settings, lockService) - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, step, metadata) 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", "some error", updatedManagedIndexMetaData.info!!["cause"]) + verify(snapshotActionMetrics.failures).add(ArgumentMatchers.eq(1.0), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt index 2a236b093..6f6d2cc16 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/AttemptTransitionStepTests.kt @@ -40,6 +40,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.step.transition.Attem 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.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepMetaData @@ -101,11 +102,11 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val indexMetadataProvider = IndexMetadataProvider(settings, client, clusterService, mutableMapOf()) runBlocking { - val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, ActionMetaData("transition", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val transitionsAction = TransitionsAction(listOf(Transition("some_state", Conditions(docCount = 5L))), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) val context = StepContext(managedIndexMetadata, clusterService, client, null, null, scriptService, settings, lockService) - attemptTransitionStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptTransitionStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptTransitionStep, managedIndexMetadata) val updatedManagedIndexMetaData = attemptTransitionStep.getUpdatedManagedIndexMetadata(managedIndexMetadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get correct failed message", AttemptTransitionStep.getFailedStatsMessage(indexName), updatedManagedIndexMetaData.info!!["message"]) @@ -120,11 +121,11 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val indexMetadataProvider = IndexMetadataProvider(settings, client, clusterService, mutableMapOf()) runBlocking { - val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, ActionMetaData("transition", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val transitionsAction = TransitionsAction(listOf(Transition("some_state", Conditions(docCount = 5L))), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) val context = StepContext(managedIndexMetadata, clusterService, client, null, null, scriptService, settings, lockService) - attemptTransitionStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptTransitionStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptTransitionStep, managedIndexMetadata) val updatedManagedIndexMetaData = attemptTransitionStep.getUpdatedManagedIndexMetadata(managedIndexMetadata) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) assertEquals("Did not get cause from nested exception", "example", updatedManagedIndexMetaData.info!!["cause"]) @@ -139,11 +140,11 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val indexMetadataProvider = IndexMetadataProvider(settings, client, clusterService, mutableMapOf()) runBlocking { - val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, ActionMetaData("transition", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val transitionsAction = TransitionsAction(listOf(Transition("some_state", Conditions(docCount = 5L))), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) val context = StepContext(managedIndexMetadata, clusterService, client, null, null, scriptService, settings, lockService) - attemptTransitionStep.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + attemptTransitionStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, attemptTransitionStep, managedIndexMetadata) val updatedManagedIndexMetaData = attemptTransitionStep.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"]) @@ -155,7 +156,7 @@ class AttemptTransitionStepTests : OpenSearchTestCase() { val indexMetadataProvider = IndexMetadataProvider(settings, mock(), clusterService, mutableMapOf()) runBlocking { val completedStartTime = Instant.now() - val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, null, StepMetaData("attempt_transition", completedStartTime.toEpochMilli(), Step.StepStatus.COMPLETED), null, null) + val managedIndexMetadata = ManagedIndexMetaData(indexName, indexUUID, "policy_id", null, null, null, null, null, null, null, ActionMetaData("transition", Instant.now().toEpochMilli(), 0, false, 1, null, null), StepMetaData("attempt_transition", completedStartTime.toEpochMilli(), Step.StepStatus.COMPLETED), null, null) val transitionsAction = TransitionsAction(listOf(Transition("some_state", null)), indexMetadataProvider) val attemptTransitionStep = AttemptTransitionStep(transitionsAction) Thread.sleep(50) // Make sure we give enough time for the instants to be different 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 a3a70ca6c..beed36762 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadOnlyStepTests.kt @@ -9,8 +9,12 @@ import com.nhaarman.mockitokotlin2.any import com.nhaarman.mockitokotlin2.doAnswer import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock +import com.nhaarman.mockitokotlin2.verify import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking +import org.junit.Before +import org.mockito.ArgumentMatchers.anyString +import org.mockito.ArgumentMatchers.eq import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -18,32 +22,54 @@ 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.metrics.IndexManagementActionsMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.metrics.actionmetrics.SetReadOnlyActionMetrics +import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ActionMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.ManagedIndexMetaData import org.opensearch.indexmanagement.spi.indexstatemanagement.model.StepContext import org.opensearch.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService +import org.opensearch.telemetry.metrics.Counter +import org.opensearch.telemetry.metrics.MetricsRegistry +import org.opensearch.telemetry.metrics.tags.Tags import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException +import java.time.Instant class SetReadOnlyStepTests : OpenSearchTestCase() { private val clusterService: ClusterService = mock() private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) + private lateinit var metricsRegistry: MetricsRegistry + private lateinit var setReadOnlyActionMetrics: SetReadOnlyActionMetrics + + @Before + fun setup() { + metricsRegistry = mock() + whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { + mock() + } + IndexManagementActionsMetrics.instance.initialize(metricsRegistry) + ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) + setReadOnlyActionMetrics = IndexManagementActionsMetrics.instance.getActionMetrics(IndexManagementActionsMetrics.SET_READ_ONLY) as SetReadOnlyActionMetrics + } fun `test read only step sets step status to failed when not acknowledged`() { val setReadOnlyResponse = AcknowledgedResponse(false) val client = getClient(getAdminClient(getIndicesAdminClient(setReadOnlyResponse, null))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_read_only", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val setReadOnlyStep = SetReadOnlyStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadOnlyStep.preExecute(logger, context).execute() + setReadOnlyStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, setReadOnlyStep, managedIndexMetaData) val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(setReadOnlyActionMetrics.failures).add(eq(1.0), any()) } } @@ -52,12 +78,13 @@ class SetReadOnlyStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_read_only", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val setReadOnlyStep = SetReadOnlyStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadOnlyStep.preExecute(logger, context).execute() + setReadOnlyStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, setReadOnlyStep, managedIndexMetaData) val updatedManagedIndexMetaData = setReadOnlyStep.getUpdatedManagedIndexMetadata(managedIndexMetaData) assertEquals("Step status is not FAILED", Step.StepStatus.FAILED, updatedManagedIndexMetaData.stepMetaData?.stepStatus) + verify(setReadOnlyActionMetrics.failures).add(eq(1.0), any()) } } @@ -66,13 +93,14 @@ class SetReadOnlyStepTests : OpenSearchTestCase() { val client = getClient(getAdminClient(getIndicesAdminClient(null, exception))) runBlocking { - val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, null, null, null, null) + val managedIndexMetaData = ManagedIndexMetaData("test", "indexUuid", "policy_id", null, null, null, null, null, null, null, ActionMetaData("set_read_only", Instant.now().toEpochMilli(), 0, false, 1, null, null), null, null, null) val setReadOnlyStep = SetReadOnlyStep() val context = StepContext(managedIndexMetaData, clusterService, client, null, null, scriptService, settings, lockService) - setReadOnlyStep.preExecute(logger, context).execute() + setReadOnlyStep.preExecute(logger, context).execute().postExecute(logger, IndexManagementActionsMetrics.instance, setReadOnlyStep, managedIndexMetaData) 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"]) + verify(setReadOnlyActionMetrics.failures).add(eq(1.0), any()) } } diff --git a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt index 8f945cf26..bbd0bc99e 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/WaitForTransformCompletionStepTests.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.transform.AttemptCreateTransformJobStep import org.opensearch.indexmanagement.indexstatemanagement.step.transform.WaitForTransformCompletionStep import org.opensearch.indexmanagement.spi.indexstatemanagement.Step @@ -72,7 +71,7 @@ class WaitForTransformCompletionStepTests : OpenSearchTestCase() { val step = WaitForTransformCompletionStep() runBlocking { - step.preExecute(logger, context).execute(ManagedIndexRunner.indexManagementActionMetrics) + step.preExecute(logger, context).execute() } val updatedManagedIndexMetaData = step.getUpdatedManagedIndexMetadata(metadata) From 197f439134517b908f525712d57ea5daa1fac4b3 Mon Sep 17 00:00:00 2001 From: harycash Date: Wed, 3 Jul 2024 14:53:37 +0530 Subject: [PATCH 12/14] Updates on Action Metrics Signed-off-by: harycash --- .../step/SetReadWriteStepTests.kt | 19 +------------------ 1 file changed, 1 insertion(+), 18 deletions(-) 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 cde5845e5..d9f6b41de 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt @@ -11,8 +11,6 @@ import com.nhaarman.mockitokotlin2.doReturn import com.nhaarman.mockitokotlin2.mock import com.nhaarman.mockitokotlin2.whenever import kotlinx.coroutines.runBlocking -import org.junit.Before -import org.mockito.ArgumentMatchers.anyString import org.opensearch.action.support.master.AcknowledgedResponse import org.opensearch.client.AdminClient import org.opensearch.client.Client @@ -20,16 +18,12 @@ 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.readwrite.SetReadWriteStep 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.jobscheduler.spi.utils.LockService import org.opensearch.script.ScriptService -import org.opensearch.telemetry.metrics.Counter -import org.opensearch.telemetry.metrics.MetricsRegistry import org.opensearch.test.OpenSearchTestCase import org.opensearch.transport.RemoteTransportException @@ -38,17 +32,6 @@ class SetReadWriteStepTests : OpenSearchTestCase() { private val scriptService: ScriptService = mock() private val settings: Settings = Settings.EMPTY private val lockService: LockService = LockService(mock(), clusterService) - private lateinit var metricsRegistry: MetricsRegistry - - @Before - fun setup() { - metricsRegistry = mock() - whenever(metricsRegistry.createCounter(anyString(), anyString(), anyString())).thenAnswer { - mock() - } - IndexManagementActionsMetrics.instance.initialize(metricsRegistry) - ManagedIndexRunner.registerIndexManagementActionMetrics(IndexManagementActionsMetrics.instance) - } fun `test read write step sets step status to failed when not acknowledged`() { val setReadWriteResponse = AcknowledgedResponse(false) @@ -110,4 +93,4 @@ class SetReadWriteStepTests : OpenSearchTestCase() { }.whenever(this.mock).updateSettings(any(), any()) } } -} +} \ No newline at end of file From 20073c4ef41ee9261ab7f828f7b576d0a0cda923 Mon Sep 17 00:00:00 2001 From: harycash Date: Wed, 3 Jul 2024 14:55:26 +0530 Subject: [PATCH 13/14] Build issues fixed Signed-off-by: harycash --- .../indexstatemanagement/step/SetReadWriteStepTests.kt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 d9f6b41de..77211adde 100644 --- a/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt +++ b/src/test/kotlin/org/opensearch/indexmanagement/indexstatemanagement/step/SetReadWriteStepTests.kt @@ -93,4 +93,4 @@ class SetReadWriteStepTests : OpenSearchTestCase() { }.whenever(this.mock).updateSettings(any(), any()) } } -} \ No newline at end of file +} From 4d6176fc3bfc6563bdd202f3da42e22b30f74af9 Mon Sep 17 00:00:00 2001 From: harycash Date: Thu, 4 Jul 2024 14:01:46 +0530 Subject: [PATCH 14/14] Build issues fixed Signed-off-by: harycash --- .../indexstatemanagement/Step.kt | 17 +++++++++++++---- .../metrics/IndexManagementActionsMetrics.kt | 2 +- .../step/rollover/AttemptRolloverStep.kt | 11 +++++------ 3 files changed, 19 insertions(+), 11 deletions(-) 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 ce347ac1a..b6fb65187 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 @@ -36,6 +36,16 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { ): Step { logger.info("Finished executing $name for ${context?.metadata?.index}") val updatedStepMetaData = step.getUpdatedManagedIndexMetadata(startingManagedIndexMetaData) + emitTelemetry(indexManagementActionMetrics, updatedStepMetaData, logger) + this.context = null + return this + } + + private fun emitTelemetry( + indexManagementActionMetrics: IndexManagementActionsMetrics, + updatedStepMetaData: ManagedIndexMetaData, + logger: Logger, + ) { when (context?.metadata?.actionMetaData?.name) { IndexManagementActionsMetrics.ROLLOVER -> indexManagementActionMetrics.getActionMetrics( IndexManagementActionsMetrics.ROLLOVER, @@ -61,6 +71,7 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { IndexManagementActionsMetrics.TRANSITION, ) ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + IndexManagementActionsMetrics.NOTIFICATION -> indexManagementActionMetrics.getActionMetrics( IndexManagementActionsMetrics.NOTIFICATION, ) @@ -110,6 +121,7 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { IndexManagementActionsMetrics.ALLOCATION, ) ?.emitMetrics(context!!, indexManagementActionMetrics, updatedStepMetaData.stepMetaData) + else -> { logger.info( "Action Metrics is not supported for this action [%s]", @@ -117,8 +129,6 @@ abstract class Step(val name: String, val isSafeToDisableOn: Boolean = true) { ) } } - this.context = null - return this } abstract fun getUpdatedManagedIndexMetadata(currentMetadata: ManagedIndexMetaData): ManagedIndexMetaData @@ -137,8 +147,7 @@ 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 8dc8345b2..725893a21 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 @@ -33,7 +33,7 @@ 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) + .addTag("index_uuid", context.metadata.indexUuid) return tags } 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 f01c33e1b..5b7d455d5 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 @@ -305,12 +305,11 @@ class AttemptRolloverStep(private val action: RolloverAction) : Step(name) { // ISM cannot auto recover from this case, so the status is COMPLETED logger.error("$indexName rolled over but cannot find the rolledOverIndexName to copy aliases to") stepStatus = StepStatus.COMPLETED - info = listOfNotNull( - - "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), - if (conditions != null) "conditions" to conditions else null, - - ).toMap() + info = + listOfNotNull( + "message" to getCopyAliasRolledOverIndexNotFoundMessage(indexName), + if (conditions != null) "conditions" to conditions else null, + ).toMap() return }