-
Couldn't load subscription status.
- Fork 130
Improve integration with data streams #13
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -28,7 +28,9 @@ package org.opensearch.indexmanagement.indexstatemanagement.action | |
|
|
||
| import org.apache.http.entity.ContentType | ||
| import org.apache.http.entity.StringEntity | ||
| import org.opensearch.cluster.metadata.DataStream | ||
| import org.opensearch.indexmanagement.indexstatemanagement.IndexStateManagementRestTestCase | ||
| 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.RolloverActionConfig | ||
|
|
@@ -264,4 +266,152 @@ class RolloverActionIT : IndexStateManagementRestTestCase() { | |
| } | ||
| Assert.assertTrue("New rollover index does not exist.", indexExists("$indexNameBase-000002")) | ||
| } | ||
|
|
||
| fun `test data stream rollover no condition`() { | ||
| val dataStreamName = "${testIndexName}_data_stream" | ||
| val policyID = "${testIndexName}_rollover_policy" | ||
|
|
||
| // Create the rollover policy | ||
| val rolloverActionConfig = RolloverActionConfig(null, null, null, 0) | ||
| val states = listOf(State(name = "default", actions = listOf(rolloverActionConfig), transitions = listOf())) | ||
| val policy = Policy( | ||
| id = policyID, | ||
| description = "rollover policy description", | ||
| schemaVersion = 1L, | ||
| lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), | ||
| errorNotification = randomErrorNotification(), | ||
| defaultState = states[0].name, | ||
| states = states, | ||
| ismTemplate = ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS)) | ||
| ) | ||
| createPolicy(policy, policyID) | ||
|
|
||
| // Create the data stream | ||
| val firstIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1L) | ||
| client().makeRequest( | ||
| "PUT", | ||
| "/_index_template/rollover-data-stream-template", | ||
| StringEntity("{ \"index_patterns\": [ \"$dataStreamName\" ], \"data_stream\": { } }", ContentType.APPLICATION_JSON) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Curious about There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The index pattern matches the name of the data stream instead of the backing indices. This is by design and consistent with how index patterns work in index templates as well. A data stream named I could also define |
||
| ) | ||
| client().makeRequest("PUT", "/_data_stream/$dataStreamName") | ||
|
|
||
| var managedIndexConfig = getExistingManagedIndexConfig(firstIndexName) | ||
|
|
||
| // Change the start time so that the job will trigger in 2 seconds. This will trigger the first initialization of the policy. | ||
| updateManagedIndexConfigStartTime(managedIndexConfig) | ||
| waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(firstIndexName).policyID) } | ||
|
|
||
| // Speed up to the second execution of the policy where it will trigger the first execution of the action. | ||
| updateManagedIndexConfigStartTime(managedIndexConfig) | ||
| waitFor { | ||
| val info = getExplainManagedIndexMetaData(firstIndexName).info as Map<String, Any?> | ||
| assertEquals( | ||
| "Data stream did not rollover.", | ||
| AttemptRolloverStep.getSuccessDataStreamRolloverMessage(dataStreamName, firstIndexName), | ||
| info["message"] | ||
| ) | ||
| assertNull("Should not have conditions if none specified", info["conditions"]) | ||
| } | ||
|
|
||
| val secondIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2L) | ||
| Assert.assertTrue("New rollover index does not exist.", indexExists(secondIndexName)) | ||
bowenlan-amzn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| // Ensure that that policy is applied to the newly created index as well. | ||
| managedIndexConfig = getExistingManagedIndexConfig(secondIndexName) | ||
| updateManagedIndexConfigStartTime(managedIndexConfig) | ||
| waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(secondIndexName).policyID) } | ||
| } | ||
|
|
||
| @Suppress("UNCHECKED_CAST") | ||
| fun `test data stream rollover multi condition doc size`() { | ||
| val dataStreamName = "${testIndexName}_data_stream_multi" | ||
| val policyID = "${testIndexName}_rollover_policy_multi" | ||
|
|
||
| // Create the rollover policy | ||
| val rolloverActionConfig = RolloverActionConfig(null, 3, TimeValue.timeValueDays(2), 0) | ||
| val states = listOf(State(name = "default", actions = listOf(rolloverActionConfig), transitions = listOf())) | ||
| val policy = Policy( | ||
| id = policyID, | ||
| description = "rollover policy description", | ||
| schemaVersion = 1L, | ||
| lastUpdatedTime = Instant.now().truncatedTo(ChronoUnit.MILLIS), | ||
| errorNotification = randomErrorNotification(), | ||
| defaultState = states[0].name, | ||
| states = states, | ||
| ismTemplate = ISMTemplate(listOf(dataStreamName), 100, Instant.now().truncatedTo(ChronoUnit.MILLIS)) | ||
| ) | ||
| createPolicy(policy, policyID) | ||
|
|
||
| // Create the data stream | ||
| val firstIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 1L) | ||
| client().makeRequest( | ||
| "PUT", | ||
| "/_index_template/rollover-data-stream-template", | ||
| StringEntity("{ \"index_patterns\": [ \"$dataStreamName\" ], \"data_stream\": { } }", ContentType.APPLICATION_JSON) | ||
| ) | ||
| client().makeRequest("PUT", "/_data_stream/$dataStreamName") | ||
|
|
||
| val managedIndexConfig = getExistingManagedIndexConfig(firstIndexName) | ||
|
|
||
| // Change the start time so that the job will trigger in 2 seconds. This will trigger the first initialization of the policy. | ||
| updateManagedIndexConfigStartTime(managedIndexConfig) | ||
| waitFor { assertEquals(policyID, getExplainManagedIndexMetaData(firstIndexName).policyID) } | ||
|
|
||
| // Speed up to the second execution of the policy where it will trigger the first execution of the action. | ||
| // Rollover shouldn't have happened yet as the conditions aren't met. | ||
| updateManagedIndexConfigStartTime(managedIndexConfig) | ||
| waitFor { | ||
| val info = getExplainManagedIndexMetaData(firstIndexName).info as Map<String, Any?> | ||
| assertEquals( | ||
| "Index rollover before it met the condition.", | ||
| AttemptRolloverStep.getPendingMessage(firstIndexName), | ||
| info["message"] | ||
| ) | ||
|
|
||
| val conditions = info["conditions"] as Map<String, Any?> | ||
| assertEquals( | ||
| "Did not have exclusively min age and min doc count conditions", | ||
| setOf(RolloverActionConfig.MIN_INDEX_AGE_FIELD, RolloverActionConfig.MIN_DOC_COUNT_FIELD), | ||
| conditions.keys | ||
| ) | ||
|
|
||
| val minAge = conditions[RolloverActionConfig.MIN_INDEX_AGE_FIELD] as Map<String, Any?> | ||
| val minDocCount = conditions[RolloverActionConfig.MIN_DOC_COUNT_FIELD] as Map<String, Any?> | ||
| assertEquals("Incorrect min age condition", "2d", minAge["condition"]) | ||
| assertEquals("Incorrect min docs condition", 3, minDocCount["condition"]) | ||
| assertThat("Missing min age current", minAge["current"], isA(String::class.java)) | ||
| assertEquals("Incorrect min docs current", 0, minDocCount["current"]) | ||
| } | ||
|
|
||
| insertSampleData(index = dataStreamName, docCount = 5, jsonString = "{ \"@timestamp\": \"2020-12-06T11:04:05.000Z\" }") | ||
|
|
||
| // Speed up to the third execution of the policy where it will trigger the second execution of the action. | ||
| // Rollover should have happened as the conditions were met. | ||
| updateManagedIndexConfigStartTime(managedIndexConfig) | ||
| waitFor { | ||
| val info = getExplainManagedIndexMetaData(firstIndexName).info as Map<String, Any?> | ||
| assertEquals( | ||
| "Data stream did not rollover", | ||
| AttemptRolloverStep.getSuccessDataStreamRolloverMessage(dataStreamName, firstIndexName), | ||
| info["message"] | ||
| ) | ||
|
|
||
| val conditions = info["conditions"] as Map<String, Any?> | ||
| assertEquals( | ||
| "Did not have exclusively min age and min doc count conditions", | ||
| setOf(RolloverActionConfig.MIN_INDEX_AGE_FIELD, RolloverActionConfig.MIN_DOC_COUNT_FIELD), | ||
| conditions.keys | ||
| ) | ||
|
|
||
| val minAge = conditions[RolloverActionConfig.MIN_INDEX_AGE_FIELD] as Map<String, Any?> | ||
| val minDocCount = conditions[RolloverActionConfig.MIN_DOC_COUNT_FIELD] as Map<String, Any?> | ||
| assertEquals("Incorrect min age condition", "2d", minAge["condition"]) | ||
| assertEquals("Incorrect min docs condition", 3, minDocCount["condition"]) | ||
| assertThat("Missing min age current", minAge["current"], isA(String::class.java)) | ||
| assertEquals("Incorrect min docs current", 5, minDocCount["current"]) | ||
| } | ||
|
|
||
| val secondIndexName = DataStream.getDefaultBackingIndexName(dataStreamName, 2L) | ||
| Assert.assertTrue("New rollover index does not exist.", indexExists(secondIndexName)) | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.