stackdriver: move getLabels from query_ctrl to datasource

so can reuse for annotation query ctrl.
This commit is contained in:
Daniel Lee 2018-09-24 15:26:49 +02:00
parent e101bcdb13
commit c9ee05422f
3 changed files with 22 additions and 17 deletions

View File

@ -5,7 +5,7 @@ export default class StackdriverDatasource {
baseUrl: string;
projectName: string;
constructor(instanceSettings, private backendSrv, private templateSrv) {
constructor(instanceSettings, private backendSrv, private templateSrv, private timeSrv) {
this.baseUrl = `/stackdriver/`;
this.url = instanceSettings.url;
this.doRequest = this.doRequest;
@ -54,6 +54,23 @@ export default class StackdriverDatasource {
return data;
}
async getLabels(metricType, refId) {
return await this.getTimeSeries({
targets: [
{
refId: refId,
datasourceId: this.id,
metricType: this.templateSrv.replace(metricType),
aggregation: {
crossSeriesReducer: 'REDUCE_NONE',
},
view: 'HEADERS',
},
],
range: this.timeSrv.timeRange(),
});
}
interpolateGroupBys(groupBys: string[], scopedVars): string[] {
let interpolatedGroupBys = [];
(groupBys || []).forEach(gb => {

View File

@ -62,7 +62,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
filterSegments: any;
/** @ngInject */
constructor($scope, $injector, private uiSegmentSrv, private timeSrv, private templateSrv) {
constructor($scope, $injector, private uiSegmentSrv, private templateSrv) {
super($scope, $injector);
_.defaultsDeep(this.target, this.defaults);
@ -130,25 +130,13 @@ export class StackdriverQueryCtrl extends QueryCtrl {
async getLabels() {
this.loadLabelsPromise = new Promise(async resolve => {
try {
const data = await this.datasource.getTimeSeries({
targets: [
{
refId: this.target.refId,
datasourceId: this.datasource.id,
metricType: this.templateSrv.replace(this.target.metricType),
aggregation: {
crossSeriesReducer: 'REDUCE_NONE',
},
view: 'HEADERS',
},
],
range: this.timeSrv.timeRange(),
});
const data = await this.datasource.getLabels(this.target.metricType, this.target.refId);
this.metricLabels = data.results[this.target.refId].meta.metricLabels;
this.resourceLabels = data.results[this.target.refId].meta.resourceLabels;
resolve();
} catch (error) {
appEvents.emit('ds-request-error', 'Error loading metric labels for ' + this.target.metricType);
resolve();
}
});

View File

@ -408,7 +408,7 @@ function createCtrlWithFakes(existingFilters?: string[]) {
return { type: 'condition', value: val };
},
};
return new StackdriverQueryCtrl(null, null, fakeSegmentServer, null, new TemplateSrvStub());
return new StackdriverQueryCtrl(null, null, fakeSegmentServer, new TemplateSrvStub());
}
function createTarget(existingFilters?: string[]) {