From 79d58fe9b21bfed30f89cd7287c701b4b8dd40f0 Mon Sep 17 00:00:00 2001 From: Luca Bello Date: Wed, 3 Jan 2024 09:57:37 +0100 Subject: [PATCH] use the generic cloud integrator charm --- src/grafana_agent.py | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/src/grafana_agent.py b/src/grafana_agent.py index b0fe36c..0db784a 100644 --- a/src/grafana_agent.py +++ b/src/grafana_agent.py @@ -588,31 +588,29 @@ def _enrich_endpoints(self) -> Tuple[List[Dict[str, Any]], List[Dict[str, Any]]] prometheus_endpoints: List[Dict[str, Any]] = self._remote_write.endpoints if self._cloud.prometheus_ready: - prometheus_endpoints.append( - { - "url": self._cloud.prometheus_url, - "basic_auth": { - "username": self._cloud.credentials.username, - "password": self._cloud.credentials.password, - }, + prometheus_endpoint = {"url": self._cloud.prometheus_url} + if self._cloud.credentials: + prometheus_endpoint["basic_auth"] = { + "username": self._cloud.credentials.username, + "password": self._cloud.credentials.password, } - ) + prometheus_endpoints.append(prometheus_endpoint) loki_endpoints = self._loki_consumer.loki_endpoints if self._cloud.loki_ready: - loki_endpoints.append( - { - "url": self._cloud.loki_url, - "headers": { - "Content-Encoding": "snappy", - }, - "basic_auth": { - "username": self._cloud.credentials.username, - "password": self._cloud.credentials.password, - }, + loki_endpoint = { + "url": self._cloud.loki_url, + "headers": { + "Content-Encoding": "snappy", + }, + } + if self._cloud.credentials: + loki_endpoint["basic_auth"] = { + "username": self._cloud.credentials.username, + "password": self._cloud.credentials.password, } - ) + loki_endpoints.append(loki_endpoint) for endpoint in prometheus_endpoints + loki_endpoints: endpoint["tls_config"] = {