From 957c9c304bca8ef8416041f96b0e2d5bb0f0a0dc Mon Sep 17 00:00:00 2001 From: Ernesto Puerta Date: Mon, 31 May 2021 13:45:40 +0200 Subject: [PATCH] mgr/dashboard: pass Grafana datasource in URL 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 --- .../components/grafana/grafana.component.spec.ts | 16 ++++++---------- .../components/grafana/grafana.component.ts | 2 ++ 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.spec.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.spec.ts index 9bbfba1908485..63733fd759ccc 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.spec.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.spec.ts @@ -18,6 +18,8 @@ import { GrafanaComponent } from './grafana.component'; describe('GrafanaComponent', () => { let component: GrafanaComponent; let fixture: ComponentFixture; + 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 }); }); diff --git a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.ts b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.ts index e3baecb89ae4d..a687959b747f8 100644 --- a/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.ts +++ b/src/pybind/mgr/dashboard/frontend/src/app/shared/components/grafana/grafana.component.ts @@ -19,6 +19,7 @@ export class GrafanaComponent implements OnInit, OnChanges { panelStyle: any; grafanaExist = false; mode = '&kiosk'; + datasource = 'Dashboard1'; loading = true; styles: Record = {}; dashboardExist = true; @@ -171,6 +172,7 @@ export class GrafanaComponent implements OnInit, OnChanges { '/' + this.grafanaPath + '&refresh=2s' + + `&var-datasource=${this.datasource}` + this.mode + '&' + this.time; -- 2.39.5