From d945fc1336bc30969ff8fb4efdf4a7cc832ab44c Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Bj=C3=B6rn=20Vonheiden?= <bjoern.vonheiden@hotmail.de>
Date: Sat, 26 Sep 2020 15:59:36 +0200
Subject: [PATCH] Get prometheus url in run uc for the lag analysis

---
 execution/lib/cli_parser.py |  4 ++++
 execution/run_uc.py         | 17 +++++++++++------
 2 files changed, 15 insertions(+), 6 deletions(-)

diff --git a/execution/lib/cli_parser.py b/execution/lib/cli_parser.py
index 4ab3155e0..cb4abcaba 100644
--- a/execution/lib/cli_parser.py
+++ b/execution/lib/cli_parser.py
@@ -50,6 +50,10 @@ def default_parser(description):
     parser.add_argument('--reset-only',
                         action="store_true",
                         help='Only resets the environment. Ignores all other parameters')
+    parser.add_argument('--prometheus',
+                        metavar='<URL>',
+                        default=os.environ.get('PROMETHEUS_BASE_URL'),
+                        help='Defines where to find the prometheus instance')
     return parser
 
 def benchmark_parser(description):
diff --git a/execution/run_uc.py b/execution/run_uc.py
index 3b46c50ac..8cd6f0621 100644
--- a/execution/run_uc.py
+++ b/execution/run_uc.py
@@ -4,7 +4,7 @@ from kubernetes import client, config  # kubernetes api
 from kubernetes.stream import stream
 import lag_analysis
 import logging  # logging
-from os import path  # path utilities
+from os import path, environ  # path utilities
 from lib.cli_parser import execution_parser
 import subprocess  # execute bash commands
 import sys  # for exit of program
@@ -244,7 +244,7 @@ def wait_execution(execution_minutes):
     return
 
 
-def run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes):
+def run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes, prometheus_base_url=None):
     """
     Runs the evaluation function
     :param string exp_id: ID of the experiment.
@@ -254,7 +254,12 @@ def run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes):
     :param int execution_minutes: How long the use case where executed.
     """
     print('Run evaluation function')
-    lag_analysis.main(exp_id, f'uc{uc_id}', dim_value, instances, execution_minutes)
+    if prometheus_base_url is None and environ.get('PROMETHEUS_BASE_URL') is None:
+        lag_analysis.main(exp_id, f'uc{uc_id}', dim_value, instances, execution_minutes)
+    elif prometheus_base_url is not None:
+        lag_analysis.main(exp_id, f'uc{uc_id}', dim_value, instances, execution_minutes, prometheus_base_url)
+    else:
+        lag_analysis.main(exp_id, f'uc{uc_id}', dim_value, instances, execution_minutes, environ.get('PROMETHEUS_BASE_URL'))
     return
 
 
@@ -449,7 +454,7 @@ def reset_cluster(wg, app_svc, app_svc_monitor, app_jmx, app_deploy, topics):
     stop_lag_exporter()
 
 
-def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limit, commit_interval_ms, execution_minutes, reset, reset_only):
+def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limit, commit_interval_ms, execution_minutes, prometheus_base_url=None, reset=False, reset_only=False):
     """
     Main method to execute one time the benchmark for a given use case.
     Start workload generator/application -> execute -> analyse -> stop all
@@ -514,7 +519,7 @@ def main(exp_id, uc_id, dim_value, instances, partitions, cpu_limit, memory_limi
     wait_execution(execution_minutes)
     print('---------------------')
 
-    run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes)
+    run_evaluation(exp_id, uc_id, dim_value, instances, execution_minutes, prometheus_base_url)
     print('---------------------')
 
     # Reset cluster regular, therefore abort exit not needed anymore
@@ -528,5 +533,5 @@ if __name__ == '__main__':
     print('---------------------')
     main(args.exp_id, args.uc, args.load, args.instances,
          args.partitions, args.cpu_limit, args.memory_limit,
-         args.commit_ms, args.duration, args.reset,
+         args.commit_ms, args.duration, args.prometheus, args.reset,
          args.reset_only)
-- 
GitLab