From 62826cd93cb5497070d6d6184527d01364134ad1 Mon Sep 17 00:00:00 2001 From: sed-i <82407168+sed-i@users.noreply.github.com> Date: Thu, 9 Jan 2025 16:29:43 -0500 Subject: [PATCH] Comment out WIP --- .../grafana_k8s/v0/grafana_dashboard.py | 96 +++++++++---------- 1 file changed, 48 insertions(+), 48 deletions(-) diff --git a/lib/charms/grafana_k8s/v0/grafana_dashboard.py b/lib/charms/grafana_k8s/v0/grafana_dashboard.py index 3ef122c6..73a7d765 100644 --- a/lib/charms/grafana_k8s/v0/grafana_dashboard.py +++ b/lib/charms/grafana_k8s/v0/grafana_dashboard.py @@ -392,54 +392,54 @@ def __init__(self, *args): } -def load_from_dir(dashboards_path: Path): - # Path.glob uses fnmatch on the backend, which is pretty limited, so use a - # custom function for the filter - def _is_dashboard(p: Path) -> bool: - return p.is_file() and p.name.endswith((".json", ".json.tmpl", ".tmpl")) - - for path in filter(_is_dashboard, Path(dashboards_path).glob("*")): - id = "file:{}".format(path.stem) - - # If we're running this class from within an aggregator (such as grafana agent), then the uid was - # already rendered there, so we do not want to overwrite it with a uid generated from aggregator's info. - # We overwrite the uid only if it's not a valid "Path40" uid. - try: - dashboard_dict = json.loads(path.read_bytes()) - except json.JSONDecodeError as e: - logger.error("Failed to load dashboard '%s': %s", path, e) - continue - if type(dashboard_dict) is not dict: - logger.error( - "Invalid dashboard '%s': expected dict, got %s", path, type(dashboard_dict) - ) - - if not DashboardPath40UID.is_valid(original_uid := dashboard_dict.get("uid", "")): - rel_path = str( - path.relative_to(self._charm.charm_dir) if path.is_absolute() else path - ) - dashboard_dict["uid"] = DashboardPath40UID.generate( - self._charm.meta.name, rel_path - ) - logger.debug( - "Processed dashboard '%s': replaced original uid '%s' with '%s'", - path, - original_uid, - dashboard_dict["uid"], - ) - else: - logger.debug( - "Processed dashboard '%s': kept original uid '%s'", path, original_uid - ) - - stored_dashboard_templates[id] = _content_to_dashboard_object( - charm_name=self._charm.meta.name, - content=LZMABase64.compress(json.dumps(dashboard_dict)), - inject_dropdowns=inject_dropdowns, - juju_topology=self._juju_topology, - ) - - stored_dashboard_templates[id]["dashboard_alt_uid"] = self._generate_alt_uid(id) +# def load_from_dir(dashboards_path: Path): +# # Path.glob uses fnmatch on the backend, which is pretty limited, so use a +# # custom function for the filter +# def _is_dashboard(p: Path) -> bool: +# return p.is_file() and p.name.endswith((".json", ".json.tmpl", ".tmpl")) +# +# for path in filter(_is_dashboard, Path(dashboards_path).glob("*")): +# id = "file:{}".format(path.stem) +# +# # If we're running this class from within an aggregator (such as grafana agent), then the uid was +# # already rendered there, so we do not want to overwrite it with a uid generated from aggregator's info. +# # We overwrite the uid only if it's not a valid "Path40" uid. +# try: +# dashboard_dict = json.loads(path.read_bytes()) +# except json.JSONDecodeError as e: +# logger.error("Failed to load dashboard '%s': %s", path, e) +# continue +# if type(dashboard_dict) is not dict: +# logger.error( +# "Invalid dashboard '%s': expected dict, got %s", path, type(dashboard_dict) +# ) +# +# if not DashboardPath40UID.is_valid(original_uid := dashboard_dict.get("uid", "")): +# rel_path = str( +# path.relative_to(self._charm.charm_dir) if path.is_absolute() else path +# ) +# dashboard_dict["uid"] = DashboardPath40UID.generate( +# self._charm.meta.name, rel_path +# ) +# logger.debug( +# "Processed dashboard '%s': replaced original uid '%s' with '%s'", +# path, +# original_uid, +# dashboard_dict["uid"], +# ) +# else: +# logger.debug( +# "Processed dashboard '%s': kept original uid '%s'", path, original_uid +# ) +# +# stored_dashboard_templates[id] = _content_to_dashboard_object( +# charm_name=self._charm.meta.name, +# content=LZMABase64.compress(json.dumps(dashboard_dict)), +# inject_dropdowns=inject_dropdowns, +# juju_topology=self._juju_topology, +# ) +# +# stored_dashboard_templates[id]["dashboard_alt_uid"] = self._generate_alt_uid(id) class RelationNotFoundError(Exception):