From 6be9c7156150413f74a68599d0d5ceeb6806f32b Mon Sep 17 00:00:00 2001 From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de> Date: Thu, 15 Apr 2021 16:09:29 +0200 Subject: [PATCH] Make result folder configurable --- execution/theodolite.yaml | 8 +++- .../src/main/docker/Dockerfile.jvm | 2 - .../src/main/docker/Dockerfile.native | 2 - .../theodolite/evaluation/AnalysisExecutor.kt | 7 +++- .../kotlin/theodolite/execution/Shutdown.kt | 9 ++++- .../execution/TheodoliteExecutor.kt | 39 +++++++++++++++++-- 6 files changed, 56 insertions(+), 11 deletions(-) diff --git a/execution/theodolite.yaml b/execution/theodolite.yaml index c9fcf7e3f..1282531b5 100644 --- a/execution/theodolite.yaml +++ b/execution/theodolite.yaml @@ -1,7 +1,7 @@ apiVersion: batch/v1 kind: Job metadata: - name: theodolite + name: bw-theodolite spec: template: spec: @@ -14,7 +14,7 @@ spec: - containerPort: 80 name: analysis - name: theodolite - image: ghcr.io/cau-se/theodolite:theodolite-kotlin-latest + image: benediktwetzel/theodolite-test #ghcr.io/cau-se/theodolite:theodolite-kotlin-latest imagePullPolicy: Always env: - name: NAMESPACE @@ -27,6 +27,10 @@ spec: value: /etc/benchmark/example-benchmark-yaml-resource.yaml - name: THEODOLITE_APP_RESOURCES value: /etc/app-resources + - name: RESULTS_FOLDER + value: results + - name: CREATE_RESULTS_FOLDER + value: "true" volumeMounts: - mountPath: "/deployments/results" name: theodolite-pv-storage diff --git a/theodolite-quarkus/src/main/docker/Dockerfile.jvm b/theodolite-quarkus/src/main/docker/Dockerfile.jvm index ebe10de12..6733d5d44 100644 --- a/theodolite-quarkus/src/main/docker/Dockerfile.jvm +++ b/theodolite-quarkus/src/main/docker/Dockerfile.jvm @@ -33,8 +33,6 @@ RUN microdnf install curl ca-certificates ${JAVA_PACKAGE} \ && microdnf clean all \ && mkdir /deployments \ && chown 1001 /deployments \ - && mkdir deployments/results \ - && chown 777 deployments/results \ && chmod "g+rwX" /deployments \ && chown 1001:root /deployments \ && curl https://repo1.maven.org/maven2/io/fabric8/run-java-sh/${RUN_JAVA_VERSION}/run-java-sh-${RUN_JAVA_VERSION}-sh.sh -o /deployments/run-java.sh \ diff --git a/theodolite-quarkus/src/main/docker/Dockerfile.native b/theodolite-quarkus/src/main/docker/Dockerfile.native index 67d904d30..29836a714 100644 --- a/theodolite-quarkus/src/main/docker/Dockerfile.native +++ b/theodolite-quarkus/src/main/docker/Dockerfile.native @@ -17,8 +17,6 @@ FROM registry.access.redhat.com/ubi8/ubi-minimal:8.3 WORKDIR /deployments RUN chown 1001 /deployments \ - && mkdir results \ - && chown 777 deployments/results \ && chmod "g+rwX" /deployments \ && chown 1001:root /deployments COPY --chown=1001:root build/*-runner /deployments/application diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt index ddf2c7b5c..8c74c7388 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt @@ -41,7 +41,12 @@ class AnalysisExecutor( query = "sum by(group)(kafka_consumergroup_group_lag >= 0)" ) - CsvExporter().toCsv(name = "results/$executionId-${load.get()}-${res.get()}-${slo.sloType}", prom = prometheusData) + var resultsFolder: String = System.getenv("RESULTS_FOLDER") + if (resultsFolder.isNotEmpty()){ + resultsFolder += "/" + } + + CsvExporter().toCsv(name = "$resultsFolder$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/Shutdown.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt index f5c0251c2..a50a38e79 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/Shutdown.kt @@ -5,6 +5,7 @@ import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.KubernetesBenchmark import theodolite.util.LoadDimension import theodolite.util.Resource +import java.lang.Exception private val logger = KotlinLogging.logger {} @@ -23,6 +24,7 @@ class Shutdown(private val benchmarkExecution: BenchmarkExecution, private val b */ override fun run() { // Build Configuration to teardown + try { logger.info { "Received shutdown signal -> Shutting down" } val deployment = benchmark.buildDeployment( @@ -30,8 +32,13 @@ class Shutdown(private val benchmarkExecution: BenchmarkExecution, private val b res = Resource(0, emptyList()), configurationOverrides = benchmarkExecution.configOverrides ) + deployment.teardown() + } catch (e: Exception) { + logger.warn { "Could not delete all specified resources from Kubernetes. " + + "This could be the case, if not all resources are deployed and running." } + + } logger.info { "Teardown everything deployed" } - deployment.teardown() logger.info { "Teardown completed" } } } diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt index e8008a0fd..01ed386ac 100644 --- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt +++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/TheodoliteExecutor.kt @@ -1,6 +1,7 @@ package theodolite.execution import com.google.gson.GsonBuilder +import mu.KotlinLogging import theodolite.benchmark.BenchmarkExecution import theodolite.benchmark.KubernetesBenchmark import theodolite.patcher.PatcherDefinitionFactory @@ -10,9 +11,17 @@ import theodolite.util.Config import theodolite.util.LoadDimension import theodolite.util.Resource import theodolite.util.Results +import java.io.File import java.io.PrintWriter +import java.lang.IllegalArgumentException +import java.lang.Thread.sleep +import java.nio.file.Files +import java.nio.file.Path import java.time.Duration + +private val logger = KotlinLogging.logger {} + /** * The Theodolite executor runs all the experiments defined with the given execution and benchmark configuration. * @@ -92,13 +101,37 @@ class TheodoliteExecutor( return this.kubernetesBenchmark } + private fun getResultFolderString(): String { + var resultsFolder: String = System.getenv("RESULTS_FOLDER") + val createResultsFolder = System.getenv("CREATE_RESULTS_FOLDER") ?: "false" + + logger.info { "RESULT_FOLDER: $resultsFolder" } + + if (resultsFolder.isNotEmpty()){ + resultsFolder += "/" + } + + val directory = File(resultsFolder) + if (!directory.exists()) { + logger.error { "Folder $resultsFolder does not exist" } + if (createResultsFolder.toBoolean()) { + directory.mkdirs() + } else { + throw IllegalArgumentException("Result folder not found") + } + } + logger.info { "RESULT_FOLDER: $resultsFolder" } + return resultsFolder + } + /** * Run all experiments which are specified in the corresponding * execution and benchmark objects. */ fun run() { - storeAsFile(this.config, "results/${this.config.executionId}-execution-configuration") - storeAsFile(kubernetesBenchmark, "results/${this.config.executionId}-benchmark-configuration") + val resultsFolder = getResultFolderString() + storeAsFile(this.config, "$resultsFolder${this.config.executionId}-execution-configuration") + storeAsFile(kubernetesBenchmark, "$resultsFolder/${this.config.executionId}-benchmark-configuration") val config = buildConfig() // execute benchmarks for each load @@ -107,7 +140,7 @@ class TheodoliteExecutor( config.compositeStrategy.findSuitableResource(load, config.resources) } } - storeAsFile(config.compositeStrategy.benchmarkExecutor.results, "results/${this.config.executionId}-result") + storeAsFile(config.compositeStrategy.benchmarkExecutor.results, "$resultsFolder${this.config.executionId}-result") } private fun <T> storeAsFile(saveObject: T, filename: String) { -- GitLab