allow templating for test datasource (#33447)

pull/35462/head^2
Stephanie Closson 4 years ago committed by GitHub
parent 83f26e9ce2
commit cee30a05a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 7
      public/app/plugins/datasource/testdata/datasource.ts

@ -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);

Loading…
Cancel
Save