diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt b/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt index 281c68e318784ee8206473cd014f814b3f5152a9..9a1315e7a88f0cdcae06dbb7ead757e1c0ce9931 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt @@ -37,7 +37,6 @@ class AnalysisExecutor( * @return true if the experiment succeeded. */ fun analyze(load: LoadDimension, res: Resource, executionIntervals: List<Pair<Instant, Instant>>): Boolean { - var result: Boolean var repetitionCounter = 1 try { @@ -50,7 +49,7 @@ class AnalysisExecutor( fetcher.fetchMetric( start = interval.first, end = interval.second, - query = SloConfigHandler.getQueryString(sloType = slo.sloType) + query = SloConfigHandler.getQueryString(slo = slo) ) } @@ -68,12 +67,11 @@ class AnalysisExecutor( load = load ) - result = sloChecker.evaluate(prometheusData) + return sloChecker.evaluate(prometheusData) } catch (e: Exception) { - throw EvaluationFailedException("Evaluation failed for resource '${res.get()}' and load '${load.get()} ", e) + throw EvaluationFailedException("Evaluation failed for resource '${res.get()}' and load '${load.get()}", e) } - return result } private val NONLATIN: Pattern = Pattern.compile("[^\\w-]") diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt b/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt index d646286b70bc5880df1f603afdc2bda22bcc3259..9fd00c4dbe3c006f2ebbf3eca2b831a955aadcdc 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt @@ -1,6 +1,5 @@ package theodolite.evaluation -import com.google.gson.Gson import khttp.post import mu.KotlinLogging import theodolite.util.PrometheusResponse @@ -39,7 +38,7 @@ class ExternalSloChecker( val data = SloJson.Builder() .results(fetchedData.map { it.data?.result }) .addMetadata("threshold", threshold) - .addMetadata( "warmup", warmup) + .addMetadata("warmup", warmup) .build() .toJson() @@ -47,10 +46,10 @@ class ExternalSloChecker( val result = post(externalSlopeURL, data = data, timeout = TIMEOUT) if (result.statusCode != 200) { counter++ - logger.error { "Could not reach external SLO checker" } + logger.error { "Could not reach external SLO checker." } } else { val booleanResult = result.text.toBoolean() - logger.info { "SLO checker result is: $booleanResult" } + logger.info { "SLO checker result is: $booleanResult." } return booleanResult } } diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloChecker.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloChecker.kt index af70fa5dca3f0556d38791ed96c2af30b9a44a68..82f903f5be868731d58ebefd6279d5d438bd5eab 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloChecker.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloChecker.kt @@ -11,7 +11,7 @@ interface SloChecker { * Evaluates [fetchedData] and returns if the experiments were successful. * * @param fetchedData from Prometheus that will be evaluated. - * @return true if experiments were successful. Otherwise false. + * @return true if experiments were successful. Otherwise, false. */ fun evaluate(fetchedData: List<PrometheusResponse>): Boolean } diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt index 64f9110cd931feef41dc65f88d6623e82f4e03a2..b47a347196ecf41d1128d1c2f437edfd7eef4e1d 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt @@ -43,15 +43,14 @@ class SloCheckerFactory { properties: MutableMap<String, String>, load: LoadDimension ): SloChecker { - return when (sloType.toLowerCase()) { - SloTypes.LAG_TREND.value, SloTypes.DROPPED_RECORDS.value -> ExternalSloChecker( + return when (SloTypes.from(sloType)) { + SloTypes.GENERIC, SloTypes.LAG_TREND, SloTypes.DROPPED_RECORDS -> ExternalSloChecker( externalSlopeURL = properties["externalSloUrl"] ?: throw IllegalArgumentException("externalSloUrl expected"), threshold = properties["threshold"]?.toInt() ?: throw IllegalArgumentException("threshold expected"), warmup = properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected") ) - - SloTypes.LAG_TREND_RATIO.value, SloTypes.DROPPED_RECORDS_RATIO.value -> { + SloTypes.LAG_TREND_RATIO, SloTypes.DROPPED_RECORDS_RATIO -> { val thresholdRatio = properties["ratio"]?.toDouble() ?: throw IllegalArgumentException("ratio for threshold expected") @@ -68,7 +67,6 @@ class SloCheckerFactory { warmup = properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected") ) } - else -> throw IllegalArgumentException("Slotype $sloType not found.") } } } diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt index 93929218c822030ff065dafb19cce1fbaa69a179..425a4f3b0634d53f8b1d5c4b8abdba9ca81c3f2b 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt @@ -1,5 +1,6 @@ package theodolite.evaluation +import theodolite.benchmark.BenchmarkExecution import theodolite.util.InvalidPatcherConfigurationException import javax.enterprise.context.ApplicationScoped @@ -7,13 +8,14 @@ private const val CONSUMER_LAG_QUERY = "sum by(group)(kafka_consumergroup_group_ private const val DROPPED_RECORDS_QUERY = "sum by(job) (kafka_streams_stream_task_metrics_dropped_records_total>=0)" @ApplicationScoped -class SloConfigHandler() { +class SloConfigHandler { companion object { - fun getQueryString(sloType: String): String { - return when (sloType.toLowerCase()) { + fun getQueryString(slo: BenchmarkExecution.Slo): String { + return when (slo.sloType.toLowerCase()) { + SloTypes.GENERIC.value -> slo.properties["promQLQuery"] ?: throw IllegalArgumentException("promQLQuery expected") SloTypes.LAG_TREND.value, SloTypes.LAG_TREND_RATIO.value -> CONSUMER_LAG_QUERY SloTypes.DROPPED_RECORDS.value, SloTypes.DROPPED_RECORDS_RATIO.value -> DROPPED_RECORDS_QUERY - else -> throw InvalidPatcherConfigurationException("Could not find Prometheus query string for slo type $sloType") + else -> throw InvalidPatcherConfigurationException("Could not find Prometheus query string for slo type $slo.sloType") } } } diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloTypes.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloTypes.kt index ac9de35861b0bd9c012bfb0b8cfcb2e1aa5aed68..812b50de779d2f3abfd5788b8aee145edc959e6c 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloTypes.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloTypes.kt @@ -1,10 +1,14 @@ package theodolite.evaluation enum class SloTypes(val value: String) { + GENERIC("generic"), 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"); + companion object { + fun from(type: String): SloTypes = + values().find { it.value == type } ?: throw IllegalArgumentException("Requested SLO does not exist") + } } \ No newline at end of file