+
Alias patterns
- $m = replaced with measurement name
@@ -58,7 +58,7 @@
-
+
Stacking and fill
- When stacking is enabled it important that points align
@@ -69,7 +69,7 @@
-
+
Group by time
- Group by time is important, otherwise the query could return many thousands of datapoints that will slow down Grafana
@@ -80,8 +80,6 @@
- Example: >60s if you write metrics to InfluxDB every 60 seconds
-
-
diff --git a/public/app/plugins/datasource/influxdb/query_ctrl.js b/public/app/plugins/datasource/influxdb/query_ctrl.js
index adb0acb2218..f7f17beb459 100644
--- a/public/app/plugins/datasource/influxdb/query_ctrl.js
+++ b/public/app/plugins/datasource/influxdb/query_ctrl.js
@@ -15,13 +15,15 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
queryPart = queryPart.default;
module.controller('InfluxQueryCtrl', function($scope, templateSrv, $q, uiSegmentSrv) {
+ var panelCtrl = $scope.ctrl;
+ $scope.panelCtrl = panelCtrl;
$scope.init = function() {
if (!$scope.target) { return; }
$scope.target = $scope.target;
$scope.queryModel = new InfluxQuery($scope.target);
- $scope.queryBuilder = new InfluxQueryBuilder($scope.target, $scope.datasource.database);
+ $scope.queryBuilder = new InfluxQueryBuilder($scope.target, panelCtrl.datasource.database);
$scope.groupBySegment = uiSegmentSrv.newPlusButton();
$scope.resultFormats = [
{text: 'Time series', value: 'time_series'},
@@ -75,7 +77,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope.getGroupByOptions = function() {
var query = $scope.queryBuilder.buildExploreQuery('TAG_KEYS');
- return $scope.datasource.metricFindQuery(query)
+ return panelCtrl.datasource.metricFindQuery(query)
.then(function(tags) {
var options = [];
if (!$scope.queryModel.hasFill()) {
@@ -97,26 +99,26 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
var plusButton = uiSegmentSrv.newPlusButton();
$scope.groupBySegment.value = plusButton.value;
$scope.groupBySegment.html = plusButton.html;
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.removeGroupByPart = function(part, index) {
$scope.queryModel.removeGroupByPart(part, index);
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.addSelectPart = function(selectParts, cat, subitem) {
$scope.queryModel.addSelectPart(selectParts, subitem.value);
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.removeSelectPart = function(selectParts, part) {
$scope.queryModel.removeSelectPart(selectParts, part);
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.selectPartUpdated = function() {
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.fixTagSegments = function() {
@@ -130,19 +132,19 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope.measurementChanged = function() {
$scope.target.measurement = $scope.measurementSegment.value;
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.getPolicySegments = function() {
var policiesQuery = $scope.queryBuilder.buildExploreQuery('RETENTION POLICIES');
- return $scope.datasource.metricFindQuery(policiesQuery)
+ return panelCtrl.datasource.metricFindQuery(policiesQuery)
.then($scope.transformToSegments(false))
.then(null, $scope.handleQueryError);
};
$scope.policyChanged = function() {
$scope.target.policy = $scope.policySegment.value;
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.toggleQueryMode = function () {
@@ -151,19 +153,19 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope.getMeasurements = function () {
var query = $scope.queryBuilder.buildExploreQuery('MEASUREMENTS');
- return $scope.datasource.metricFindQuery(query)
+ return panelCtrl.datasource.metricFindQuery(query)
.then($scope.transformToSegments(true), $scope.handleQueryError);
};
$scope.getPartOptions = function(part) {
if (part.def.type === 'field') {
var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS');
- return $scope.datasource.metricFindQuery(fieldsQuery)
+ return panelCtrl.datasource.metricFindQuery(fieldsQuery)
.then($scope.transformToSegments(true), $scope.handleQueryError);
}
if (part.def.type === 'tag') {
var tagsQuery = $scope.queryBuilder.buildExploreQuery('TAG_KEYS');
- return $scope.datasource.metricFindQuery(tagsQuery)
+ return panelCtrl.datasource.metricFindQuery(tagsQuery)
.then($scope.transformToSegments(true), $scope.handleQueryError);
}
};
@@ -211,7 +213,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
addTemplateVars = true;
}
- return $scope.datasource.metricFindQuery(query)
+ return panelCtrl.datasource.metricFindQuery(query)
.then($scope.transformToSegments(addTemplateVars))
.then(function(results) {
if (segment.type === 'key') {
@@ -224,7 +226,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope.getFieldSegments = function() {
var fieldsQuery = $scope.queryBuilder.buildExploreQuery('FIELDS');
- return $scope.datasource.metricFindQuery(fieldsQuery)
+ return panelCtrl.datasource.metricFindQuery(fieldsQuery)
.then($scope.transformToSegments(false))
.then(null, $scope.handleQueryError);
};
@@ -234,7 +236,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
$scope.setFill = function(fill) {
$scope.target.fill = fill;
- $scope.get_data();
+ panelCtrl.refresh();
};
$scope.tagSegmentUpdated = function(segment, index) {
@@ -300,7 +302,7 @@ function (angular, _, InfluxQueryBuilder, InfluxQuery, queryPart) {
});
$scope.target.tags = tags;
- $scope.$parent.get_data();
+ panelCtrl.refresh();
};
$scope.getTagValueOperator = function(tagValue, tagOperator) {
diff --git a/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts b/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts
index 94d58adf8a0..16077513d7b 100644
--- a/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts
+++ b/public/app/plugins/datasource/influxdb/specs/query_ctrl_specs.ts
@@ -10,14 +10,20 @@ describe('InfluxDBQueryCtrl', function() {
beforeEach(angularMocks.module('grafana.controllers'));
beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase());
- beforeEach(ctx.createControllerPhase('InfluxQueryCtrl'));
+
+ beforeEach(angularMocks.inject(($rootScope, $controller, $q) => {
+ ctx.$q = $q;
+ ctx.scope = $rootScope.$new();
+ ctx.scope.ctrl = {panel: ctx.panel};
+ ctx.panelCtrl = ctx.scope.ctrl;
+ ctx.controller = $controller('InfluxQueryCtrl', {$scope: ctx.scope});
+ }));
beforeEach(function() {
ctx.scope.target = {};
- ctx.scope.$parent = { get_data: sinon.spy() };
-
- ctx.scope.datasource = ctx.datasource;
- ctx.scope.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
+ ctx.panelCtrl.refresh = sinon.spy();
+ ctx.panelCtrl.datasource = ctx.datasource;
+ ctx.panelCtrl.datasource.metricFindQuery = sinon.stub().returns(ctx.$q.when([]));
});
describe('init', function() {
diff --git a/public/test/specs/helpers.js b/public/test/specs/helpers.js
index 65b7cd34355..c1cc56b00b9 100644
--- a/public/test/specs/helpers.js
+++ b/public/test/specs/helpers.js
@@ -44,7 +44,7 @@ define([
self.$browser = $browser;
self.$q = $q;
self.panel = {type: 'test'};
- self.dashboard = {};
+ self.dashboard = {meta: {}};
$rootScope.appEvent = sinon.spy();
$rootScope.onAppEvent = sinon.spy();
@@ -67,7 +67,7 @@ define([
self.scope.contextSrv = {};
self.scope.panel = {};
self.scope.row = { panels:[] };
- self.scope.dashboard = {};
+ self.scope.dashboard = {meta: {}};
self.scope.dashboardMeta = {};
self.scope.dashboardViewState = new DashboardViewStateStub();
self.scope.appEvent = sinon.spy();