]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: enable different URL for users of browser to Grafana 39136/head
authorPatrick Seidensal <pseidensal@suse.com>
Tue, 3 Nov 2020 12:47:23 +0000 (13:47 +0100)
committerPatrick Seidensal <patrick@nawracay.de>
Mon, 1 Feb 2021 12:39:02 +0000 (13:39 +0100)
Fixes: https://tracker.ceph.com/issues/47386
Signed-off-by: Patrick Seidensal <pseidensal@suse.com>
(cherry picked from commit 676f82923d875cfe9528a401963c09f29a6de7f4)

Conflicts:
        doc/mgr/dashboard.rst
        src/pybind/mgr/dashboard/controllers/grafana.py

Resolved some trivial conflicts and replaced the heading of the newly
added section in the documentation to another level, as the
documentation between master and octopus differs quite much.

(cherry picked from commit 56f304d31b154d87362620f08046720a3e0f3203)

Conflicts:

Removed cephadm documentation from cherry-picked commit as cephadm is
not part of Ceph Nautilus.

Removed paragraph that mentioned cephadm in dashboard documentation.

doc/mgr/dashboard.rst
src/pybind/mgr/dashboard/controllers/grafana.py
src/pybind/mgr/dashboard/settings.py

index 5d14be6c91cf8231c13b3e68808baf707afc2f1a..f92bd19d5a4f088c19158161fead7450d7c8a9c6 100644 (file)
@@ -439,7 +439,8 @@ More details can be found in the documentation of the :ref:`mgr-prometheus`.
 After you have set up Grafana and Prometheus, you will need to configure the
 connection information that the Ceph Dashboard will use to access Grafana.
 
-You need to tell the dashboard on which url Grafana instance is running/deployed::
+You need to tell the dashboard on which URL the Grafana instance is
+running/deployed::
 
   $ ceph dashboard set-grafana-api-url <grafana-server-url>  # default: ''
 
@@ -462,6 +463,35 @@ e.g. caused by certificates signed by unknown CA or not matching the host name::
 
 You can directly access Grafana Instance as well to monitor your cluster.
 
+Alternative URL for Browsers
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The Ceph Dashboard backend requires the Grafana URL to be able to verify the
+existence of Grafana Dashboards before the frontend even loads them. Due to the
+nature of how Grafana is implemented in Ceph Dashboard, this means that two
+working connections are required in order to be able to see Grafana graphs in
+Ceph Dashboard:
+
+- The backend (Ceph Mgr module) needs to verify the existence of the requested
+  graph. If this request succeeds, it lets the frontend know that it can safely
+  access Grafana.
+- The frontend then requests the Grafana graphs directly from the user's
+  browser using an iframe. The Grafana instance is accessed directly without any
+  detour through Ceph Dashboard.
+
+Now, it might be the case that your environment makes it difficult for the
+user's browser to directly access the URL configured in Ceph Dashboard. To solve
+this issue, a separate URL can be configured which will solely be used to tell
+the frontend (the user's browser) which URL it should use to access Grafana.
+
+To change the URL that is returned to the frontend issue the following command::
+
+  $ ceph dashboard set-grafana-frontend-api-url <grafana-server-url>
+
+If no value is set for that option, it will simply fall back to the value of the
+GRAFANA_API_URL option. If set, it will instruct the browser to use this URL to
+access Grafana.
+
 .. _dashboard-sso-support:
 
 Enabling Single Sign-On (SSO)
index 0d4331ff246372348aafc8378db7b019062dd42c..001367c7c291e483696e810d8db693c1adecd5bb 100644 (file)
@@ -3,6 +3,7 @@ from __future__ import absolute_import
 
 from . import (ApiController, BaseController, Endpoint, ReadPermission,
                UpdatePermission)
+from .. import mgr
 from ..exceptions import DashboardException
 from ..grafana import GrafanaRestClient, push_local_dashboards
 from ..security import Scope
@@ -11,11 +12,17 @@ from ..settings import Settings
 
 @ApiController('/grafana', Scope.GRAFANA)
 class Grafana(BaseController):
-
     @Endpoint()
     @ReadPermission
     def url(self):
-        response = {'instance': Settings.GRAFANA_API_URL}
+        grafana_url = mgr.get_module_option('GRAFANA_API_URL')
+        grafana_frontend_url = mgr.get_module_option('GRAFANA_FRONTEND_API_URL')
+        if grafana_frontend_url != '' and grafana_url == '':
+            url = ''
+        else:
+            url = (mgr.get_module_option('GRAFANA_FRONTEND_API_URL')
+                   or mgr.get_module_option('GRAFANA_API_URL')).rstrip('/')
+        response = {'instance': url}
         return response
 
     @Endpoint()
@@ -23,7 +30,7 @@ class Grafana(BaseController):
     def validation(self, params):
         grafana = GrafanaRestClient()
         method = 'GET'
-        url = Settings.GRAFANA_API_URL.rstrip('/') + \
+        url = str(Settings.GRAFANA_API_URL).rstrip('/') + \
             '/api/dashboards/uid/' + params
         response = grafana.url_validation(method, url)
         return response
index d9936b5008d4ce8bb8914d31c386c72bb144216c..95b1cdf4194d6008bc7af60920640edcf04019dd 100644 (file)
@@ -39,6 +39,7 @@ class Options(object):
 
     # Grafana settings
     GRAFANA_API_URL = ('', str)
+    GRAFANA_FRONTEND_API_URL = ('', str)
     GRAFANA_API_USERNAME = ('admin', str)
     GRAFANA_API_PASSWORD = ('admin', str)
     GRAFANA_API_SSL_VERIFY = (True, bool)