From 141a5693e23171c8f4bc17e279274529382ee6f0 Mon Sep 17 00:00:00 2001
From: Marcel Becker <stu117960@mail.uni-kiel.de>
Date: Thu, 24 Feb 2022 14:59:58 +0100
Subject: [PATCH] Added review suggestions

---
 theodolite/crd/crd-execution.yaml             |  2 +-
 .../theodolite/evaluation/AnalysisExecutor.kt |  8 +++---
 .../evaluation/SloCheckerFactory.kt           |  6 ++++-
 .../execution/BenchmarkExecutorImpl.kt        |  3 ++-
 .../InitialGuessSearchStrategy.kt             | 27 ++++---------------
 .../searchstrategy/SearchStrategy.kt          |  3 +--
 6 files changed, 19 insertions(+), 30 deletions(-)

diff --git a/theodolite/crd/crd-execution.yaml b/theodolite/crd/crd-execution.yaml
index d2d537a48..874a78480 100644
--- a/theodolite/crd/crd-execution.yaml
+++ b/theodolite/crd/crd-execution.yaml
@@ -20,7 +20,7 @@ spec:
         properties:
           spec:
             type: object
-            required: ["benchmark", "load", "resources", "slos", "execution", "configOverrides"]
+            required: ["benchmark", "loads", "resources", "slos", "execution", "configOverrides"]
             properties:
               name:
                 description: This field exists only for technical reasons and should not be set by the user. The value of the field will be overwritten.
diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt b/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt
index 911740f7b..70a20fead 100644
--- a/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt
+++ b/theodolite/src/main/kotlin/theodolite/evaluation/AnalysisExecutor.kt
@@ -1,6 +1,7 @@
 package theodolite.evaluation
 
 import theodolite.benchmark.BenchmarkExecution
+import theodolite.strategies.Metric
 import theodolite.util.EvaluationFailedException
 import theodolite.util.IOHandler
 import java.text.Normalizer
@@ -31,7 +32,7 @@ class AnalysisExecutor(
      *  @param executionIntervals list of start and end points of experiments
      *  @return true if the experiment succeeded.
      */
-    fun analyze(load: Int, resource: Int, executionIntervals: List<Pair<Instant, Instant>>): Boolean {
+    fun analyze(load: Int, resource: Int, executionIntervals: List<Pair<Instant, Instant>>, metric: Metric): Boolean {
         var repetitionCounter = 1
 
         try {
@@ -56,11 +57,12 @@ class AnalysisExecutor(
                 )
             }
 
-            //TODO: CHECK WHETHER WE NEED TO DIFFERENTIATE BETWEEN METRICS AND HAVE SOME NEW KIND OF SLOCHECKER WHICH GETS RESOURCE AS PARAMETER
             val sloChecker = SloCheckerFactory().create(
                 sloType = slo.sloType,
                 properties = slo.properties,
-                load = load
+                load = load,
+                resource = resource,
+                metric = metric
             )
 
             return sloChecker.evaluate(prometheusData)
diff --git a/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt b/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt
index acb08442c..7ab6a0255 100644
--- a/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt
+++ b/theodolite/src/main/kotlin/theodolite/evaluation/SloCheckerFactory.kt
@@ -1,5 +1,7 @@
 package theodolite.evaluation
 
+import theodolite.strategies.Metric
+
 
 /**
  * Factory used to potentially create different [SloChecker]s.
@@ -40,7 +42,9 @@ class SloCheckerFactory {
     fun create(
         sloType: String,
         properties: MutableMap<String, String>,
-        load: Int
+        load: Int,
+        resource: Int,
+        metric: Metric
     ): SloChecker {
         return when (SloTypes.from(sloType)) {
             SloTypes.GENERIC -> ExternalSloChecker(
diff --git a/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt b/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
index 3e86a4ee9..e2b6c0930 100644
--- a/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
+++ b/theodolite/src/main/kotlin/theodolite/execution/BenchmarkExecutorImpl.kt
@@ -65,7 +65,8 @@ class BenchmarkExecutorImpl(
                     .analyze(
                         load = load,
                         resource = resource,
-                        executionIntervals = executionIntervals
+                        executionIntervals = executionIntervals,
+                        metric = this.results.metric
                     )
             }
 
diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt
index bd7fa71a2..6b56e22a8 100644
--- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt
+++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/InitialGuessSearchStrategy.kt
@@ -14,21 +14,14 @@ private val logger = KotlinLogging.logger {}
  * @param guessStrategy Strategy that provides us with a guess for the first resource amount.
  * @param results current results of all previously performed benchmarks.
  */
-class InitialGuessSearchStrategy(benchmarkExecutor: BenchmarkExecutor, guessStrategy: GuessStrategy, results: Results) :
-        SearchStrategy(benchmarkExecutor, guessStrategy, results) {
+class InitialGuessSearchStrategy(
+        benchmarkExecutor: BenchmarkExecutor,
+        private val guessStrategy: GuessStrategy,
+        private var results: Results
+) : SearchStrategy(benchmarkExecutor) {
 
     override fun findSuitableResource(load: Int, resources: List<Int>): Int? {
 
-        if(this.guessStrategy == null){
-            logger.info { "Your InitialGuessSearchStrategy doesn't have a GuessStrategy. This is not supported." }
-            return null
-        }
-
-        if(results == null){
-            logger.info { "The results need to be initialized." }
-            return null
-        }
-
         var lastLowestResource : Int? = null
 
         // Getting the lastLowestResource from results and calling firstGuess() with it
@@ -83,16 +76,6 @@ class InitialGuessSearchStrategy(benchmarkExecutor: BenchmarkExecutor, guessStra
 
     override fun findSuitableLoad(resource: Int, loads: List<Int>): Int?{
 
-        if(this.guessStrategy == null){
-            logger.info { "Your InitialGuessSearchStrategy doesn't have a GuessStrategy. This is not supported." }
-            return null
-        }
-
-        if(results == null){
-            logger.info { "The results need to be initialized." }
-            return null
-        }
-
         var lastMaxLoad : Int? = null
 
         // Getting the lastLowestLoad from results and calling firstGuess() with it
diff --git a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt
index bd380f25a..962504c7d 100644
--- a/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt
+++ b/theodolite/src/main/kotlin/theodolite/strategies/searchstrategy/SearchStrategy.kt
@@ -14,8 +14,7 @@ import theodolite.util.Results
  * @param results the [Results] object.
  */
 @RegisterForReflection
-abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor, val guessStrategy: GuessStrategy? = null,
-                              val results: Results? = null) {
+abstract class SearchStrategy(val benchmarkExecutor: BenchmarkExecutor) {
 
 
     /**
-- 
GitLab