Skip to content
Snippets Groups Projects
Commit 9bac7e0d authored by Benedikt Wetzel's avatar Benedikt Wetzel
Browse files

Allow to set config overrides via EnvVarPatcher

parent a919a926
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!85Introduce new Benchmark class and Patcher,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
Showing
with 49 additions and 29 deletions
package theodolite.benchmark
import theodolite.util.LoadDimension
import theodolite.util.OverridePatcherDefinition
import theodolite.util.Resource
interface Benchmark {
fun buildDeployment(load: LoadDimension, res: Resource, override: Map<String, String>): BenchmarkDeployment
fun buildDeployment(load: LoadDimension, res: Resource, overrides: List<OverridePatcherDefinition>): BenchmarkDeployment
}
\ No newline at end of file
package theodolite.benchmark
import theodolite.util.OverridePatcherDefinition
import theodolite.util.PatcherDefinition
import kotlin.properties.Delegates
......@@ -10,7 +12,7 @@ class BenchmarkContext() {
lateinit var resources: List<Int>
lateinit var slos: List<Slo>
lateinit var execution: Execution
lateinit var configOverrides: Map<String, String>
lateinit var configOverrides: List<OverridePatcherDefinition>
class Execution() {
lateinit var strategy: String
......
......@@ -5,6 +5,7 @@ import io.fabric8.kubernetes.client.DefaultKubernetesClient
import theodolite.k8s.YamlLoader
import theodolite.patcher.PatcherManager
import theodolite.util.LoadDimension
import theodolite.util.OverridePatcherDefinition
import theodolite.util.Resource
import theodolite.util.TypeName
......@@ -33,7 +34,7 @@ class KubernetesBenchmark(): Benchmark {
override fun buildDeployment(load: LoadDimension, res: Resource, override: Map<String, String>): BenchmarkDeployment {
override fun buildDeployment(load: LoadDimension, res: Resource, overrides: List<OverridePatcherDefinition>): BenchmarkDeployment {
// TODO("set node selector")
val resources = loadKubernetesResources(this.appResource + this.loadGenResource)
val patcherManager = PatcherManager()
......@@ -42,9 +43,10 @@ class KubernetesBenchmark(): Benchmark {
patcherManager.applyPatcher(res.getType(), this.resourceTypes, resources, res.get())
patcherManager.applyPatcher(load.getType(), this.loadTypes, resources, load.get().toString())
resources.forEach {x -> println(x)}
// patch overrides
overrides.forEach {override -> patcherManager.applyPatcher(override, resources)}
// handle overrides (resource, container, variableName, variableValue)
resources.forEach {x -> println(x)}
return KubernetesBenchmarkDeployment(emptyList(), hashMapOf<String, Any>(), "", emptyList())
}
......
......@@ -3,10 +3,7 @@ package theodolite.execution
import mu.KotlinLogging
import theodolite.benchmark.Benchmark
import theodolite.benchmark.KubernetesBenchmark
import theodolite.util.AbstractBenchmark
import theodolite.util.LoadDimension
import theodolite.util.Resource
import theodolite.util.Results
import theodolite.util.*
import java.time.Duration
private val logger = KotlinLogging.logger {}
......@@ -19,7 +16,7 @@ private val logger = KotlinLogging.logger {}
* @property executionDuration
* @constructor Create empty Benchmark executor
*/
abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results, val executionDuration: Duration, override: Map<String, String>) {
abstract class BenchmarkExecutor(val benchmark: Benchmark, val results: Results, val executionDuration: Duration, overrides: List<OverridePatcherDefinition>) {
/**
* Run a experiment for the given parametrization, evaluate the experiment and save the result.
......
package theodolite.execution
import theodolite.benchmark.Benchmark
import theodolite.benchmark.KubernetesBenchmark
import theodolite.util.AbstractBenchmark
import theodolite.util.LoadDimension
import theodolite.util.Resource
import theodolite.util.Results
import theodolite.util.*
import java.time.Duration
class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration, private val overrides: Map<String, String>) : BenchmarkExecutor(benchmark, results, executionDuration, overrides) {
class BenchmarkExecutorImpl(benchmark: Benchmark, results: Results, executionDuration: Duration, private val overrides: List<OverridePatcherDefinition>) : BenchmarkExecutor(benchmark, results, executionDuration, overrides) {
override fun runExperiment(load: LoadDimension, res: Resource): Boolean {
val benchmarkDeployment = benchmark.buildDeployment(load, res, this.overrides)
benchmarkDeployment.setup()
......
......@@ -10,7 +10,7 @@ import java.time.Duration
class TestBenchmarkExecutorImpl(private val mockResults: Array<Array<Boolean>>, benchmark: Benchmark, results: Results):
BenchmarkExecutor(benchmark, results, executionDuration = Duration.ofSeconds(1),
override = emptyMap<String,String>()
overrides = emptyList()
) {
override fun runExperiment(load: LoadDimension, res: Resource): Boolean {
......
package theodolite.patcher
import io.fabric8.kubernetes.api.model.KubernetesResource
import theodolite.util.OverridePatcherDefinition
import theodolite.util.PatcherDefinition
import theodolite.util.TypeName
import java.lang.IllegalArgumentException
......@@ -16,17 +17,28 @@ class PatcherManager {
}
}
private fun getPatcherDef(requiredType: String, resourceTypes: List<TypeName>): List<PatcherDefinition> {
return resourceTypes
private fun getPatcherDef(requiredType: String, patcherTypes: List<TypeName>): List<PatcherDefinition> {
return patcherTypes
.filter { type -> type.typeName == requiredType}
.flatMap { type -> type.patchers}
}
fun applyPatcher(type: String, resourceTypes: List<TypeName>, resources: List<Pair<String, KubernetesResource>>, value: Any) {
this.getPatcherDef(type, resourceTypes)
fun applyPatcher(type: String, patcherTypes: List<TypeName>, resources: List<Pair<String, KubernetesResource>>, value: Any) {
this.getPatcherDef(type, patcherTypes)
.forEach {patcherDef ->
createK8sPatcher(patcherDef, resources).patch(value) }
}
fun applyPatcher(overrides: OverridePatcherDefinition, resources: List<Pair<String, KubernetesResource>>){
var pdef = PatcherDefinition()
pdef.type = overrides.type
pdef.container = overrides.container
pdef.resource = overrides.resource
overrides.overrides.forEach{ override ->
pdef.variableName = override.key
this.createK8sPatcher(pdef, resources).patch(override.value)
}
}
}
\ No newline at end of file
package theodolite.util
class OverridePatcherDefinition() {
lateinit var type: String
lateinit var resource: String
lateinit var container: String
lateinit var overrides: Map<String, String>
}
......@@ -5,4 +5,5 @@ class PatcherDefinition() {
lateinit var resource: String
lateinit var container: String
lateinit var variableName: String
lateinit var value: String
}
......@@ -41,7 +41,7 @@ class TestBenchmark : AbstractBenchmark(
override fun buildDeployment(
load: LoadDimension,
res: Resource,
override: Map<String, String>
override: List<OverridePatcherDefinition>
): BenchmarkDeployment {
TODO("Not yet implemented")
}
......
......@@ -15,8 +15,4 @@ loadTypes:
- type: "EnvVarPatcher"
resource: "workloadGenerator.yaml"
container: "workload-generator"
variableName: "NUM_SENSORS"
EnvVars:
- typeName: "override"
patchers:
- type: "EnvVarPatcher"
\ No newline at end of file
variableName: "NUM_SENSORS"
\ No newline at end of file
......@@ -16,4 +16,9 @@ execution:
restrictions:
- "LowerBound"
configOverrides:
key: "value"
\ No newline at end of file
- type: "EnvVarPatcher"
resource: "workloadGenerator.yaml"
container: "workload-generator"
overrides:
overrideTestA: "8888"
overrideTestB: "6666"
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment