canonical / cos-lite-bundle

Canonical Observability Stack Lite, or COS Lite, is a light-weight, highly-integrated, Juju-based observability suite running on Kubernetes.
https://charmhub.io/cos-lite
Apache License 2.0
10 stars 10 forks source link

grafana_dashboard lib raises when processing dashboards exported by Grafana 9 (COS Lite version) #58

Closed gtrkiller closed 1 year ago

gtrkiller commented 1 year ago

Bug Description

I have found this same error in Grafana's unit while trying to deploy a charm with a Grafana 9 Dashboard and relate it with the COS lite bundle. When inspecting the Grafana charm's code accessing the container, the fix applied to the code to solve this bug wasn't implemented there, so maybe the charm in the bundle needs an update, could you please check if that is the case? Thank you! :D

To Reproduce

Clone this branch: https://github.com/canonical/content-cache-k8s-operator/tree/add_cos Then, inside the repo: change the grafana dashboard to a grafana 9 dashboard (copy & paste) docker build . -t localhost:32000/content-cache:latest --no-cache -f content-cache.Dockerfile docker push localhost:32000/content-cache:latest charmcraft pack juju add-model cosdepl && juju deploy cos-lite --trust --overlay offer.yaml juju add-model contentdepl && juju deploy ./content-cache-k8s_ubuntu-22.04-amd64.charm --resource content-cache-image=localhost:32000/content-cache:latest --resource nginx-prometheus-exporter-image=nginx/nginx-prometheus-exporter:0.11.0 && juju deploy hello-kubecon && juju deploy nginx-ingress-integrator && juju relate hello-kubecon content-cache-k8s:ingress-proxy && juju relate nginx-ingress-integrator content-cache-k8s:ingress juju relate content-cache-k8s:grafana-dashboard admin/cosdepl.grafana-dashboards juju relate content-cache-k8s:metrics-endpoint admin/cosdepl.prometheus-scrape juju relate content-cache-k8s:logging admin/cosdepl.loki-logging juju switch cosdepl microk8s kubectl exec -ti -n grafana-0 /bin/bash tac /var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py Then you can inspect the code and the fix is not there.

Environment

Deploying everything locally on my juju/microk8s installation

Relevant log output

unit-grafana-0: 14:03:20 ERROR unit.grafana/0.juju-log grafana-dashboard:23: Uncaught exception while in charm code:
Traceback (most recent call last):
  File "./src/charm.py", line 1156, in <module>
    main(GrafanaCharm, use_juju_for_storage=True)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/main.py", line 438, in main
    _emit_charm_event(charm, dispatcher.event_name)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/main.py", line 150, in _emit_charm_event
    event_to_emit.emit(*args, **kwargs)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/framework.py", line 355, in emit
    framework._emit(event)  # noqa
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/framework.py", line 856, in _emit
    self._reemit(event_path)
  File "/var/lib/juju/agents/unit-grafana-0/charm/venv/ops/framework.py", line 931, in _reemit
    custom_handler(event)
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1272, in _on_grafana_dashboard_relation_changed
    changes = self._render_dashboards_and_signal_changed(event.relation)
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 1369, in _render_dashboards_and_signal_changed
    content = _convert_dashboard_fields(content, inject_dropdowns)
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 599, in _convert_dashboard_fields
    dict_content = _replace_template_fields(dict_content, datasources, existing_templates)
  File "/var/lib/juju/agents/unit-grafana-0/charm/lib/charms/grafana_k8s/v0/grafana_dashboard.py", line 633, in _replace_template_fields
    if panel["datasource"].lower() in replacements.values():
AttributeError: 'dict' object has no attribute 'lower'
unit-grafana-0: 14:03:20 ERROR juju.worker.uniter.operation hook "grafana-dashboard-relation-changed" (via hook dispatching script: dispatch) failed: exit status 1

Additional context

No response

sed-i commented 1 year ago

Hi @gtrkiller, The lib version (0.21) on charmhub already has a fix for this. The problem is when you juju deploy cos-lite, then grafana comes from stable. Any chance you could try with juju deploy cos-lite --channel=edge?

We plan to release to stable soon. (cc: @rbarry82)

rbarry82 commented 1 year ago

We're planning a re-release of all the COS charms. Grafana is waiting for that, which is slated to be this week.

gtrkiller commented 1 year ago

Thank you! I'll try again with the edge channel and let you know if I experience any trouble :+1:

simskij commented 1 year ago

Since there's not been a word in this issue since early January, I'm going to assume the issue is solved. If not, feel free to (preferably) open a new issue, or reopen this one! 👍🏼