mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: fix init labels bug
This commit is contained in:
parent
0b41303e10
commit
f243da756b
@ -30,7 +30,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
defaultFilterValue = 'select value';
|
defaultFilterValue = 'select value';
|
||||||
defaultRemoveGroupByValue = '-- remove group by --';
|
defaultRemoveGroupByValue = '-- remove group by --';
|
||||||
defaultRemoveFilterValue = '-- remove filter --';
|
defaultRemoveFilterValue = '-- remove filter --';
|
||||||
initPromise: Promise<any>;
|
loadLabelsPromise: Promise<any>;
|
||||||
|
|
||||||
defaults = {
|
defaults = {
|
||||||
project: {
|
project: {
|
||||||
@ -80,15 +80,9 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
|
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
|
||||||
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
|
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
|
||||||
|
|
||||||
this.initPromise = new Promise(async resolve => {
|
this.getCurrentProject()
|
||||||
this.getCurrentProject()
|
.then(this.getMetricTypes.bind(this))
|
||||||
.then(this.getMetricTypes.bind(this))
|
.then(this.getLabels.bind(this));
|
||||||
.then(this.getLabels.bind(this))
|
|
||||||
.then(resolve)
|
|
||||||
.catch(err => {
|
|
||||||
console.log(err);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
this.initSegments();
|
this.initSegments();
|
||||||
}
|
}
|
||||||
@ -161,23 +155,30 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getLabels() {
|
async getLabels() {
|
||||||
const data = await this.datasource.getTimeSeries({
|
this.loadLabelsPromise = new Promise(async resolve => {
|
||||||
targets: [
|
try {
|
||||||
{
|
const data = await this.datasource.getTimeSeries({
|
||||||
refId: this.target.refId,
|
targets: [
|
||||||
datasourceId: this.datasource.id,
|
{
|
||||||
metricType: this.target.metricType,
|
refId: this.target.refId,
|
||||||
aggregation: {
|
datasourceId: this.datasource.id,
|
||||||
crossSeriesReducer: 'REDUCE_NONE',
|
metricType: this.target.metricType,
|
||||||
},
|
aggregation: {
|
||||||
view: 'HEADERS',
|
crossSeriesReducer: 'REDUCE_NONE',
|
||||||
},
|
},
|
||||||
],
|
view: 'HEADERS',
|
||||||
range: this.timeSrv.timeRange(),
|
},
|
||||||
});
|
],
|
||||||
|
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();
|
||||||
|
} catch (error) {
|
||||||
|
resolve();
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
async onMetricTypeChange() {
|
async onMetricTypeChange() {
|
||||||
@ -186,9 +187,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
async getGroupBys(segment, index, removeText?: string, removeUsed = true) {
|
async getGroupBys(segment, index, removeText?: string, removeUsed = true) {
|
||||||
if (!this.metricLabels || Object.keys(this.metricLabels).length === 0) {
|
await this.loadLabelsPromise;
|
||||||
await this.initPromise;
|
|
||||||
}
|
|
||||||
const metricLabels = Object.keys(this.metricLabels)
|
const metricLabels = Object.keys(this.metricLabels)
|
||||||
.filter(ml => {
|
.filter(ml => {
|
||||||
if (!removeUsed) {
|
if (!removeUsed) {
|
||||||
@ -256,7 +255,17 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (segment.type === 'key' || segment.type === 'plus-button') {
|
if (segment.type === 'key' || segment.type === 'plus-button') {
|
||||||
return this.getGroupBys(null, null, this.defaultRemoveFilterValue, false);
|
if (
|
||||||
|
this.metricLabels &&
|
||||||
|
Object.keys(this.metricLabels).length === 0 &&
|
||||||
|
segment.value &&
|
||||||
|
segment.value !== this.defaultRemoveFilterValue
|
||||||
|
) {
|
||||||
|
this.removeSegment.value = this.defaultRemoveFilterValue;
|
||||||
|
return Promise.resolve([this.removeSegment]);
|
||||||
|
} else {
|
||||||
|
return this.getGroupBys(null, null, this.defaultRemoveFilterValue, false);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (segment.type === 'value') {
|
if (segment.type === 'value') {
|
||||||
@ -339,6 +348,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
if (anySeriesFromQuery) {
|
if (anySeriesFromQuery) {
|
||||||
this.lastQueryMeta = anySeriesFromQuery.meta;
|
this.lastQueryMeta = anySeriesFromQuery.meta;
|
||||||
this.lastQueryMeta.rawQueryString = decodeURIComponent(this.lastQueryMeta.rawQuery);
|
this.lastQueryMeta.rawQueryString = decodeURIComponent(this.lastQueryMeta.rawQuery);
|
||||||
|
} else {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -359,5 +369,6 @@ export class StackdriverQueryCtrl extends QueryCtrl {
|
|||||||
this.lastQueryError = jsonBody.error.message;
|
this.lastQueryError = jsonBody.error.message;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
console.error(err);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user