From 396f87d5fa46c5d8e3f433e2b1c61fc0eed8683c Mon Sep 17 00:00:00 2001 From: Max Edwards Date: Fri, 6 Sep 2024 11:19:49 +0100 Subject: [PATCH] grafana running behind caddy --- resources/charts/caddy/values.yaml | 2 +- resources/manifests/grafana_values.yaml | 3 +++ test/data/logging/network.yaml | 4 +++- test/logging_test.py | 27 ++++++------------------- 4 files changed, 13 insertions(+), 23 deletions(-) diff --git a/resources/charts/caddy/values.yaml b/resources/charts/caddy/values.yaml index 509ef9e37..01338e9ac 100644 --- a/resources/charts/caddy/values.yaml +++ b/resources/charts/caddy/values.yaml @@ -99,7 +99,7 @@ caddyConfig: | } handle_path /grafana/* { - reverse_proxy grafana:3000 + reverse_proxy loki-grafana:80 } } diff --git a/resources/manifests/grafana_values.yaml b/resources/manifests/grafana_values.yaml index 110622911..a6d16e3ab 100644 --- a/resources/manifests/grafana_values.yaml +++ b/resources/manifests/grafana_values.yaml @@ -16,6 +16,9 @@ grafana.ini: auth: disable_login_form: true disable_signout_menu: true + server: + # this is required to use Grafana behind a reverse proxy (caddy) + root_url: "%(protocol)s://%(domain)s:%(http_port)s/grafana/" auth.anonymous: enabled: true org_name: Main Org. diff --git a/test/data/logging/network.yaml b/test/data/logging/network.yaml index 59de12158..a06a5ea24 100644 --- a/test/data/logging/network.yaml +++ b/test/data/logging/network.yaml @@ -10,4 +10,6 @@ nodes: metrics: txrate=getchaintxstats(10)["txrate"] - name: tank-0002 connect: - - tank-0000 \ No newline at end of file + - tank-0000 +caddy: + enabled: true \ No newline at end of file diff --git a/test/logging_test.py b/test/logging_test.py index 5f547fb53..bb55c6676 100755 --- a/test/logging_test.py +++ b/test/logging_test.py @@ -2,14 +2,15 @@ import logging import os -import threading from datetime import datetime from pathlib import Path -from subprocess import PIPE, Popen, run +from subprocess import run import requests from test_base import TestBase +GRAFANA_URL = "http://localhost:2019/grafana/" + class LoggingTest(TestBase): def __init__(self): @@ -35,22 +36,6 @@ def start_logging(self): self.log.info("Running install_logging.sh") # Block until complete run([f"{self.scripts_dir / 'install_logging.sh'}"]) - self.log.info("Running connect_logging.sh") - # Stays alive in background - self.connect_logging_process = Popen( - [f"{self.scripts_dir / 'connect_logging.sh'}"], - stdout=PIPE, - stderr=PIPE, - bufsize=1, - universal_newlines=True, - ) - self.log.info("connect_logging.sh started...") - self.connect_logging_thread = threading.Thread( - target=self.output_reader, - args=(self.connect_logging_process.stdout, self.connect_logging_logger.info), - ) - self.connect_logging_thread.daemon = True - self.connect_logging_thread.start() def setup_network(self): self.log.info("Setting up network") @@ -64,7 +49,7 @@ def wait_for_endpoint_ready(self): def check_endpoint(): try: - response = requests.get("http://localhost:3000/login") + response = requests.get(f"{GRAFANA_URL}login") return response.status_code == 200 except requests.RequestException: return False @@ -79,7 +64,7 @@ def make_grafana_api_request(self, ds_uid, start, metric): "from": f"{start}", "to": "now", } - reply = requests.post("http://localhost:3000/api/ds/query", json=data) + reply = requests.post(f"{GRAFANA_URL}api/ds/query", json=data) if reply.status_code != 200: self.log.error(f"Grafana API request failed with status code {reply.status_code}") self.log.error(f"Response content: {reply.text}") @@ -96,7 +81,7 @@ def test_prometheus_and_grafana(self): self.warnet(f"run {miner_file} --allnodes --interval=5 --mature") self.warnet(f"run {tx_flood_file} --interval=1") - prometheus_ds = requests.get("http://localhost:3000/api/datasources/name/Prometheus") + prometheus_ds = requests.get(f"{GRAFANA_URL}api/datasources/name/Prometheus") assert prometheus_ds.status_code == 200 prometheus_uid = prometheus_ds.json()["uid"] self.log.info(f"Got Prometheus data source uid from Grafana: {prometheus_uid}")