mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore: Remove angular dependency from data sources (#27735)
* Chore: Remove angular dependency from data sources * Removes default export for time and template srvs Also uses @grafana/runtime versions of the interfaces where possible * Replace usage of internal templateSrv where possible * Use runtime templateSrv in a couple more places
This commit is contained in:
@@ -18,8 +18,8 @@ import { ElasticQueryBuilder } from './query_builder';
|
||||
import { toUtc } from '@grafana/data';
|
||||
import * as queryDef from './query_def';
|
||||
import { getBackendSrv } from '@grafana/runtime';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { getTemplateSrv, TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { getTimeSrv, TimeSrv } from 'app/features/dashboard/services/TimeSrv';
|
||||
import { DataLinkConfig, ElasticsearchOptions, ElasticsearchQuery } from './types';
|
||||
|
||||
// Those are metadata fields as defined in https://www.elastic.co/guide/en/elasticsearch/reference/current/mapping-fields.html#_identity_metadata_fields.
|
||||
@@ -53,11 +53,10 @@ export class ElasticDatasource extends DataSourceApi<ElasticsearchQuery, Elastic
|
||||
dataLinks: DataLinkConfig[];
|
||||
languageProvider: LanguageProvider;
|
||||
|
||||
/** @ngInject */
|
||||
constructor(
|
||||
instanceSettings: DataSourceInstanceSettings<ElasticsearchOptions>,
|
||||
private templateSrv: TemplateSrv,
|
||||
private timeSrv: TimeSrv
|
||||
private readonly templateSrv: TemplateSrv = getTemplateSrv(),
|
||||
private readonly timeSrv: TimeSrv = getTimeSrv()
|
||||
) {
|
||||
super(instanceSettings);
|
||||
this.basicAuth = instanceSettings.basicAuth;
|
||||
|
||||
@@ -4,27 +4,21 @@ import { ElasticDatasource } from './datasource';
|
||||
import { DataSourceInstanceSettings, dateTime } from '@grafana/data';
|
||||
import { ElasticsearchOptions } from './types';
|
||||
import { TemplateSrv } from '../../../features/templating/template_srv';
|
||||
import { getTimeSrv, TimeSrv } from '../../../features/dashboard/services/TimeSrv';
|
||||
import { getTemplateSrv } from '@grafana/runtime';
|
||||
import { TimeSrv } from '../../../features/dashboard/services/TimeSrv';
|
||||
|
||||
jest.mock('app/features/templating/template_srv', () => {
|
||||
return {
|
||||
getAdhocFilters: jest.fn(() => [] as any[]),
|
||||
replace: jest.fn((a: string) => a),
|
||||
};
|
||||
});
|
||||
const templateSrvStub = {
|
||||
getAdhocFilters: jest.fn(() => [] as any[]),
|
||||
replace: jest.fn((a: string) => a),
|
||||
} as any;
|
||||
|
||||
jest.mock('app/features/dashboard/services/TimeSrv', () => ({
|
||||
__esModule: true,
|
||||
getTimeSrv: jest.fn().mockReturnValue({
|
||||
timeRange(): any {
|
||||
return {
|
||||
from: dateTime(1531468681),
|
||||
to: dateTime(1531489712),
|
||||
};
|
||||
},
|
||||
}),
|
||||
}));
|
||||
const timeSrvStub = {
|
||||
timeRange(): any {
|
||||
return {
|
||||
from: dateTime(1531468681),
|
||||
to: dateTime(1531489712),
|
||||
};
|
||||
},
|
||||
} as any;
|
||||
|
||||
const dataSource = new ElasticDatasource(
|
||||
{
|
||||
@@ -36,8 +30,8 @@ const dataSource = new ElasticDatasource(
|
||||
timeField: '@time',
|
||||
},
|
||||
} as DataSourceInstanceSettings<ElasticsearchOptions>,
|
||||
getTemplateSrv() as TemplateSrv,
|
||||
getTimeSrv() as TimeSrv
|
||||
templateSrvStub as TemplateSrv,
|
||||
timeSrvStub as TimeSrv
|
||||
);
|
||||
describe('transform prometheus query to elasticsearch query', () => {
|
||||
it('Prometheus query with exact equals labels ( 2 labels ) and metric __name__', () => {
|
||||
|
||||
Reference in New Issue
Block a user