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 { ...@@ -5,7 +5,7 @@ export default class StackdriverDatasource {
baseUrl: string; baseUrl: string;
projectName: string; projectName: string;
constructor(instanceSettings, private backendSrv, private templateSrv) { constructor(instanceSettings, private backendSrv, private templateSrv, private timeSrv) {
this.baseUrl = `/stackdriver/`; this.baseUrl = `/stackdriver/`;
this.url = instanceSettings.url; this.url = instanceSettings.url;
this.doRequest = this.doRequest; this.doRequest = this.doRequest;
...@@ -54,6 +54,23 @@ export default class StackdriverDatasource { ...@@ -54,6 +54,23 @@ export default class StackdriverDatasource {
return data; 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[] { interpolateGroupBys(groupBys: string[], scopedVars): string[] {
let interpolatedGroupBys = []; let interpolatedGroupBys = [];
(groupBys || []).forEach(gb => { (groupBys || []).forEach(gb => {
......
...@@ -62,7 +62,7 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -62,7 +62,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
filterSegments: any; filterSegments: any;
/** @ngInject */ /** @ngInject */
constructor($scope, $injector, private uiSegmentSrv, private timeSrv, private templateSrv) { constructor($scope, $injector, private uiSegmentSrv, private templateSrv) {
super($scope, $injector); super($scope, $injector);
_.defaultsDeep(this.target, this.defaults); _.defaultsDeep(this.target, this.defaults);
...@@ -130,25 +130,13 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -130,25 +130,13 @@ export class StackdriverQueryCtrl extends QueryCtrl {
async getLabels() { async getLabels() {
this.loadLabelsPromise = new Promise(async resolve => { this.loadLabelsPromise = new Promise(async resolve => {
try { try {
const data = await this.datasource.getTimeSeries({ const data = await this.datasource.getLabels(this.target.metricType, this.target.refId);
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(),
});
this.metricLabels = data.results[this.target.refId].meta.metricLabels; this.metricLabels = data.results[this.target.refId].meta.metricLabels;
this.resourceLabels = data.results[this.target.refId].meta.resourceLabels; this.resourceLabels = data.results[this.target.refId].meta.resourceLabels;
resolve(); resolve();
} catch (error) { } catch (error) {
appEvents.emit('ds-request-error', 'Error loading metric labels for ' + this.target.metricType);
resolve(); resolve();
} }
}); });
......
...@@ -408,7 +408,7 @@ function createCtrlWithFakes(existingFilters?: string[]) { ...@@ -408,7 +408,7 @@ function createCtrlWithFakes(existingFilters?: string[]) {
return { type: 'condition', value: val }; 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[]) { 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