Skip to content

Commit

Permalink
Comment out WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
sed-i committed Jan 9, 2025
1 parent 1a70fd2 commit 62826cd
Showing 1 changed file with 48 additions and 48 deletions.
96 changes: 48 additions & 48 deletions lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 62826cd

Please sign in to comment.