diff --git a/packages/grafana-data/src/types/datasource.ts b/packages/grafana-data/src/types/datasource.ts index da6404504ce..1c3ada963f2 100644 --- a/packages/grafana-data/src/types/datasource.ts +++ b/packages/grafana-data/src/types/datasource.ts @@ -487,7 +487,7 @@ export interface DataQueryRequest { timezone: string; app: CoreApp | string; - cacheTimeout?: string; + cacheTimeout?: string | null; rangeRaw?: RawTimeRange; timeInfo?: string; // The query time description (blue text in the upper right) panelId?: number; diff --git a/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx b/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx index 7b7e684df57..abdf6ffc6bb 100644 --- a/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx +++ b/public/app/features/dashboard/components/PanelEditor/PanelEditorQueries.tsx @@ -4,6 +4,7 @@ import { PanelModel } from '../../state'; import { getLocationSrv } from '@grafana/runtime'; import { QueryGroupDataSource, QueryGroupOptions } from 'app/types'; import { DataQuery } from '@grafana/data'; +import { getDatasourceSrv } from 'app/features/plugins/datasource_srv'; interface Props { /** Current panel */ @@ -27,7 +28,10 @@ export class PanelEditorQueries extends PureComponent { default: true, }; + const datasourceSettings = getDatasourceSrv().getInstanceSettings(dataSource.uid); + return { + cacheTimeout: datasourceSettings?.meta.queryOptions?.cacheTimeout ? panel.cacheTimeout : undefined, dataSource, queries: panel.targets, maxDataPoints: panel.maxDataPoints, diff --git a/public/app/features/dashboard/containers/DashboardPage.test.tsx b/public/app/features/dashboard/containers/DashboardPage.test.tsx index 98cd65d0cbc..1c14842c54a 100644 --- a/public/app/features/dashboard/containers/DashboardPage.test.tsx +++ b/public/app/features/dashboard/containers/DashboardPage.test.tsx @@ -3,7 +3,7 @@ import { Provider } from 'react-redux'; import { render, screen } from '@testing-library/react'; import { Props, UnthemedDashboardPage } from './DashboardPage'; import { Router } from 'react-router-dom'; -import { locationService } from '@grafana/runtime'; +import { locationService, setDataSourceSrv } from '@grafana/runtime'; import { DashboardModel } from '../state'; import { configureStore } from '../../../store/configureStore'; import { mockToolkitActionCreator } from 'test/core/redux/mocks'; @@ -208,6 +208,12 @@ describe('DashboardPage', () => { }); dashboardPageScenario('When going into edit mode', (ctx) => { + setDataSourceSrv({ + get: jest.fn().mockResolvedValue({}), + getInstanceSettings: jest.fn().mockReturnValue({ meta: {} }), + getList: jest.fn(), + }); + ctx.setup(() => { ctx.mount({ dashboard: getTestDashboard(), diff --git a/public/app/features/dashboard/state/PanelModel.ts b/public/app/features/dashboard/state/PanelModel.ts index a23607a96a6..8202b03286e 100644 --- a/public/app/features/dashboard/state/PanelModel.ts +++ b/public/app/features/dashboard/state/PanelModel.ts @@ -171,7 +171,7 @@ export class PanelModel implements DataConfigSource, IPanelModel { isInView = false; configRev = 0; // increments when configs change hasRefreshed?: boolean; - cacheTimeout?: any; + cacheTimeout?: string | null; cachedPluginOptions: Record = {}; legend?: { show: boolean; sort?: string; sortDesc?: boolean }; plugin?: PanelPlugin; @@ -449,6 +449,7 @@ export class PanelModel implements DataConfigSource, IPanelModel { uid: dataSource.uid, type: dataSource.type, }; + this.cacheTimeout = options.cacheTimeout; this.timeFrom = options.timeRange?.from; this.timeShift = options.timeRange?.shift; this.hideTimeOverride = options.timeRange?.hide; diff --git a/public/app/features/query/state/PanelQueryRunner.ts b/public/app/features/query/state/PanelQueryRunner.ts index 8b0ce2b93f9..d6a0a22a81f 100644 --- a/public/app/features/query/state/PanelQueryRunner.ts +++ b/public/app/features/query/state/PanelQueryRunner.ts @@ -51,7 +51,7 @@ export interface QueryRunnerOptions< maxDataPoints: number; minInterval: string | undefined | null; scopedVars?: ScopedVars; - cacheTimeout?: string; + cacheTimeout?: string | null; transformations?: DataTransformerConfig[]; }