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

Grafana 8: Incorrect diff checking for Grafana dashboards not in default folder #216

Open
Feliksas opened this issue Feb 23, 2022 · 0 comments

Comments

@Feliksas
Copy link

Feliksas commented Feb 23, 2022

SUMMARY

In modern Grafana versions (I am using 8.3.4), the dashboard difference check is being performed incorrectly, if the dashboard is not in the default folder with ID 0 (such dashboards will always be marked as changed). The problem is likely to be here https://github.com/ansible-collections/community.grafana/blob/main/plugins/modules/grafana_dashboard.py#L281 - this condition will always be false, since the folderId key is located in the meta dictionary, which is being deleted at https://github.com/ansible-collections/community.grafana/blob/main/plugins/modules/grafana_dashboard.py#L276
Therefore, the key is always being added to the downloaded JSON schema, and the equality check at https://github.com/ansible-collections/community.grafana/blob/main/plugins/modules/grafana_dashboard.py#L290 will always fail for dashboards with a non-default folderId.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

community.grafana.grafana_dashboard

ANSIBLE VERSION
ansible [core 2.12.1]
  config file = /home/feliksas/work/ansible/ansible.cfg
  configured module search path = ['/home/feliksas/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /home/linuxbrew/.linuxbrew/opt/python@3.9/lib/python3.9/site-packages/ansible
  ansible collection location = /home/feliksas/.ansible/collections:/usr/share/ansible/collections
  executable location = /home/linuxbrew/.linuxbrew/bin/ansible
  python version = 3.9.9 (main, Nov 15 2021, 18:05:17) [GCC 5.4.0 20160609]
  jinja version = 3.0.3
  libyaml = True
COLLECTION VERSION
# /home/linuxbrew/.linuxbrew/opt/python@3.9/lib/python3.9/site-packages/ansible_collections
Collection        Version
----------------- -------
community.grafana 1.3.0
CONFIGURATION
ANSIBLE_FORCE_COLOR(/home/feliksas/work/ansible/ansible.cfg) = True
DEFAULT_HOST_LIST(/home/feliksas/work/ansible/ansible.cfg) = ['/home/feliksas/work/ansible/inventory']
DEFAULT_VAULT_PASSWORD_FILE(/home/feliksas/work/ansible/ansible.cfg) = /home/feliksas/work/ansible/vault.pwd
HOST_KEY_CHECKING(/home/feliksas/work/ansible/ansible.cfg) = False
INVENTORY_ENABLED(/home/feliksas/work/ansible/ansible.cfg) = ['aws_ec2']
OS / ENVIRONMENT

Ubuntu 20.04, Grafana v8.3.4

STEPS TO REPRODUCE
  1. Create a dashboard in Grafana, place it in a custom folder (not General)
  2. Export the dashboard's JSON model, save it to a file
  3. Specify the file's path from step 2 as Ansible community.grafana.grafana_dashboard module's argument path
  4. Set the module's folder argument to actual folder name the dashboard from step 1 was created
  5. Apply configuration with module's overwrite parameter set to no
- name: Install Grafana dashboards - Scylla folder
  community.grafana.grafana_dashboard:
    grafana_url: https://grafana.example.com/
    grafana_api_key: "{{ grafana_api_key }}"
    state: present
    folder: Scylla
    overwrite: no
    path: "/tmp/{{ item }}"
  with_items:
    - grafana_dashboards/scylla/scylla_advanced.json
    - grafana_dashboards/scylla/scylla_cql.json
    - grafana_dashboards/scylla/scylla_detailed.json
    - grafana_dashboards/scylla/scylla_keyspace.json
    - grafana_dashboards/scylla/scylla_overview.json
EXPECTED RESULTS

If the dashboard's json file contents and the dashboard state were unchanged - receive the ok after running the module, indicating that no changes are necessary.

ACTUAL RESULTS

Module run fails, since it attempts to create the dashboard as if it didn't exist or was changed, while overwrite was set to no.

TASK [prometheus : Install Grafana dashboards - Scylla folder] *****************************************************************************************************************************************************************************
failed: [prometheus] (item=grafana_dashboards/scylla/scylla_advanced.json) => {"ansible_loop_var": "item", "changed": false, "item": "grafana_dashboards/scylla/scylla_advanced.json", "msg": "error : Unable to update the dashboard advanced-4-5 : The dashboard has been changed by someone else (HTTP: 412)"}
failed: [prometheus] (item=grafana_dashboards/scylla/scylla_cql.json) => {"ansible_loop_var": "item", "changed": false, "item": "grafana_dashboards/scylla/scylla_cql.json", "msg": "error : Unable to update the dashboard cql-4-5 : The dashboard has been changed by someone else (HTTP: 412)"}
failed: [prometheus] (item=grafana_dashboards/scylla/scylla_detailed.json) => {"ansible_loop_var": "item", "changed": false, "item": "grafana_dashboards/scylla/scylla_detailed.json", "msg": "error : Unable to update the dashboard detailed-4-5 : The dashboard has been changed by someone else (HTTP: 412)"}
failed: [prometheus] (item=grafana_dashboards/scylla/scylla_keyspace.json) => {"ansible_loop_var": "item", "changed": false, "item": "grafana_dashboards/scylla/scylla_keyspace.json", "msg": "error : Unable to update the dashboard ks-4-5 : The dashboard has been changed by someone else (HTTP: 412)"}
failed: [prometheus] (item=grafana_dashboards/scylla/scylla_overview.json) => {"ansible_loop_var": "item", "changed": false, "item": "grafana_dashboards/scylla/scylla_overview.json", "msg": "error : Unable to update the dashboard overview-4-5 : The dashboard has been changed by someone else (HTTP: 412)"}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant