canonical / grafana-k8s-operator

https://charmhub.io/grafana-k8s
Apache License 2.0
6 stars 22 forks source link

hook failed: "grafana-dashboard-relation-broken" #292

Closed chanchiwai-ray closed 9 months ago

chanchiwai-ray commented 9 months ago

Bug Description

sunbeam disable observability (removing cos-lite terraform plan) failed because of hook failed: "grafana-dashboard-relation-broken"

Reference for the cos-lite terraform: https://github.com/canonical/snap-openstack/tree/main/sunbeam-python/sunbeam/plugins/observability/etc/deploy-cos

To Reproduce

In the terraform plan directory

  1. terraform init
  2. terraform apply
  3. Wait untill all applications are ready and active
  4. terraform apply -destroy

While waiting for the model to be destroyed, the grafana unit goes into error state: hook failed: "grafana-dashboard-relation-broken"

Environment

The environment (e.g. the channel) is defined in the terraform plan. Also,

Name       Version  Rev    Tracking       Publisher      Notes
juju       3.3.0    25355  latest/stable  canonical✓     -
terraform  1.7.0    626    latest/stable  snapcrafters✪  classic

Relevant log output

unit-grafana-0: 15:52:40 ERROR unit.grafana/0.juju-log grafana-dashboard:22: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 1308, in <module>
    main(GrafanaCharm, use_juju_for_storage=True)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/main.py", line 441, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/main.py", line 149, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/framework.py", line 342, in emit
    framework._emit(event)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/framework.py", line 839, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/framework.py", line 928, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1390, in _on_grafana_dashboard_relation_broken
    self._remove_all_dashboards_for_relation(event.relation)
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1524, in _remove_all_dashboards_for_relation
    if self._get_stored_dashboards(relation.id):
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1557, in _get_stored_dashboards
    return self.get_peer_data("dashboards").get(str(relation_id), {})
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1572, in get_peer_data
    data = self._charm.peers.data[self._charm.app].get(key, "")  # type: ignore[attr-defined]
AttributeError: 'NoneType' object has no attribute 'data'

Additional context

This issue is related to #281, and possibly having the same root.

sed-i commented 9 months ago

This is happening on relation-broken, so seems like self.model.get_relation(PEER) is returning a None. @jameinel is it correct for a peer relation to be gone before a regular relation? I recall this was discussed but didn't find the thread.

sed-i commented 9 months ago

For future reference: