Skip to content
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

fix number of shards of query index to 0 and auto expand replicas to 0-1 #1702

Merged
merged 4 commits into from
Oct 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import org.opensearch.alerting.MonitorRunnerService.monitorCtx
import org.opensearch.alerting.opensearchapi.suspendUntil
import org.opensearch.client.Client
import org.opensearch.cluster.ClusterState
import org.opensearch.cluster.metadata.IndexMetadata
import org.opensearch.cluster.service.ClusterService
import org.opensearch.common.settings.Settings
import org.opensearch.common.unit.TimeValue
Expand Down Expand Up @@ -130,6 +131,8 @@ class DocLevelMonitorQueries(private val client: Client, private val clusterServ
.alias(Alias(alias))
.settings(
Settings.builder().put("index.hidden", true)
.put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "0-1")
.build()
)
return try {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest
import org.opensearch.action.admin.indices.open.OpenIndexRequest
import org.opensearch.action.admin.indices.refresh.RefreshRequest
import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse
import org.opensearch.action.bulk.BulkRequest
import org.opensearch.action.bulk.BulkResponse
import org.opensearch.action.fieldcaps.FieldCapabilitiesRequest
Expand All @@ -30,6 +31,7 @@ import org.opensearch.alerting.transport.AlertingSingleNodeTestCase
import org.opensearch.alerting.util.DocLevelMonitorQueries
import org.opensearch.alerting.util.DocLevelMonitorQueries.Companion.INDEX_PATTERN_SUFFIX
import org.opensearch.alerting.workflow.CompositeWorkflowRunner
import org.opensearch.cluster.metadata.IndexMetadata
import org.opensearch.common.settings.Settings
import org.opensearch.common.xcontent.LoggingDeprecationHandler
import org.opensearch.common.xcontent.XContentHelper
Expand Down Expand Up @@ -6174,4 +6176,61 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
Assert.assertEquals(completedAlert1.alerts[0].state, Alert.State.COMPLETED)
Assert.assertTrue(completedAlert1.alerts[0].endTime!! > acknowledgedAlert.alerts[0].lastNotificationTime!!)
}

fun `test query index created with single primary and single replica shard`() {
val docQuery = DocLevelQuery(query = "test_field:\"us-west-2\"", name = "3", fields = listOf())
val docLevelInput = DocLevelMonitorInput("description", listOf(index), listOf(docQuery))
val trigger = randomDocumentLevelTrigger(condition = ALWAYS_RUN)
var monitor = randomDocumentLevelMonitor(
inputs = listOf(docLevelInput),
triggers = listOf(trigger),
dataSources = DataSources(queryIndex = ".opensearch-alerting-custom-queries")
)
val monitorResponse = createMonitor(monitor)
val testTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now().truncatedTo(MILLIS))
val testDoc = """{
"message" : "This is an error from IAD region",
"test_strict_date_time" : "$testTime",
"test_field" : "us-west-2"
}"""
assertFalse(monitorResponse?.id.isNullOrEmpty())
monitor = monitorResponse!!.monitor
indexDoc(index, "1", testDoc)
val id = monitorResponse.id
executeMonitor(monitor, id, false)

var response: GetSettingsResponse? = getIndexSettings(".opensearch-alerting-custom-queries-000001")
assertEquals(
"1",
response!!.getSetting(
".opensearch-alerting-custom-queries-000001",
IndexMetadata.SETTING_NUMBER_OF_SHARDS
)
)
assertEquals(
"0",
response.getSetting(
".opensearch-alerting-custom-queries-000001",
IndexMetadata.SETTING_NUMBER_OF_REPLICAS
)
)

executeMonitor(monitor, id, false)

response = getIndexSettings(".opensearch-alerting-custom-queries-000001")
assertEquals(
"1",
response!!.getSetting(
".opensearch-alerting-custom-queries-000001",
IndexMetadata.SETTING_NUMBER_OF_SHARDS
)
)
assertEquals(
"0",
response.getSetting(
".opensearch-alerting-custom-queries-000001",
IndexMetadata.SETTING_NUMBER_OF_REPLICAS
)
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ import org.opensearch.action.admin.indices.get.GetIndexRequestBuilder
import org.opensearch.action.admin.indices.get.GetIndexResponse
import org.opensearch.action.admin.indices.refresh.RefreshAction
import org.opensearch.action.admin.indices.refresh.RefreshRequest
import org.opensearch.action.admin.indices.settings.get.GetSettingsRequest
import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse
import org.opensearch.action.support.IndicesOptions
import org.opensearch.action.support.WriteRequest
import org.opensearch.alerting.AlertingPlugin
Expand Down Expand Up @@ -493,6 +495,11 @@ abstract class AlertingSingleNodeTestCase : OpenSearchSingleNodeTestCase() {
return client().execute(ExecuteWorkflowAction.INSTANCE, request).get()
}

protected fun getIndexSettings(index: String): GetSettingsResponse? {
val request = GetSettingsRequest().indices(index)
return client().admin().indices().getSettings(request).get()
}

override fun nodeSettings(): Settings {
return Settings.builder()
.put(super.nodeSettings())
Expand Down
Loading