Skip to content
Snippets Groups Projects
Commit d80dd0c3 authored by Sören Henning's avatar Sören Henning
Browse files

Support overriding threshold

parent 7a38b045
No related branches found
No related tags found
No related merge requests found
Pipeline #10429 passed
...@@ -60,9 +60,9 @@ class SloCheckerFactory { ...@@ -60,9 +60,9 @@ class SloCheckerFactory {
"repetitionAggregation" to (properties["repetitionAggregation"] "repetitionAggregation" to (properties["repetitionAggregation"]
?: throw IllegalArgumentException("repetitionAggregation expected")), ?: throw IllegalArgumentException("repetitionAggregation expected")),
"operator" to (properties["operator"] ?: throw IllegalArgumentException("operator expected")), "operator" to (properties["operator"] ?: throw IllegalArgumentException("operator expected")),
"threshold" to (properties["threshold"]?.toDouble() "threshold" to (properties["threshold"]?.toDoubleOrNull()
?: properties["thresholdRelToLoad"]?.toDouble()?.times(load) ?: properties["thresholdRelToLoad"]?.toDoubleOrNull()?.times(load)
?: properties["thresholdRelToResources"]?.toDouble()?.times(resources) ?: properties["thresholdRelToResources"]?.toDoubleOrNull()?.times(resources)
?: throw IllegalArgumentException("'threshold', 'thresholdRelToLoad' or 'thresholdRelToResources' expected")) ?: throw IllegalArgumentException("'threshold', 'thresholdRelToLoad' or 'thresholdRelToResources' expected"))
) )
) )
...@@ -71,10 +71,10 @@ class SloCheckerFactory { ...@@ -71,10 +71,10 @@ class SloCheckerFactory {
?: throw IllegalArgumentException("externalSloUrl expected"), ?: throw IllegalArgumentException("externalSloUrl expected"),
metadata = mapOf( metadata = mapOf(
"warmup" to (properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected")), "warmup" to (properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected")),
"threshold" to (properties["threshold"]?.toDouble() "threshold" to (properties["threshold"]?.toDoubleOrNull()
?: properties["thresholdRelToLoad"]?.toDouble()?.times(load) ?: properties["thresholdRelToLoad"]?.toDoubleOrNull()?.times(load)
?: properties["thresholdRelToResources"]?.toDouble()?.times(resources) ?: properties["thresholdRelToResources"]?.toDoubleOrNull()?.times(resources)
?: throw IllegalArgumentException("'threshold', 'thresholdRelToLoad' or 'thresholdRelToResources' expected")) ?: throw IllegalArgumentException("Valid 'threshold', 'thresholdRelToLoad' or 'thresholdRelToResources' expected"))
) )
) )
SloTypes.LAG_TREND_RATIO, SloTypes.DROPPED_RECORDS_RATIO -> { SloTypes.LAG_TREND_RATIO, SloTypes.DROPPED_RECORDS_RATIO -> {
......
...@@ -152,6 +152,30 @@ internal class SloCheckerFactoryTest { ...@@ -152,6 +152,30 @@ internal class SloCheckerFactoryTest {
assertEquals(10.0, computedThreshold as Double, 0.001) assertEquals(10.0, computedThreshold as Double, 0.001)
} }
@Test
fun testCreateGenericSloWithThresholdRelToLoadAndInvalidThreshold() {
val factory = SloCheckerFactory()
val sloChecker = factory.create(
SloTypes.GENERIC.value,
mapOf(
"externalSloUrl" to "http://localhost:1234",
"warmup" to "60",
"queryAggregation" to "median",
"repetitionAggregation" to "median",
"operator" to "lte",
"threshold" to "",
"thresholdRelToLoad" to "0.1"
),
100,
5,
Metric.DEMAND
)
assertTrue(sloChecker is ExternalSloChecker)
val computedThreshold = (sloChecker as ExternalSloChecker).metadata["threshold"]
assertTrue(computedThreshold is Double)
assertEquals(10.0, computedThreshold as Double, 0.001)
}
@Test @Test
fun testCreateGenericSloWithThresholdRelToResources() { fun testCreateGenericSloWithThresholdRelToResources() {
val factory = SloCheckerFactory() val factory = SloCheckerFactory()
...@@ -290,6 +314,27 @@ internal class SloCheckerFactoryTest { ...@@ -290,6 +314,27 @@ internal class SloCheckerFactoryTest {
assertEquals(10.0, computedThreshold as Double, 0.001) assertEquals(10.0, computedThreshold as Double, 0.001)
} }
@Test
fun testCreateLagTrendSloWithThresholdRelToLoadAndInvalidThreshold() {
val factory = SloCheckerFactory()
val sloChecker = factory.create(
SloTypes.LAG_TREND.value,
mapOf(
"externalSloUrl" to "http://localhost:1234",
"warmup" to "60",
"threshold" to "",
"thresholdRelToLoad" to "0.1"
),
100,
5,
Metric.DEMAND
)
assertTrue(sloChecker is ExternalSloChecker)
val computedThreshold = (sloChecker as ExternalSloChecker).metadata["threshold"]
assertTrue(computedThreshold is Double)
assertEquals(10.0, computedThreshold as Double, 0.001)
}
@Test @Test
fun testCreateLagTrendSloWithThresholdRelToResources() { fun testCreateLagTrendSloWithThresholdRelToResources() {
val factory = SloCheckerFactory() val factory = SloCheckerFactory()
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment