Skip to content

Commit

Permalink
Adds default action retries (opensearch-project#212)
Browse files Browse the repository at this point in the history
Signed-off-by: Drew Baugher <[email protected]>
  • Loading branch information
dbbaughe authored and downsrob committed Mar 9, 2022
1 parent 5074b72 commit 2f75077
Show file tree
Hide file tree
Showing 6 changed files with 19 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,7 @@ abstract class ActionConfig(
) : ToXContentFragment, Writeable {

var configTimeout: ActionTimeout? = null
private set
var configRetry: ActionRetry? = null
private set

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
configTimeout?.toXContent(builder, params)
Expand Down Expand Up @@ -76,6 +74,8 @@ abstract class ActionConfig(
}

companion object {
private const val DEFAULT_RETRIES = 3L

// TODO clean up for actionIndex
@JvmStatic
@Throws(IOException::class)
Expand Down Expand Up @@ -115,7 +115,7 @@ abstract class ActionConfig(
fun parse(xcp: XContentParser, index: Int): ActionConfig {
var actionConfig: ActionConfig? = null
var timeout: ActionTimeout? = null
var retry: ActionRetry? = null
var retry: ActionRetry? = ActionRetry(DEFAULT_RETRIES)

ensureExpectedToken(Token.START_OBJECT, xcp.currentToken(), xcp)
while (xcp.nextToken() != Token.END_OBJECT) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ data class ActionRetry(
val delay: TimeValue = TimeValue.timeValueMinutes(1)
) : ToXContentFragment, Writeable {

init { require(count > 0) { "Count for ActionRetry must be greater than 0" } }
init { require(count >= 0) { "Count for ActionRetry must be a non-negative number" } }

override fun toXContent(builder: XContentBuilder, params: ToXContent.Params): XContentBuilder {
builder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,10 @@ abstract class ODFERestTestCase : OpenSearchRestTestCase() {

@Throws(IOException::class)
open fun wipeAllODFEIndices() {
// Delete all data stream indices
client().performRequest(Request("DELETE", "/_data_stream/*"))

// Delete all indices
val response = client().performRequest(Request("GET", "/_cat/indices?format=json&expand_wildcards=all"))

val xContentType = XContentType.fromMediaTypeOrFormat(response.entity.contentType.value)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementR
import org.opensearch.indexmanagement.indexstatemanagement.model.ISMTemplate
import org.opensearch.indexmanagement.indexstatemanagement.model.Policy
import org.opensearch.indexmanagement.indexstatemanagement.model.State
import org.opensearch.indexmanagement.indexstatemanagement.model.action.ActionRetry
import org.opensearch.indexmanagement.indexstatemanagement.model.action.RolloverActionConfig
import org.opensearch.indexmanagement.indexstatemanagement.randomErrorNotification
import org.opensearch.indexmanagement.indexstatemanagement.resthandler.RestRetryFailedManagedIndexAction
Expand Down Expand Up @@ -277,6 +278,7 @@ class RolloverActionIT : IndexStateManagementRestTestCase() {
val alias1 = "x"
val policyID = "${testIndexName}_precheck"
val actionConfig = RolloverActionConfig(null, 3, TimeValue.timeValueDays(2), 0)
actionConfig.configRetry = ActionRetry(0)
val states = listOf(State(name = "RolloverAction", actions = listOf(actionConfig), transitions = listOf()))
val policy = Policy(
id = policyID,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@ class ActionConfigTests : OpenSearchTestCase() {
}
}

fun `test action retry count of zero fails`() {
fun `test action retry count of -1 fails`() {
assertFailsWith(IllegalArgumentException::class, "Expected IllegalArgumentException for retry count less than 1") {
ActionRetry(count = 0)
ActionRetry(count = -1)
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ package org.opensearch.indexmanagement.indexstatemanagement.resthandler
import org.opensearch.client.ResponseException
import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase
import org.opensearch.indexmanagement.indexstatemanagement.model.ManagedIndexMetaData
import org.opensearch.indexmanagement.indexstatemanagement.model.action.ActionRetry
import org.opensearch.indexmanagement.indexstatemanagement.model.action.AllocationActionConfig
import org.opensearch.indexmanagement.indexstatemanagement.model.managedindexmetadata.ActionMetaData
import org.opensearch.indexmanagement.indexstatemanagement.randomForceMergeActionConfig
Expand Down Expand Up @@ -208,10 +209,12 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() {

fun `test index failed`() {
val indexName = "${testIndexName}_blueberry"
val config = AllocationActionConfig(require = mapOf("..//" to "value"), exclude = emptyMap(), include = emptyMap(), index = 0)
config.configRetry = ActionRetry(0)
val states = listOf(
randomState().copy(
transitions = listOf(),
actions = listOf(AllocationActionConfig(require = mapOf("..//" to "value"), exclude = emptyMap(), include = emptyMap(), index = 0))
actions = listOf(config)
)
)
val invalidPolicy = randomPolicy().copy(
Expand Down Expand Up @@ -251,7 +254,9 @@ class RestRetryFailedManagedIndexActionIT : IndexStateManagementRestTestCase() {
fun `test reset action start time`() {
val indexName = "${testIndexName}_drewberry"
val policyID = "${testIndexName}_policy_1"
val policy = randomPolicy(states = listOf(randomState(actions = listOf(randomForceMergeActionConfig(maxNumSegments = 1)))))
val config = randomForceMergeActionConfig(maxNumSegments = 1)
config.configRetry = ActionRetry(0)
val policy = randomPolicy(states = listOf(randomState(actions = listOf(config))))
createPolicy(policy, policyId = policyID)
createIndex(indexName, policyID)

Expand Down

0 comments on commit 2f75077

Please sign in to comment.