stackdriver: use correct naming convention

This commit is contained in:
Erik Sundell 2018-09-26 11:23:46 +02:00
parent 186dcc001c
commit 508601c28c
2 changed files with 24 additions and 23 deletions

View File

@ -11,9 +11,9 @@
</div> --> </div> -->
<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">Service</span>
<gf-form-dropdown model="ctrl.target.resourceType" get-options="ctrl.getResourceTypes()" class="min-width-20" <gf-form-dropdown model="ctrl.target.service" get-options="ctrl.getServices()" class="min-width-20" disabled type="text"
disabled type="text" allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onResourceTypeChange(ctrl.target.metricService)"></gf-form-dropdown> allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onServiceChange(ctrl.target.metricService)"></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,8 @@
<div class="gf-form-inline"> <div class="gf-form-inline">
<div class="gf-form"> <div class="gf-form">
<span class="gf-form-label query-keyword width-9">Alias By</span> <span class="gf-form-label query-keyword width-9">Alias By</span>
<input type="text" class="gf-form-input width-30" ng-model="ctrl.target.aliasBy" ng-change="ctrl.refresh()" ng-model-options="{ debounce: 500 }" /> <input type="text" class="gf-form-input width-30" ng-model="ctrl.target.aliasBy" ng-change="ctrl.refresh()"
ng-model-options="{ debounce: 500 }" />
</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>
@ -109,4 +110,4 @@
<div class="gf-form" ng-show="ctrl.lastQueryError"> <div class="gf-form" ng-show="ctrl.lastQueryError">
<pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre> <pre class="gf-form-pre alert alert-error">{{ctrl.lastQueryError}}</pre>
</div> </div>
</query-editor-row> </query-editor-row>

View File

@ -19,7 +19,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
name: string; name: string;
}; };
metricType: string; metricType: string;
resourceType: string; service: string;
refId: string; refId: string;
aggregation: { aggregation: {
crossSeriesReducer: string; crossSeriesReducer: string;
@ -33,7 +33,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
valueType: any; valueType: any;
}; };
defaultDropdownValue = 'select metric'; defaultDropdownValue = 'select metric';
defaultMetricResourcesValue = 'all'; defaultServiceValue = 'all';
defaultRemoveGroupByValue = '-- remove group by --'; defaultRemoveGroupByValue = '-- remove group by --';
loadLabelsPromise: Promise<any>; loadLabelsPromise: Promise<any>;
stackdriverConstants; stackdriverConstants;
@ -44,7 +44,7 @@ export class StackdriverQueryCtrl extends QueryCtrl {
name: 'loading project...', name: 'loading project...',
}, },
metricType: this.defaultDropdownValue, metricType: this.defaultDropdownValue,
resourceType: this.defaultMetricResourcesValue, service: this.defaultServiceValue,
metric: '', metric: '',
aggregation: { aggregation: {
crossSeriesReducer: 'REDUCE_MEAN', crossSeriesReducer: 'REDUCE_MEAN',
@ -133,40 +133,40 @@ export class StackdriverQueryCtrl extends QueryCtrl {
} }
} }
getResourceTypes() { getServices() {
const defaultValue = { value: this.defaultMetricResourcesValue, text: this.defaultMetricResourcesValue }; const defaultValue = { value: this.defaultServiceValue, text: this.defaultServiceValue };
const resources = this.metricDescriptors.map(m => { const services = this.metricDescriptors.map(m => {
const [resource] = m.type.split('/'); const [service] = m.type.split('/');
const [service] = resource.split('.'); const [serviceShortName] = service.split('.');
return { return {
value: resource, value: service,
text: service, text: serviceShortName,
}; };
}); });
return resources.length > 0 ? [defaultValue, ..._.uniqBy(resources, 'value')] : []; return services.length > 0 ? [defaultValue, ..._.uniqBy(services, 'value')] : [];
} }
getMetrics() { getMetrics() {
const metrics = this.metricDescriptors.map(m => { const metrics = this.metricDescriptors.map(m => {
const [resource] = m.type.split('/'); const [service] = m.type.split('/');
const [service] = resource.split('.'); const [serviceShortName] = service.split('.');
return { return {
resource,
value: m.type,
service, service,
value: m.type,
serviceShortName,
text: m.displayName, text: m.displayName,
title: m.description, title: m.description,
}; };
}); });
if (this.target.resourceType === this.defaultMetricResourcesValue) { if (this.target.service === this.defaultServiceValue) {
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.resourceType); return metrics.filter(m => m.service === this.target.service);
} }
} }
onResourceTypeChange(resource) { onServiceChange() {
this.metrics = this.getMetrics(); this.metrics = this.getMetrics();
if (!this.metrics.find(m => m.value === this.target.metricType)) { if (!this.metrics.find(m => m.value === this.target.metricType)) {
this.target.metricType = this.defaultDropdownValue; this.target.metricType = this.defaultDropdownValue;