mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: add aggregation query
This commit is contained in:
parent
b1db07789b
commit
ca77cdc37e
@ -2,6 +2,7 @@ import {
|
|||||||
extractServicesFromMetricDescriptors,
|
extractServicesFromMetricDescriptors,
|
||||||
getMetricTypesByService,
|
getMetricTypesByService,
|
||||||
getAlignmentOptionsByMetric,
|
getAlignmentOptionsByMetric,
|
||||||
|
getAggregationOptionsByMetric,
|
||||||
} from './functions';
|
} from './functions';
|
||||||
import { alignmentPeriods } from './constants';
|
import { alignmentPeriods } from './constants';
|
||||||
import has from 'lodash/has';
|
import has from 'lodash/has';
|
||||||
@ -24,6 +25,8 @@ export default class StackdriverMetricFindQuery {
|
|||||||
return this.handleAlignersType(query);
|
return this.handleAlignersType(query);
|
||||||
case 'alignmentPeriods':
|
case 'alignmentPeriods':
|
||||||
return this.handleAlignmentPeriodType();
|
return this.handleAlignmentPeriodType();
|
||||||
|
case 'aggregations':
|
||||||
|
return this.handleAggregationType(query);
|
||||||
default:
|
default:
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
@ -107,6 +110,18 @@ export default class StackdriverMetricFindQuery {
|
|||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async handleAggregationType({ metricType }) {
|
||||||
|
if (!metricType) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
const metricDescriptors = await this.datasource.getMetricTypes(this.datasource.projectName);
|
||||||
|
const { valueType, metricKind } = metricDescriptors.find(m => m.type === metricType);
|
||||||
|
return getAggregationOptionsByMetric(valueType, metricKind).map(o => ({
|
||||||
|
...o,
|
||||||
|
expandable: true,
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
|
||||||
handleAlignmentPeriodType() {
|
handleAlignmentPeriodType() {
|
||||||
return alignmentPeriods.map(s => ({
|
return alignmentPeriods.map(s => ({
|
||||||
...s,
|
...s,
|
||||||
|
@ -134,6 +134,7 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
|
|||||||
</React.Fragment>
|
</React.Fragment>
|
||||||
);
|
);
|
||||||
case 'alignerns':
|
case 'alignerns':
|
||||||
|
case 'aggregations':
|
||||||
return (
|
return (
|
||||||
<React.Fragment>
|
<React.Fragment>
|
||||||
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
|
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { alignOptions } from './constants';
|
import { alignOptions, aggOptions } from './constants';
|
||||||
import uniqBy from 'lodash/uniqBy';
|
import uniqBy from 'lodash/uniqBy';
|
||||||
|
|
||||||
export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');
|
export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');
|
||||||
@ -13,3 +13,11 @@ export const getAlignmentOptionsByMetric = (metricValueType, metricKind) => {
|
|||||||
return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
|
return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export const getAggregationOptionsByMetric = (valueType, metricKind) => {
|
||||||
|
return !metricKind
|
||||||
|
? []
|
||||||
|
: aggOptions.filter(i => {
|
||||||
|
return i.valueTypes.indexOf(valueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
|
||||||
|
});
|
||||||
|
};
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
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 * as options from './constants';
|
||||||
import { getAlignmentOptionsByMetric } from './functions';
|
import { getAlignmentOptionsByMetric, getAggregationOptionsByMetric } from './functions';
|
||||||
import kbn from 'app/core/utils/kbn';
|
import kbn from 'app/core/utils/kbn';
|
||||||
|
|
||||||
export class StackdriverAggregation {
|
export class StackdriverAggregation {
|
||||||
@ -49,13 +49,7 @@ export class StackdriverAggregationCtrl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
setAggOptions() {
|
setAggOptions() {
|
||||||
this.aggOptions = !this.target.metricKind
|
this.aggOptions = getAggregationOptionsByMetric(this.target.valueType, this.target.metricKind);
|
||||||
? []
|
|
||||||
: options.aggOptions.filter(i => {
|
|
||||||
return (
|
|
||||||
i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
|
|
||||||
);
|
|
||||||
});
|
|
||||||
|
|
||||||
if (!this.aggOptions.find(o => o.value === this.target.aggregation.crossSeriesReducer)) {
|
if (!this.aggOptions.find(o => o.value === this.target.aggregation.crossSeriesReducer)) {
|
||||||
this.deselectAggregationOption('REDUCE_NONE');
|
this.deselectAggregationOption('REDUCE_NONE');
|
||||||
|
Loading…
Reference in New Issue
Block a user