Skip to content

Commit

Permalink
chore: update charm libraries (#143)
Browse files Browse the repository at this point in the history
Co-authored-by: Github Actions <[email protected]>
  • Loading branch information
observability-noctua-bot and Github Actions authored Mar 23, 2023
1 parent 283bdfe commit 36682fb
Showing 1 changed file with 21 additions and 12 deletions.
33 changes: 21 additions & 12 deletions lib/charms/grafana_k8s/v0/grafana_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ def __init__(self, *args):
# Increment this PATCH version before using `charmcraft publish-lib` or reset
# to 0 if you are raising the major API version

LIBPATCH = 26
LIBPATCH = 27

logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -1691,7 +1691,11 @@ def _update_remote_grafana(self, _: Optional[RelationEvent] = None) -> None:

def remove_dashboards(self, event: RelationBrokenEvent) -> None:
"""Remove a dashboard if the relation is broken."""
app_ids = _type_convert_stored(self._stored.id_mappings[event.app.name]) # type: ignore
app_ids = _type_convert_stored(self._stored.id_mappings.get(event.app.name, "")) # type: ignore

if not app_ids:
logger.info("Could not look up stored dashboards for %s", event.app.name) # type: ignore
return

del self._stored.id_mappings[event.app.name] # type: ignore
for id in app_ids:
Expand Down Expand Up @@ -1731,22 +1735,18 @@ def _strip_existing_datasources(self, dash: dict) -> dict: # noqa: C901
for i in range(len(dash["templating"]["list"])):
if (
"datasource" in dash["templating"]["list"][i]
and "Juju" in dash["templating"]["list"][i]["datasource"]
):
dash["templating"]["list"][i]["datasource"] = r"${prometheusds}"
if (
"name" in dash["templating"]["list"][i]
and dash["templating"]["list"][i]["name"] == "host"
and dash["templating"]["list"][i]["datasource"] is not None
):
dash["templating"]["list"][i] = REACTIVE_CONVERTER
if "Juju" in dash["templating"]["list"][i].get("datasource", ""):
dash["templating"]["list"][i]["datasource"] = r"${prometheusds}"

# Strip out newly-added 'juju_application' template variables which
# don't line up with our drop-downs
dash_mutable = dash
for i in range(len(dash["templating"]["list"])):
if (
"name" in dash["templating"]["list"][i]
and dash["templating"]["list"][i]["name"] == "app"
and dash["templating"]["list"][i].get("name", "") == "app"
):
del dash_mutable["templating"]["list"][i]

Expand All @@ -1758,7 +1758,7 @@ def _strip_existing_datasources(self, dash: dict) -> dict: # noqa: C901
if "__inputs" in dash:
inputs = dash
for i in range(len(dash["__inputs"])):
if dash["__inputs"][i]["pluginName"] == "Prometheus":
if dash["__inputs"][i].get("pluginName", "") == "Prometheus":
del inputs["__inputs"][i]
if inputs:
dash["__inputs"] = inputs["__inputs"]
Expand Down Expand Up @@ -1812,14 +1812,23 @@ def _handle_reactive_dashboards(self, event: RelationEvent) -> Optional[Dict]:
# Replace the old-style datasource templates
dash = re.sub(r"<< datasource >>", r"${prometheusds}", dash)
dash = re.sub(r'"datasource": "prom.*?"', r'"datasource": "${prometheusds}"', dash)
dash = re.sub(
r'"datasource": "\$datasource"', r'"datasource": "${prometheusds}"', dash
)
dash = re.sub(r'"uid": "\$datasource"', r'"uid": "${prometheusds}"', dash)
dash = re.sub(
r'"datasource": "(!?\w)[\w|\s|-]+?Juju generated.*?"',
r'"datasource": "${prometheusds}"',
dash,
)

# Yank out "new"+old LMA topology
dash = re.sub(r'(,?juju_application=~)"\$app"', r'\1"\$juju_application"', dash)
dash = re.sub(
r'(,?\s?juju_application=~)\\"\$app\\"', r'\1\\"$juju_application\\"', dash
)

# Replace old piechart panels
dash = re.sub(r'"type": "grafana-piechart-panel"', '"type": "piechart"', dash)

from jinja2 import Template

Expand Down

0 comments on commit 36682fb

Please sign in to comment.