diff --git a/public/app/plugins/datasource/influxdb/influx_query.ts b/public/app/plugins/datasource/influxdb/influx_query.ts index 8a236e04626..6108040fd66 100644 --- a/public/app/plugins/datasource/influxdb/influx_query.ts +++ b/public/app/plugins/datasource/influxdb/influx_query.ts @@ -12,6 +12,7 @@ export default class InfluxQuery { constructor(target) { this.target = target; + target.policy = target.policy || 'default'; target.dsType = 'influxdb'; target.resultFormat = target.resultFormat || 'time_series'; target.tags = target.tags || []; diff --git a/public/app/plugins/datasource/influxdb/partials/query.editor.html b/public/app/plugins/datasource/influxdb/partials/query.editor.html index b4451c15eda..9510cc3d92c 100644 --- a/public/app/plugins/datasource/influxdb/partials/query.editor.html +++ b/public/app/plugins/datasource/influxdb/partials/query.editor.html @@ -45,6 +45,9 @@
  • FROM
  • +
  • + +
  • diff --git a/public/app/plugins/datasource/influxdb/query_builder.js b/public/app/plugins/datasource/influxdb/query_builder.js index 523003bd70d..fb6a4066ebc 100644 --- a/public/app/plugins/datasource/influxdb/query_builder.js +++ b/public/app/plugins/datasource/influxdb/query_builder.js @@ -62,6 +62,9 @@ function (_) { } else if (type === 'FIELDS') { query = 'SHOW FIELD KEYS FROM "' + this.target.measurement + '"'; return query; + } else if (type === 'RETENTION POLICIES') { + query = 'SHOW RETENTION POLICIES'; + return query; } if (measurement) { diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.js b/public/app/plugins/datasource/influxdb/query_ctrl.js index 29bd251ef28..eb47c17129c 100644 --- a/public/app/plugins/datasource/influxdb/query_ctrl.js +++ b/public/app/plugins/datasource/influxdb/query_ctrl.js @@ -28,6 +28,8 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { {text: 'Table', value: 'table'}, ]; + $scope.policySegment = uiSegmentSrv.newSegment($scope.target.policy); + if (!$scope.target.measurement) { $scope.measurementSegment = uiSegmentSrv.newSelectMeasurement(); } else { @@ -131,6 +133,18 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) { $scope.get_data(); }; + $scope.getPolicySegments = function() { + var policiesQuery = $scope.queryBuilder.buildExploreQuery('RETENTION POLICIES'); + return $scope.datasource.metricFindQuery(policiesQuery) + .then($scope.transformToSegments(false)) + .then(null, $scope.handleQueryError); + }; + + $scope.policyChanged = function() { + $scope.target.policy = $scope.policySegment.value; + $scope.get_data(); + }; + $scope.toggleQueryMode = function () { $scope.target.rawQuery = !$scope.target.rawQuery; }; diff --git a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts b/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts index af8d0dcc757..87b96775e38 100644 --- a/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts +++ b/public/app/plugins/datasource/influxdb/specs/query_builder_specs.ts @@ -70,6 +70,10 @@ describe('InfluxQueryBuilder', function() { expect(query).to.be('SHOW FIELD KEYS FROM "cpu"'); }); + it('should build show retention policies query', function() { + var builder = new InfluxQueryBuilder({measurement: 'cpu', tags: []}); + var query = builder.buildExploreQuery('RETENTION POLICIES'); + expect(query).to.be('SHOW RETENTION POLICIES'); + }); }); - });