From: Ernesto Puerta Date: Mon, 31 May 2021 11:45:40 +0000 (+0200) Subject: mgr/dashboard: pass Grafana datasource in URL X-Git-Tag: v17.1.0~1791^2 X-Git-Url: http://git-server-git.apps.pok.os.sepia.ceph.com/?a=commitdiff_plain;h=refs%2Fpull%2F41598%2Fhead;p=ceph.git 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 --- 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 9bbfba190848..63733fd759cc 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 e3baecb89ae4..a687959b747f 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;