Merge ~adam-collard/maas-ci/+git/system-tests:extract_o11y into ~maas-committers/maas-ci/+git/system-tests:master

Proposed by Adam Collard
Status: Merged
Approved by: Adam Collard
Approved revision: e7691c3fe13f2b63957a7ae8c22f84334c8dc8dc
Merge reported by: MAAS Lander
Merged at revision: not available
Proposed branch: ~adam-collard/maas-ci/+git/system-tests:extract_o11y
Merge into: ~maas-committers/maas-ci/+git/system-tests:master
Diff against target: 117 lines (+53/-40)
2 files modified
systemtests/fixtures.py (+2/-40)
systemtests/o11y.py (+51/-0)
Reviewer Review Type Date Requested Status
Christian Grabowski Approve
MAAS Lander Approve
Review via email: mp+435675@code.launchpad.net

Commit message

Extract o11y configuration to o11y.py

To post a comment you must log in.
Revision history for this message
MAAS Lander (maas-lander) wrote :

UNIT TESTS
-b extract_o11y lp:~adam-collard/maas-ci/+git/system-tests into -b master lp:~maas-committers/maas-ci/+git/system-tests

STATUS: SUCCESS
COMMIT: e7691c3fe13f2b63957a7ae8c22f84334c8dc8dc

review: Approve
Revision history for this message
Christian Grabowski (cgrabowski) wrote :

+1

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1diff --git a/systemtests/fixtures.py b/systemtests/fixtures.py
2index 3b3b045..eff8651 100644
3--- a/systemtests/fixtures.py
4+++ b/systemtests/fixtures.py
5@@ -15,6 +15,7 @@ from pytest_steps import one_fixture_per_step
6 from .api import UnauthenticatedMAASAPIClient
7 from .config import ADMIN_EMAIL, ADMIN_PASSWORD, ADMIN_USER
8 from .lxd import CLILXD, get_lxd
9+from .o11y import setup_o11y
10 from .region import MAASRegion
11 from .tls import MAAS_CONTAINER_CERTS_PATH, setup_tls
12 from .vault import Vault, VaultNotReadyError, setup_vault
13@@ -494,46 +495,7 @@ def maas_region(
14 yaml.dump(credentials, fh)
15
16 if o11y := config.get("o11y"):
17- host_path_to_agent = o11y["grafana_agent_file_path"].strip()
18- agent_path = "/opt/agent/agent-linux-amd64"
19- if not lxd.file_exists(maas_container, agent_path):
20- lxd.execute(maas_container, ["mkdir", "-p", "/opt/agent"])
21- lxd.push_file(
22- maas_container,
23- host_path_to_agent,
24- agent_path,
25- mode="0755",
26- )
27- agent_maas_sample = "/usr/share/maas/grafana_agent/agent.yaml.example"
28- if installed_from_snap:
29- agent_maas_sample = f"/snap/maas/current{agent_maas_sample}"
30- lxd.execute(
31- maas_container,
32- ["cp", agent_maas_sample, "/opt/agent/agent.yml"],
33- )
34- o11y_ip = o11y["o11y_ip"]
35- # FIXME: Could we have an uniq identifier for each system-tests execution?
36- # hostname could be the name of the jenkins job execution?
37- hostname = "maas-system-maas"
38- telemetry_run_cmd = dedent(
39- f"""
40- systemd-run -u telemetry \
41- -E HOSTNAME="{hostname}" \
42- -E AGENT_WAL_DIR="/var/lib/grafana-agent/wal" \
43- -E AGENT_POS_DIR="/var/lib/grafana-agent/positions" \
44- -E PROMETHEUS_REMOTE_WRITE_URL="http://{o11y_ip}:9090/api/v1/write" \
45- -E LOKI_API_URL="http://{o11y_ip}:3100/loki/api/v1/push" \
46- -E MAAS_LOGS="/var/snap/maas/common/log/" \
47- -E MAAS_IS_REGION="true" \
48- -E MAAS_IS_RACK="true" \
49- -E MAAS_AZ="default" \
50- {agent_path} \
51- -config.expand-env \
52- -config.file=/opt/agent/agent.yml \
53- -server.http.address="0.0.0.0:3100" -server.grpc.address="0.0.0.0:9095"
54- """
55- )
56- lxd.execute(maas_container, ["sh", "-c", telemetry_run_cmd])
57+ setup_o11y(o11y, lxd, maas_container, installed_from_snap)
58 yield region
59
60
61diff --git a/systemtests/o11y.py b/systemtests/o11y.py
62new file mode 100644
63index 0000000..f26e1a6
64--- /dev/null
65+++ b/systemtests/o11y.py
66@@ -0,0 +1,51 @@
67+from textwrap import dedent
68+from typing import TYPE_CHECKING, Any
69+
70+if TYPE_CHECKING:
71+ from .lxd import CLILXD
72+
73+AGENT_PATH = "/opt/agent/agent-linux-amd64"
74+
75+
76+def setup_o11y(
77+ o11y: dict[str, Any], lxd: CLILXD, maas_container: str, installed_from_snap: bool
78+) -> None:
79+ if not lxd.file_exists(maas_container, AGENT_PATH):
80+ host_path_to_agent = o11y["grafana_agent_file_path"].strip()
81+ lxd.execute(maas_container, ["mkdir", "-p", "/opt/agent"])
82+ lxd.push_file(
83+ maas_container,
84+ host_path_to_agent,
85+ AGENT_PATH,
86+ mode="0755",
87+ )
88+ agent_maas_sample = "/usr/share/maas/grafana_agent/agent.yaml.example"
89+ if installed_from_snap:
90+ agent_maas_sample = f"/snap/maas/current{agent_maas_sample}"
91+ lxd.execute(
92+ maas_container,
93+ ["cp", agent_maas_sample, "/opt/agent/agent.yml"],
94+ )
95+ o11y_ip = o11y["o11y_ip"]
96+ # FIXME: Could we have an uniq identifier for each system-tests execution?
97+ # hostname could be the name of the jenkins job execution?
98+ hostname = "maas-system-maas"
99+ telemetry_run_cmd = dedent(
100+ f"""
101+ systemd-run -u telemetry \
102+-E HOSTNAME="{hostname}" \
103+-E AGENT_WAL_DIR="/var/lib/grafana-agent/wal" \
104+-E AGENT_POS_DIR="/var/lib/grafana-agent/positions" \
105+-E PROMETHEUS_REMOTE_WRITE_URL="http://{o11y_ip}:9090/api/v1/write" \
106+-E LOKI_API_URL="http://{o11y_ip}:3100/loki/api/v1/push" \
107+-E MAAS_LOGS="/var/snap/maas/common/log/" \
108+-E MAAS_IS_REGION="true" \
109+-E MAAS_IS_RACK="true" \
110+-E MAAS_AZ="default" \
111+{AGENT_PATH} \
112+ -config.expand-env \
113+ -config.file=/opt/agent/agent.yml \
114+ -server.http.address="0.0.0.0:3100" -server.grpc.address="0.0.0.0:9095"
115+ """
116+ )
117+ lxd.execute(maas_container, ["sh", "-c", telemetry_run_cmd])

Subscribers

People subscribed via source and target branches

to all changes: