diff --git a/theodolite/src/main/kotlin/theodolite/patcher/DataVolumeLoadGeneratorReplicaPatcher.kt b/theodolite/src/main/kotlin/theodolite/patcher/DataVolumeLoadGeneratorReplicaPatcher.kt new file mode 100644 index 0000000000000000000000000000000000000000..bdc107910edc8ddfb41e7757c775977086a25a26 --- /dev/null +++ b/theodolite/src/main/kotlin/theodolite/patcher/DataVolumeLoadGeneratorReplicaPatcher.kt @@ -0,0 +1,38 @@ +package theodolite.patcher + +import io.fabric8.kubernetes.api.model.KubernetesResource + +/** + * The DataVolumeLoadGeneratorReplicaPatcher takes the total load that should be generated + * and computes the number of instances needed for this load based on the `maxVolume` + * ((load + maxVolume - 1) / maxVolume) and calculates the load per instance + * (loadPerInstance = load / instances). + * The number of instances are set for the load generator and the given variable is set to the + * load per instance. + * + * @property k8sResource Kubernetes resource to be patched. + * @property maxVolume per load generator instance + * @property container Container to be patched. + * @property variableName Name of the environment variable to be patched. + */ +class DataVolumeLoadGeneratorReplicaPatcher( + k8sResource: KubernetesResource, + private val maxVolume: Int, + container: String, + variableName: String +) : AbstractPatcher(k8sResource) { + + private val replicaPatcher = ReplicaPatcher(k8sResource) + private val envVarPatcher = EnvVarPatcher(k8sResource, container, variableName) + + override fun <T> patch(value: T) { + // calculate number of load generator instances and load per instance + val load = Integer.parseInt(value.toString()) + val loadGenInstances = (load + maxVolume - 1) / maxVolume + val loadPerInstance = load / loadGenInstances + + // Patch instance values and load value of generators + replicaPatcher.patch(loadGenInstances.toString()) + envVarPatcher.patch(loadPerInstance.toString()) + } +} diff --git a/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt b/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt index 29723355ce23810c709fe4537242d1fd7e195d25..9350cecc46451a405a5d5445165c8991aede47c1 100644 --- a/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt +++ b/theodolite/src/main/kotlin/theodolite/patcher/PatcherFactory.kt @@ -48,6 +48,12 @@ class PatcherFactory { k8sResource = resource, loadGenMaxRecords = patcherDefinition.properties["loadGenMaxRecords"]!! ) + "DataVolumeLoadGeneratorReplicaPatcher" -> DataVolumeLoadGeneratorReplicaPatcher( + k8sResource = resource, + maxVolume = patcherDefinition.properties["maxVolume"]!!.toInt(), + container = patcherDefinition.properties["container"]!!, + variableName = patcherDefinition.properties["variableName"]!! + ) "EnvVarPatcher" -> EnvVarPatcher( k8sResource = resource, container = patcherDefinition.properties["container"]!!,