Public Dashboards: Pubdash panels get data from pubdash api (#50556)

* Public dashboard query API

* Create new API on service for building metric request

* Flesh out testing, implement BuildPublicDashboardMetricRequest

* Test for errors and missing panels

* WIP: Test for multiple datasources

* Refactor tests, add supporting code for multiple datasources

* Gets the panel data from the pubdash query api

* Adds tests to make sure we get the correct api url from retrieving panel data

* Public dashboard query API

* Create new API on service for building metric request

* Flesh out testing, implement BuildPublicDashboardMetricRequest

* Test for errors and missing panels

* WIP: Test for multiple datasources

* Refactor tests, add supporting code for multiple datasources

* Handle queries from multiple datasources

* Replace dashboard time range with pubdash time range settings

* Fix comments from review, build failure

* removes changes to DataSourceWithBackend.ts regarding getting the pubdash panel query url. Going to do this in a new class, PublicDashboardDataSource.ts

* Include pubdash Uid in dashboard meta

* Creates new PublicDashboardDataSource.ts and adds test

* Passes pubdash uid down to PanelQueryRunner.ts to a PublicDashboardDatasource can be chosen when were looking at a public dashboard

* removes comment

* checks for error when unmarshalling json

* Only replace dashboard time settings with pubdash time settings when pubdash time settings exist

* formatting and added comment

Co-authored-by: Jesse Weaver <jesse.weaver@grafana.com>
Co-authored-by: Jeff Levin <jeff@levinology.com>
This commit is contained in:
owensmallwood
2022-06-13 18:03:43 -06:00
committed by GitHub
co-authored by Jesse Weaver Jeff Levin
parent 0371884cdd
commit 1bb2d2599c
13 changed files with 199 additions and 20 deletions
@@ -477,6 +477,8 @@ export interface DataQueryRequest<TQuery extends DataQuery = DataQuery> {
timeInfo?: string; // The query time description (blue text in the upper right)
panelId?: number;
dashboardId?: number;
// Temporary prop for public dashboards, to be replaced by publicAccessKey
publicDashboardUid?: string;
// Request Timing
startTime: number;
@@ -0,0 +1,48 @@
import { of } from 'rxjs';
import { BackendSrv, BackendSrvRequest } from 'src/services';
import { DataQueryRequest, DataSourceRef } from '@grafana/data';
import { PublicDashboardDataSource } from '../../../../public/app/features/dashboard/services/PublicDashboardDataSource';
const mockDatasourceRequest = jest.fn();
const backendSrv = {
fetch: (options: BackendSrvRequest) => {
return of(mockDatasourceRequest(options));
},
} as unknown as BackendSrv;
jest.mock('../services', () => ({
...(jest.requireActual('../services') as any),
getBackendSrv: () => backendSrv,
getDataSourceSrv: () => {
return {
getInstanceSettings: (ref?: DataSourceRef) => ({ type: ref?.type ?? '?', uid: ref?.uid ?? '?' }),
};
},
}));
describe('PublicDashboardDatasource', () => {
test('Fetches results from the pubdash query endpoint', () => {
mockDatasourceRequest.mockReset();
mockDatasourceRequest.mockReturnValue(Promise.resolve({}));
const ds = new PublicDashboardDataSource();
const panelId = 1;
const publicDashboardUid = 'abc123';
ds.query({
maxDataPoints: 10,
intervalMs: 5000,
targets: [{ refId: 'A' }, { refId: 'B', datasource: { type: 'sample' } }],
panelId,
publicDashboardUid,
} as DataQueryRequest);
const mock = mockDatasourceRequest.mock;
expect(mock.calls.length).toBe(1);
expect(mock.lastCall[0].url).toEqual(`/api/public/dashboards/${publicDashboardUid}/panels/${panelId}/query`);
});
});