@@ -70,4 +70,4 @@
-
+
\ No newline at end of file
diff --git a/public/app/plugins/datasource/stackdriver/partials/query.filter.html b/public/app/plugins/datasource/stackdriver/partials/query.filter.html
index 5043161c492..b96b0720e33 100644
--- a/public/app/plugins/datasource/stackdriver/partials/query.filter.html
+++ b/public/app/plugins/datasource/stackdriver/partials/query.filter.html
@@ -1,37 +1,52 @@
diff --git a/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts
index 6cd6c805463..628cc494242 100644
--- a/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts
+++ b/public/app/plugins/datasource/stackdriver/query_aggregation_ctrl.ts
@@ -1,6 +1,7 @@
import coreModule from 'app/core/core_module';
import _ from 'lodash';
import * as options from './constants';
+import { getAlignmentOptionsByMetric, getAggregationOptionsByMetric } from './functions';
import kbn from 'app/core/utils/kbn';
export class StackdriverAggregation {
@@ -25,7 +26,7 @@ export class StackdriverAggregationCtrl {
target: any;
/** @ngInject */
- constructor(private $scope) {
+ constructor(private $scope, private templateSrv) {
this.$scope.ctrl = this;
this.target = $scope.target;
this.alignmentPeriods = options.alignmentPeriods;
@@ -41,28 +42,16 @@ 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
- );
- });
- if (!this.alignOptions.find(o => o.value === this.target.aggregation.perSeriesAligner)) {
+ 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 : '';
}
}
setAggOptions() {
- this.aggOptions = !this.target.metricKind
- ? []
- : options.aggOptions.filter(i => {
- return (
- i.valueTypes.indexOf(this.target.valueType) !== -1 && i.metricKinds.indexOf(this.target.metricKind) !== -1
- );
- });
+ this.aggOptions = getAggregationOptionsByMetric(this.target.valueType, this.target.metricKind);
- if (!this.aggOptions.find(o => o.value === this.target.aggregation.crossSeriesReducer)) {
+ if (!this.aggOptions.find(o => o.value === this.templateSrv.replace(this.target.aggregation.crossSeriesReducer))) {
this.deselectAggregationOption('REDUCE_NONE');
}
@@ -73,8 +62,12 @@ export class StackdriverAggregationCtrl {
}
formatAlignmentText() {
- const selectedAlignment = this.alignOptions.find(ap => ap.value === this.target.aggregation.perSeriesAligner);
- return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${selectedAlignment.text})`;
+ const selectedAlignment = this.alignOptions.find(
+ ap => ap.value === this.templateSrv.replace(this.target.aggregation.perSeriesAligner)
+ );
+ return `${kbn.secondsToHms(this.$scope.alignmentPeriod)} interval (${
+ selectedAlignment ? selectedAlignment.text : ''
+ })`;
}
deselectAggregationOption(notValidOptionValue: string) {
diff --git a/public/app/plugins/datasource/stackdriver/query_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_ctrl.ts
index 3a1961eb14e..c2607964456 100644
--- a/public/app/plugins/datasource/stackdriver/query_ctrl.ts
+++ b/public/app/plugins/datasource/stackdriver/query_ctrl.ts
@@ -62,7 +62,6 @@ export class StackdriverQueryCtrl extends QueryCtrl {
constructor($scope, $injector) {
super($scope, $injector);
_.defaultsDeep(this.target, this.defaults);
-
this.panelCtrl.events.on('data-received', this.onDataReceived.bind(this), $scope);
this.panelCtrl.events.on('data-error', this.onDataError.bind(this), $scope);
}
diff --git a/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts b/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts
index 4c383e5d09e..0f5dce559fd 100644
--- a/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts
+++ b/public/app/plugins/datasource/stackdriver/query_filter_ctrl.ts
@@ -139,7 +139,7 @@ export class StackdriverFilterCtrl {
result = metrics.filter(m => m.service === this.target.service);
}
- if (result.find(m => m.value === this.target.metricType)) {
+ if (result.find(m => m.value === this.templateSrv.replace(this.target.metricType))) {
this.metricType = this.target.metricType;
} else if (result.length > 0) {
this.metricType = this.target.metricType = result[0].value;
@@ -150,10 +150,10 @@ export class StackdriverFilterCtrl {
async getLabels() {
this.loadLabelsPromise = new Promise(async resolve => {
try {
- const data = await this.datasource.getLabels(this.target.metricType, this.target.refId);
- this.metricLabels = data.results[this.target.refId].meta.metricLabels;
- this.resourceLabels = data.results[this.target.refId].meta.resourceLabels;
- this.resourceTypes = data.results[this.target.refId].meta.resourceTypes;
+ const { meta } = await this.datasource.getLabels(this.target.metricType, this.target.refId);
+ this.metricLabels = meta.metricLabels;
+ this.resourceLabels = meta.resourceLabels;
+ this.resourceTypes = meta.resourceTypes;
resolve();
} catch (error) {
if (error.data && error.data.message) {
@@ -187,7 +187,9 @@ export class StackdriverFilterCtrl {
setMetricType() {
this.target.metricType = this.metricType;
- const { valueType, metricKind, unit } = this.metricDescriptors.find(m => m.type === this.target.metricType);
+ const { valueType, metricKind, unit } = this.metricDescriptors.find(
+ m => m.type === this.templateSrv.replace(this.metricType)
+ );
this.target.unit = unit;
this.target.valueType = valueType;
this.target.metricKind = metricKind;
diff --git a/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts b/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts
index ac9ea2ac6bc..81011f5dfe0 100644
--- a/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts
+++ b/public/app/plugins/datasource/stackdriver/specs/query_aggregation_ctrl.test.ts
@@ -6,10 +6,19 @@ describe('StackdriverAggregationCtrl', () => {
describe('when new query result is returned from the server', () => {
describe('and result is double and gauge and no group by is used', () => {
beforeEach(async () => {
- ctrl = new StackdriverAggregationCtrl({
- $on: () => {},
- target: { valueType: 'DOUBLE', metricKind: 'GAUGE', aggregation: { crossSeriesReducer: '', groupBys: [] } },
- });
+ ctrl = new StackdriverAggregationCtrl(
+ {
+ $on: () => {},
+ target: {
+ valueType: 'DOUBLE',
+ metricKind: 'GAUGE',
+ aggregation: { crossSeriesReducer: '', groupBys: [] },
+ },
+ },
+ {
+ replace: s => s,
+ }
+ );
});
it('should populate all aggregate options except two', () => {
@@ -31,14 +40,19 @@ describe('StackdriverAggregationCtrl', () => {
describe('and result is double and gauge and a group by is used', () => {
beforeEach(async () => {
- ctrl = new StackdriverAggregationCtrl({
- $on: () => {},
- target: {
- valueType: 'DOUBLE',
- metricKind: 'GAUGE',
- aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
+ ctrl = new StackdriverAggregationCtrl(
+ {
+ $on: () => {},
+ target: {
+ valueType: 'DOUBLE',
+ metricKind: 'GAUGE',
+ aggregation: { crossSeriesReducer: 'REDUCE_NONE', groupBys: ['resource.label.projectid'] },
+ },
},
- });
+ {
+ replace: s => s,
+ }
+ );
});
it('should populate all aggregate options except three', () => {
diff --git a/public/app/plugins/datasource/stackdriver/types.ts b/public/app/plugins/datasource/stackdriver/types.ts
new file mode 100644
index 00000000000..df4c2886522
--- /dev/null
+++ b/public/app/plugins/datasource/stackdriver/types.ts
@@ -0,0 +1,21 @@
+export enum MetricFindQueryTypes {
+ Services = 'services',
+ MetricTypes = 'metricTypes',
+ LabelKeys = 'labelKeys',
+ LabelValues = 'labelValues',
+ ResourceTypes = 'resourceTypes',
+ Aggregations = 'aggregations',
+ Aligners = 'aligners',
+ AlignmentPeriods = 'alignmentPeriods',
+}
+
+export interface VariableQueryData {
+ selectedQueryType: string;
+ metricDescriptors: any[];
+ selectedService: string;
+ selectedMetricType: string;
+ labels: string[];
+ labelKey: string;
+ metricTypes: Array<{ value: string; name: string }>;
+ services: Array<{ value: string; name: string }>;
+}
diff --git a/public/app/types/plugins.ts b/public/app/types/plugins.ts
index 817777669d8..9e3264be70c 100644
--- a/public/app/types/plugins.ts
+++ b/public/app/types/plugins.ts
@@ -6,6 +6,7 @@ export interface PluginExports {
QueryCtrl?: any;
ConfigCtrl?: any;
AnnotationsQueryCtrl?: any;
+ VariableQueryEditor?: any;
ExploreQueryField?: any;
ExploreStartPage?: any;
@@ -98,3 +99,10 @@ export interface PluginsState {
hasFetched: boolean;
dashboards: PluginDashboard[];
}
+
+export interface VariableQueryProps {
+ query: any;
+ onChange: (query: any, definition: string) => void;
+ datasource: any;
+ templateSrv: any;
+}