From 45348ebeb09a84e3885ce535c7eb65896b099734 Mon Sep 17 00:00:00 2001
From: "stu126940@mail.uni-kiel.de" <stu126940@mail.uni-kiel.de>
Date: Thu, 22 Apr 2021 15:39:31 +0200
Subject: [PATCH] Fix creation of JSON to request external slo

---
 slope-evaluator/app/main.py                            |  9 ++++++++-
 slope-evaluator/requirements.txt                       |  1 +
 .../kotlin/theodolite/evaluation/AnalysisExecutor.kt   |  2 +-
 .../kotlin/theodolite/evaluation/ExternalSloChecker.kt | 10 +++++-----
 .../theodolite/execution/BenchmarkExecutorImpl.kt      |  2 +-
 5 files changed, 16 insertions(+), 8 deletions(-)

diff --git a/slope-evaluator/app/main.py b/slope-evaluator/app/main.py
index 83709c0f7..b3941d1fe 100644
--- a/slope-evaluator/app/main.py
+++ b/slope-evaluator/app/main.py
@@ -46,6 +46,13 @@ def execute(results, threshold, warmup):
 @app.post("/evaluate-slope",response_model=bool)
 async def evaluate_slope(request: Request):
     data = json.loads(await request.body())
-    return execute(data['total_lag'], data['threshold'], data['warmup'])
+    results = []
+    for total_lag in data['total_lags']:
+        results.append(execute(total_lag, data['threshold'], data['warmup'] ))
+    
+    for result in results:
+        if not result:
+            return False
+    return True 
 
 logger.info("Slope evaluator is online")
\ No newline at end of file
diff --git a/slope-evaluator/requirements.txt b/slope-evaluator/requirements.txt
index ca77b6c89..6934f4b78 100644
--- a/slope-evaluator/requirements.txt
+++ b/slope-evaluator/requirements.txt
@@ -1,3 +1,4 @@
 fastapi==0.55.1
 scikit-learn==0.20.3
 pandas==1.0.3
+uvicorn
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt
index 5916e10c3..2fbe81e94 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt
@@ -20,7 +20,7 @@ class AnalysisExecutor(private val slo: BenchmarkExecution.Slo) {
         var result = false
         val exporter = CsvExporter()
         val prometheusData = executionIntervals.map { interval -> fetcher.fetchMetric( start = interval.first, end = interval.second, query = "sum by(group)(kafka_consumergroup_group_lag >= 0)") }
-        var repetitionCounter = 0
+        var repetitionCounter = 1
         prometheusData.forEach{ data -> exporter.toCsv(name = "${load.get()}_${res.get()}_${slo.sloType}_rep_${repetitionCounter++}", prom = data) }
         prometheusData.forEach { logger.info { "prom-data: $it" }}
 
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt
index 211117ade..e19527359 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/ExternalSloChecker.kt
@@ -21,14 +21,14 @@ class ExternalSloChecker(
 
     override fun evaluate(fetchedData: List<PrometheusResponse>): Boolean {
         var counter = 0
-        var requestData = fetchedData.map { entry -> Gson().toJson(mapOf("total_lag" to entry.data?.result)) }.toMutableList()
-        requestData.add(mapOf("threshold" to threshold).toString())
-        requestData.add(mapOf("warmup" to warmup).toString())
-
 
+        val data = Gson().toJson(mapOf(
+            "total_lags" to fetchedData.map { it.data?.result },
+            "threshold" to threshold,
+            "warmup" to warmup))
 
         while (counter < RETRIES) {
-            val result = post(externalSlopeURL, data = requestData, timeout = TIMEOUT)
+            val result = post(externalSlopeURL, data = data, timeout = TIMEOUT)
             if (result.statusCode != 200) {
                 counter++
                 logger.error { "Could not reach external slope analysis" }
diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
index 3b21886f0..e16fd0e6b 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
@@ -25,6 +25,7 @@ class BenchmarkExecutorImpl(
         val executionIntervals: MutableList<Pair<Instant, Instant>> = ArrayList(repetitions)
 
         for (i in 1.rangeTo(repetitions)) {
+            logger.info { "Run repetition $i/$repetitions" }
             if (this.run.get()) {
                 executionIntervals.add(runSingleExperiment(load,res))
             } else {
@@ -33,7 +34,6 @@ class BenchmarkExecutorImpl(
         }
 
         if (this.run.get()) {
-            executionIntervals.forEach{ logger.info { "interval for evaluation; from: ${it.first}, to: ${it.second}"}}
             result =AnalysisExecutor(slo = slo)
                     .analyze(load = load, res = res, executionIntervals = executionIntervals)
             this.results.setResult(Pair(load, res), result)
-- 
GitLab