Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Automatically overwrite dashboard UIDs with a prescribed naming pattern, on the provider side #363

Merged
merged 4 commits into from
Jan 20, 2025

Conversation

sed-i
Copy link
Contributor

@sed-i sed-i commented Dec 6, 2024

Issue

Solution

Use shake_256 to generate a prescribed uid, overwriting any pre-existing uid.

In tandem with:

Context

Testing Instructions

First, prepare the charms locally:

  1. Copy the grafana_dashboard lib from this PR into grafana-agent-operator from Automatically overwrite dashboard UIDs with a prescribed naming pattern grafana-agent-operator#224.
  2. Copy cos-agent lib from Automatically overwrite dashboard UIDs with a prescribed naming pattern grafana-agent-operator#224 into zookeeper.
  3. In zookeeper, update deps using the following commands. Then remove all the --hash from requirements.txt:
poetry update
poetry lock
poetry install
poetry export -f requirements.txt --output requirements.tx
  1. Pack and deploy all charms as follows:
graph LR
subgraph lxd
zookeeper --- grafana-agent
zookeeper2 --- grafana-agent
end
subgraph microk8s
grafana-agent --- grafana
end
Loading
bundle: kubernetes
applications:
  graf:
    charm: ./grafana-k8s_ubuntu-20.04-amd64.charm
    scale: 1
    trust: true
--- # overlay.yaml
applications:
  graf:
    offers:
      graf:
        endpoints:
        - grafana-dashboard
        acl:
          admin: admin
default-base: [email protected]/stable
saas:
  graf:
    url: microk8s:admin/graf.graf
applications:
  ga2:
    charm: ./grafana-agent_ubuntu-22.04-amd64.charm
  zk:
    charm: ./zookeeper_ubuntu-22.04-amd64.charm
    num_units: 2
  zk2:
    charm: ./zookeeper_ubuntu-22.04-amd64.charm
    num_units: 2
relations:
- - ga2:cos-agent
  - zk:cos-agent
- - ga2:cos-agent
  - zk2:cos-agent
- - ga2:grafana-dashboards-provider
  - graf:grafana-dashboard

Upgrade Notes

  • This change will break existing bookmarks to existing dashboards, because charms that fetch-lib this change would have the uid of all dashboards changed.
  • If you have more than one app of the same charm deployed, they would all need to be refreshed together to avoid dashboard title collision. If you do not refresh all of them, grafana will output the following logs:
    • dashboard title is not unique in folder
    • dashboards provisioning provider has no database write permissions because of duplicates
    • Not saving new dashboard due to restricted database access

To enable automatic uid collision prevention for the dashboards in your charm:

  1. If cos-lib (cosl) is pinned in your charm, bump it to 0.0.50 or higher.
  2. Fetch-lib cos-agent. You should use 0.13 or higher.
  3. Refresh your charm.
  4. Refresh grafana-agent to revision 369+.

@sed-i
Copy link
Contributor Author

sed-i commented Dec 6, 2024

@jdkandersson
Copy link

I'll delegate to @cbartz who has the best understanding of the issue in our team, thank you for preparing the PR!

@sed-i sed-i force-pushed the feature/uid-collision branch from 62826cd to 1076450 Compare January 10, 2025 19:32
Base automatically changed from feature/dashlib-refactor to main January 10, 2025 20:06
@sed-i sed-i force-pushed the feature/uid-collision branch from 9953221 to e40b35e Compare January 16, 2025 18:31
@sed-i
Copy link
Contributor Author

sed-i commented Jan 19, 2025

Tested with:

graph LR
graf --- am
graf --- am2
Loading

Where alertmanager was first deployed from edge (with the "old" dashboard lib), then refreshed from path with the new lib from this PR.

bundle: kubernetes
applications:
  am:
    charm: local:alertmanager-k8s-1
    resources:
      alertmanager-image: 99
    scale: 2
    trust: true
  am2:
    charm: local:alertmanager-k8s-2
    resources:
      alertmanager-image: 99
    scale: 1
    trust: true
  graf:
    charm: grafana-k8s
    channel: latest/stable
    revision: 122
    resources:
      grafana-image: 70
      litestream-image: 45
    scale: 1
    trust: true
relations:
- - graf:grafana-dashboard
  - am:grafana-dashboard
- - graf:grafana-dashboard
  - am2:grafana-dashboard

@sed-i sed-i marked this pull request as ready for review January 19, 2025 05:44
@sed-i sed-i requested a review from a team as a code owner January 19, 2025 05:44
Copy link
Contributor

@lucabello lucabello left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approving, but please fix integration tests before merging :)

@sed-i sed-i merged commit ef1c398 into main Jan 20, 2025
13 checks passed
@sed-i sed-i deleted the feature/uid-collision branch January 20, 2025 18:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants