Skip to content
Snippets Groups Projects
Commit 4e225ac5 authored by Lorenz Boguhn's avatar Lorenz Boguhn Committed by Lorenz Boguhn
Browse files

Refactored Analysis

parent 4a2d4763
No related branches found
No related tags found
4 merge requests!159Re-implementation of Theodolite with Kotlin/Quarkus,!157Update Graal Image in CI pipeline,!105Introduce CSV exporter,!83WIP: Re-implementation of Theodolite with Kotlin/Quarkus
......@@ -3,56 +3,46 @@ package theodolite.evaluation
import mu.KotlinLogging
import theodolite.benchmark.BenchmarkExecution
import theodolite.util.LoadDimension
import theodolite.util.PrometheusResponse
import theodolite.util.Resource
import java.time.Duration
import java.time.Instant
private val logger = KotlinLogging.logger {}
/**
* Executes the Analysis.
*/
class AnalysisExecutor {
class AnalysisExecutor(private val slo: BenchmarkExecution.Slo) {
fun analyse(load:LoadDimension,executionDuration: Duration, res: Resource,slo: BenchmarkExecution.Slo): Boolean {
private val fetcher = MetricFetcher(
prometheusURL = slo.prometheusUrl,
offset = Duration.ofHours(slo.offset.toLong())
)
fun analyse(load: LoadDimension, res: Resource, executionDuration: Duration): Boolean {
var result = false
try {
val prometheusData = fetcher.fetchMetric(
start = Instant.now().minus(executionDuration),
end = Instant.now(),
query = "sum by(group)(kafka_consumergroup_group_lag >= 0)"
)
val prometheusData = fetch(Instant.now().minus(executionDuration),
Instant.now(),
slo,
"sum by(group)(kafka_consumergroup_group_lag >= 0)")
CsvExporter().toCsv("${load.get()}_${res.get()}_${slo.sloType}",prometheusData)
CsvExporter().toCsv(name = "${load.get()}_${res.get()}_${slo.sloType}", prom = prometheusData)
val sloChecker = SloCheckerFactory().create(
slotype = slo.sloType,
prometheusURL = slo.prometheusUrl,
query = "sum by(group)(kafka_consumergroup_group_lag >= 0)",
externalSlopeURL = slo.externalSloUrl,
threshold = slo.threshold,
offset = Duration.ofHours(slo.offset.toLong()),
warmup = slo.warmup
)
result = sloChecker.evaluate(start = Instant.now().minus(executionDuration),
end = Instant.now(),fetchedData = prometheusData)
result = sloChecker.evaluate(
start = Instant.now().minus(executionDuration),
end = Instant.now(), fetchedData = prometheusData
)
} catch (e: Exception) {
logger.error { "Evaluation failed for resource: ${res.get()} and load: ${load.get()} error: $e" }
}
return result
}
fun fetch(start: Instant, end: Instant,slo: BenchmarkExecution.Slo,query: String): PrometheusResponse {
val metricFetcher = MetricFetcher(prometheusURL = slo.prometheusUrl,
offset = Duration.ofHours(slo.offset.toLong()))
val fetchedData = metricFetcher.fetchMetric(start, end, query)
return fetchedData
}
}
......@@ -12,32 +12,32 @@ class CsvExporter {
/**
* Uses the PrintWriter to transform a PrometheusResponse to Csv
*/
fun toCsv(name : String,prom: PrometheusResponse){
fun toCsv(name: String, prom: PrometheusResponse) {
val responseArray = toArray(prom)
val csvOutputFile: File = File("$name.csv")
val csvOutputFile = File("$name.csv")
PrintWriter(csvOutputFile).use { pw ->
pw.println(listOf("name","time","value").joinToString())
responseArray.forEach{
pw.println(listOf("name", "time", "value").joinToString())
responseArray.forEach {
pw.println(it.joinToString())
}
}
logger.debug{csvOutputFile.absolutePath}
logger.info { "Wrote csv to $name" }
logger.debug { csvOutputFile.absolutePath }
logger.info { "Wrote csv file: $name to ${csvOutputFile.absolutePath}" }
}
/**
* Converts a PrometheusResponse into a List of List of Strings
*/
private fun toArray(prom : PrometheusResponse): MutableList<List<String>> {
private fun toArray(prom: PrometheusResponse): MutableList<List<String>> {
val name = prom.data?.result?.get(0)?.metric?.group.toString()
val values = prom.data?.result?.get(0)?.values
val dataList = mutableListOf<List<String>>()
if (values != null) {
for (x in values){
for (x in values) {
val y = x as List<*>
dataList.add(listOf(name,"${y[0]}","${y[1]}"))
dataList.add(listOf(name, "${y[0]}", "${y[1]}"))
}
}
return dataList
......
......@@ -9,11 +9,8 @@ import java.time.Duration
import java.time.Instant
class ExternalSloChecker(
private val prometheusURL: String,
private val query: String,
private val externalSlopeURL: String,
private val threshold: Int,
private val offset: Duration,
private val warmup: Int
) :
SloChecker {
......
......@@ -6,21 +6,15 @@ class SloCheckerFactory {
fun create(
slotype: String,
prometheusURL: String,
query: String,
externalSlopeURL: String,
threshold: Int,
offset: Duration,
warmup: Int
): SloChecker {
return when (slotype) {
"lag trend" -> ExternalSloChecker(
prometheusURL = prometheusURL,
query = query,
externalSlopeURL = externalSlopeURL,
threshold = threshold,
offset = offset,
warmup = warmup
)
else -> throw IllegalArgumentException("Slotype $slotype not found.")
......
......@@ -4,13 +4,11 @@ import mu.KotlinLogging
import theodolite.benchmark.Benchmark
import theodolite.benchmark.BenchmarkExecution
import theodolite.evaluation.AnalysisExecutor
import theodolite.evaluation.SloCheckerFactory
import theodolite.util.ConfigurationOverride
import theodolite.util.LoadDimension
import theodolite.util.Resource
import theodolite.util.Results
import java.time.Duration
import java.time.Instant
private val logger = KotlinLogging.logger {}
......@@ -26,7 +24,7 @@ class BenchmarkExecutorImpl(
benchmarkDeployment.setup()
this.waitAndLog()
var result = AnalysisExecutor().analyse(load,executionDuration,res,slo)
val result = AnalysisExecutor(slo = slo).analyse(load = load, res = res, executionDuration = executionDuration)
benchmarkDeployment.teardown()
......
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