diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt b/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt index bdbdbc53edf1bb06cf1c5b023a16b61b9b2eb574..7fb5417e200f64b0db74a8bebe69a751c5d484b8 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt @@ -8,8 +8,7 @@ import java.net.ConnectException /** * [SloChecker] that uses an external source for the concrete evaluation. * @param externalSlopeURL The url under which the external evaluation can be reached. - * @param threshold threshold that should not be exceeded to evaluate to true. - * @param warmup time that is not taken into consideration for the evaluation. + * @param metadata metadata passed to the external SLO checker. */ class ExternalSloChecker( private val externalSlopeURL: String, @@ -26,19 +25,16 @@ class ExternalSloChecker( * Will try to reach the external service until success or [RETRIES] times. * Each request will timeout after [TIMEOUT]. * - * @param start point of the experiment. - * @param end point of the experiment. * @param fetchedData that should be evaluated - * @return true if the experiment was successful(the threshold was not exceeded. + * @return true if the experiment was successful (the threshold was not exceeded). * @throws ConnectException if the external service could not be reached. */ override fun evaluate(fetchedData: List<PrometheusResponse>): Boolean { var counter = 0 - val data = SloJson.Builder() - .results(fetchedData.map { it.data?.result }) - .addMetadata(metadata) - .build() - .toJson() + val data = SloJson( + results = fetchedData.map { it.data?.result ?: listOf() }, + metadata = metadata + ).toJson() while (counter < RETRIES) { val result = post(externalSlopeURL, data = data, timeout = TIMEOUT) diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt index 0c643c009d293a5ee6118daf59671bc02a324039..205389276f2c1adef6cba6c745baf99744c8d2dd 100644 --- a/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt +++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloJson.kt @@ -3,58 +3,17 @@ package theodolite.evaluation import com.google.gson.Gson import theodolite.util.PromResult -class SloJson private constructor( - val results: List<List<PromResult>?>? = null, - var metadata: MutableMap<String, Any>? = null +class SloJson constructor( + val results: List<List<PromResult>>, + var metadata: Map<String, Any> ) { - data class Builder( - var results:List<List<PromResult>?>? = null, - var metadata: MutableMap<String, Any>? = null - ) { - - /** - * Set the results - * - * @param results list of prometheus results - */ - fun results(results: List<List<PromResult>?>) = apply { this.results = results } - - /** - * Add metadata as key value pairs - * - * @param key key of the metadata to be added - * @param value value of the metadata to be added - */ - fun addMetadata(key: String, value: Any) = apply { - if (this.metadata.isNullOrEmpty()) { - this.metadata = mutableMapOf(key to value) - } else { - this.metadata!![key] = value - } - } - - /** - * Add metadata as map of key value pairs. - * - * @param metadata map of key-value pairs to be added to be added - */ - fun addMetadata(metadata: Map<String, Any>) = apply { - for (entry in metadata) { - this.addMetadata(entry.key, entry.value) - } - } - - fun build() = SloJson( - results = results, - metadata = metadata + fun toJson(): String { + return Gson().toJson( + mapOf( + "results" to this.results, + "metadata" to this.metadata + ) ) } - - fun toJson(): String { - return Gson().toJson(mapOf( - "results" to this.results, - "metadata" to this.metadata - )) - } } \ No newline at end of file