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