Commit c9ee0542 by Daniel Lee

stackdriver: move getLabels from query_ctrl to datasource

so can reuse for annotation query ctrl.
parent e101bcdb
......@@ -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 => {
......
......@@ -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();
}
});
......
......@@ -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[]) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment