Skip to content

Commit

Permalink
Add condition to the templateArg of BucketLevelTrigger (opensearch-pr…
Browse files Browse the repository at this point in the history
…oject#576)

* Add condition to templateArg of BucketLevelTrigger

Signed-off-by: Chase Engelbrecht <[email protected]>

* Remove debug println

Signed-off-by: Chase Engelbrecht <[email protected]>

---------

Signed-off-by: Chase Engelbrecht <[email protected]>
  • Loading branch information
engechas authored Dec 21, 2023
1 parent 2ff995b commit 195b17d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -69,14 +69,19 @@ data class BucketLevelTrigger(
NAME_FIELD to name,
SEVERITY_FIELD to severity,
ACTIONS_FIELD to actions.map { it.asTemplateArg() },
PARENT_BUCKET_PATH to getParentBucketPath()
PARENT_BUCKET_PATH to getParentBucketPath(),
CONDITION_FIELD to getCondition()
)
}

fun getParentBucketPath(): String {
return bucketSelector.parentBucketPath
}

fun getCondition(): String {
return bucketSelector.script.idOrCode
}

companion object {
const val BUCKET_LEVEL_TRIGGER_FIELD = "bucket_level_trigger"
const val CONDITION_FIELD = "condition"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.opensearch.commons.alerting.model

import org.junit.jupiter.api.Test
import org.opensearch.commons.alerting.randomBucketLevelTrigger
import kotlin.test.assertEquals

class BucketLevelTriggerTests {

@Test
fun `test asTemplateArgs returns expected values`() {
val bucketLevelTrigger = randomBucketLevelTrigger()
val templateArg = bucketLevelTrigger.asTemplateArg()

assertEquals(templateArg[Trigger.ID_FIELD], bucketLevelTrigger.id)
assertEquals(templateArg[Trigger.NAME_FIELD], bucketLevelTrigger.name)
assertEquals(templateArg[Trigger.SEVERITY_FIELD], bucketLevelTrigger.severity)
assertEquals(templateArg[Trigger.ACTIONS_FIELD], bucketLevelTrigger.actions.map { it.asTemplateArg() })
assertEquals(templateArg[BucketLevelTrigger.PARENT_BUCKET_PATH], bucketLevelTrigger.bucketSelector.parentBucketPath)
assertEquals(templateArg[BucketLevelTrigger.CONDITION_FIELD], bucketLevelTrigger.bucketSelector.script.idOrCode)
}
}

0 comments on commit 195b17d

Please sign in to comment.