Skip to content
Snippets Groups Projects
Commit 22fcf15a authored by Sören Henning's avatar Sören Henning
Browse files

Pass generic SLO checker config to container

parent 1092f5f2
Branches
Tags
1 merge request!224Add generic SLO checker
Pipeline #6001 passed
...@@ -13,8 +13,7 @@ import java.net.ConnectException ...@@ -13,8 +13,7 @@ import java.net.ConnectException
*/ */
class ExternalSloChecker( class ExternalSloChecker(
private val externalSlopeURL: String, private val externalSlopeURL: String,
private val threshold: Int, private val metadata: Map<String, Any>
private val warmup: Int
) : SloChecker { ) : SloChecker {
private val RETRIES = 2 private val RETRIES = 2
...@@ -37,8 +36,7 @@ class ExternalSloChecker( ...@@ -37,8 +36,7 @@ class ExternalSloChecker(
var counter = 0 var counter = 0
val data = SloJson.Builder() val data = SloJson.Builder()
.results(fetchedData.map { it.data?.result }) .results(fetchedData.map { it.data?.result })
.addMetadata("threshold", threshold) .addMetadata(metadata)
.addMetadata("warmup", warmup)
.build() .build()
.toJson() .toJson()
......
...@@ -44,11 +44,30 @@ class SloCheckerFactory { ...@@ -44,11 +44,30 @@ class SloCheckerFactory {
load: LoadDimension load: LoadDimension
): SloChecker { ): SloChecker {
return when (SloTypes.from(sloType)) { return when (SloTypes.from(sloType)) {
SloTypes.GENERIC, SloTypes.LAG_TREND, SloTypes.DROPPED_RECORDS -> ExternalSloChecker( SloTypes.GENERIC -> ExternalSloChecker(
externalSlopeURL = properties["externalSloUrl"] externalSlopeURL = properties["externalSloUrl"]
?: throw IllegalArgumentException("externalSloUrl expected"), ?: throw IllegalArgumentException("externalSloUrl expected"),
threshold = properties["threshold"]?.toInt() ?: throw IllegalArgumentException("threshold expected"), // TODO validate property contents
warmup = properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected") 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 -> { SloTypes.LAG_TREND_RATIO, SloTypes.DROPPED_RECORDS_RATIO -> {
val thresholdRatio = val thresholdRatio =
...@@ -63,8 +82,11 @@ class SloCheckerFactory { ...@@ -63,8 +82,11 @@ class SloCheckerFactory {
ExternalSloChecker( ExternalSloChecker(
externalSlopeURL = properties["externalSloUrl"] externalSlopeURL = properties["externalSloUrl"]
?: throw IllegalArgumentException("externalSloUrl expected"), ?: throw IllegalArgumentException("externalSloUrl expected"),
threshold = threshold, metadata = mapOf(
warmup = properties["warmup"]?.toInt() ?: throw IllegalArgumentException("warmup expected") "warmup" to (properties["warmup"]?.toInt()
?: throw IllegalArgumentException("warmup expected")),
"threshold" to threshold
)
) )
} }
} }
......
...@@ -26,7 +26,7 @@ class SloJson private constructor( ...@@ -26,7 +26,7 @@ class SloJson private constructor(
* @param key key of the metadata to be added * @param key key of the metadata to be added
* @param value value 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()) { if (this.metadata.isNullOrEmpty()) {
this.metadata = mutableMapOf(key to value) this.metadata = mutableMapOf(key to value)
} else { } else {
...@@ -35,16 +35,13 @@ class SloJson private constructor( ...@@ -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 metadata map of key-value pairs to be added to be added
* @param value value of the metadata to be added
*/ */
fun addMetadata(key: String, value: Int) = apply { fun addMetadata(metadata: Map<String, Any>) = apply {
if (this.metadata.isNullOrEmpty()) { for (entry in metadata) {
this.metadata = mutableMapOf(key to value) this.addMetadata(entry.key, entry.value)
} else {
this.metadata!![key] = value
} }
} }
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment