mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
feat(plugins): upgraded opentsdb
This commit is contained in:
parent
b76449d151
commit
35f40b7312
@ -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,
|
||||||
})
|
})
|
||||||
|
3
public/app/plugins/datasource/opentsdb/datasource.d.ts
vendored
Normal file
3
public/app/plugins/datasource/opentsdb/datasource.d.ts
vendored
Normal file
@ -0,0 +1,3 @@
|
|||||||
|
declare var Datasource: any;
|
||||||
|
export default Datasource;
|
||||||
|
|
@ -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) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
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) {
|
|||||||
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) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
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) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
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) {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
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) {
|
|||||||
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) {
|
|||||||
return date.valueOf();
|
return date.valueOf();
|
||||||
}
|
}
|
||||||
|
|
||||||
return OpenTSDBDatasource;
|
}
|
||||||
});
|
|
||||||
|
|
||||||
|
return OpenTSDBDatasource;
|
||||||
});
|
});
|
||||||
|
@ -1,7 +1,8 @@
|
|||||||
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) {
|
|||||||
};
|
};
|
||||||
});
|
});
|
||||||
|
|
||||||
|
module.directive('datasourceCustomSettingsViewOpentsdb', function() {
|
||||||
|
return {templateUrl: 'app/plugins/datasource/opentsdb/partials/config.html'};
|
||||||
|
});
|
||||||
|
|
||||||
|
return {
|
||||||
|
Datasource: OpenTsDatasource
|
||||||
|
};
|
||||||
});
|
});
|
@ -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"
|
||||||
|
@ -0,0 +1,71 @@
|
|||||||
|
import {describe, beforeEach, it, sinon, expect, angularMocks} from 'test/lib/common';
|
||||||
|
import helpers from 'test/specs/helpers';
|
||||||
|
import Datasource from "../datasource";
|
||||||
|
|
||||||
|
describe('opentsdb', function() {
|
||||||
|
var ctx = new helpers.ServiceTestContext();
|
||||||
|
var instanceSettings = {url: '' };
|
||||||
|
|
||||||
|
beforeEach(angularMocks.module('grafana.core'));
|
||||||
|
beforeEach(angularMocks.module('grafana.services'));
|
||||||
|
beforeEach(ctx.providePhase(['backendSrv']));
|
||||||
|
|
||||||
|
beforeEach(angularMocks.inject(function($q, $rootScope, $httpBackend, $injector) {
|
||||||
|
ctx.$q = $q;
|
||||||
|
ctx.$httpBackend = $httpBackend;
|
||||||
|
ctx.$rootScope = $rootScope;
|
||||||
|
ctx.ds = $injector.instantiate(Datasource, {instanceSettings: instanceSettings});
|
||||||
|
}));
|
||||||
|
|
||||||
|
describe('When performing metricFindQuery', function() {
|
||||||
|
var results;
|
||||||
|
var requestOptions;
|
||||||
|
|
||||||
|
beforeEach(function() {
|
||||||
|
ctx.backendSrv.datasourceRequest = function(options) {
|
||||||
|
requestOptions = options;
|
||||||
|
return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
|
||||||
|
};
|
||||||
|
});
|
||||||
|
|
||||||
|
it('metrics() should generate api suggest query', function() {
|
||||||
|
ctx.ds.metricFindQuery('metrics(pew)').then(function(data) { results = data; });
|
||||||
|
ctx.$rootScope.$apply();
|
||||||
|
expect(requestOptions.url).to.be('/api/suggest');
|
||||||
|
expect(requestOptions.params.type).to.be('metrics');
|
||||||
|
expect(requestOptions.params.q).to.be('pew');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tag_names(cpu) should generate looku query', function() {
|
||||||
|
ctx.ds.metricFindQuery('tag_names(cpu)').then(function(data) { results = data; });
|
||||||
|
ctx.$rootScope.$apply();
|
||||||
|
expect(requestOptions.url).to.be('/api/search/lookup');
|
||||||
|
expect(requestOptions.params.m).to.be('cpu');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('tag_values(cpu, test) should generate looku query', function() {
|
||||||
|
ctx.ds.metricFindQuery('tag_values(cpu, hostname)').then(function(data) { results = data; });
|
||||||
|
ctx.$rootScope.$apply();
|
||||||
|
expect(requestOptions.url).to.be('/api/search/lookup');
|
||||||
|
expect(requestOptions.params.m).to.be('cpu{hostname=*}');
|
||||||
|
});
|
||||||
|
|
||||||
|
it('suggest_tagk() should generate api suggest query', function() {
|
||||||
|
ctx.ds.metricFindQuery('suggest_tagk(foo)').then(function(data) { results = data; });
|
||||||
|
ctx.$rootScope.$apply();
|
||||||
|
expect(requestOptions.url).to.be('/api/suggest');
|
||||||
|
expect(requestOptions.params.type).to.be('tagk');
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
});
|
||||||
|
|
@ -1,71 +0,0 @@
|
|||||||
define([
|
|
||||||
'./helpers',
|
|
||||||
'app/plugins/datasource/opentsdb/datasource'
|
|
||||||
], function(helpers) {
|
|
||||||
'use strict';
|
|
||||||
|
|
||||||
describe('opentsdb', function() {
|
|
||||||
var ctx = new helpers.ServiceTestContext();
|
|
||||||
|
|
||||||
beforeEach(module('grafana.core'));
|
|
||||||
beforeEach(module('grafana.services'));
|
|
||||||
beforeEach(ctx.providePhase(['backendSrv']));
|
|
||||||
|
|
||||||
beforeEach(ctx.createService('OpenTSDBDatasource'));
|
|
||||||
beforeEach(function() {
|
|
||||||
ctx.ds = new ctx.service({ url: [''] });
|
|
||||||
});
|
|
||||||
|
|
||||||
describe('When performing metricFindQuery', function() {
|
|
||||||
var results;
|
|
||||||
var requestOptions;
|
|
||||||
|
|
||||||
beforeEach(function() {
|
|
||||||
ctx.backendSrv.datasourceRequest = function(options) {
|
|
||||||
requestOptions = options;
|
|
||||||
return ctx.$q.when({data: [{ target: 'prod1.count', datapoints: [[10, 1], [12,1]] }]});
|
|
||||||
};
|
|
||||||
});
|
|
||||||
|
|
||||||
it('metrics() should generate api suggest query', function() {
|
|
||||||
ctx.ds.metricFindQuery('metrics(pew)').then(function(data) { results = data; });
|
|
||||||
ctx.$rootScope.$apply();
|
|
||||||
expect(requestOptions.url).to.be('/api/suggest');
|
|
||||||
expect(requestOptions.params.type).to.be('metrics');
|
|
||||||
expect(requestOptions.params.q).to.be('pew');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('tag_names(cpu) should generate looku query', function() {
|
|
||||||
ctx.ds.metricFindQuery('tag_names(cpu)').then(function(data) { results = data; });
|
|
||||||
ctx.$rootScope.$apply();
|
|
||||||
expect(requestOptions.url).to.be('/api/search/lookup');
|
|
||||||
expect(requestOptions.params.m).to.be('cpu');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('tag_values(cpu, test) should generate looku query', function() {
|
|
||||||
ctx.ds.metricFindQuery('tag_values(cpu, hostname)').then(function(data) { results = data; });
|
|
||||||
ctx.$rootScope.$apply();
|
|
||||||
expect(requestOptions.url).to.be('/api/search/lookup');
|
|
||||||
expect(requestOptions.params.m).to.be('cpu{hostname=*}');
|
|
||||||
});
|
|
||||||
|
|
||||||
it('suggest_tagk() should generate api suggest query', function() {
|
|
||||||
ctx.ds.metricFindQuery('suggest_tagk(foo)').then(function(data) { results = data; });
|
|
||||||
ctx.$rootScope.$apply();
|
|
||||||
expect(requestOptions.url).to.be('/api/suggest');
|
|
||||||
expect(requestOptions.params.type).to.be('tagk');
|
|
||||||
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');
|
|
||||||
});
|
|
||||||
|
|
||||||
});
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user