mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
Chore/Tech debt: Remove (most) instances of $q angular service use (#20668)
* Chore/Tech debt: Remove (most) instances of $q angular service use Removes instances where the angular $q service is used and replaces it with native Promises.
This commit is contained in:
@@ -1,8 +1,6 @@
|
||||
import Datasource from '../datasource';
|
||||
import { DataFrame, toUtc } from '@grafana/data';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
// @ts-ignore
|
||||
import Q from 'q';
|
||||
|
||||
describe('AppInsightsDatasource', () => {
|
||||
const ctx: any = {
|
||||
@@ -11,13 +9,12 @@ describe('AppInsightsDatasource', () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.$q = Q;
|
||||
ctx.instanceSettings = {
|
||||
jsonData: { appInsightsAppId: '3ad4400f-ea7d-465d-a8fb-43fb20555d85' },
|
||||
url: 'http://appinsightsapi',
|
||||
};
|
||||
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv, ctx.$q);
|
||||
ctx.ds = new Datasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv);
|
||||
});
|
||||
|
||||
describe('When performing testDatasource', () => {
|
||||
@@ -42,7 +39,7 @@ describe('AppInsightsDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -67,7 +64,7 @@ describe('AppInsightsDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.reject(error);
|
||||
return Promise.reject(error);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -95,7 +92,7 @@ describe('AppInsightsDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.reject(error);
|
||||
return Promise.reject(error);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -162,7 +159,7 @@ describe('AppInsightsDatasource', () => {
|
||||
expect(options.data.queries[0].appInsights.timeColumn).toEqual('timestamp');
|
||||
expect(options.data.queries[0].appInsights.valueColumn).toEqual('max');
|
||||
expect(options.data.queries[0].appInsights.segmentColumn).toBeUndefined();
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -205,7 +202,7 @@ describe('AppInsightsDatasource', () => {
|
||||
expect(options.data.queries[0].appInsights.timeColumn).toEqual('timestamp');
|
||||
expect(options.data.queries[0].appInsights.valueColumn).toEqual('max');
|
||||
expect(options.data.queries[0].appInsights.segmentColumn).toEqual('partition');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -266,7 +263,7 @@ describe('AppInsightsDatasource', () => {
|
||||
expect(options.data.queries[0].refId).toBe('A');
|
||||
expect(options.data.queries[0].appInsights.rawQueryString).toBeUndefined();
|
||||
expect(options.data.queries[0].appInsights.metricName).toBe('exceptions/server');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -309,7 +306,7 @@ describe('AppInsightsDatasource', () => {
|
||||
expect(options.data.queries[0].appInsights.rawQueryString).toBeUndefined();
|
||||
expect(options.data.queries[0].appInsights.metricName).toBe('exceptions/server');
|
||||
expect(options.data.queries[0].appInsights.timeGrain).toBe('PT30M');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -363,7 +360,7 @@ describe('AppInsightsDatasource', () => {
|
||||
expect(options.data.queries[0].appInsights.rawQueryString).toBeUndefined();
|
||||
expect(options.data.queries[0].appInsights.metricName).toBe('exceptions/server');
|
||||
expect(options.data.queries[0].appInsights.dimension).toBe('client/city');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -402,7 +399,7 @@ describe('AppInsightsDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('/metrics/metadata');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -440,7 +437,7 @@ describe('AppInsightsDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('/metrics/metadata');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -468,7 +465,7 @@ describe('AppInsightsDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('/metrics/metadata');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -506,7 +503,7 @@ describe('AppInsightsDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('/metrics/metadata');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
import AzureMonitorDatasource from '../datasource';
|
||||
import FakeSchemaData from './__mocks__/schema';
|
||||
// @ts-ignore
|
||||
import Q from 'q';
|
||||
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { KustoSchema } from '../types';
|
||||
import { toUtc } from '@grafana/data';
|
||||
@@ -13,13 +12,12 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.$q = Q;
|
||||
ctx.instanceSettings = {
|
||||
jsonData: { logAnalyticsSubscriptionId: 'xxx' },
|
||||
url: 'http://azureloganalyticsapi',
|
||||
};
|
||||
|
||||
ctx.ds = new AzureMonitorDatasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv, ctx.$q);
|
||||
ctx.ds = new AzureMonitorDatasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv);
|
||||
});
|
||||
|
||||
describe('When the config option "Same as Azure Monitor" has been chosen', () => {
|
||||
@@ -58,15 +56,15 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
ctx.instanceSettings.jsonData.tenantId = 'xxx';
|
||||
ctx.instanceSettings.jsonData.clientId = 'xxx';
|
||||
ctx.instanceSettings.jsonData.azureLogAnalyticsSameAs = true;
|
||||
ctx.ds = new AzureMonitorDatasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv, ctx.$q);
|
||||
ctx.ds = new AzureMonitorDatasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv);
|
||||
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
if (options.url.indexOf('Microsoft.OperationalInsights/workspaces') > -1) {
|
||||
workspacesUrl = options.url;
|
||||
return ctx.$q.when({ data: workspaceResponse, status: 200 });
|
||||
return Promise.resolve({ data: workspaceResponse, status: 200 });
|
||||
} else {
|
||||
azureLogAnalyticsUrl = options.url;
|
||||
return ctx.$q.when({ data: tableResponseWithOneColumn, status: 200 });
|
||||
return Promise.resolve({ data: tableResponseWithOneColumn, status: 200 });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -97,7 +95,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
ctx.instanceSettings.jsonData.logAnalyticsTenantId = 'xxx';
|
||||
ctx.instanceSettings.jsonData.logAnalyticsClientId = 'xxx';
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.reject(error);
|
||||
return Promise.reject(error);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -170,7 +168,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('query=AzureActivity');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -209,7 +207,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
};
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('query=AzureActivity');
|
||||
return ctx.$q.when({ data: invalidResponse, status: 200 });
|
||||
return Promise.resolve({ data: invalidResponse, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -226,7 +224,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
options.targets[0].azureLogAnalytics.resultFormat = 'table';
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('query=AzureActivity');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -253,7 +251,7 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('metadata');
|
||||
return ctx.$q.when({ data: FakeSchemaData.getlogAnalyticsFakeMetadata(), status: 200 });
|
||||
return Promise.resolve({ data: FakeSchemaData.getlogAnalyticsFakeMetadata(), status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -306,9 +304,9 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
beforeEach(async () => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
if (options.url.indexOf('Microsoft.OperationalInsights/workspaces') > -1) {
|
||||
return ctx.$q.when({ data: workspaceResponse, status: 200 });
|
||||
return Promise.resolve({ data: workspaceResponse, status: 200 });
|
||||
} else {
|
||||
return ctx.$q.when({ data: tableResponseWithOneColumn, status: 200 });
|
||||
return Promise.resolve({ data: tableResponseWithOneColumn, status: 200 });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -368,9 +366,9 @@ describe('AzureLogAnalyticsDatasource', () => {
|
||||
beforeEach(async () => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
if (options.url.indexOf('Microsoft.OperationalInsights/workspaces') > -1) {
|
||||
return ctx.$q.when({ data: workspaceResponse, status: 200 });
|
||||
return Promise.resolve({ data: workspaceResponse, status: 200 });
|
||||
} else {
|
||||
return ctx.$q.when({ data: tableResponse, status: 200 });
|
||||
return Promise.resolve({ data: tableResponse, status: 200 });
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import AzureMonitorDatasource from '../datasource';
|
||||
// @ts-ignore
|
||||
import Q from 'q';
|
||||
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { toUtc, DataFrame } from '@grafana/data';
|
||||
|
||||
@@ -11,14 +10,13 @@ describe('AzureMonitorDatasource', () => {
|
||||
};
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.$q = Q;
|
||||
ctx.instanceSettings = {
|
||||
url: 'http://azuremonitor.com',
|
||||
jsonData: { subscriptionId: '9935389e-9122-4ef9-95f9-1513dd24753f' },
|
||||
cloudName: 'azuremonitor',
|
||||
};
|
||||
|
||||
ctx.ds = new AzureMonitorDatasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv, ctx.$q);
|
||||
ctx.ds = new AzureMonitorDatasource(ctx.instanceSettings, ctx.backendSrv, ctx.templateSrv);
|
||||
});
|
||||
|
||||
describe('When performing testDatasource', () => {
|
||||
@@ -38,7 +36,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
ctx.instanceSettings.jsonData.tenantId = 'xxx';
|
||||
ctx.instanceSettings.jsonData.clientId = 'xxx';
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.reject(error);
|
||||
return Promise.reject(error);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -65,7 +63,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
ctx.instanceSettings.jsonData.tenantId = 'xxx';
|
||||
ctx.instanceSettings.jsonData.clientId = 'xxx';
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -128,7 +126,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('/api/tsdb/query');
|
||||
return ctx.$q.when({ data: response, status: 200 });
|
||||
return Promise.resolve({ data: response, status: 200 });
|
||||
};
|
||||
});
|
||||
|
||||
@@ -160,7 +158,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -186,7 +184,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -213,7 +211,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = (options: { url: string }) => {
|
||||
expect(options.url).toContain('11112222-eeee-4949-9b2d-9106972f9123');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -249,7 +247,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodesapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -283,7 +281,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/11112222-eeee-4949-9b2d-9106972f9123/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodesapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -321,7 +319,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodeapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -359,7 +357,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/11112222-eeee-4949-9b2d-9106972f9123/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodeapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -407,7 +405,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
'/nodeapp/providers/microsoft.insights/components/rn/providers/microsoft.insights/' +
|
||||
'metricdefinitions?api-version=2018-01-01&metricnamespace=default'
|
||||
);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -456,7 +454,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
'/nodeapp/providers/microsoft.insights/components/rn/providers/microsoft.insights/' +
|
||||
'metricdefinitions?api-version=2018-01-01&metricnamespace=default'
|
||||
);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -506,7 +504,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
baseUrl +
|
||||
'/nodeapp/providers/Microsoft.Compute/virtualMachines/rn/providers/microsoft.insights/metricNamespaces?api-version=2017-12-01-preview'
|
||||
);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -554,7 +552,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
baseUrl +
|
||||
'/nodeapp/providers/Microsoft.Compute/virtualMachines/rn/providers/microsoft.insights/metricNamespaces?api-version=2017-12-01-preview'
|
||||
);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -604,7 +602,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -628,7 +626,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
ctx.backendSrv.datasourceRequest = () => {
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -680,7 +678,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodesapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -731,7 +729,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodeapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -769,7 +767,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
const baseUrl =
|
||||
'http://azuremonitor.com/azuremonitor/subscriptions/9935389e-9122-4ef9-95f9-1513dd24753f/resourceGroups';
|
||||
expect(options.url).toBe(baseUrl + '/nodeapp/resources?api-version=2018-01-01');
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -838,7 +836,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
'/providers/microsoft.insights/components/resource1' +
|
||||
'/providers/microsoft.insights/metricdefinitions?api-version=2018-01-01&metricnamespace=default';
|
||||
expect(options.url).toBe(expected);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -910,7 +908,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
'/providers/microsoft.insights/components/resource1' +
|
||||
'/providers/microsoft.insights/metricdefinitions?api-version=2018-01-01&metricnamespace=default';
|
||||
expect(options.url).toBe(expected);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -984,7 +982,7 @@ describe('AzureMonitorDatasource', () => {
|
||||
'/providers/microsoft.insights/components/resource1' +
|
||||
'/providers/microsoft.insights/metricdefinitions?api-version=2018-01-01&metricnamespace=default';
|
||||
expect(options.url).toBe(expected);
|
||||
return ctx.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import { AzureMonitorQuery, AzureDataSourceJsonData } from './types';
|
||||
import { DataSourceApi, DataQueryRequest, DataSourceInstanceSettings } from '@grafana/data';
|
||||
import { BackendSrv } from 'app/core/services/backend_srv';
|
||||
import { TemplateSrv } from 'app/features/templating/template_srv';
|
||||
import { IQService } from 'angular';
|
||||
|
||||
export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDataSourceJsonData> {
|
||||
azureMonitorDatasource: AzureMonitorDatasource;
|
||||
@@ -17,8 +16,7 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
||||
constructor(
|
||||
instanceSettings: DataSourceInstanceSettings<AzureDataSourceJsonData>,
|
||||
private backendSrv: BackendSrv,
|
||||
private templateSrv: TemplateSrv,
|
||||
private $q: IQService
|
||||
private templateSrv: TemplateSrv
|
||||
) {
|
||||
super(instanceSettings);
|
||||
this.azureMonitorDatasource = new AzureMonitorDatasource(instanceSettings, this.backendSrv, this.templateSrv);
|
||||
@@ -63,7 +61,7 @@ export default class Datasource extends DataSourceApi<AzureMonitorQuery, AzureDa
|
||||
}
|
||||
|
||||
if (promises.length === 0) {
|
||||
return this.$q.when({ data: [] });
|
||||
return Promise.resolve({ data: [] });
|
||||
}
|
||||
|
||||
return Promise.all(promises).then(results => {
|
||||
|
||||
@@ -18,7 +18,6 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
};
|
||||
AzureMonitorQueryCtrl.prototype.target = {} as any;
|
||||
AzureMonitorQueryCtrl.prototype.datasource = {
|
||||
$q: Q,
|
||||
appInsightsDatasource: { isConfigured: () => false },
|
||||
azureMonitorDatasource: { isConfigured: () => false },
|
||||
};
|
||||
@@ -54,7 +53,7 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
queryCtrl.datasource.getResourceGroups = () => {
|
||||
return queryCtrl.datasource.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
queryCtrl.datasource.azureMonitorDatasource = {
|
||||
isConfigured: () => {
|
||||
@@ -80,10 +79,10 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
beforeEach(() => {
|
||||
queryCtrl.target.subscription = 'sub1';
|
||||
queryCtrl.target.azureMonitor.resourceGroup = 'test';
|
||||
queryCtrl.datasource.getMetricDefinitions = function(subscriptionId: any, query: any) {
|
||||
queryCtrl.datasource.getMetricDefinitions = (subscriptionId: any, query: any) => {
|
||||
expect(subscriptionId).toBe('sub1');
|
||||
expect(query).toBe('test');
|
||||
return this.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -117,15 +116,11 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
queryCtrl.target.subscription = 'sub1';
|
||||
queryCtrl.target.azureMonitor.resourceGroup = 'test';
|
||||
queryCtrl.target.azureMonitor.metricDefinition = 'Microsoft.Compute/virtualMachines';
|
||||
queryCtrl.datasource.getResourceNames = function(
|
||||
subscriptionId: any,
|
||||
resourceGroup: any,
|
||||
metricDefinition: any
|
||||
) {
|
||||
queryCtrl.datasource.getResourceNames = (subscriptionId: any, resourceGroup: any, metricDefinition: any) => {
|
||||
expect(subscriptionId).toBe('sub1');
|
||||
expect(resourceGroup).toBe('test');
|
||||
expect(metricDefinition).toBe('Microsoft.Compute/virtualMachines');
|
||||
return this.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -162,19 +157,19 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
queryCtrl.target.azureMonitor.metricDefinition = 'Microsoft.Compute/virtualMachines';
|
||||
queryCtrl.target.azureMonitor.resourceName = 'test';
|
||||
queryCtrl.target.azureMonitor.metricNamespace = 'test';
|
||||
queryCtrl.datasource.getMetricNames = function(
|
||||
queryCtrl.datasource.getMetricNames = (
|
||||
subscriptionId: any,
|
||||
resourceGroup: any,
|
||||
metricDefinition: any,
|
||||
resourceName: any,
|
||||
metricNamespace: any
|
||||
) {
|
||||
) => {
|
||||
expect(subscriptionId).toBe('sub1');
|
||||
expect(resourceGroup).toBe('test');
|
||||
expect(metricDefinition).toBe('Microsoft.Compute/virtualMachines');
|
||||
expect(resourceName).toBe('test');
|
||||
expect(metricNamespace).toBe('test');
|
||||
return this.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -218,21 +213,21 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
queryCtrl.target.azureMonitor.resourceName = 'test';
|
||||
queryCtrl.target.azureMonitor.metricNamespace = 'test';
|
||||
queryCtrl.target.azureMonitor.metricName = 'Percentage CPU';
|
||||
queryCtrl.datasource.getMetricMetadata = function(
|
||||
queryCtrl.datasource.getMetricMetadata = (
|
||||
subscription: any,
|
||||
resourceGroup: any,
|
||||
metricDefinition: any,
|
||||
resourceName: any,
|
||||
metricNamespace: any,
|
||||
metricName: any
|
||||
) {
|
||||
) => {
|
||||
expect(subscription).toBe('sub1');
|
||||
expect(resourceGroup).toBe('test');
|
||||
expect(metricDefinition).toBe('Microsoft.Compute/virtualMachines');
|
||||
expect(resourceName).toBe('test');
|
||||
expect(metricNamespace).toBe('test');
|
||||
expect(metricName).toBe('Percentage CPU');
|
||||
return this.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -289,7 +284,7 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
beforeEach(() => {
|
||||
queryCtrl.datasource.appInsightsDatasource.isConfigured = () => true;
|
||||
queryCtrl.datasource.getAppInsightsMetricNames = () => {
|
||||
return queryCtrl.datasource.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
@@ -324,9 +319,9 @@ describe('AzureMonitorQueryCtrl', () => {
|
||||
|
||||
beforeEach(() => {
|
||||
queryCtrl.target.appInsights.metricName = 'requests/failed';
|
||||
queryCtrl.datasource.getAppInsightsMetricMetadata = function(metricName: string) {
|
||||
queryCtrl.datasource.getAppInsightsMetricMetadata = (metricName: string) => {
|
||||
expect(metricName).toBe('requests/failed');
|
||||
return this.$q.when(response);
|
||||
return Promise.resolve(response);
|
||||
};
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user