@@ -18,6 +18,7 @@ import org.opensearch.action.admin.indices.mapping.get.GetMappingsRequest
18
18
import org.opensearch.action.admin.indices.mapping.put.PutMappingRequest
19
19
import org.opensearch.action.admin.indices.open.OpenIndexRequest
20
20
import org.opensearch.action.admin.indices.refresh.RefreshRequest
21
+ import org.opensearch.action.admin.indices.settings.get.GetSettingsResponse
21
22
import org.opensearch.action.bulk.BulkRequest
22
23
import org.opensearch.action.bulk.BulkResponse
23
24
import org.opensearch.action.fieldcaps.FieldCapabilitiesRequest
@@ -30,6 +31,7 @@ import org.opensearch.alerting.transport.AlertingSingleNodeTestCase
30
31
import org.opensearch.alerting.util.DocLevelMonitorQueries
31
32
import org.opensearch.alerting.util.DocLevelMonitorQueries.Companion.INDEX_PATTERN_SUFFIX
32
33
import org.opensearch.alerting.workflow.CompositeWorkflowRunner
34
+ import org.opensearch.cluster.metadata.IndexMetadata
33
35
import org.opensearch.common.settings.Settings
34
36
import org.opensearch.common.xcontent.LoggingDeprecationHandler
35
37
import org.opensearch.common.xcontent.XContentHelper
@@ -6174,4 +6176,61 @@ class MonitorDataSourcesIT : AlertingSingleNodeTestCase() {
6174
6176
Assert .assertEquals(completedAlert1.alerts[0 ].state, Alert .State .COMPLETED )
6175
6177
Assert .assertTrue(completedAlert1.alerts[0 ].endTime!! > acknowledgedAlert.alerts[0 ].lastNotificationTime!! )
6176
6178
}
6179
+
6180
+ fun `test query index created with single primary and single replica shard` () {
6181
+ val docQuery = DocLevelQuery (query = " test_field:\" us-west-2\" " , name = " 3" , fields = listOf ())
6182
+ val docLevelInput = DocLevelMonitorInput (" description" , listOf (index), listOf (docQuery))
6183
+ val trigger = randomDocumentLevelTrigger(condition = ALWAYS_RUN )
6184
+ var monitor = randomDocumentLevelMonitor(
6185
+ inputs = listOf (docLevelInput),
6186
+ triggers = listOf (trigger),
6187
+ dataSources = DataSources (queryIndex = " .opensearch-alerting-custom-queries" )
6188
+ )
6189
+ val monitorResponse = createMonitor(monitor)
6190
+ val testTime = DateTimeFormatter .ISO_OFFSET_DATE_TIME .format(ZonedDateTime .now().truncatedTo(MILLIS ))
6191
+ val testDoc = """ {
6192
+ "message" : "This is an error from IAD region",
6193
+ "test_strict_date_time" : "$testTime ",
6194
+ "test_field" : "us-west-2"
6195
+ }"""
6196
+ assertFalse(monitorResponse?.id.isNullOrEmpty())
6197
+ monitor = monitorResponse!! .monitor
6198
+ indexDoc(index, " 1" , testDoc)
6199
+ val id = monitorResponse.id
6200
+ executeMonitor(monitor, id, false )
6201
+
6202
+ var response: GetSettingsResponse ? = getIndexSettings(" .opensearch-alerting-custom-queries-000001" )
6203
+ assertEquals(
6204
+ " 1" ,
6205
+ response!! .getSetting(
6206
+ " .opensearch-alerting-custom-queries-000001" ,
6207
+ IndexMetadata .SETTING_NUMBER_OF_SHARDS
6208
+ )
6209
+ )
6210
+ assertEquals(
6211
+ " 0" ,
6212
+ response.getSetting(
6213
+ " .opensearch-alerting-custom-queries-000001" ,
6214
+ IndexMetadata .SETTING_NUMBER_OF_REPLICAS
6215
+ )
6216
+ )
6217
+
6218
+ executeMonitor(monitor, id, false )
6219
+
6220
+ response = getIndexSettings(" .opensearch-alerting-custom-queries-000001" )
6221
+ assertEquals(
6222
+ " 1" ,
6223
+ response!! .getSetting(
6224
+ " .opensearch-alerting-custom-queries-000001" ,
6225
+ IndexMetadata .SETTING_NUMBER_OF_SHARDS
6226
+ )
6227
+ )
6228
+ assertEquals(
6229
+ " 0" ,
6230
+ response.getSetting(
6231
+ " .opensearch-alerting-custom-queries-000001" ,
6232
+ IndexMetadata .SETTING_NUMBER_OF_REPLICAS
6233
+ )
6234
+ )
6235
+ }
6177
6236
}
0 commit comments