From 0529664671dffc9e08341a887b7331555c7f2a10 Mon Sep 17 00:00:00 2001 From: Marcel Becker <stu117960@mail.uni-kiel.de> Date: Tue, 1 Mar 2022 12:46:40 +0100 Subject: [PATCH] Finished SLOFactory, constructing SLOs from Benchmark and Execution yaml --- .../examples/operator/example-benchmark.yaml | 9 +++++++++ .../examples/operator/example-execution.yaml | 6 +----- .../theodolite/benchmark/BenchmarkExecution.kt | 15 ++++++--------- .../theodolite/benchmark/KubernetesBenchmark.kt | 2 +- .../theodolite/evaluation/SloConfigHandler.kt | 3 +-- .../kotlin/theodolite/execution/SloFactory.kt | 16 +++++++++------- .../execution/operator/BenchmarkCRDummy.kt | 1 + .../k8s-resource-files/test-benchmark.yaml | 9 +++++++++ .../k8s-resource-files/test-execution-1.yaml | 2 +- .../test-execution-update.yaml | 6 +----- .../k8s-resource-files/test-execution.yaml | 6 +----- 11 files changed, 40 insertions(+), 35 deletions(-) diff --git a/theodolite/examples/operator/example-benchmark.yaml b/theodolite/examples/operator/example-benchmark.yaml index 62920091e..be7116c46 100644 --- a/theodolite/examples/operator/example-benchmark.yaml +++ b/theodolite/examples/operator/example-benchmark.yaml @@ -33,6 +33,15 @@ spec: resource: "uc1-load-generator-deployment.yaml" properties: loadGenMaxRecords: "150000" + slos: + - name: "lag trend" + sloType: "lag trend" + prometheusUrl: "http://prometheus-operated:9090" + offset: 0 + properties: + threshold: 3000 + externalSloUrl: "http://localhost:80/evaluate-slope" + warmup: 60 # in seconds kafkaConfig: bootstrapServer: "theodolite-kafka-kafka-bootstrap:9092" topics: diff --git a/theodolite/examples/operator/example-execution.yaml b/theodolite/examples/operator/example-execution.yaml index 576a74b90..d1573e3f4 100644 --- a/theodolite/examples/operator/example-execution.yaml +++ b/theodolite/examples/operator/example-execution.yaml @@ -11,13 +11,9 @@ spec: resourceType: "Instances" resourceValues: [1, 2, 3, 4, 5] slos: - - sloType: "lag trend" - prometheusUrl: "http://prometheus-operated:9090" - offset: 0 + - name: "lag trend" properties: threshold: 2000 - externalSloUrl: "http://localhost:80/evaluate-slope" - warmup: 60 # in seconds execution: strategy: "LinearSearch" duration: 300 # in seconds diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt index 1b295116e..02e9553d2 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt @@ -30,7 +30,7 @@ class BenchmarkExecution : KubernetesResource { lateinit var benchmark: String lateinit var load: LoadDefinition lateinit var resources: ResourceDefinition - lateinit var slos: List<KubernetesBenchmark.Slo> + lateinit var slos: List<Slo> lateinit var execution: Execution lateinit var configOverrides: MutableList<ConfigurationOverride?> @@ -49,25 +49,22 @@ class BenchmarkExecution : KubernetesResource { var afterTeardownDelay = 5L } - //TODO: use new SLO class since the values do not need to be set (just optional) /** * Measurable metric. - * [sloType] determines the type of the metric. * It is evaluated using the [theodolite.evaluation.ExternalSloChecker] by data measured by Prometheus. * The evaluation checks if a [threshold] is reached or not. * [offset] determines the shift in hours by which the start and end timestamps should be shifted. * The [warmup] determines after which time the metric should be evaluated to avoid starting interferences. * The [warmup] time unit depends on the Slo: for the lag trend it is in seconds. */ - /* @JsonDeserialize + @JsonDeserialize @RegisterForReflection class Slo : KubernetesResource { lateinit var name: String - lateinit var sloType: String - lateinit var prometheusUrl: String - var offset by Delegates.notNull<Int>() - lateinit var properties: MutableMap<String, String> - }*/ + var prometheusUrl: String? = null + var offset : Int? = null + var properties: MutableMap<String, String>? = null + } /** * Represents a Load that should be created and checked. diff --git a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index 62dd30c67..d4f9f58fc 100644 --- a/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -40,7 +40,7 @@ class KubernetesBenchmark : KubernetesResource, Benchmark { lateinit var name: String lateinit var resourceTypes: List<TypeName> lateinit var loadTypes: List<TypeName> - lateinit var slos: List<Slo> + lateinit var slos: MutableList<Slo> var kafkaConfig: KafkaConfig? = null lateinit var infrastructure: Resources lateinit var sut: Resources diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt index 75ae8672e..b3e13362b 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloConfigHandler.kt @@ -7,12 +7,11 @@ import javax.enterprise.context.ApplicationScoped private const val CONSUMER_LAG_QUERY = "sum by(consumergroup) (kafka_consumergroup_lag >= 0)" private const val DROPPED_RECORDS_QUERY = "sum by(job) (kafka_streams_stream_task_metrics_dropped_records_total>=0)" -//TODO: slo.sloType.toLowerCase() is deprecated @ApplicationScoped class SloConfigHandler { companion object { fun getQueryString(slo: KubernetesBenchmark.Slo): String { - return when (slo.sloType.toLowerCase()) { + return when (slo.sloType.lowercase()) { 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 diff --git a/theodolite/src/main/kotlin/theodolite/execution/SloFactory.kt b/theodolite/src/main/kotlin/theodolite/execution/SloFactory.kt index 89b815d0f..966e19bdc 100644 --- a/theodolite/src/main/kotlin/theodolite/execution/SloFactory.kt +++ b/theodolite/src/main/kotlin/theodolite/execution/SloFactory.kt @@ -8,14 +8,16 @@ class SloFactory { fun createSlos(execution: BenchmarkExecution, benchmark: KubernetesBenchmark): List<KubernetesBenchmark.Slo> { var benchmarkSlos = benchmark.slos var executionSlos = execution.slos - //TODO: test if we can actually overwrite entries of the objects + for(executionSlo in executionSlos) { - for(benchmarkSlo in benchmarkSlos) { - if(executionSlo.name == benchmarkSlo.name) { - benchmarkSlo.offset = executionSlo.offset ?: benchmarkSlo.offset - benchmarkSlo.prometheusUrl = executionSlo.prometheusUrl ?: benchmarkSlo.prometheusUrl - for(executionProperty in executionSlo.properties) { - benchmarkSlo.properties[executionProperty.key] = executionProperty.value + for(i in 0..benchmarkSlos.size) { + if(executionSlo.name == benchmarkSlos[i].name) { + benchmarkSlos[i].offset = executionSlo.offset ?: benchmarkSlos[i].offset + benchmarkSlos[i].prometheusUrl = executionSlo.prometheusUrl ?: benchmarkSlos[i].prometheusUrl + if (executionSlo.properties != null) { + for (executionProperty in executionSlo.properties!!) { + benchmarkSlos[i].properties[executionProperty.key] = executionProperty.value + } } } } diff --git a/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt b/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt index cbddbfbfc..bf73ea9db 100644 --- a/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt +++ b/theodolite/src/test/kotlin/theodolite/execution/operator/BenchmarkCRDummy.kt @@ -43,6 +43,7 @@ class BenchmarkCRDummy(name: String) { benchmark.resourceTypes = emptyList() benchmark.loadTypes = emptyList() + benchmark.slos = mutableListOf() benchmark.kafkaConfig = kafkaConfig benchmark.name = benchmarkCR.metadata.name } diff --git a/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml b/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml index 1ba204bb2..a15b8259f 100644 --- a/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml +++ b/theodolite/src/test/resources/k8s-resource-files/test-benchmark.yaml @@ -28,6 +28,15 @@ spec: resource: "uc1-load-generator-deployment.yaml" properties: loadGenMaxRecords: "15000" + slos: + - name: "lag trend" + sloType: "lag trend" + prometheusUrl: "http://prometheus-operated:9090" + offset: 0 + properties: + threshold: 3000 + externalSloUrl: "http://localhost:80/evaluate-slope" + warmup: 60 # in seconds kafkaConfig: bootstrapServer: "theodolite-kafka-kafka-bootstrap:9092" topics: diff --git a/theodolite/src/test/resources/k8s-resource-files/test-execution-1.yaml b/theodolite/src/test/resources/k8s-resource-files/test-execution-1.yaml index 1407a9952..27a24946e 100644 --- a/theodolite/src/test/resources/k8s-resource-files/test-execution-1.yaml +++ b/theodolite/src/test/resources/k8s-resource-files/test-execution-1.yaml @@ -12,7 +12,7 @@ spec: resourceType: "Instances" resourceValues: [1, 2, 3, 4, 5] slos: - - sloType: "lag trend" + - name: "lag trend" threshold: 2000 prometheusUrl: "http://prometheus-operated:9090" externalSloUrl: "http://localhost:80/evaluate-slope" diff --git a/theodolite/src/test/resources/k8s-resource-files/test-execution-update.yaml b/theodolite/src/test/resources/k8s-resource-files/test-execution-update.yaml index c075702da..8c9c861f0 100644 --- a/theodolite/src/test/resources/k8s-resource-files/test-execution-update.yaml +++ b/theodolite/src/test/resources/k8s-resource-files/test-execution-update.yaml @@ -12,13 +12,9 @@ spec: resourceType: "Instances" resourceValues: [1, 2, 3, 4, 5] slos: - - sloType: "lag trend" - prometheusUrl: "http://prometheus-operated:9090" - offset: 0 + - name: "lag trend" properties: threshold: 2000 - externalSloUrl: "http://localhost:80/evaluate-slope" - warmup: 60 # in seconds execution: strategy: "LinearSearch" duration: 300 # in seconds diff --git a/theodolite/src/test/resources/k8s-resource-files/test-execution.yaml b/theodolite/src/test/resources/k8s-resource-files/test-execution.yaml index e12c851da..cafe02260 100644 --- a/theodolite/src/test/resources/k8s-resource-files/test-execution.yaml +++ b/theodolite/src/test/resources/k8s-resource-files/test-execution.yaml @@ -12,13 +12,9 @@ spec: resourceType: "Instances" resourceValues: [1, 2, 3, 4, 5] slos: - - sloType: "lag trend" - prometheusUrl: "http://prometheus-operated:9090" - offset: 0 + - name: "lag trend" properties: threshold: 2000 - externalSloUrl: "http://localhost:80/evaluate-slope" - warmup: 60 # in seconds execution: strategy: "LinearSearch" duration: 300 # in seconds -- GitLab