diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt index a2d649ab38f4c0fda31d7c99d687cc253efe1ea8..36fd00795e3f075ca1fbd171fa59339df8151f85 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/BenchmarkExecution.kt @@ -11,6 +11,7 @@ import kotlin.properties.Delegates @JsonDeserialize @RegisterForReflection class BenchmarkExecution : CustomResource(), Namespaced { + var executionId: Int = 0 lateinit var name: String lateinit var benchmark: String lateinit var load: LoadDefinition diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt index a75cd96efdb1be3999bf040f0a7fc0b1d8bb739e..a348deb9ff2acf592458635712b99c8d23fb0577 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/benchmark/KubernetesBenchmark.kt @@ -26,7 +26,6 @@ class KubernetesBenchmark : Benchmark, CustomResource(), Namespaced { private fun loadKubernetesResources(resources: List<String>): List<Pair<String, KubernetesResource>> { val parser = YamlParser() - val loader = K8sResourceLoader(DefaultKubernetesClient().inNamespace(namespace)) return resources .map { resource -> diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt index ce63f23a31840b8e47cb15b71a026d35e438e953..0b6c681c9123adace08bc60946a067442ca2baa1 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt @@ -9,7 +9,10 @@ import java.time.Instant private val logger = KotlinLogging.logger {} -class AnalysisExecutor(private val slo: BenchmarkExecution.Slo) { +class AnalysisExecutor( + private val slo: BenchmarkExecution.Slo, + private val executionId: Int +) { private val fetcher = MetricFetcher( prometheusURL = slo.prometheusUrl, @@ -26,8 +29,7 @@ class AnalysisExecutor(private val slo: BenchmarkExecution.Slo) { query = "sum by(group)(kafka_consumergroup_group_lag >= 0)" ) - CsvExporter().toCsv(name = "${load.get()}_${res.get()}_${slo.sloType}", prom = prometheusData) - + CsvExporter().toCsv(name = "$executionId-${load.get()}-${res.get()}-${slo.sloType}", prom = prometheusData) val sloChecker = SloCheckerFactory().create( slotype = slo.sloType, externalSlopeURL = slo.externalSloUrl, diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt index 9332af89810d24f87016fd02ce56d35a5ab07ca5..a6eae8bbfb1273b90e3d457db3287d6fc1546fbe 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutor.kt @@ -25,7 +25,8 @@ abstract class BenchmarkExecutor( val results: Results, val executionDuration: Duration, configurationOverrides: List<ConfigurationOverride?>, - val slo: BenchmarkExecution.Slo + val slo: BenchmarkExecution.Slo, + val executionId: Int ) { var run: AtomicBoolean = AtomicBoolean(true) diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt index 027b9328336adcfc66299c94335a895d48a7181f..03c66e757abab9de69bc97ff98a67fffdafdf3d1 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt @@ -19,8 +19,9 @@ class BenchmarkExecutorImpl( results: Results, executionDuration: Duration, private val configurationOverrides: List<ConfigurationOverride?>, - slo: BenchmarkExecution.Slo -) : BenchmarkExecutor(benchmark, results, executionDuration, configurationOverrides, slo) { + slo: BenchmarkExecution.Slo, + executionId: Int +) : BenchmarkExecutor(benchmark, results, executionDuration, configurationOverrides, slo, executionId) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean { var result = false val benchmarkDeployment = benchmark.buildDeployment(load, res, this.configurationOverrides) @@ -36,7 +37,7 @@ class BenchmarkExecutorImpl( if (this.run.get()) { result = - AnalysisExecutor(slo = slo).analyze(load = load, res = res, executionDuration = executionDuration) + AnalysisExecutor(slo = slo, executionId = executionId).analyze(load = load, res = res, executionDuration = executionDuration) this.results.setResult(Pair(load, res), result) } benchmarkDeployment.teardown() diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index 3d7718214e15488ad8c0d7c1cea7441474653571..0c3e0d2fd6d1f40df5299c64b214d84323cba853 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -1,5 +1,6 @@ package theodolite.execution +import com.google.gson.GsonBuilder import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.KubernetesBenchmark import theodolite.patcher.PatcherDefinitionFactory @@ -9,6 +10,7 @@ import theodolite.util.Config import theodolite.util.LoadDimension import theodolite.util.Resource import theodolite.util.Results +import java.io.PrintWriter import java.time.Duration class TheodoliteExecutor( @@ -37,11 +39,12 @@ class TheodoliteExecutor( executor = BenchmarkExecutorImpl( - kubernetesBenchmark, - results, - executionDuration, - config.configOverrides, - config.slos[0] + benchmark = kubernetesBenchmark, + results = results, + executionDuration = executionDuration, + configurationOverrides = config.configOverrides, + slo = config.slos[0], + executionId = config.executionId ) return Config( @@ -72,6 +75,9 @@ class TheodoliteExecutor( } fun run() { + storeAsFile(this.config, "${this.config.executionId}-execution-configuration") + storeAsFile(kubernetesBenchmark, "${this.config.executionId}-benchmark-configuration") + val config = buildConfig() // execute benchmarks for each load for (load in config.loads) { @@ -79,5 +85,14 @@ class TheodoliteExecutor( config.compositeStrategy.findSuitableResource(load, config.resources) } } + storeAsFile(config.compositeStrategy.benchmarkExecutor.results, "${this.config.executionId}-result") + } + + private fun <T> storeAsFile(saveObject: T, filename: String) { + val gson = GsonBuilder().enableComplexMapKeySerialization().setPrettyPrinting().create() + + PrintWriter(filename).use { pw -> + pw.println(gson.toJson(saveObject)) + } } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt index c966739a4744f448f60223738d379753b098c060..9e6280cf3c8160ef686fd6dcee45276de7e67fa7 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteController.kt @@ -2,6 +2,7 @@ package theodolite.execution.operator import io.fabric8.kubernetes.client.NamespacedKubernetesClient import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext +import khttp.patch import mu.KotlinLogging import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.KubernetesBenchmark @@ -10,17 +11,20 @@ import java.lang.Thread.sleep import java.util.concurrent.ConcurrentHashMap import java.util.concurrent.ConcurrentLinkedDeque import java.util.concurrent.atomic.AtomicBoolean +import java.util.concurrent.atomic.AtomicInteger private val logger = KotlinLogging.logger {} class TheodoliteController( val client: NamespacedKubernetesClient, - val executionContext: CustomResourceDefinitionContext + val executionContext: CustomResourceDefinitionContext, + val path: String ) { lateinit var executor: TheodoliteExecutor val executionsQueue: ConcurrentLinkedDeque<BenchmarkExecution> = ConcurrentLinkedDeque() val benchmarks: ConcurrentHashMap<String, KubernetesBenchmark> = ConcurrentHashMap() var isUpdated = AtomicBoolean(false) + var executionID = AtomicInteger(0) fun run() { while (true) { @@ -59,7 +63,9 @@ class TheodoliteController( @Synchronized fun runExecution(execution: BenchmarkExecution, benchmark: KubernetesBenchmark) { + execution.executionId = executionID.getAndSet(executionID.get() + 1) isUpdated.set(false) + benchmark.path = path logger.info { "Start execution ${execution.name} with benchmark ${benchmark.name}." } executor = TheodoliteExecutor(config = execution, kubernetesBenchmark = benchmark) executor.run() diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt index 4a34f26c29f4dc087d952b030002e26a35efc523..c6181d19bcedfdb36e455b540e19bf0a54a2a297 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/operator/TheodoliteOperator.kt @@ -44,7 +44,8 @@ class TheodoliteOperator { val executionContext = contextFactory.create(API_VERSION, SCOPE, GROUP, EXECUTION_PLURAL) val benchmarkContext = contextFactory.create(API_VERSION, SCOPE, GROUP, BENCHMARK_PLURAL) - val controller = TheodoliteController(client = client, executionContext = executionContext) + val appResource = System.getenv("THEODOLITE_APP_RESOURCES") ?: "./config" + val controller = TheodoliteController(client = client, executionContext = executionContext, path = appResource) val informerFactory = client.informers() val informerExecution = informerFactory.sharedIndexInformerForCustomResource( diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt index 67c9857220a0d419183644ffaf8c6a6e16a6ce9b..7802529bfda309131cafc0ab3f39fda43285c32f 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/CompositeStrategyTest.kt @@ -31,7 +31,7 @@ class CompositeStrategyTest { val results = Results() val benchmark = TestBenchmark() val sloChecker: BenchmarkExecution.Slo = BenchmarkExecution.Slo() - val benchmarkExecutor = TestBenchmarkExecutorImpl(mockResults, benchmark, results, sloChecker) + val benchmarkExecutor = TestBenchmarkExecutorImpl(mockResults, benchmark, results, sloChecker, 0) val linearSearch = LinearSearch(benchmarkExecutor) val lowerBoundRestriction = LowerBoundRestriction(results) val strategy = @@ -65,7 +65,7 @@ class CompositeStrategyTest { val benchmark = TestBenchmark() val sloChecker: BenchmarkExecution.Slo = BenchmarkExecution.Slo() val benchmarkExecutorImpl = - TestBenchmarkExecutorImpl(mockResults, benchmark, results, sloChecker) + TestBenchmarkExecutorImpl(mockResults, benchmark, results, sloChecker, 0) val binarySearch = BinarySearch(benchmarkExecutorImpl) val lowerBoundRestriction = LowerBoundRestriction(results) val strategy = @@ -98,7 +98,7 @@ class CompositeStrategyTest { val results = Results() val benchmark = TestBenchmark() val sloChecker: BenchmarkExecution.Slo = BenchmarkExecution.Slo() - val benchmarkExecutor = TestBenchmarkExecutorImpl(mockResults, benchmark, results, sloChecker) + val benchmarkExecutor = TestBenchmarkExecutorImpl(mockResults, benchmark, results, sloChecker, 0) val binarySearch = BinarySearch(benchmarkExecutor) val lowerBoundRestriction = LowerBoundRestriction(results) val strategy = diff --git a/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt b/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt index 2de07d48dbe59313506745e6c97b2ae9a5ed114e..2bafcb76dfc3463d9aa350b88c9f73d52cea6629 100644 --- a/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt +++ b/theodolite-quarkus/src/test/kotlin/theodolite/TestBenchmarkExecutorImpl.kt @@ -12,14 +12,16 @@ class TestBenchmarkExecutorImpl( private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results, - slo: BenchmarkExecution.Slo + slo: BenchmarkExecution.Slo, + executionId: Int ) : BenchmarkExecutor( benchmark, results, executionDuration = Duration.ofSeconds(1), configurationOverrides = emptyList(), - slo = slo + slo = slo, + executionId = executionId ) { override fun runExperiment(load: LoadDimension, res: Resource): Boolean {