diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt b/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt index 9fd00c4dbe3c006f2ebbf3eca2b831a955aadcdc..bdbdbc53edf1bb06cf1c5b023a16b61b9b2eb574 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt @@ -13,8 +13,7 @@ import java.net.ConnectException */ class ExternalSloChecker( private val externalSlopeURL: String, - private val threshold: Int, - private val warmup: Int + private val metadata: Map<String, Any> ) : SloChecker { private val RETRIES = 2 @@ -37,8 +36,7 @@ class ExternalSloChecker( var counter = 0 val data = SloJson.Builder() .results(fetchedData.map { it.data?.result }) - .addMetadata("threshold", threshold) - .addMetadata("warmup", warmup) + .addMetadata(metadata) .build() .toJson() diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt index b47a347196ecf41d1128d1c2f437edfd7eef4e1d..c2514469925bcfc20c15377e93963df04a3b91f6 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt @@ -44,11 +44,30 @@ class SloCheckerFactory { load: LoadDimension ): SloChecker { return when (SloTypes.from(sloType)) { - SloTypes.GENERIC, SloTypes.LAG_TREND, SloTypes.DROPPED_RECORDS -> ExternalSloChecker( + SloTypes.GENERIC -> ExternalSloChecker( externalSlopeURL = properties["externalSloUrl"] ?: throw IllegalArgumentException("externalSloUrl expected"), - threshold = properties["threshold"]?.toInt() ?: throw IllegalArgumentException("threshold expected"), - warmup = properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected") + // TODO validate property contents + metadata = mapOf( + "warmup" to (properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected")), + "queryAggregation" to (properties["warmup"]?.toInt() + ?: throw IllegalArgumentException("queryAggregation expected")), + "repetitionAggregation" to (properties["warmup"]?.toInt() + ?: throw IllegalArgumentException("repetitionAggregation expected")), + "operator" to (properties["warmup"]?.toInt() + ?: throw IllegalArgumentException("operator expected")), + "threshold" to (properties["threshold"]?.toInt() + ?: throw IllegalArgumentException("threshold expected")) + ) + ) + SloTypes.LAG_TREND, SloTypes.DROPPED_RECORDS -> ExternalSloChecker( + externalSlopeURL = properties["externalSloUrl"] + ?: throw IllegalArgumentException("externalSloUrl expected"), + metadata = mapOf( + "warmup" to (properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected")), + "threshold" to (properties["threshold"]?.toInt() + ?: throw IllegalArgumentException("threshold expected")) + ) ) SloTypes.LAG_TREND_RATIO, SloTypes.DROPPED_RECORDS_RATIO -> { val thresholdRatio = @@ -63,8 +82,11 @@ class SloCheckerFactory { ExternalSloChecker( externalSlopeURL = properties["externalSloUrl"] ?: throw IllegalArgumentException("externalSloUrl expected"), - threshold = threshold, - warmup = properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected") + metadata = mapOf( + "warmup" to (properties["warmup"]?.toInt() + ?: throw IllegalArgumentException("warmup expected")), + "threshold" to threshold + ) ) } } diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt index fc9fe17b255dbb5ae68881538d8d2a50a191edb1..0c643c009d293a5ee6118daf59671bc02a324039 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt @@ -26,7 +26,7 @@ class SloJson private constructor( * @param key key of the metadata to be added * @param value value of the metadata to be added */ - fun addMetadata(key: String, value: String) = apply { + fun addMetadata(key: String, value: Any) = apply { if (this.metadata.isNullOrEmpty()) { this.metadata = mutableMapOf(key to value) } else { @@ -35,16 +35,13 @@ class SloJson private constructor( } /** - * Add metadata as key value pairs + * Add metadata as map of key value pairs. * - * @param key key of the metadata to be added - * @param value value of the metadata to be added + * @param metadata map of key-value pairs to be added to be added */ - fun addMetadata(key: String, value: Int) = apply { - if (this.metadata.isNullOrEmpty()) { - this.metadata = mutableMapOf(key to value) - } else { - this.metadata!![key] = value + fun addMetadata(metadata: Map<String, Any>) = apply { + for (entry in metadata) { + this.addMetadata(entry.key, entry.value) } }