From 4151af827f4e04ffa7ea3235fbc4899183ea99bb Mon Sep 17 00:00:00 2001
From: lorenz <stu203404@mail.uni-kiel.de>
Date: Fri, 12 Mar 2021 12:02:29 +0100
Subject: [PATCH] Enhance empty query case

---
 .../main/kotlin/theodolite/evaluation/MetricFetcher.kt | 10 ++++++++++
 1 file changed, 10 insertions(+)

diff --git a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/MetricFetcher.kt b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/MetricFetcher.kt
index 883ead52c..da70ab10b 100644
--- a/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/MetricFetcher.kt
+++ b/theodolite-quarkus/src/main/kotlin/theodolite/evaluation/MetricFetcher.kt
@@ -3,10 +3,13 @@ package theodolite.evaluation
 import com.google.gson.Gson
 import khttp.get
 import khttp.responses.Response
+import mu.KotlinLogging
 import theodolite.util.PrometheusResponse
 import java.net.ConnectException
 import java.util.*
 
+private val logger = KotlinLogging.logger {}
+
 
 class MetricFetcher(private val prometheusURL: String) {
 
@@ -22,8 +25,15 @@ class MetricFetcher(private val prometheusURL: String) {
         while (trys < 2) {
             val response = get("$prometheusURL/api/v1/query_range", params = parameter)
             if (response.statusCode != 200) {
+                val message = response.jsonObject.toString()
+                logger.warn { "Could not connect to Prometheus: $message, retrying now" }
                 trys++
             } else {
+                var values = parseValues(response)
+                if (values.data?.result.isNullOrEmpty()) {
+                    logger.warn { "Empty query result: $values" }
+                    throw NoSuchFieldException()
+                }
                 return parseValues(response)
             }
         }
-- 
GitLab