]> git-server-git.apps.pok.os.sepia.ceph.com Git - ceph.git/commitdiff
mgr/dashboard: pass Grafana datasource in URL 41598/head
authorErnesto Puerta <epuertat@redhat.com>
Mon, 31 May 2021 11:45:40 +0000 (13:45 +0200)
committerErnesto Puerta <epuertat@redhat.com>
Mon, 31 May 2021 14:19:44 +0000 (16:19 +0200)
PR https://github.com/ceph/ceph/pull/24314 added support for
specifying the Grafana datasource via $datasource template variable, but
this hadn't been used from the Dashboard side so far.

As per https://grafana.com/docs/grafana/latest/variables/#templates, by
adding `var-datasource=Dashboard1`, Dashboard can specify the
datasource.

Fixes: https://tracker.ceph.com/issues/51026
Signed-off-by: Ernesto Puerta <epuertat@redhat.com>
src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.spec.ts
src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.ts

index 9bbfba19084856856d80bbe106b0942f570a5633..63733fd759cccd79423ee02fe9b097cf14787947 100644 (file)
@@ -18,6 +18,8 @@ import { GrafanaComponent } from './grafana.component';
 describe('GrafanaComponent', () => {
   let component: GrafanaComponent;
   let fixture: ComponentFixture<GrafanaComponent>;
+  const expected_url =
+    'http:localhost:3000/d/foo/somePath&refresh=2s&var-datasource=Dashboard1&kiosk&from=now-1h&to=now';
 
   configureTestBed({
     declarations: [GrafanaComponent, AlertPanelComponent, LoadingPanelComponent, DocComponent],
@@ -56,24 +58,18 @@ describe('GrafanaComponent', () => {
       expect(component.grafanaExist).toBe(true);
       expect(component.baseUrl).toBe('http:localhost:3000/d/');
       expect(component.loading).toBe(false);
-      expect(component.url).toBe(
-        'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
-      );
+      expect(component.url).toBe(expected_url);
       expect(component.grafanaSrc).toEqual({
-        changingThisBreaksApplicationSecurity:
-          'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
+        changingThisBreaksApplicationSecurity: expected_url
       });
     });
 
     it('should reset the values', () => {
       component.reset();
       expect(component.time).toBe('from=now-1h&to=now');
-      expect(component.url).toBe(
-        'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
-      );
+      expect(component.url).toBe(expected_url);
       expect(component.grafanaSrc).toEqual({
-        changingThisBreaksApplicationSecurity:
-          'http:localhost:3000/d/foo/somePath&refresh=2s&kiosk&from=now-1h&to=now'
+        changingThisBreaksApplicationSecurity: expected_url
       });
     });
 
index e3baecb89ae4d4e2990cb3507f115f985b4bc284..a687959b747f8532a7b03a69e8a642000a21655e 100644 (file)
@@ -19,6 +19,7 @@ export class GrafanaComponent implements OnInit, OnChanges {
   panelStyle: any;
   grafanaExist = false;
   mode = '&kiosk';
+  datasource = 'Dashboard1';
   loading = true;
   styles: Record<string, string> = {};
   dashboardExist = true;
@@ -171,6 +172,7 @@ export class GrafanaComponent implements OnInit, OnChanges {
       '/' +
       this.grafanaPath +
       '&refresh=2s' +
+      `&var-datasource=${this.datasource}` +
       this.mode +
       '&' +
       this.time;