diff --git a/public/app/plugins/datasource/kairosdb/datasource.js b/public/app/plugins/datasource/kairosdb/datasource.js index a93febf9ff4..da3f8ca665f 100644 --- a/public/app/plugins/datasource/kairosdb/datasource.js +++ b/public/app/plugins/datasource/kairosdb/datasource.js @@ -44,7 +44,7 @@ function (angular, _, kbn) { d.resolve({ data: [] }); return d.promise; } - return this.performTimeSeriesQuery(queries, start, end).then(handleKairosDBQueryResponseAlias,handleQueryError); + return this.performTimeSeriesQuery(queries, start, end).then(handleKairosDBQueryResponseAlias, handleQueryError); }; /////////////////////////////////////////////////////////////////////// @@ -56,8 +56,8 @@ function (angular, _, kbn) { metrics: queries }; reqBody.cache_time = 0; - convertToKairosTime(start,reqBody,'start'); - convertToKairosTime(end,reqBody,'end'); + convertToKairosTime(start, reqBody, 'start'); + convertToKairosTime(end, reqBody, 'end'); var options = { method: 'POST', url: '/api/v1/datapoints/query', @@ -86,10 +86,10 @@ function (angular, _, kbn) { }; - KairosDBDatasource.prototype.performTagSuggestQuery = function(metricname,range,type,keyValue) { + KairosDBDatasource.prototype.performTagSuggestQuery = function(metricname, range, type, keyValue) { if (tagList && (metricname === tagList.metricName) && (range.from === tagList.range.from) && (range.to === tagList.range.to)) { - return getTagListFromResponse(tagList.results,type,keyValue); + return getTagListFromResponse(tagList.results, type, keyValue); } tagList = { metricName:metricname, @@ -98,8 +98,8 @@ function (angular, _, kbn) { var body = { metrics : [{name : metricname}] }; - convertToKairosTime(range.from,body,'start'); - convertToKairosTime(range.to,body,'end'); + convertToKairosTime(range.from, body, 'start'); + convertToKairosTime(range.to, body, 'end'); var options = { url : this.url + '/api/v1/datapoints/query/tags', method : 'POST', @@ -107,7 +107,7 @@ function (angular, _, kbn) { }; return $http(options).then(function(results) { tagList.results = results; - return getTagListFromResponse(results,type,keyValue); + return getTagListFromResponse(results, type, keyValue); }); }; @@ -116,14 +116,14 @@ function (angular, _, kbn) { /// Formatting methods //////////////////////////////////////////////////////////////////////// - function getTagListFromResponse(results,type,keyValue) { + function getTagListFromResponse(results, type, keyValue) { if (!results.data) { return []; } if (type === "key") { return _.keys(results.data.queries[0].results[0].tags); } - else if (type === "value" && _.has(results.data.queries[0].results[0].tags,keyValue)) { + else if (type === "value" && _.has(results.data.queries[0].results[0].tags, keyValue)) { return results.data.queries[0].results[0].tags[keyValue]; } return []; @@ -150,9 +150,6 @@ function (angular, _, kbn) { var output = []; var index = 0; _.each(results.data.queries, function(series) { - var sample_size = series.sample_size; - console.log("sample_size:" + sample_size + " samples"); - _.each(series.results, function(result) { //var target = result.name; @@ -194,7 +191,7 @@ function (angular, _, kbn) { return output2; } - function convertTargetToQuery(options,target) { + function convertTargetToQuery(options, target) { if (!target.metric || target.hide) { return null; } diff --git a/public/app/plugins/datasource/kairosdb/partials/query.editor.html b/public/app/plugins/datasource/kairosdb/partials/query.editor.html index 23ddecabc4e..dc272ebbf4c 100644 --- a/public/app/plugins/datasource/kairosdb/partials/query.editor.html +++ b/public/app/plugins/datasource/kairosdb/partials/query.editor.html @@ -2,7 +2,7 @@
@@ -345,7 +345,7 @@
-
+
  • diff --git a/public/app/plugins/datasource/kairosdb/queryCtrl.js b/public/app/plugins/datasource/kairosdb/queryCtrl.js index 0de3c953152..9aad7c41fc9 100644 --- a/public/app/plugins/datasource/kairosdb/queryCtrl.js +++ b/public/app/plugins/datasource/kairosdb/queryCtrl.js @@ -9,7 +9,7 @@ function (angular, _) { var metricList = null; var targetLetters = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O']; - module.controller('KairosDBTargetCtrl', function($scope) { + module.controller('KairosDBQueryCtrl', function($scope) { $scope.init = function() { $scope.metric = { @@ -72,12 +72,12 @@ function (angular, _) { }; $scope.suggestTagKeys = function(query, callback) { - callback($scope.datasource.performTagSuggestQuery($scope.target.metric, $scope.rangeUnparsed, 'key','')); + callback($scope.datasource.performTagSuggestQuery($scope.target.metric, $scope.rangeUnparsed, 'key', '')); }; $scope.suggestTagValues = function(query, callback) { callback($scope.datasource - .performTagSuggestQuery($scope.target.metric,$scope.rangeUnparsed, 'value',$scope.target.currentTagKey)); + .performTagSuggestQuery($scope.target.metric, $scope.rangeUnparsed, 'value', $scope.target.currentTagKey)); }; // Filter metric by tag @@ -94,7 +94,7 @@ function (angular, _) { $scope.validateFilterTag(); if (!$scope.target.errors.tags) { - if (!_.has($scope.target.tags,$scope.target.currentTagKey)) { + if (!_.has($scope.target.tags, $scope.target.currentTagKey)) { $scope.target.tags[$scope.target.currentTagKey] = []; } $scope.target.tags[$scope.target.currentTagKey].push($scope.target.currentTagValue); diff --git a/public/test/specs/kairosdb-datasource-specs.js b/public/test/specs/kairosdb-datasource-specs.js new file mode 100644 index 00000000000..43004656573 --- /dev/null +++ b/public/test/specs/kairosdb-datasource-specs.js @@ -0,0 +1,63 @@ +define([ + 'helpers', + 'plugins/datasource/kairosdb/datasource' +], function(helpers) { + 'use strict'; + + describe('KairosDBDatasource', function() { + var ctx = new helpers.ServiceTestContext(); + + beforeEach(module('grafana.services')); + beforeEach(ctx.providePhase(['templateSrv'])); + beforeEach(ctx.createService('KairosDBDatasource')); + beforeEach(function() { + ctx.ds = new ctx.service({ url: ''}); + }); + + describe('When querying kairosdb with one target using query editor target spec', function() { + var results; + var urlExpected = "/api/v1/datapoints/query"; + var bodyExpected = { + metrics: [{ name: "test" }], + cache_time: 0, + start_relative: { + value: "1", + unit: "hours" + } + }; + + var query = { + range: { from: 'now-1h', to: 'now' }, + targets: [{ metric: 'test', downsampling: '(NONE)'}] + }; + + var response = { + queries: [{ + sample_size: 60, + results: [{ + name: "test", + values: [[1420070400000, 1]] + }] + }] + }; + + beforeEach(function() { + ctx.$httpBackend.expect('POST', urlExpected, bodyExpected).respond(response); + ctx.ds.query(query).then(function(data) { results = data; }); + ctx.$httpBackend.flush(); + }); + + it('should generate the correct query', function() { + ctx.$httpBackend.verifyNoOutstandingExpectation(); + }); + + it('should return series list', function() { + expect(results.data.length).to.be(1); + expect(results.data[0].target).to.be('test'); + }); + + }); + + }); + +}); diff --git a/public/test/test-main.js b/public/test/test-main.js index a38f8dca32b..b6fca85e9e5 100644 --- a/public/test/test-main.js +++ b/public/test/test-main.js @@ -128,6 +128,7 @@ require([ 'specs/influxQueryBuilder-specs', 'specs/influx09-querybuilder-specs', 'specs/influxdb-datasource-specs', + 'specs/kairosdb-datasource-specs', 'specs/graph-ctrl-specs', 'specs/graph-specs', 'specs/graph-tooltip-specs', @@ -150,4 +151,3 @@ require([ window.__karma__.start(); }); }); -