Commit b700c6b0 by Erik Sundell

stackdriver: populate alignment and aggregation dropdowns based on metric type and value type

parent e101bcdb
...@@ -299,6 +299,9 @@ func (e *StackdriverExecutor) parseResponse(queryRes *tsdb.QueryResult, data Sta ...@@ -299,6 +299,9 @@ 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)
......
export enum MetricKind {
METRIC_KIND_UNSPECIFIED = 'METRIC_KIND_UNSPECIFIED',
GAUGE = 'GAUGE',
DELTA = 'DELTA',
CUMULATIVE = 'CUMULATIVE',
}
export enum ValueTypes {
VALUE_TYPE_UNSPECIFIED = 'VALUE_TYPE_UNSPECIFIED',
BOOL = 'BOOL',
INT64 = 'INT64',
DOUBLE = 'DOUBLE',
STRING = 'STRING',
DISTRIBUTION = 'DISTRIBUTION',
MONEY = 'MONEY',
}
export const alignOptions = [ export const alignOptions = [
{ text: 'none', value: 'ALIGN_NONE' }, {
{ text: 'delta', value: 'ALIGN_DELTA' }, text: 'none',
{ text: 'rate', value: 'ALIGN_RATE' }, value: 'ALIGN_NONE',
{ text: 'interpolate', value: 'ALIGN_INTERPOLATE' }, valueTypes: [
{ text: 'next older', value: 'ALIGN_NEXT_OLDER' }, ValueTypes.INT64,
{ text: 'min', value: 'ALIGN_MIN' }, ValueTypes.DOUBLE,
{ text: 'max', value: 'ALIGN_MAX' }, ValueTypes.MONEY,
{ text: 'mean', value: 'ALIGN_MEAN' }, ValueTypes.DISTRIBUTION,
{ text: 'count', value: 'ALIGN_COUNT' }, ValueTypes.BOOL,
{ text: 'sum', value: 'ALIGN_SUM' }, ValueTypes.STRING,
{ text: 'stddev', value: 'ALIGN_STDDEV' }, ],
{ text: 'count true', value: 'ALIGN_COUNT_TRUE' }, metricKinds: [MetricKind.GAUGE, MetricKind.DELTA, MetricKind.CUMULATIVE, MetricKind.METRIC_KIND_UNSPECIFIED],
{ text: 'count false', value: 'ALIGN_COUNT_FALSE' }, },
{ text: 'fraction true', value: 'ALIGN_FRACTION_TRUE' }, {
{ text: 'percentile 99', value: 'ALIGN_PERCENTILE_99' }, text: 'delta',
{ text: 'percentile 95', value: 'ALIGN_PERCENTILE_95' }, value: 'ALIGN_DELTA',
{ text: 'percentile 50', value: 'ALIGN_PERCENTILE_50' }, valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
{ text: 'percentile 05', value: 'ALIGN_PERCENTILE_05' }, metricKinds: [MetricKind.CUMULATIVE, MetricKind.DELTA],
{ text: 'percent change', value: 'ALIGN_PERCENT_CHANGE' }, },
{
text: 'rate',
value: 'ALIGN_RATE',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.CUMULATIVE, MetricKind.DELTA],
},
{
text: 'interpolate',
value: 'ALIGN_INTERPOLATE',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE],
},
{
text: 'next older',
value: 'ALIGN_NEXT_OLDER',
valueTypes: [
ValueTypes.INT64,
ValueTypes.DOUBLE,
ValueTypes.MONEY,
ValueTypes.DISTRIBUTION,
ValueTypes.STRING,
ValueTypes.VALUE_TYPE_UNSPECIFIED,
ValueTypes.BOOL,
],
metricKinds: [MetricKind.GAUGE],
},
{
text: 'min',
value: 'ALIGN_MIN',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'max',
value: 'ALIGN_MAX',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'mean',
value: 'ALIGN_MEAN',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'count',
value: 'ALIGN_COUNT',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.BOOL],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'sum',
value: 'ALIGN_SUM',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'stddev',
value: 'ALIGN_STDDEV',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'count true',
value: 'ALIGN_COUNT_TRUE',
valueTypes: [ValueTypes.BOOL],
metricKinds: [MetricKind.GAUGE],
},
{
text: 'count false',
value: 'ALIGN_COUNT_FALSE',
valueTypes: [ValueTypes.BOOL],
metricKinds: [MetricKind.GAUGE],
},
{
text: 'fraction true',
value: 'ALIGN_FRACTION_TRUE',
valueTypes: [ValueTypes.BOOL],
metricKinds: [MetricKind.GAUGE],
},
{
text: 'percentile 99',
value: 'ALIGN_PERCENTILE_99',
valueTypes: [ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'percentile 95',
value: 'ALIGN_PERCENTILE_95',
valueTypes: [ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'percentile 50',
value: 'ALIGN_PERCENTILE_50',
valueTypes: [ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'percentile 05',
value: 'ALIGN_PERCENTILE_05',
valueTypes: [ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'percent change',
value: 'ALIGN_PERCENT_CHANGE',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
]; ];
export const aggOptions = [ export const aggOptions = [
{ text: 'none', value: 'REDUCE_NONE' }, {
{ text: 'mean', value: 'REDUCE_MEAN' }, text: 'none',
{ text: 'min', value: 'REDUCE_MIN' }, value: 'REDUCE_NONE',
{ text: 'max', value: 'REDUCE_MAX' }, valueTypes: [
{ text: 'sum', value: 'REDUCE_SUM' }, ValueTypes.INT64,
{ text: 'std. dev.', value: 'REDUCE_STDDEV' }, ValueTypes.DOUBLE,
{ text: 'count', value: 'REDUCE_COUNT' }, ValueTypes.MONEY,
{ text: '99th percentile', value: 'REDUCE_PERCENTILE_99' }, ValueTypes.DISTRIBUTION,
{ text: '95th percentile', value: 'REDUCE_PERCENTILE_95' }, ValueTypes.BOOL,
{ text: '50th percentile', value: 'REDUCE_PERCENTILE_50' }, ValueTypes.STRING,
{ text: '5th percentile', value: 'REDUCE_PERCENTILE_05' }, ],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA, MetricKind.CUMULATIVE, MetricKind.METRIC_KIND_UNSPECIFIED],
},
{
text: 'mean',
value: 'REDUCE_MEAN',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'min',
value: 'REDUCE_MIN',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'max',
value: 'REDUCE_MAX',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'sum',
value: 'REDUCE_SUM',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'std. dev.',
value: 'REDUCE_STDDEV',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'count',
value: 'REDUCE_COUNT',
valueTypes: [
ValueTypes.INT64,
ValueTypes.DOUBLE,
ValueTypes.MONEY,
ValueTypes.DISTRIBUTION,
ValueTypes.BOOL,
ValueTypes.STRING,
],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'count',
value: 'REDUCE_COUNT_TRUE',
valueTypes: [ValueTypes.BOOL],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: 'count',
value: 'REDUCE_COUNT_FALSE',
valueTypes: [ValueTypes.BOOL],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: '99th percentile',
value: 'REDUCE_PERCENTILE_99',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: '95th percentile',
value: 'REDUCE_PERCENTILE_95',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: '50th percentile',
value: 'REDUCE_PERCENTILE_50',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
{
text: '5th percentile',
value: 'REDUCE_PERCENTILE_05',
valueTypes: [ValueTypes.INT64, ValueTypes.DOUBLE, ValueTypes.MONEY, ValueTypes.DISTRIBUTION],
metricKinds: [MetricKind.GAUGE, MetricKind.DELTA],
},
]; ];
export const alignmentPeriods = [ export const alignmentPeriods = [
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,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 Type</span> <span class="gf-form-label width-9">Metric Type</span>
<gf-form-dropdown model="ctrl.target.metricType" get-options="ctrl.getMetricTypes($query)" class="min-width-20" disabled <gf-form-dropdown model="ctrl.target.metricType" get-options="ctrl.getMetricTypes($query)" class="min-width-20"
type="text" allow-custom="true" lookup-text="true" css-class="min-width-12" on-change="ctrl.onMetricTypeChange()"></gf-form-dropdown> disabled type="text" 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>
...@@ -35,7 +35,7 @@ ...@@ -35,7 +35,7 @@
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label query-keyword width-9">Aggregation</label> <label class="gf-form-label query-keyword width-9">Aggregation</label>
<div class="gf-form-select-wrapper gf-form-select-wrapper--caret-indent"> <div class="gf-form-select-wrapper gf-form-select-wrapper--caret-indent">
<select class="gf-form-input width-12" ng-model="ctrl.target.aggregation.crossSeriesReducer" ng-options="f.value as f.text for f in ctrl.stackdriverConstants.aggOptions" <select class="gf-form-input width-12" ng-model="ctrl.target.aggregation.crossSeriesReducer" ng-options="f.value as f.text for f in ctrl.getAggOptions()"
ng-change="ctrl.refresh()"></select> ng-change="ctrl.refresh()"></select>
</div> </div>
</div> </div>
...@@ -53,7 +53,7 @@ ...@@ -53,7 +53,7 @@
<div class="gf-form offset-width-9"> <div class="gf-form offset-width-9">
<label class="gf-form-label query-keyword width-12">Aligner</label> <label class="gf-form-label query-keyword width-12">Aligner</label>
<div class="gf-form-select-wrapper gf-form-select-wrapper--caret-indent"> <div class="gf-form-select-wrapper gf-form-select-wrapper--caret-indent">
<select class="gf-form-input width-14" ng-model="ctrl.target.aggregation.perSeriesAligner" ng-options="f.value as f.text for f in ctrl.stackdriverConstants.alignOptions" <select class="gf-form-input width-14" ng-model="ctrl.target.aggregation.perSeriesAligner" ng-options="f.value as f.text for f in ctrl.getAlignOptions()"
ng-change="ctrl.refresh()"></select> ng-change="ctrl.refresh()"></select>
</div> </div>
...@@ -85,8 +85,8 @@ ...@@ -85,8 +85,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">Project</span> <span class="gf-form-label width-9">Project</span>
<input class="gf-form-input" disabled type="text" ng-model='ctrl.target.project.name' get-options="ctrl.getProjects()" css-class="min-width-12" <input class="gf-form-input" disabled type="text" ng-model='ctrl.target.project.name' get-options="ctrl.getProjects()"
/> css-class="min-width-12" />
</div> </div>
<div class="gf-form"> <div class="gf-form">
<label class="gf-form-label query-keyword" ng-click="ctrl.showHelp = !ctrl.showHelp"> <label class="gf-form-label query-keyword" ng-click="ctrl.showHelp = !ctrl.showHelp">
......
...@@ -28,6 +28,8 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -28,6 +28,8 @@ export class StackdriverQueryCtrl extends QueryCtrl {
}; };
filters: string[]; filters: string[];
aliasBy: string; aliasBy: string;
metricKind: any;
valueType: any;
}; };
defaultDropdownValue = 'select metric'; defaultDropdownValue = 'select metric';
defaultRemoveGroupByValue = '-- remove group by --'; defaultRemoveGroupByValue = '-- remove group by --';
...@@ -49,8 +51,12 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -49,8 +51,12 @@ export class StackdriverQueryCtrl extends QueryCtrl {
filters: [], filters: [],
showAggregationOptions: false, showAggregationOptions: false,
aliasBy: '', aliasBy: '',
metricKind: '',
valueType: '',
}; };
alignOptions: any[];
aggOptions: any[];
groupBySegments: any[]; groupBySegments: any[];
removeSegment: any; removeSegment: any;
showHelp: boolean; showHelp: boolean;
...@@ -69,6 +75,8 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -69,6 +75,8 @@ 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.stackdriverConstants = options; this.stackdriverConstants = options;
this.aggOptions = options.aggOptions;
this.alignOptions = options.alignOptions;
this.getCurrentProject() this.getCurrentProject()
.then(this.getMetricTypes.bind(this)) .then(this.getMetricTypes.bind(this))
...@@ -256,6 +264,31 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -256,6 +264,31 @@ export class StackdriverQueryCtrl extends QueryCtrl {
} }
} }
getAlignOptions() {
return !this.target.valueType
? options.alignOptions
: options.alignOptions.filter(i => {
return (
i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
);
});
}
getAggOptions() {
if (this.target.aggregation.perSeriesAligner === 'ALIGN_NONE') {
this.target.aggregation.crossSeriesReducer = options.aggOptions[0].value;
return options.aggOptions.slice(0, 1);
}
return !this.target.metricKind
? options.aggOptions
: options.aggOptions.filter(i => {
return (
i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
);
});
}
onDataReceived(dataList) { onDataReceived(dataList) {
this.lastQueryError = null; this.lastQueryError = null;
this.lastQueryMeta = null; this.lastQueryMeta = null;
...@@ -264,7 +297,8 @@ export class StackdriverQueryCtrl extends QueryCtrl { ...@@ -264,7 +297,8 @@ export class StackdriverQueryCtrl extends QueryCtrl {
if (anySeriesFromQuery) { if (anySeriesFromQuery) {
this.lastQueryMeta = anySeriesFromQuery.meta; this.lastQueryMeta = anySeriesFromQuery.meta;
this.lastQueryMeta.rawQueryString = decodeURIComponent(this.lastQueryMeta.rawQuery); this.lastQueryMeta.rawQueryString = decodeURIComponent(this.lastQueryMeta.rawQuery);
} else { this.target.valueType = anySeriesFromQuery.meta.valueType;
this.target.metricKind = anySeriesFromQuery.meta.metricKind;
} }
} }
......
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