Commit 49cd31ab by Erik Sundell

stackdriver: get value type and metric kind from metric descriptor instead of…

stackdriver: get value type and metric kind from metric descriptor instead of from latest metric result
parent 2d602bfc
......@@ -316,9 +316,6 @@ func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data Sta
Name: metricName,
Points: points,
})
queryRes.Meta.Set("metricKind", series.MetricKind)
queryRes.Meta.Set("valueType", series.ValueType)
}
queryRes.Meta.Set("resourceLabels", resourceLabels)
......
......@@ -12,7 +12,7 @@
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9">Resource type</span>
<gf-form-dropdown model="ctrl.target.metricService" get-options="ctrl.getMetricServices()" class="min-width-20"
<gf-form-dropdown model="ctrl.target.resourceType" get-options="ctrl.getResourceTypes()" class="min-width-20"
disabled type="text" allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onResourceTypeChange(ctrl.target.metricService)"></gf-form-dropdown>
</div>
<div class="gf-form gf-form--grow">
......@@ -22,8 +22,8 @@
<div class="gf-form-inline">
<div class="gf-form">
<span class="gf-form-label width-9">Metric</span>
<gf-form-dropdown model="ctrl.target.metricType" title="Tooltip" get-options="ctrl.metrics" class="min-width-20"
disabled type="text" allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onMetricTypeChange()"></gf-form-dropdown>
<gf-form-dropdown model="ctrl.target.metricType" get-options="ctrl.metrics" class="min-width-20" disabled type="text"
allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onMetricTypeChange()"></gf-form-dropdown>
</div>
<div class="gf-form gf-form--grow">
<div class="gf-form-label gf-form-label--grow"></div>
......
......@@ -55,7 +55,7 @@ export class StackdriverAggregationCtrl {
getAlignOptions() {
return !this.target.valueType
? options.alignOptions
? []
: options.alignOptions.filter(i => {
return (
i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
......@@ -65,7 +65,7 @@ export class StackdriverAggregationCtrl {
getAggOptions() {
return !this.target.metricKind
? options.aggOptions
? []
: options.aggOptions.filter(i => {
return (
i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
......
......@@ -19,7 +19,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
name: string;
};
metricType: string;
metricService: string;
resourceType: string;
refId: string;
aggregation: {
crossSeriesReducer: string;
......@@ -44,7 +44,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
name: 'loading project...',
},
metricType: this.defaultDropdownValue,
metricService: this.defaultMetricResourcesValue,
resourceType: this.defaultMetricResourcesValue,
metric: '',
aggregation: {
crossSeriesReducer: 'REDUCE_MEAN',
......@@ -80,7 +80,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
this.getCurrentProject()
.then(this.getMetricTypes.bind(this))
.then(this.loadMetricDescriptors.bind(this))
.then(this.getLabels.bind(this));
this.initSegments();
}
......@@ -123,21 +123,17 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}
}
async getMetricTypes() {
async loadMetricDescriptors() {
if (this.target.project.id !== 'default') {
const metricTypes = await this.datasource.getMetricTypes(this.target.project.id);
this.metricDescriptors = metricTypes;
if (this.target.metricType === this.defaultDropdownValue && metricTypes.length > 0) {
this.$scope.$apply(() => (this.target.metricType = metricTypes[0].id));
}
return metricTypes.map(mt => ({ value: mt.type, text: mt.type }));
this.metricDescriptors = await this.datasource.getMetricTypes(this.target.project.id);
this.metrics = this.getMetrics();
return this.metricDescriptors;
} else {
return [];
}
}
getMetricServices() {
getResourceTypes() {
const defaultValue = { value: this.defaultMetricResourcesValue, text: this.defaultMetricResourcesValue };
const resources = this.metricDescriptors.map(m => {
const [resource] = m.type.split('/');
......@@ -162,10 +158,11 @@ export class StackdriverQueryCtrl extends QueryCtrl {
title: m.description,
};
});
if (this.target.metricService === this.defaultMetricResourcesValue) {
if (this.target.resourceType === this.defaultMetricResourcesValue) {
return metrics.map(m => ({ ...m, text: `${m.service} - ${m.text}` }));
} else {
return metrics.filter(m => m.resource === this.target.metricService);
return metrics.filter(m => m.resource === this.target.resourceType);
}
}
......@@ -182,12 +179,8 @@ export class StackdriverQueryCtrl extends QueryCtrl {
this.loadLabelsPromise = new Promise(async resolve => {
try {
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;
this.target.valueType = data.results[this.target.refId].meta.valueType;
this.target.metricKind = data.results[this.target.refId].meta.metricKind;
resolve();
} catch (error) {
console.log(error.data.message);
......@@ -198,6 +191,9 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}
async onMetricTypeChange() {
const { valueType, metricKind } = this.metricDescriptors.find(m => m.type === this.target.metricType);
this.target.valueType = valueType;
this.target.metricKind = metricKind;
this.refresh();
this.getLabels();
}
......
......@@ -373,8 +373,8 @@ function createCtrlWithFakes(existingFilters?: string[]) {
refresh: () => {},
};
StackdriverQueryCtrl.prototype.target = createTarget(existingFilters);
StackdriverQueryCtrl.prototype.getMetricTypes = () => {
return Promise.resolve();
StackdriverQueryCtrl.prototype.loadMetricDescriptors = () => {
return Promise.resolve([]);
};
StackdriverQueryCtrl.prototype.getLabels = () => {
return Promise.resolve();
......
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