From ac95105d0ce5b9e478e50f9f6536aa871f6527c1 Mon Sep 17 00:00:00 2001 From: lorenz <stu203404@mail.uni-kiel.de> Date: Sat, 13 Mar 2021 12:18:53 +0100 Subject: [PATCH] Add slo Factory --- ...nalSLOChecker.kt => ExternalSloChecker.kt} | 2 +- .../evaluation/SloCheckerFactory.kt | 29 +++++++++++++++++++ .../execution/BenchmarkExecutorImpl.kt | 18 ++++++------ .../resources/yaml/BenchmarkExecution.yaml | 2 +- 4 files changed, 40 insertions(+), 11 deletions(-) rename theodolite-quarkus/src/main/kotlin/theodolite/evaluation/{ExternalSLOChecker.kt => ExternalSloChecker.kt} (97%) create mode 100644 theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSLOChecker.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt similarity index 97% rename from theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSLOChecker.kt rename to theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt index f3cbbe828..fea4c3485 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSLOChecker.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt @@ -6,7 +6,7 @@ import java.net.ConnectException import java.time.Duration import java.time.Instant -class ExternalSLOChecker( +class ExternalSloChecker( private val prometheusURL: String, private val query: String, private val externalSlopeURL: String, diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt new file mode 100644 index 000000000..2170ef7b6 --- /dev/null +++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt @@ -0,0 +1,29 @@ +package theodolite.evaluation + +import java.time.Duration + +class SloCheckerFactory { + + fun create( + slotype: String, + prometheusURL: String, + query: String, + externalSlopeURL: String, + threshold: Int, + offset: Duration, + warmup: Int + ): SloChecker { + + return when (slotype) { + "lag trend" -> ExternalSloChecker( + prometheusURL = prometheusURL, + query = query, + externalSlopeURL = externalSlopeURL, + threshold = threshold, + offset = offset, + warmup = warmup + ) + else -> throw IllegalArgumentException("Slotype $slotype not found.") + } + } +} diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index e498c3dec..19a0cb61c 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -3,7 +3,7 @@ package theodolite.execution import mu.KotlinLogging import theodolite.benchmark.Benchmark import theodolite.benchmark.BenchmarkExecution -import theodolite.evaluation.ExternalSLOChecker +import theodolite.evaluation.SloCheckerFactory import theodolite.util.ConfigurationOverride import theodolite.util.LoadDimension import theodolite.util.Resource @@ -26,17 +26,17 @@ class BenchmarkExecutorImpl( benchmarkDeployment.setup() this.waitAndLog() benchmarkDeployment.teardown() - // todo evaluate var result = false try { - result = ExternalSLOChecker( - slo.prometheusUrl, - "sum by(group)(kafka_consumergroup_group_lag >= 0)", - slo.externalSloUrl, - slo.threshold, - Duration.ofHours(slo.offset.toLong()), - slo.warmup + result = SloCheckerFactory().create( + slotype = slo.sloType, + prometheusURL = slo.prometheusUrl, + query = "sum by(group)(kafka_consumergroup_group_lag >= 0)", + externalSlopeURL = slo.externalSloUrl, + threshold = slo.threshold, + offset = Duration.ofHours(slo.offset.toLong()), + warmup = slo.warmup ) .evaluate( Instant.now().minus(executionDuration), diff --git a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml index f1646fb21..a91d12362 100644 --- a/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml +++ b/theodolite-quarkus/src/main/resources/yaml/BenchmarkExecution.yaml @@ -9,7 +9,7 @@ resources: resourceValues: - 1 slos: - - sloType: "slo type" + - sloType: "lag trend" threshold: 1000 prometheusUrl: "http://localhost:32656" externalSloUrl: "http://localhost:80/evaluate-slope" -- GitLab