mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
@@ -32,6 +32,7 @@ import { isStreamingDataFrame } from 'app/features/live/data/utils';
|
||||
import { getDatasourceSrv } from 'app/features/plugins/datasource_srv';
|
||||
|
||||
import { isSharedDashboardQuery, runSharedRequest } from '../../../plugins/datasource/dashboard';
|
||||
import { PublicDashboardDataSource } from '../../dashboard/services/PublicDashboardDataSource';
|
||||
import { PanelModel } from '../../dashboard/state';
|
||||
|
||||
import { getDashboardQueryRunner } from './DashboardQueryRunner/DashboardQueryRunner';
|
||||
@@ -46,6 +47,7 @@ export interface QueryRunnerOptions<
|
||||
queries: TQuery[];
|
||||
panelId?: number;
|
||||
dashboardId?: number;
|
||||
publicDashboardUid?: string;
|
||||
timezone: TimeZone;
|
||||
timeRange: TimeRange;
|
||||
timeInfo?: string; // String description of time range for display
|
||||
@@ -201,6 +203,7 @@ export class PanelQueryRunner {
|
||||
datasource,
|
||||
panelId,
|
||||
dashboardId,
|
||||
publicDashboardUid,
|
||||
timeRange,
|
||||
timeInfo,
|
||||
cacheTimeout,
|
||||
@@ -220,6 +223,7 @@ export class PanelQueryRunner {
|
||||
timezone,
|
||||
panelId,
|
||||
dashboardId,
|
||||
publicDashboardUid,
|
||||
range: timeRange,
|
||||
timeInfo,
|
||||
interval: '',
|
||||
@@ -235,8 +239,9 @@ export class PanelQueryRunner {
|
||||
(request as any).rangeRaw = timeRange.raw;
|
||||
|
||||
try {
|
||||
const ds = await getDataSource(datasource, request.scopedVars);
|
||||
const ds = await getDataSource(datasource, request.scopedVars, publicDashboardUid);
|
||||
const isMixedDS = ds.meta?.mixed;
|
||||
|
||||
// Attach the data source to each query
|
||||
request.targets = request.targets.map((query) => {
|
||||
const isExpressionQuery = query.datasource?.type === ExpressionDatasourceRef.type;
|
||||
@@ -353,10 +358,16 @@ export class PanelQueryRunner {
|
||||
|
||||
async function getDataSource(
|
||||
datasource: DataSourceRef | string | DataSourceApi | null,
|
||||
scopedVars: ScopedVars
|
||||
scopedVars: ScopedVars,
|
||||
publicDashboardUid?: string
|
||||
): Promise<DataSourceApi> {
|
||||
if (publicDashboardUid) {
|
||||
return new PublicDashboardDataSource();
|
||||
}
|
||||
|
||||
if (datasource && (datasource as any).query) {
|
||||
return datasource as DataSourceApi;
|
||||
}
|
||||
|
||||
return await getDatasourceSrv().get(datasource as string, scopedVars);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user