mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
stackdriver: add aligner query
This commit is contained in:
@@ -1,4 +1,8 @@
|
||||
import { extractServicesFromMetricDescriptors, getMetricTypesByService } from './functions';
|
||||
import {
|
||||
extractServicesFromMetricDescriptors,
|
||||
getMetricTypesByService,
|
||||
getAlignmentOptionsByMetric,
|
||||
} from './functions';
|
||||
import has from 'lodash/has';
|
||||
|
||||
export default class StackdriverMetricFindQuery {
|
||||
@@ -15,6 +19,8 @@ export default class StackdriverMetricFindQuery {
|
||||
return this.handleLabelQueryType(query);
|
||||
case 'resourceTypes':
|
||||
return this.handleResourceType(query);
|
||||
case 'alignerns':
|
||||
return this.handleAlignersType(query);
|
||||
default:
|
||||
return [];
|
||||
}
|
||||
@@ -85,4 +91,13 @@ export default class StackdriverMetricFindQuery {
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
async handleAlignersType({ metricType }) {
|
||||
if (!metricType) {
|
||||
return [];
|
||||
}
|
||||
const metricDescriptors = await this.datasource.getMetricTypes(this.datasource.projectName);
|
||||
const { valueType, metricKind } = metricDescriptors.find(m => m.type === metricType);
|
||||
return getAlignmentOptionsByMetric(valueType, metricKind);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -133,6 +133,17 @@ export class StackdriverTemplateQueryComponent extends PureComponent<TemplateQue
|
||||
{dropdown}
|
||||
</React.Fragment>
|
||||
);
|
||||
case 'alignerns':
|
||||
return (
|
||||
<React.Fragment>
|
||||
<ServiceSelector metricDescriptors={this.state.metricDescriptors} onServiceChange={this.onServiceChange} />
|
||||
<MetricTypeSelector
|
||||
selectedService={this.state.service}
|
||||
metricDescriptors={this.state.metricDescriptors}
|
||||
onMetricTypeChange={this.onMetricTypeChange}
|
||||
/>
|
||||
</React.Fragment>
|
||||
);
|
||||
default:
|
||||
return '';
|
||||
}
|
||||
|
||||
@@ -1,6 +1,15 @@
|
||||
import { alignOptions } from './constants';
|
||||
import uniqBy from 'lodash/uniqBy';
|
||||
|
||||
export const extractServicesFromMetricDescriptors = metricDescriptors => uniqBy(metricDescriptors, 'service');
|
||||
|
||||
export const getMetricTypesByService = (metricDescriptors, service) =>
|
||||
metricDescriptors.filter(m => m.service === service);
|
||||
|
||||
export const getAlignmentOptionsByMetric = (metricValueType, metricKind) => {
|
||||
return !metricValueType
|
||||
? []
|
||||
: alignOptions.filter(i => {
|
||||
return i.valueTypes.indexOf(metricValueType) !== -1 && i.metricKinds.indexOf(metricKind) !== -1;
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import coreModule from 'app/core/core_module';
|
||||
import _ from 'lodash';
|
||||
import * as options from './constants';
|
||||
import { getAlignmentOptionsByMetric } from './functions';
|
||||
import kbn from 'app/core/utils/kbn';
|
||||
|
||||
export class StackdriverAggregation {
|
||||
@@ -41,13 +42,7 @@ export class StackdriverAggregationCtrl {
|
||||
}
|
||||
|
||||
setAlignOptions() {
|
||||
this.alignOptions = !this.target.valueType
|
||||
? []
|
||||
: options.alignOptions.filter(i => {
|
||||
return (
|
||||
i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
|
||||
);
|
||||
});
|
||||
this.alignOptions = getAlignmentOptionsByMetric(this.target.valueType, this.target.metricKind);
|
||||
if (!this.alignOptions.find(o => o.value === this.target.aggregation.perSeriesAligner)) {
|
||||
this.target.aggregation.perSeriesAligner = this.alignOptions.length > 0 ? this.alignOptions[0].value : '';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user