|
@@ -1,6 +1,6 @@
|
|
|
import coreModule from 'app/core/core_module';
|
|
import coreModule from 'app/core/core_module';
|
|
|
import _ from 'lodash';
|
|
import _ from 'lodash';
|
|
|
-import * as options from './constants';
|
|
|
|
|
|
|
+import { alignmentPeriods } from './constants';
|
|
|
import { getAlignmentOptionsByMetric, getAggregationOptionsByMetric } from './functions';
|
|
import { getAlignmentOptionsByMetric, getAggregationOptionsByMetric } from './functions';
|
|
|
import kbn from 'app/core/utils/kbn';
|
|
import kbn from 'app/core/utils/kbn';
|
|
|
|
|
|
|
@@ -29,9 +29,16 @@ export class StackdriverAggregationCtrl {
|
|
|
constructor(private $scope, private templateSrv) {
|
|
constructor(private $scope, private templateSrv) {
|
|
|
this.$scope.ctrl = this;
|
|
this.$scope.ctrl = this;
|
|
|
this.target = $scope.target;
|
|
this.target = $scope.target;
|
|
|
- this.alignmentPeriods = options.alignmentPeriods;
|
|
|
|
|
- this.aggOptions = options.aggOptions;
|
|
|
|
|
- this.alignOptions = options.alignOptions;
|
|
|
|
|
|
|
+ this.alignmentPeriods = [
|
|
|
|
|
+ this.getTemplateVariablesGroup(),
|
|
|
|
|
+ {
|
|
|
|
|
+ label: 'Alignment Periods',
|
|
|
|
|
+ options: alignmentPeriods.map(ap => ({
|
|
|
|
|
+ ...ap,
|
|
|
|
|
+ label: ap.text,
|
|
|
|
|
+ })),
|
|
|
|
|
+ },
|
|
|
|
|
+ ];
|
|
|
this.setAggOptions();
|
|
this.setAggOptions();
|
|
|
this.setAlignOptions();
|
|
this.setAlignOptions();
|
|
|
const self = this;
|
|
const self = this;
|
|
@@ -39,30 +46,68 @@ export class StackdriverAggregationCtrl {
|
|
|
self.setAggOptions();
|
|
self.setAggOptions();
|
|
|
self.setAlignOptions();
|
|
self.setAlignOptions();
|
|
|
});
|
|
});
|
|
|
|
|
+ this.handleAlignmentChange = this.handleAlignmentChange.bind(this);
|
|
|
|
|
+ this.handleAggregationChange = this.handleAggregationChange.bind(this);
|
|
|
|
|
+ this.handleAlignmentPeriodChange = this.handleAlignmentPeriodChange.bind(this);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setAlignOptions() {
|
|
setAlignOptions() {
|
|
|
- this.alignOptions = getAlignmentOptionsByMetric(this.target.valueType, this.target.metricKind);
|
|
|
|
|
- if (!this.alignOptions.find(o => o.value === this.templateSrv.replace(this.target.aggregation.perSeriesAligner))) {
|
|
|
|
|
- this.target.aggregation.perSeriesAligner = this.alignOptions.length > 0 ? this.alignOptions[0].value : '';
|
|
|
|
|
|
|
+ const alignments = getAlignmentOptionsByMetric(this.target.valueType, this.target.metricKind).map(a => ({
|
|
|
|
|
+ ...a,
|
|
|
|
|
+ label: a.text,
|
|
|
|
|
+ }));
|
|
|
|
|
+ this.alignOptions = [
|
|
|
|
|
+ this.getTemplateVariablesGroup(),
|
|
|
|
|
+ {
|
|
|
|
|
+ label: 'Alignment Options',
|
|
|
|
|
+ options: alignments,
|
|
|
|
|
+ },
|
|
|
|
|
+ ];
|
|
|
|
|
+ if (!alignments.find(o => o.value === this.templateSrv.replace(this.target.aggregation.perSeriesAligner))) {
|
|
|
|
|
+ this.target.aggregation.perSeriesAligner = alignments.length > 0 ? alignments[0].value : '';
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
setAggOptions() {
|
|
setAggOptions() {
|
|
|
- this.aggOptions = getAggregationOptionsByMetric(this.target.valueType, this.target.metricKind);
|
|
|
|
|
-
|
|
|
|
|
- if (!this.aggOptions.find(o => o.value === this.templateSrv.replace(this.target.aggregation.crossSeriesReducer))) {
|
|
|
|
|
|
|
+ let aggregations = getAggregationOptionsByMetric(this.target.valueType, this.target.metricKind).map(a => ({
|
|
|
|
|
+ ...a,
|
|
|
|
|
+ label: a.text,
|
|
|
|
|
+ }));
|
|
|
|
|
+ if (!aggregations.find(o => o.value === this.templateSrv.replace(this.target.aggregation.crossSeriesReducer))) {
|
|
|
this.deselectAggregationOption('REDUCE_NONE');
|
|
this.deselectAggregationOption('REDUCE_NONE');
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (this.target.aggregation.groupBys.length > 0) {
|
|
if (this.target.aggregation.groupBys.length > 0) {
|
|
|
- this.aggOptions = this.aggOptions.filter(o => o.value !== 'REDUCE_NONE');
|
|
|
|
|
|
|
+ aggregations = this.aggOptions.filter(o => o.value !== 'REDUCE_NONE');
|
|
|
this.deselectAggregationOption('REDUCE_NONE');
|
|
this.deselectAggregationOption('REDUCE_NONE');
|
|
|
}
|
|
}
|
|
|
|
|
+ this.aggOptions = [
|
|
|
|
|
+ this.getTemplateVariablesGroup(),
|
|
|
|
|
+ {
|
|
|
|
|
+ label: 'Aggregations',
|
|
|
|
|
+ options: aggregations,
|
|
|
|
|
+ },
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ handleAlignmentChange(value) {
|
|
|
|
|
+ this.target.aggregation.perSeriesAligner = value;
|
|
|
|
|
+ this.$scope.refresh();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ handleAggregationChange(value) {
|
|
|
|
|
+ this.target.aggregation.crossSeriesReducer = value;
|
|
|
|
|
+ this.$scope.refresh();
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ handleAlignmentPeriodChange(value) {
|
|
|
|
|
+ this.target.aggregation.alignmentPeriod = value;
|
|
|
|
|
+ this.$scope.refresh();
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
formatAlignmentText() {
|
|
formatAlignmentText() {
|
|
|
- const selectedAlignment = this.alignOptions.find(
|
|
|
|
|
|
|
+ const alignments = getAlignmentOptionsByMetric(this.target.valueType, this.target.metricKind);
|
|
|
|
|
+ const selectedAlignment = alignments.find(
|
|
|
ap => ap.value === this.templateSrv.replace(this.target.aggregation.perSeriesAligner)
|
|
ap => ap.value === this.templateSrv.replace(this.target.aggregation.perSeriesAligner)
|
|
|
);
|
|
);
|
|
|
return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${
|
|
return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${
|
|
@@ -74,6 +119,16 @@ export class StackdriverAggregationCtrl {
|
|
|
const newValue = this.aggOptions.find(o => o.value !== notValidOptionValue);
|
|
const newValue = this.aggOptions.find(o => o.value !== notValidOptionValue);
|
|
|
this.target.aggregation.crossSeriesReducer = newValue ? newValue.value : '';
|
|
this.target.aggregation.crossSeriesReducer = newValue ? newValue.value : '';
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ getTemplateVariablesGroup() {
|
|
|
|
|
+ return {
|
|
|
|
|
+ label: 'Template Variables',
|
|
|
|
|
+ options: this.templateSrv.variables.map(v => ({
|
|
|
|
|
+ label: `$${v.name}`,
|
|
|
|
|
+ value: `$${v.name}`,
|
|
|
|
|
+ })),
|
|
|
|
|
+ };
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
coreModule.directive('stackdriverAggregation', StackdriverAggregation);
|
|
coreModule.directive('stackdriverAggregation', StackdriverAggregation);
|