From 87b5037e1025823e76582b492c918ab4e2138492 Mon Sep 17 00:00:00 2001 From: Github Actions Date: Thu, 12 Oct 2023 16:15:57 +0000 Subject: [PATCH] chore: update charm libraries --- .../v0/cloud_config_requirer.py | 64 ++++++++++++------- lib/charms/loki_k8s/v0/loki_push_api.py | 14 +++- 2 files changed, 53 insertions(+), 25 deletions(-) diff --git a/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py b/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py index d28d2eb3..6e01c26d 100644 --- a/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py +++ b/lib/charms/grafana_cloud_integrator/v0/cloud_config_requirer.py @@ -6,7 +6,7 @@ LIBID = "e6f580481c1b4388aa4d2cdf412a47fa" LIBAPI = 0 -LIBPATCH = 3 +LIBPATCH = 4 DEFAULT_RELATION_NAME = "grafana-cloud-config" @@ -45,7 +45,7 @@ def __init__(self, charm, relation_name = DEFAULT_RELATION_NAME): super().__init__(charm, relation_name) self._charm = charm self._relation_name = relation_name - + for event in self._change_events: self.framework.observe(event, self._on_relation_changed) @@ -56,14 +56,6 @@ def _on_relation_changed(self, event): if not self._charm.unit.is_leader(): return - if not all( - self._is_not_empty(x) - for x in [ - event.relation.data[event.app].get("username", ""), - event.relation.data[event.app].get("password", ""), - ]): - return - self.on.cloud_config_available.emit() # pyright: ignore def _on_relation_broken(self, event): @@ -96,29 +88,55 @@ def _events(self): @property def credentials(self): - return Credentials( - self._data.get("username", ""), - self._data.get("password", "") - ) + """Return the credentials, if any; otherwise, return None.""" + if not all( + self._is_not_empty(x) + for x in [ + self._data.get("username", ""), + self._data.get("password", ""), + ]): + return Credentials( + self._data.get("username", ""), + self._data.get("password", "") + ) + return None @property def loki_ready(self): - return ( - self._is_not_empty(self.credentials.username) - and self._is_not_empty(self.credentials.password) - and self._is_not_empty(self.loki_url)) + return self._is_not_empty(self.loki_url) + + @property + def loki_endpoint(self) -> dict: + """Return the loki endpoint dict.""" + if not self.loki_ready: + return {} + + endpoint = {} + endpoint["url"] = self.loki_url + if self.credentials: + endpoint["basic_auth"] = {"username": self.credentials.username, "password": self.credentials.password} + return endpoint @property def prometheus_ready(self): - return ( - self._is_not_empty(self.credentials.username) - and self._is_not_empty(self.credentials.password) - and self._is_not_empty(self.prometheus_url)) + return self._is_not_empty(self.prometheus_url) + + @property + def prometheus_endpoint(self) -> dict: + """Return the prometheus endpoint dict.""" + if not self.prometheus_ready: + return {} + + endpoint = {} + endpoint["url"] = self.prometheus_url + if self.credentials: + endpoint["basic_auth"] = {"username": self.credentials.username, "password": self.credentials.password} + return endpoint @property def loki_url(self): return self._data.get("loki_url", "") - + @property def prometheus_url(self): return self._data.get("prometheus_url", "") diff --git a/lib/charms/loki_k8s/v0/loki_push_api.py b/lib/charms/loki_k8s/v0/loki_push_api.py index 1547a3b0..9f9372d2 100644 --- a/lib/charms/loki_k8s/v0/loki_push_api.py +++ b/lib/charms/loki_k8s/v0/loki_push_api.py @@ -480,7 +480,7 @@ def _alert_rules_error(self, event): # Increment this PATCH version before using `charmcraft publish-lib` or reset # to 0 if you are raising the major API version -LIBPATCH = 21 +LIBPATCH = 22 logger = logging.getLogger(__name__) @@ -1773,6 +1773,8 @@ def __init__( recursive: bool = False, container_name: str = "", promtail_resource_name: Optional[str] = None, + *, # TODO: In v1, move the star up so everything after 'charm' is a kwarg + insecure_skip_verify: bool = False, ): super().__init__(charm, relation_name, alert_rules_path, recursive) self._charm = charm @@ -1792,6 +1794,7 @@ def __init__( self._is_syslog = enable_syslog self.topology = JujuTopology.from_charm(charm) self._promtail_resource_name = promtail_resource_name or "promtail-bin" + self.insecure_skip_verify = insecure_skip_verify # architecture used for promtail binary arch = platform.processor() @@ -2153,8 +2156,15 @@ def _current_config(self) -> dict: @property def _promtail_config(self) -> dict: - """Generates the config file for Promtail.""" + """Generates the config file for Promtail. + + Reference: https://grafana.com/docs/loki/latest/send-data/promtail/configuration + """ config = {"clients": self._clients_list()} + if self.insecure_skip_verify: + for client in config["clients"]: + client["tls_config"] = {"insecure_skip_verify": True} + config.update(self._server_config()) config.update(self._positions()) config.update(self._scrape_configs())