]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
cephadm:persist the grafana.db file
authorPaul Cuzner <pcuzner@redhat.com>
Thu, 1 Apr 2021 04:38:18 +0000 (17:38 +1300)
committerSage Weil <sage@newdream.net>
Sat, 10 Apr 2021 13:06:59 +0000 (08:06 -0500)
This patch persists the grafana.db file, so the user can
create there own dashboard referencing ceph and node
metrics and not lose them on grafana restart! This also
ensures changes to users/passwords within grafana are
persisted.

Fixes: https://tracker.ceph.com/issues/49954
Signed-off-by: Paul Cuzner <pcuzner@redhat.com>
(cherry picked from commit 581250d943915cb3f8e7e4071440ee5cad5e5908)

src/cephadm/cephadm

index e0383c609745f5d201c748c92c18ca88adcf971c..fe870f6e814e60f87294ff2fecd513879f91527c 100755 (executable)
@@ -43,6 +43,7 @@ from io import StringIO
 from threading import Thread, RLock
 from urllib.error import HTTPError
 from urllib.request import urlopen
+from pathlib import Path
 
 # Default container images -----------------------------------------------------
 DEFAULT_IMAGE = 'docker.io/ceph/ceph:v16'
@@ -903,6 +904,15 @@ class CustomContainer(object):
 ##################################
 
 
+def touch(file_path: str, uid: Optional[int] = None, gid: Optional[int] = None) -> None:
+    Path(file_path).touch()
+    if uid and gid:
+        os.chown(file_path, uid, gid)
+
+
+##################################
+
+
 def dict_get(d: Dict, key: str, default: Any = None, require: bool = False) -> Any:
     """
     Helper function to get a key from a dictionary.
@@ -2140,6 +2150,7 @@ def create_daemon_dirs(ctx, fsid, daemon_type, daemon_id, uid, gid,
             makedirs(os.path.join(data_dir_root, config_dir, 'certs'), uid, gid, 0o755)
             makedirs(os.path.join(data_dir_root, config_dir, 'provisioning/datasources'), uid, gid, 0o755)
             makedirs(os.path.join(data_dir_root, 'data'), uid, gid, 0o755)
+            touch(os.path.join(data_dir_root, 'data', 'grafana.db'), uid, gid)
         elif daemon_type == 'alertmanager':
             data_dir_root = get_data_dir(fsid, ctx.data_dir,
                                          daemon_type, daemon_id)
@@ -2326,6 +2337,7 @@ def get_container_mounts(ctx, fsid, daemon_type, daemon_id,
             mounts[os.path.join(data_dir, 'etc/grafana/grafana.ini')] = '/etc/grafana/grafana.ini:Z'
             mounts[os.path.join(data_dir, 'etc/grafana/provisioning/datasources')] = '/etc/grafana/provisioning/datasources:Z'
             mounts[os.path.join(data_dir, 'etc/grafana/certs')] = '/etc/grafana/certs:Z'
+            mounts[os.path.join(data_dir, 'data/grafana.db')] = '/var/lib/grafana/grafana.db:Z'
         elif daemon_type == 'alertmanager':
             mounts[os.path.join(data_dir, 'etc/alertmanager')] = '/etc/alertmanager:Z'