Skip to content
This repository has been archived by the owner on Aug 2, 2022. It is now read-only.

Commit

Permalink
rename setting option and reverted one unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
skkosuri-amzn committed Oct 6, 2020
1 parent 956e65b commit 24c6e2b
Show file tree
Hide file tree
Showing 8 changed files with 13 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 24c6e2b

Please sign in to comment.