From 24c6e2be9a1dd57aef17878dd7665ea8b16ec428 Mon Sep 17 00:00:00 2001 From: skkosuri-amzn Date: Tue, 6 Oct 2020 10:24:16 -0700 Subject: [PATCH] rename setting option and reverted one unit test --- .../alerting/AlertingPlugin.kt | 2 +- .../alerting/MonitorRunner.kt | 2 +- .../alerting/resthandler/RestGetAlertsAction.kt | 4 ++-- .../resthandler/RestGetDestinationsAction.kt | 4 ++-- .../resthandler/RestSearchMonitorAction.kt | 4 ++-- .../alerting/settings/AlertingSettings.kt | 2 +- .../alerting/AlertingRestTestCase.kt | 2 +- .../alerting/MonitorRunnerIT.kt | 16 +++------------- 8 files changed, 13 insertions(+), 23 deletions(-) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt index 7ee4286c..d7ecc6b6 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingPlugin.kt @@ -255,7 +255,7 @@ internal class AlertingPlugin : PainlessExtension, ActionPlugin, ScriptPlugin, R AlertingSettings.ALERTING_MAX_MONITORS, AlertingSettings.REQUEST_TIMEOUT, AlertingSettings.MAX_ACTION_THROTTLE_VALUE, - AlertingSettings.FILTERBY_BACKEND_ROLES, + AlertingSettings.FILTER_BY_BACKEND_ROLES, DestinationSettings.EMAIL_USERNAME, DestinationSettings.EMAIL_PASSWORD ) diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt index f94f8379..044dab30 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunner.kt @@ -197,7 +197,7 @@ class MonitorRunner( */ var roles = if (monitor.user == null) { // fixme: discuss and remove hardcoded to settings? - settings.getAsList("", listOf("all_access,AmazonES_all_access")) + settings.getAsList("", listOf("all_access", "AmazonES_all_access")) } else { monitor.user.roles } diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetAlertsAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetAlertsAction.kt index bdb0d6d2..ac8d46bd 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetAlertsAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetAlertsAction.kt @@ -46,10 +46,10 @@ class RestGetAlertsAction( ) : BaseRestHandler() { private val log = LogManager.getLogger(RestGetAlertsAction::class.java) - @Volatile private var filterBy = AlertingSettings.FILTERBY_BACKEND_ROLES.get(settings) + @Volatile private var filterBy = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings) init { - clusterService.clusterSettings.addSettingsUpdateConsumer(AlertingSettings.FILTERBY_BACKEND_ROLES) { filterBy = it } + clusterService.clusterSettings.addSettingsUpdateConsumer(AlertingSettings.FILTER_BY_BACKEND_ROLES) { filterBy = it } } override fun getName(): String { diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetDestinationsAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetDestinationsAction.kt index fd3d9e49..f12d7f33 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetDestinationsAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestGetDestinationsAction.kt @@ -47,10 +47,10 @@ class RestGetDestinationsAction( ) : BaseRestHandler() { private val log = LogManager.getLogger(RestGetDestinationsAction::class.java) - @Volatile private var filterBy = AlertingSettings.FILTERBY_BACKEND_ROLES.get(settings) + @Volatile private var filterBy = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings) init { - clusterService.clusterSettings.addSettingsUpdateConsumer(AlertingSettings.FILTERBY_BACKEND_ROLES) { filterBy = it } + clusterService.clusterSettings.addSettingsUpdateConsumer(AlertingSettings.FILTER_BY_BACKEND_ROLES) { filterBy = it } } override fun getName(): String { diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt index a3951063..7e9228e9 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/resthandler/RestSearchMonitorAction.kt @@ -61,10 +61,10 @@ class RestSearchMonitorAction( private val restClient: RestClient ) : BaseRestHandler() { - @Volatile private var filterBy = AlertingSettings.FILTERBY_BACKEND_ROLES.get(settings) + @Volatile private var filterBy = AlertingSettings.FILTER_BY_BACKEND_ROLES.get(settings) init { - clusterService.clusterSettings.addSettingsUpdateConsumer(AlertingSettings.FILTERBY_BACKEND_ROLES) { filterBy = it } + clusterService.clusterSettings.addSettingsUpdateConsumer(AlertingSettings.FILTER_BY_BACKEND_ROLES) { filterBy = it } } override fun getName(): String { diff --git a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/settings/AlertingSettings.kt b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/settings/AlertingSettings.kt index ed374a3f..94183b6a 100644 --- a/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/settings/AlertingSettings.kt +++ b/alerting/src/main/kotlin/com/amazon/opendistroforelasticsearch/alerting/settings/AlertingSettings.kt @@ -120,7 +120,7 @@ class AlertingSettings { TimeValue.timeValueHours(24), Setting.Property.NodeScope, Setting.Property.Dynamic) - val FILTERBY_BACKEND_ROLES = Setting.boolSetting( + val FILTER_BY_BACKEND_ROLES = Setting.boolSetting( "opendistro.alerting.filterby_backendroles", false, Setting.Property.NodeScope, Setting.Property.Dynamic) diff --git a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt index 49689a4f..e1be4357 100644 --- a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt +++ b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/AlertingRestTestCase.kt @@ -605,7 +605,7 @@ abstract class AlertingRestTestCase : ODFERestTestCase() { val updateResponse = client().makeRequest("PUT", "_cluster/settings", emptyMap(), StringEntity(XContentFactory.jsonBuilder().startObject().field("persistent") - .startObject().field(AlertingSettings.FILTERBY_BACKEND_ROLES.key, true).endObject() + .startObject().field(AlertingSettings.FILTER_BY_BACKEND_ROLES.key, true).endObject() .endObject().string(), ContentType.APPLICATION_JSON)) assertEquals(updateResponse.statusLine.toString(), 200, updateResponse.statusLine.statusCode) } diff --git a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt index 979a1b72..616091b3 100644 --- a/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt +++ b/alerting/src/test/kotlin/com/amazon/opendistroforelasticsearch/alerting/MonitorRunnerIT.kt @@ -271,19 +271,9 @@ class MonitorRunnerIT : AlertingRestTestCase() { assertEquals("Alert saved for test monitor", 0, alerts.size) } - fun `test execute monitor search with star`() { - val testIndex = createTestIndex() - val twoMinsAgo = ZonedDateTime.now().minus(2, MINUTES).truncatedTo(MILLIS) - val testTime = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(twoMinsAgo) - val testDoc = """{ "test_strict_date_time" : "$testTime" }""" - indexDoc(testIndex, "1", testDoc) - - val query = QueryBuilders.rangeQuery("test_strict_date_time") - .gt("{{period_end}}||-10d") - .lte("{{period_end}}") - .format("epoch_millis") - - val input = SearchInput(indices = listOf("*"), query = SearchSourceBuilder().query(query)) + fun `test execute monitor search with period`() { + val query = QueryBuilders.rangeQuery("monitor.last_update_time").gte("{{period_start}}").lte("{{period_end}}") + val input = SearchInput(indices = listOf(".*"), query = SearchSourceBuilder().query(query)) val triggerScript = """ // make sure there is at least one monitor return ctx.results[0].hits.hits.size() > 0