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

Can't load dashboard json file #191

Closed
gaetanBelliere opened this issue Oct 19, 2021 · 2 comments · Fixed by #273
Closed

Can't load dashboard json file #191

gaetanBelliere opened this issue Oct 19, 2021 · 2 comments · Fixed by #273

Comments

@gaetanBelliere
Copy link

SUMMARY

While trying to provision a CentOS7 VM with Ansible, some dashboards configuration files fail to load. Those json files are fetched from the grafana GUI. The dashboards that fail are dashboards containing Markdown Text panel. Issue is the following :

failed: [gx-artifactory-dev] (item={'path': '/data/grafana/Endurance/endurance-home-page.json', 'folder': 'Endurance'}) => {"ansible_loop_var": "item", "changed": false, "item": {"folder": "Endurance", "path": "/data/grafana/Endurance/endurance-home-page.json"}, "msg": "error : Can't load json file 'ascii' codec can't decode byte 0xe2 in position 3872: ordinal not in range(128)"}

One quick fix is to convert the text to HTML with appropriate flags.

ISSUE TYPE
  • Bug Report
COMPONENT NAME

grafana_dashboard

ANSIBLE VERSION
ansible [core 2.11.6]
  config file = /etc/ansible/ansible.cfg
  configured module search path = ['/root/.ansible/plugins/modules', '/usr/share/ansible/plugins/modules']
  ansible python module location = /usr/lib/python3/dist-packages/ansible
  ansible collection location = /root/.ansible/collections:/usr/share/ansible/collections
  executable location = /usr/bin/ansible
  python version = 3.9.5 (default, May 11 2021, 08:20:37) [GCC 10.3.0]
  jinja version = 2.11.2
  libyaml = True
COLLECTION VERSION
community.grafana             1.2.3

CONFIGURATION

OS / ENVIRONMENT

The targeted os is a CentOS7 local VM. I use a Windows docker container as an Ansible runner.

STEPS TO REPRODUCE

Create a grafana dashboard with a Mardown text panel.
Copy the json model of the dashboard and store it in dashboard.json.
Provision grafana dashboard.

- name: Import Grafana dashboards
  community.grafana.grafana_dashboard:
    grafana_url: "{{ grafana_localhost }}"
    state: present
    path: dashboard.json
    overwrite: yes
    folder: Global  
    commit_message: "Updated by Ansible"
    url_password: "{{ grafana_password_for_admin }}"
EXPECTED RESULTS

The dashboard to load and to be provision like other dashboards with no markdown text.

ACTUAL RESULTS

Dashboard fails to load

failed: [gx-artifactory-dev] (item={'path': '/data/grafana/Endurance/endurance-home-page.json', 'folder': 'Endurance'}) => {"ansible_loop_var": "item", "changed": false, "item": {"folder": "Endurance", "path": "/data/grafana/Endurance/endurance-home-page.json"}, "msg": "error : Can't load json file 'ascii' codec can't decode byte 0xe2 in position 3872: ordinal not in range(128)"

I know how to fix this bug. I have tested it locally. Thanks to this post : https://stackoverflow.com/questions/491921/unicode-utf-8-reading-and-writing-to-files-in-python/844443#844443

Here : https://github.com/ansible-collections/community.grafana/blob/main/plugins/modules/grafana_dashboard.py#L308
Should be changed to :

with io.open(data['path'], mode='r', encoding="utf-8") as json_file:

Of course import io at the top of the file.

@rrey
Copy link
Collaborator

rrey commented Nov 26, 2021

@gaetanBelliere woud you be able to provide the dashboard that provoke the failure ? I wonder if I could add it in the tests.
I think that keeping the standard open function can work as well since it also have the encoding parameter support.

@gaetanBelliere
Copy link
Author

What's weird is that when I tried to upload the conflicting files only it would work perfectly, making my example not relevant.. So instead I used the Grafana provisioning, which is way easier to maintain than using Ansible (because it doesn't require to keep an exact list of every dashboard config file and it's destination). I guess we can close this issue, even though the problem remains

rrey added a commit that referenced this issue Aug 22, 2022
No method of reproduction was found/provided for #191, as a prevention
measure this patch specifies the encoding to use when opening a file to
avoid the open function to auto determine the preferred encoding based
on the locale.

Closes: #191
rrey added a commit that referenced this issue Aug 22, 2022
No method of reproduction was found/provided for #191, as a prevention
measure this patch specifies the encoding to use when opening a file to
avoid the open function to auto determine the preferred encoding based
on the locale.

Closes: #191
rrey added a commit that referenced this issue Oct 9, 2022
No method of reproduction was found/provided for #191, as a prevention
measure this patch specifies the encoding to use when opening a file to
avoid the open function to auto determine the preferred encoding based
on the locale.

Closes: #191
@rrey rrey closed this as completed in #273 Oct 9, 2022
rrey added a commit that referenced this issue Oct 9, 2022
No method of reproduction was found/provided for #191, as a prevention
measure this patch specifies the encoding to use when opening a file to
avoid the open function to auto determine the preferred encoding based
on the locale.

Closes: #191
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

Successfully merging a pull request may close this issue.

2 participants