Commit 35f40b73 by Torkel Ödegaard

feat(plugins): upgraded opentsdb

parent b76449d1
...@@ -42,17 +42,17 @@ define([ ...@@ -42,17 +42,17 @@ define([
controller : 'DashboardImportCtrl', controller : 'DashboardImportCtrl',
}) })
.when('/datasources', { .when('/datasources', {
templateUrl: 'app/features/org/partials/datasources.html', templateUrl: 'app/features/datasources/partials/list.html',
controller : 'DataSourcesCtrl', controller : 'DataSourcesCtrl',
resolve: loadOrgBundle, resolve: loadOrgBundle,
}) })
.when('/datasources/edit/:id', { .when('/datasources/edit/:id', {
templateUrl: 'app/features/org/partials/datasourceEdit.html', templateUrl: 'app/features/datasources/partials/edit.html',
controller : 'DataSourceEditCtrl', controller : 'DataSourceEditCtrl',
resolve: loadOrgBundle, resolve: loadOrgBundle,
}) })
.when('/datasources/new', { .when('/datasources/new', {
templateUrl: 'app/features/org/partials/datasourceEdit.html', templateUrl: 'app/features/datasources/partials/edit.html',
controller : 'DataSourceEditCtrl', controller : 'DataSourceEditCtrl',
resolve: loadOrgBundle, resolve: loadOrgBundle,
}) })
......
declare var Datasource: any;
export default Datasource;
...@@ -3,25 +3,19 @@ define([ ...@@ -3,25 +3,19 @@ define([
'lodash', 'lodash',
'app/core/utils/datemath', 'app/core/utils/datemath',
'moment', 'moment',
'./directives',
'./queryCtrl', './queryCtrl',
], ],
function (angular, _, dateMath) { function (angular, _, dateMath) {
'use strict'; 'use strict';
var module = angular.module('grafana.services'); function OpenTSDBDatasource(instanceSettings, $q, backendSrv, templateSrv) {
this.type = 'opentsdb';
module.factory('OpenTSDBDatasource', function($q, backendSrv, templateSrv) { this.url = instanceSettings.url;
this.name = instanceSettings.name;
function OpenTSDBDatasource(datasource) { this.supportMetrics = true;
this.type = 'opentsdb';
this.url = datasource.url;
this.name = datasource.name;
this.supportMetrics = true;
}
// Called once per panel (graph) // Called once per panel (graph)
OpenTSDBDatasource.prototype.query = function(options) { this.query = function(options) {
var start = convertToTSDBTime(options.rangeRaw.from, false); var start = convertToTSDBTime(options.rangeRaw.from, false);
var end = convertToTSDBTime(options.rangeRaw.to, true); var end = convertToTSDBTime(options.rangeRaw.to, true);
var qs = []; var qs = [];
...@@ -60,7 +54,7 @@ function (angular, _, dateMath) { ...@@ -60,7 +54,7 @@ function (angular, _, dateMath) {
}); });
}; };
OpenTSDBDatasource.prototype.performTimeSeriesQuery = function(queries, start, end) { this.performTimeSeriesQuery = function(queries, start, end) {
var reqBody = { var reqBody = {
start: start, start: start,
queries: queries queries: queries
...@@ -80,13 +74,13 @@ function (angular, _, dateMath) { ...@@ -80,13 +74,13 @@ function (angular, _, dateMath) {
return backendSrv.datasourceRequest(options); return backendSrv.datasourceRequest(options);
}; };
OpenTSDBDatasource.prototype._performSuggestQuery = function(query, type) { this._performSuggestQuery = function(query, type) {
return this._get('/api/suggest', {type: type, q: query, max: 1000}).then(function(result) { return this._get('/api/suggest', {type: type, q: query, max: 1000}).then(function(result) {
return result.data; return result.data;
}); });
}; };
OpenTSDBDatasource.prototype._performMetricKeyValueLookup = function(metric, key) { this._performMetricKeyValueLookup = function(metric, key) {
if(!metric || !key) { if(!metric || !key) {
return $q.when([]); return $q.when([]);
} }
...@@ -105,7 +99,7 @@ function (angular, _, dateMath) { ...@@ -105,7 +99,7 @@ function (angular, _, dateMath) {
}); });
}; };
OpenTSDBDatasource.prototype._performMetricKeyLookup = function(metric) { this._performMetricKeyLookup = function(metric) {
if(!metric) { return $q.when([]); } if(!metric) { return $q.when([]); }
return this._get('/api/search/lookup', {m: metric, limit: 1000}).then(function(result) { return this._get('/api/search/lookup', {m: metric, limit: 1000}).then(function(result) {
...@@ -122,7 +116,7 @@ function (angular, _, dateMath) { ...@@ -122,7 +116,7 @@ function (angular, _, dateMath) {
}); });
}; };
OpenTSDBDatasource.prototype._get = function(relativeUrl, params) { this._get = function(relativeUrl, params) {
return backendSrv.datasourceRequest({ return backendSrv.datasourceRequest({
method: 'GET', method: 'GET',
url: this.url + relativeUrl, url: this.url + relativeUrl,
...@@ -130,7 +124,7 @@ function (angular, _, dateMath) { ...@@ -130,7 +124,7 @@ function (angular, _, dateMath) {
}); });
}; };
OpenTSDBDatasource.prototype.metricFindQuery = function(query) { this.metricFindQuery = function(query) {
if (!query) { return $q.when([]); } if (!query) { return $q.when([]); }
var interpolated; var interpolated;
...@@ -181,14 +175,14 @@ function (angular, _, dateMath) { ...@@ -181,14 +175,14 @@ function (angular, _, dateMath) {
return $q.when([]); return $q.when([]);
}; };
OpenTSDBDatasource.prototype.testDatasource = function() { this.testDatasource = function() {
return this._performSuggestQuery('cpu', 'metrics').then(function () { return this._performSuggestQuery('cpu', 'metrics').then(function () {
return { status: "success", message: "Data source is working", title: "Success" }; return { status: "success", message: "Data source is working", title: "Success" };
}); });
}; };
var aggregatorsPromise = null; var aggregatorsPromise = null;
OpenTSDBDatasource.prototype.getAggregators = function() { this.getAggregators = function() {
if (aggregatorsPromise) { return aggregatorsPromise; } if (aggregatorsPromise) { return aggregatorsPromise; }
aggregatorsPromise = this._get('/api/aggregators').then(function(result) { aggregatorsPromise = this._get('/api/aggregators').then(function(result) {
...@@ -311,7 +305,7 @@ function (angular, _, dateMath) { ...@@ -311,7 +305,7 @@ function (angular, _, dateMath) {
return date.valueOf(); return date.valueOf();
} }
return OpenTSDBDatasource; }
});
return OpenTSDBDatasource;
}); });
define([ define([
'angular', 'angular',
'./datasource',
], ],
function (angular) { function (angular, OpenTsDatasource) {
'use strict'; 'use strict';
var module = angular.module('grafana.directives'); var module = angular.module('grafana.directives');
...@@ -13,4 +14,11 @@ function (angular) { ...@@ -13,4 +14,11 @@ function (angular) {
}; };
}); });
module.directive('datasourceCustomSettingsViewOpentsdb', function() {
return {templateUrl: 'app/plugins/datasource/opentsdb/partials/config.html'};
});
return {
Datasource: OpenTsDatasource
};
}); });
...@@ -3,12 +3,7 @@ ...@@ -3,12 +3,7 @@
"name": "OpenTSDB", "name": "OpenTSDB",
"id": "opentsdb", "id": "opentsdb",
"serviceName": "OpenTSDBDatasource", "module": "app/plugins/datasource/opentsdb/module",
"module": "app/plugins/datasource/opentsdb/datasource",
"partials": {
"config": "app/plugins/datasource/opentsdb/partials/config.html"
},
"metrics": true, "metrics": true,
"defaultMatchFormat": "pipe" "defaultMatchFormat": "pipe"
......
define([ import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
'./helpers', import helpers from 'test/specs/helpers';
'app/plugins/datasource/opentsdb/datasource' import Datasource from "../datasource";
], function(helpers) {
'use strict';
describe('opentsdb', function() { describe('opentsdb', function() {
var ctx = new helpers.ServiceTestContext(); var ctx = new helpers.ServiceTestContext();
var instanceSettings = {url: '' };
beforeEach(module('grafana.core')); beforeEach(angularMocks.module('grafana.core'));
beforeEach(module('grafana.services')); beforeEach(angularMocks.module('grafana.services'));
beforeEach(ctx.providePhase(['backendSrv'])); beforeEach(ctx.providePhase(['backendSrv']));
beforeEach(ctx.createService('OpenTSDBDatasource')); beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
beforeEach(function() { ctx.$q = $q;
ctx.ds = new ctx.service({ url: [''] }); ctx.$httpBackend = $httpBackend;
}); ctx.$rootScope = $rootScope;
ctx.ds = $injector.instantiate(Datasource, {instanceSettings: instanceSettings});
describe('When performing metricFindQuery', function() { }));
var results;
var requestOptions;
beforeEach(function() { describe('When performing metricFindQuery', function() {
ctx.backendSrv.datasourceRequest = function(options) { var results;
requestOptions = options; var requestOptions;
return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
};
});
it('metrics() should generate api suggest query', function() { beforeEach(function() {
ctx.ds.metricFindQuery('metrics(pew)').then(function(data) { results = data; }); ctx.backendSrv.datasourceRequest = function(options) {
ctx.$rootScope.$apply(); requestOptions = options;
expect(requestOptions.url).to.be('/api/suggest'); return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
expect(requestOptions.params.type).to.be('metrics'); };
expect(requestOptions.params.q).to.be('pew'); });
});
it('tag_names(cpu) should generate looku query', function() { it('metrics() should generate api suggest query', function() {
ctx.ds.metricFindQuery('tag_names(cpu)').then(function(data) { results = data; }); ctx.ds.metricFindQuery('metrics(pew)').then(function(data) { results = data; });
ctx.$rootScope.$apply(); ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/search/lookup'); expect(requestOptions.url).to.be('/api/suggest');
expect(requestOptions.params.m).to.be('cpu'); expect(requestOptions.params.type).to.be('metrics');
}); expect(requestOptions.params.q).to.be('pew');
});
it('tag_values(cpu, test) should generate looku query', function() { it('tag_names(cpu) should generate looku query', function() {
ctx.ds.metricFindQuery('tag_values(cpu, hostname)').then(function(data) { results = data; }); ctx.ds.metricFindQuery('tag_names(cpu)').then(function(data) { results = data; });
ctx.$rootScope.$apply(); ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/search/lookup'); expect(requestOptions.url).to.be('/api/search/lookup');
expect(requestOptions.params.m).to.be('cpu{hostname=*}'); expect(requestOptions.params.m).to.be('cpu');
}); });
it('suggest_tagk() should generate api suggest query', function() { it('tag_values(cpu, test) should generate looku query', function() {
ctx.ds.metricFindQuery('suggest_tagk(foo)').then(function(data) { results = data; }); ctx.ds.metricFindQuery('tag_values(cpu, hostname)').then(function(data) { results = data; });
ctx.$rootScope.$apply(); ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/suggest'); expect(requestOptions.url).to.be('/api/search/lookup');
expect(requestOptions.params.type).to.be('tagk'); expect(requestOptions.params.m).to.be('cpu{hostname=*}');
expect(requestOptions.params.q).to.be('foo'); });
});
it('suggest_tagv() should generate api suggest query', function() { it('suggest_tagk() should generate api suggest query', function() {
ctx.ds.metricFindQuery('suggest_tagv(bar)').then(function(data) { results = data; }); ctx.ds.metricFindQuery('suggest_tagk(foo)').then(function(data) { results = data; });
ctx.$rootScope.$apply(); ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/suggest'); expect(requestOptions.url).to.be('/api/suggest');
expect(requestOptions.params.type).to.be('tagv'); expect(requestOptions.params.type).to.be('tagk');
expect(requestOptions.params.q).to.be('bar'); expect(requestOptions.params.q).to.be('foo');
}); });
it('suggest_tagv() should generate api suggest query', function() {
ctx.ds.metricFindQuery('suggest_tagv(bar)').then(function(data) { results = data; });
ctx.$rootScope.$apply();
expect(requestOptions.url).to.be('/api/suggest');
expect(requestOptions.params.type).to.be('tagv');
expect(requestOptions.params.q).to.be('bar');
}); });
}); });
}); });
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