From 70c1fb2dff8b3f800617b37bdc9676f0c6341aac Mon Sep 17 00:00:00 2001 From: Ian Wienand Date: Tue, 25 Jan 2022 14:18:04 +1100 Subject: [PATCH] grafana: update docs and make an import script Update the docs to reflect not having grafyaml in the container. Also move the import into a separate helper script, which can be manually run on the host if the container needs to be restarted out-of-band for some reason. Change-Id: Ib1f6aea7e16180d9b122552a2aa30ce223426941 --- doc/source/grafana.rst | 38 +++++++++++++------ playbooks/roles/grafana/tasks/main.yaml | 15 +++++--- .../templates/update-grafana-dashboards.sh.j2 | 6 +++ 3 files changed, 42 insertions(+), 17 deletions(-) create mode 100644 playbooks/roles/grafana/templates/update-grafana-dashboards.sh.j2 diff --git a/doc/source/grafana.rst b/doc/source/grafana.rst index 15044f06d8..baaf113e39 100644 --- a/doc/source/grafana.rst +++ b/doc/source/grafana.rst @@ -25,11 +25,20 @@ Overview Apache is configured as a reverse proxy to Grafana running in a container, listening on port 3000. +Updating dashboards +=================== + +Changes to config-files in ``project-config`` will trigger the +``infra-prod-run-grafana`` job to refresh the dashboards. If the +container is restarted manually, you can run +``/usr/local/bin/update-grafana-dashboards`` on +``grafana.opendev.org`` to reload directly. + Local Development ================= -To develop dashboards, you can run the OpenDev Grafana container. +To develop dashboards, you can run the Grafana container. Firstly, get setup: .. code-block:: shell-session @@ -50,13 +59,12 @@ Then run the container with the following options: $ sudo podman run \ -p 3000:3000 \ -v ./secrets:/etc/grafana/secrets \ - -v ./project-config:/opt/project-config \ -e GF_AUTH_ANONYMOUS_ENABLED=true \ -e GF_USERS_ALLOW_SIGN_UP=false \ -e GF_SECURITY_ADMIN_PASSWORD__FILE=/etc/grafana/secrets/admin_password \ -e GF_SECURITY_ADMIN_USER__FILE=/etc/grafana/secrets/admin_user \ -e GF_SECURITY_SECRET_KEY__FILE=/etc/grafana/secrets/secret_key \ - docker.io/opendevorg/grafana + docker.io/grafana/grafana-oss At this point, Grafana will be running and listening on port 3000. You can log into as ``admin`` with ``password`` (or using your secrets @@ -64,15 +72,23 @@ above). This is unconfigured and does not yet talk to the OpenDev Graphite instance. The dashboard definitions are kept in -``project-config/grafana``. To load them ``exec`` the -``update-grafana`` script in the container (i.e. ``podman exec - update-grafana``). That will run ``grafyaml`` and -load in the updated dashboards (note it relies on things being mapped -as above). To work on dashboards, update the ``yaml`` files in -``project-config`` and re-run ``update-grafana``, then reload them in -the Grafana UI. +``project-config/grafana``. You need to run the ``grafyaml`` tool to +load them. + +.. code-block:: shell-session + + $ echo 'GRAFANA_URL=http://admin:password@localhost:3000/' > grafyaml.env + $ docker run --rm -t --network=host \ + --env-file ./grafyaml.env \ + -v ./project-config/grafana:/grafana:ro \ + opendevorg/grafyaml + +To work on dashboards, update the ``yaml`` files in ``project-config`` +and re-run the grafyaml import as above, then reload them in the +Grafana UI. Alternatively, you can use the Grafana editor to make the dashboards, and then under "Dashboard Settings" (gear icon) select "JSON Model" and commit that (it seems you have to cut-and-paste, there isn't -currently a way to export the JSON as such). +currently a way to export the JSON as such). The raw JSON can be +proposed as an addition to ``project-config``. diff --git a/playbooks/roles/grafana/tasks/main.yaml b/playbooks/roles/grafana/tasks/main.yaml index 65accea050..758fe9dd6f 100644 --- a/playbooks/roles/grafana/tasks/main.yaml +++ b/playbooks/roles/grafana/tasks/main.yaml @@ -41,6 +41,14 @@ group: root mode: 0644 +- name: Write update script + template: + src: update-grafana-dashboards.sh.j2 + dest: /usr/local/bin/update-grafana-dashboards + owner: root + group: root + mode: 0755 + - name: Install apache2 apt: name: @@ -88,9 +96,4 @@ cmd: docker image prune -f - name: Import dashboards to container - shell: - cmd: >- - docker run --rm -t --network=host - --env-file /etc/grafana/secrets/grafyaml.env - -v /opt/project-config/grafana:/grafana:ro - opendevorg/grafyaml + command: '/usr/local/bin/update-grafana-dashboards' diff --git a/playbooks/roles/grafana/templates/update-grafana-dashboards.sh.j2 b/playbooks/roles/grafana/templates/update-grafana-dashboards.sh.j2 new file mode 100644 index 0000000000..4b36307954 --- /dev/null +++ b/playbooks/roles/grafana/templates/update-grafana-dashboards.sh.j2 @@ -0,0 +1,6 @@ +#!/bin/bash + +docker run --rm -t --network=host \ + --env-file /etc/grafana/secrets/grafyaml.env \ + -v /opt/project-config/grafana:/grafana:ro \ + opendevorg/grafyaml