mirror of
https://github.com/grafana/grafana.git
synced 2025-09-25 12:13:55 +08:00
allow templating for test datasource (#33447)
This commit is contained in:

committed by
GitHub

parent
83f26e9ce2
commit
cee30a05a1
@ -12,6 +12,7 @@ import {
|
|||||||
LiveChannelScope,
|
LiveChannelScope,
|
||||||
LoadingState,
|
LoadingState,
|
||||||
TimeRange,
|
TimeRange,
|
||||||
|
ScopedVars,
|
||||||
} from '@grafana/data';
|
} from '@grafana/data';
|
||||||
import { Scenario, TestDataQuery } from './types';
|
import { Scenario, TestDataQuery } from './types';
|
||||||
import { DataSourceWithBackend, getBackendSrv, getGrafanaLiveSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
import { DataSourceWithBackend, getBackendSrv, getGrafanaLiveSrv, getTemplateSrv, TemplateSrv } from '@grafana/runtime';
|
||||||
@ -42,6 +43,8 @@ export class TestDataDataSource extends DataSourceWithBackend<TestDataQuery> {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.resolveTemplateVariables(target, options.scopedVars);
|
||||||
|
|
||||||
switch (target.scenarioId) {
|
switch (target.scenarioId) {
|
||||||
case 'live':
|
case 'live':
|
||||||
streams.push(runGrafanaLiveQuery(target, options));
|
streams.push(runGrafanaLiveQuery(target, options));
|
||||||
@ -98,6 +101,10 @@ export class TestDataDataSource extends DataSourceWithBackend<TestDataQuery> {
|
|||||||
return merge(...streams);
|
return merge(...streams);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
resolveTemplateVariables(query: TestDataQuery, scopedVars: ScopedVars) {
|
||||||
|
query.labels = this.templateSrv.replace(query.labels!, scopedVars);
|
||||||
|
}
|
||||||
|
|
||||||
annotationDataTopicTest(target: TestDataQuery, req: DataQueryRequest<TestDataQuery>): Observable<DataQueryResponse> {
|
annotationDataTopicTest(target: TestDataQuery, req: DataQueryRequest<TestDataQuery>): Observable<DataQueryResponse> {
|
||||||
const events = this.buildFakeAnnotationEvents(req.range, 10);
|
const events = this.buildFakeAnnotationEvents(req.range, 10);
|
||||||
const dataFrame = new ArrayDataFrame(events);
|
const dataFrame = new ArrayDataFrame(events);
|
||||||
|
Reference in New Issue
Block a user