diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloCheckerFactory.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloCheckerFactory.kt index a789050a106f1b95be7c1d55043cc9d46a15ffbf..3f7c1001f14ef22d1da753f77743a93f9942db0d 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloCheckerFactory.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloCheckerFactory.kt @@ -71,6 +71,24 @@ class SloCheckerFactory { ?: throw IllegalArgumentException("threshold expected")) ) ) + SloTypes.AVERAGE_LAG -> ExternalSloChecker( + externalSlopeURL = properties["externalSloUrl"] + ?: throw IllegalArgumentException("externalSloUrl expected"), + metadata = mapOf( + "warmup" to (properties["warmup"]?.toInt() + ?: throw IllegalArgumentException("warmup expected")), + "beforeWindowLength" to (properties["beforeWindowLength"]?.toInt() + ?: throw IllegalArgumentException("beforeWindowLength expected")), + "ignoreDuring" to (properties["ignoreDuring"]?.toInt() + ?: throw IllegalArgumentException("beforeWindowLength expected")), + "afterWindowLength" to (properties["afterWindowLength"]?.toInt() + ?: throw IllegalArgumentException("afterWindowLength expected")), + "error" to (properties["error"]?.toDouble() + ?: throw IllegalArgumentException("error expected")), + "ratio" to (properties["ratio"]?.toDouble()?.times(load) + ?: throw IllegalArgumentException("Threshold ratio is incorrect")) + ) + ) SloTypes.LAG_TREND_RATIO, SloTypes.DROPPED_RECORDS_RATIO -> { val thresholdRatio = properties["ratio"]?.toDouble() diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloConfigHandler.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloConfigHandler.kt index ed18e4a0b4027ce4284cc83ff4c9520738ec2ba7..8dfcec3ae0ddb2e7cbef161ae1791f676df4e9c8 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloConfigHandler.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloConfigHandler.kt @@ -14,12 +14,13 @@ class SloConfigHandler { fun getQueryString(slo: Slo): String { return when (slo.sloType.lowercase()) { SloTypes.GENERIC.value -> slo.properties["promQLQuery"] ?: throw IllegalArgumentException("promQLQuery expected") - SloTypes.LAG_TREND.value, SloTypes.LAG_TREND_RATIO.value -> slo.properties["promQLQuery"] ?: + SloTypes.LAG_TREND.value, SloTypes.LAG_TREND_RATIO.value, SloTypes.AVERAGE_LAG.value -> + slo.properties["promQLQuery"] ?: (slo.properties["consumerGroup"]?.let { "{consumergroup='$it'}" } ?: "").let { "sum by(consumergroup) ($DEFAULT_CONSUMER_LAG_METRIC_BASE$it >= 0)" } SloTypes.DROPPED_RECORDS.value, SloTypes.DROPPED_RECORDS_RATIO.value -> slo.properties["promQLQuery"] ?: DEFAULT_DROPPED_RECORDS_QUERY - SloTypes.LAG_TREND.value, SloTypes.LAG_TREND_RATIO.value -> slo.properties["promQLQuery"] ?: DEFAULT_CONSUMER_LAG_QUERY + SloTypes.LAG_TREND.value, SloTypes.LAG_TREND_RATIO.value, SloTypes.AVERAGE_LAG.value -> slo.properties["promQLQuery"] ?: DEFAULT_CONSUMER_LAG_QUERY SloTypes.DROPPED_RECORDS.value, SloTypes.DROPPED_RECORDS_RATIO.value -> slo.properties["promQLQuery"] ?: DEFAULT_DROPPED_RECORDS_QUERY else -> throw InvalidPatcherConfigurationException("Could not find Prometheus query string for slo type ${slo.sloType}") } diff --git a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloTypes.kt b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloTypes.kt index 07cbcd634ec7b46bd0e66a52f62989660575765f..7dab8b128949d0a94ceaeb945ed61ad7fc007c1d 100644 --- a/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloTypes.kt +++ b/theodolite/src/main/kotlin/rocks/theodolite/kubernetes/slo/SloTypes.kt @@ -5,7 +5,9 @@ enum class SloTypes(val value: String) { LAG_TREND("lag trend"), LAG_TREND_RATIO("lag trend ratio"), DROPPED_RECORDS("dropped records"), - DROPPED_RECORDS_RATIO("dropped records ratio"); + DROPPED_RECORDS_RATIO("dropped records ratio"), + AVERAGE_LAG("average lag"); + companion object { fun from(type: String): SloTypes =