mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Query Caching: Add per-panel query caching TTL (#61968)
* *Create Caching Config interface and OSS impl
*Create front-end facing DS Cache config
*Populate Caching Config on Datasource DTO
*Update OSS wire deps
* fix unit test
* handle query caching TTL override on the frontend
* Make sure the override works with pubdash
* move caching config to the right place in the ds info
* move caching config logic to enterprise index hook
* move queryCachingTTL to pubdash query payload
* Remove from metadata (not needed)
* rename struct and add comment
* remove invalid wire dependency
* manual revert of 395c74b
* fix frontend test
* fix backend test
* fix tests for real this time
* truly fix frontend test
* fix back end unit test for real
This commit is contained in:
@@ -203,6 +203,7 @@ class MetricsPanelCtrl extends PanelCtrl {
|
||||
publicDashboardAccessToken: this.dashboard.meta.publicDashboardAccessToken,
|
||||
scopedVars: panel.scopedVars,
|
||||
cacheTimeout: panel.cacheTimeout,
|
||||
queryCachingTTL: panel.queryCachingTTL,
|
||||
transformations: panel.transformations,
|
||||
});
|
||||
}
|
||||
|
||||
@@ -33,6 +33,7 @@ export class PanelEditorQueries extends PureComponent<Props> {
|
||||
type: datasourceSettings?.type,
|
||||
uid: datasourceSettings?.uid,
|
||||
},
|
||||
queryCachingTTL: datasourceSettings?.cachingConfig?.enabled ? panel.queryCachingTTL : undefined,
|
||||
queries: panel.targets,
|
||||
maxDataPoints: panel.maxDataPoints,
|
||||
minInterval: panel.interval,
|
||||
|
||||
@@ -86,6 +86,7 @@ export class PublicDashboardDataSource extends DataSourceApi<DataQuery, DataSour
|
||||
requestId,
|
||||
publicDashboardAccessToken,
|
||||
panelId,
|
||||
queryCachingTTL,
|
||||
range: { from: fromRange, to: toRange },
|
||||
} = request;
|
||||
let queries: DataQuery[];
|
||||
@@ -110,6 +111,7 @@ export class PublicDashboardDataSource extends DataSourceApi<DataQuery, DataSour
|
||||
const body = {
|
||||
intervalMs,
|
||||
maxDataPoints,
|
||||
queryCachingTTL,
|
||||
timeRange: { from: fromRange.valueOf().toString(), to: toRange.valueOf().toString() },
|
||||
};
|
||||
|
||||
|
||||
@@ -104,6 +104,7 @@ const mustKeepProps: { [str: string]: boolean } = {
|
||||
hasRefreshed: true,
|
||||
events: true,
|
||||
cacheTimeout: true,
|
||||
queryCachingTTL: true,
|
||||
cachedPluginOptions: true,
|
||||
transparent: true,
|
||||
pluginVersion: true,
|
||||
@@ -184,6 +185,8 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
hasSavedPanelEditChange?: boolean;
|
||||
hasRefreshed?: boolean;
|
||||
cacheTimeout?: string | null;
|
||||
queryCachingTTL?: number | null;
|
||||
|
||||
cachedPluginOptions: Record<string, PanelOptionsCache> = {};
|
||||
legend?: { show: boolean; sort?: string; sortDesc?: boolean };
|
||||
plugin?: PanelPlugin;
|
||||
@@ -366,6 +369,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
minInterval: this.interval,
|
||||
scopedVars: this.scopedVars,
|
||||
cacheTimeout: this.cacheTimeout,
|
||||
queryCachingTTL: this.queryCachingTTL,
|
||||
transformations: this.transformations,
|
||||
app: this.isEditing ? CoreApp.PanelEditor : this.isViewing ? CoreApp.PanelViewer : CoreApp.Dashboard,
|
||||
});
|
||||
@@ -532,6 +536,7 @@ export class PanelModel implements DataConfigSource, IPanelModel {
|
||||
}
|
||||
|
||||
this.cacheTimeout = options.cacheTimeout;
|
||||
this.queryCachingTTL = options.queryCachingTTL;
|
||||
this.timeFrom = options.timeRange?.from;
|
||||
this.timeShift = options.timeRange?.shift;
|
||||
this.hideTimeOverride = options.timeRange?.hide;
|
||||
|
||||
@@ -111,6 +111,21 @@ export class QueryGroupOptionsEditor extends PureComponent<Props, State> {
|
||||
});
|
||||
};
|
||||
|
||||
onQueryCachingTTLBlur = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
const { options, onChange } = this.props;
|
||||
|
||||
let ttl: number | null = parseInt(event.target.value, 10);
|
||||
|
||||
if (isNaN(ttl) || ttl === 0) {
|
||||
ttl = null;
|
||||
}
|
||||
|
||||
onChange({
|
||||
...options,
|
||||
queryCachingTTL: ttl,
|
||||
});
|
||||
};
|
||||
|
||||
onMaxDataPointsBlur = (event: ChangeEvent<HTMLInputElement>) => {
|
||||
const { options, onChange } = this.props;
|
||||
|
||||
@@ -168,6 +183,34 @@ export class QueryGroupOptionsEditor extends PureComponent<Props, State> {
|
||||
);
|
||||
}
|
||||
|
||||
renderQueryCachingTTLOption() {
|
||||
const { dataSource, options } = this.props;
|
||||
|
||||
const tooltip = `Cache time-to-live: How long results from this queries in this panel will be cached, in milliseconds. Defaults to the TTL in the caching configuration for this datasource.`;
|
||||
|
||||
if (!dataSource.cachingConfig?.enabled) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return (
|
||||
<div className="gf-form-inline">
|
||||
<div className="gf-form">
|
||||
<InlineFormLabel width={9} tooltip={tooltip}>
|
||||
Cache TTL
|
||||
</InlineFormLabel>
|
||||
<Input
|
||||
type="number"
|
||||
className="width-6"
|
||||
placeholder={`${dataSource.cachingConfig.TTLMs}`}
|
||||
spellCheck={false}
|
||||
onBlur={this.onQueryCachingTTLBlur}
|
||||
defaultValue={options.queryCachingTTL ?? undefined}
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
renderMaxDataPointsOption() {
|
||||
const { data, options } = this.props;
|
||||
const realMd = data.request?.maxDataPoints;
|
||||
@@ -312,6 +355,7 @@ export class QueryGroupOptionsEditor extends PureComponent<Props, State> {
|
||||
{this.renderMaxDataPointsOption()}
|
||||
{this.renderIntervalOption()}
|
||||
{this.renderCacheTimeoutOption()}
|
||||
{this.renderQueryCachingTTLOption()}
|
||||
|
||||
<div className="gf-form">
|
||||
<InlineFormLabel width={9}>Relative time</InlineFormLabel>
|
||||
|
||||
@@ -58,6 +58,7 @@ export interface QueryRunnerOptions<
|
||||
minInterval: string | undefined | null;
|
||||
scopedVars?: ScopedVars;
|
||||
cacheTimeout?: string | null;
|
||||
queryCachingTTL?: number | null;
|
||||
transformations?: DataTransformerConfig[];
|
||||
app?: CoreApp;
|
||||
}
|
||||
@@ -209,6 +210,7 @@ export class PanelQueryRunner {
|
||||
timeRange,
|
||||
timeInfo,
|
||||
cacheTimeout,
|
||||
queryCachingTTL,
|
||||
maxDataPoints,
|
||||
scopedVars,
|
||||
minInterval,
|
||||
@@ -236,6 +238,7 @@ export class PanelQueryRunner {
|
||||
maxDataPoints: maxDataPoints,
|
||||
scopedVars: scopedVars || {},
|
||||
cacheTimeout,
|
||||
queryCachingTTL,
|
||||
startTime: Date.now(),
|
||||
rangeRaw: timeRange.raw,
|
||||
};
|
||||
|
||||
@@ -45,6 +45,7 @@ export class QueryRunner implements QueryRunnerSrv {
|
||||
timeRange,
|
||||
timeInfo,
|
||||
cacheTimeout,
|
||||
queryCachingTTL,
|
||||
maxDataPoints,
|
||||
scopedVars,
|
||||
minInterval,
|
||||
@@ -68,6 +69,7 @@ export class QueryRunner implements QueryRunnerSrv {
|
||||
maxDataPoints: maxDataPoints,
|
||||
scopedVars: scopedVars || {},
|
||||
cacheTimeout,
|
||||
queryCachingTTL,
|
||||
startTime: Date.now(),
|
||||
};
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ export interface QueryGroupOptions {
|
||||
maxDataPoints?: number | null;
|
||||
minInterval?: string | null;
|
||||
cacheTimeout?: string | null;
|
||||
queryCachingTTL?: number | null;
|
||||
timeRange?: {
|
||||
from?: string | null;
|
||||
shift?: string | null;
|
||||
|
||||
Reference in New Issue
Block a user