Commit 232f980c by Torkel Ödegaard

More work on restoring features after moving to plugin model for datasources, no…

More work on restoring features after moving to plugin model for datasources, no annotations work again #1276 #1472
parent 4a72c37f
......@@ -38,6 +38,7 @@ func getFrontendSettingsMap(c *middleware.Context) (map[string]interface{}, erro
var dsMap = map[string]interface{}{
"type": ds.Type,
"name": ds.Name,
"url": url,
}
......
......@@ -72,7 +72,7 @@
</div>
</div>
<div ng-include src="currentDatasource.editorSrc">
<div ng-include src="currentDatasource.meta.partials.annotations">
</div>
<br>
......
......@@ -45,5 +45,5 @@
<div class="editor-row">
<br>
<button class="btn btn-success" ng-click="addLink()">Add link</button>
<button class="btn btn-inverse" ng-click="addLink()"><i class="fa fa-plus"></i> Add link</button>
</div>
......@@ -9,7 +9,7 @@
"partials": {
"config": "app/plugins/datasource/elasticsearch/partials/config.html",
"annotations": "app/plugins/datasource/elasticsearch/partials/query.editor.html"
"annotations": "app/plugins/datasource/elasticsearch/partials/annotations.editor.html"
},
"annotations": true
......
......@@ -10,7 +10,7 @@
"partials": {
"config": "app/plugins/datasource/graphite/partials/config.html",
"query": "app/plugins/datasource/graphite/partials/query.editor.html",
"annotations": "app/plugins/datasource/graphite/partials/query.editor.html"
"annotations": "app/plugins/datasource/graphite/partials/annotations.editor.html"
},
"metrics": true,
......
......@@ -10,7 +10,7 @@
"partials": {
"config": "app/plugins/datasource/influxdb/partials/config.html",
"query": "app/plugins/datasource/influxdb/partials/query.editor.html",
"annotations": "app/plugins/datasource/influxdb/partials/query.editor.html"
"annotations": "app/plugins/datasource/influxdb/partials/annotations.editor.html"
},
"metrics": true,
......
......@@ -10,7 +10,7 @@
"partials": {
"config": "app/plugins/datasource/influxdb_08/partials/config.html",
"query": "app/plugins/datasource/influxdb_08/partials/query.editor.html",
"annotations": "app/plugins/datasource/influxdb_08/partials/query.editor.html"
"annotations": "app/plugins/datasource/influxdb_08/partials/annotations.editor.html"
},
"metrics": true,
......
......@@ -20,13 +20,15 @@ function (angular, _, config) {
_.each(config.datasources, function(value, key) {
if (value.meta && value.meta.metrics) {
self.metricSources.push({ value: key, name: key });
}
self.metricSources.push({
value: key === config.defaultDatasource ? null : key,
name: key
});
if (!config.defaultDatasource) {
$rootScope.appEvent('alert-error', ["No default data source found", ""]);
}
if (value.meta && value.meta.annotations) {
self.annotationSources.push(value);
}
});
};
this.get = function(name) {
......
define([
'features/influxdb/queryBuilder'
], function(/*InfluxQueryBuilder*/) {
'plugins/datasource/influxdb_08/queryBuilder'
], function(InfluxQueryBuilder) {
'use strict';
// describe('InfluxQueryBuilder', function() {
//
// describe('series with conditon and group by', function() {
// var builder = new InfluxQueryBuilder({
// series: 'google.test',
// column: 'value',
// function: 'mean',
// condition: "code=1",
// groupby_field: 'code'
// });
//
// var query = builder.build();
//
// it('should generate correct query', function() {
// expect(query).to.be('select code, mean(value) from "google.test" where $timeFilter and code=1 ' +
// 'group by time($interval), code order asc');
// });
//
// it('should expose groupByFiled', function() {
// expect(builder.groupByField).to.be('code');
// });
//
// });
//
// describe('series with fill and minimum group by time', function() {
// var builder = new InfluxQueryBuilder({
// series: 'google.test',
// column: 'value',
// function: 'mean',
// fill: '0',
// });
//
// var query = builder.build();
//
// it('should generate correct query', function() {
// expect(query).to.be('select mean(value) from "google.test" where $timeFilter ' +
// 'group by time($interval) fill(0) order asc');
// });
//
// });
//
// describe('merge function detection', function() {
// it('should not quote wrap regex merged series', function() {
// var builder = new InfluxQueryBuilder({
// series: 'merge(/^google.test/)',
// column: 'value',
// function: 'mean'
// });
//
// var query = builder.build();
//
// expect(query).to.be('select mean(value) from merge(/^google.test/) where $timeFilter ' +
// 'group by time($interval) order asc');
// });
//
// it('should quote wrap series names that start with "merge"', function() {
// var builder = new InfluxQueryBuilder({
// series: 'merge.google.test',
// column: 'value',
// function: 'mean'
// });
//
// var query = builder.build();
//
// expect(query).to.be('select mean(value) from "merge.google.test" where $timeFilter ' +
// 'group by time($interval) order asc');
// });
//
// });
//
// });
describe('InfluxQueryBuilder', function() {
describe('series with conditon and group by', function() {
var builder = new InfluxQueryBuilder({
series: 'google.test',
column: 'value',
function: 'mean',
condition: "code=1",
groupby_field: 'code'
});
var query = builder.build();
it('should generate correct query', function() {
expect(query).to.be('select code, mean(value) from "google.test" where $timeFilter and code=1 ' +
'group by time($interval), code order asc');
});
it('should expose groupByFiled', function() {
expect(builder.groupByField).to.be('code');
});
});
describe('series with fill and minimum group by time', function() {
var builder = new InfluxQueryBuilder({
series: 'google.test',
column: 'value',
function: 'mean',
fill: '0',
});
var query = builder.build();
it('should generate correct query', function() {
expect(query).to.be('select mean(value) from "google.test" where $timeFilter ' +
'group by time($interval) fill(0) order asc');
});
});
describe('merge function detection', function() {
it('should not quote wrap regex merged series', function() {
var builder = new InfluxQueryBuilder({
series: 'merge(/^google.test/)',
column: 'value',
function: 'mean'
});
var query = builder.build();
expect(query).to.be('select mean(value) from merge(/^google.test/) where $timeFilter ' +
'group by time($interval) order asc');
});
it('should quote wrap series names that start with "merge"', function() {
var builder = new InfluxQueryBuilder({
series: 'merge.google.test',
column: 'value',
function: 'mean'
});
var query = builder.build();
expect(query).to.be('select mean(value) from "merge.google.test" where $timeFilter ' +
'group by time($interval) order asc');
});
});
});
});
define([
'helpers',
'features/influxdb/datasource'
], function(/*helpers*/) {
'plugins/datasource/influxdb_08/datasource'
], function(helpers) {
'use strict';
// describe('InfluxDatasource', function() {
// var ctx = new helpers.ServiceTestContext();
//
// beforeEach(module('grafana.services'));
// beforeEach(ctx.providePhase(['templateSrv']));
// beforeEach(ctx.createService('InfluxDatasource'));
// beforeEach(function() {
// ctx.ds = new ctx.service({ url: '', user: 'test', password: 'mupp' });
// });
//
// describe('When querying influxdb with one target using query editor target spec', function() {
// var results;
// var urlExpected = "/series?p=mupp&q=select+mean(value)+from+%22test%22"+
// "+where+time+%3E+now()-1h+group+by+time(1s)+order+asc";
// var query = {
// range: { from: 'now-1h', to: 'now' },
// targets: [{ series: 'test', column: 'value', function: 'mean' }],
// interval: '1s'
// };
//
// var response = [{
// columns: ["time", "sequence_nr", "value"],
// name: 'test',
// points: [[10, 1, 1]],
// }];
//
// beforeEach(function() {
// ctx.$httpBackend.expect('GET', urlExpected).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.value');
// });
//
// });
//
// describe('When querying influxdb with one raw query', function() {
// var results;
// var urlExpected = "/series?p=mupp&q=select+value+from+series"+
// "+where+time+%3E+now()-1h";
// var query = {
// range: { from: 'now-1h', to: 'now' },
// targets: [{ query: "select value from series where $timeFilter", rawQuery: true }]
// };
//
// var response = [];
//
// beforeEach(function() {
// ctx.$httpBackend.expect('GET', urlExpected).respond(response);
// ctx.ds.query(query).then(function(data) { results = data; });
// ctx.$httpBackend.flush();
// });
//
// it('should generate the correct query', function() {
// ctx.$httpBackend.verifyNoOutstandingExpectation();
// });
//
// });
//
// describe('When issuing annotation query', function() {
// var results;
// var urlExpected = "/series?p=mupp&q=select+title+from+events.backend_01"+
// "+where+time+%3E+now()-1h";
//
// var range = { from: 'now-1h', to: 'now' };
// var annotation = { query: 'select title from events.$server where $timeFilter' };
// var response = [];
//
// beforeEach(function() {
// ctx.templateSrv.replace = function(str) {
// return str.replace('$server', 'backend_01');
// };
// ctx.$httpBackend.expect('GET', urlExpected).respond(response);
// ctx.ds.annotationQuery(annotation, range).then(function(data) { results = data; });
// ctx.$httpBackend.flush();
// });
//
// it('should generate the correct query', function() {
// ctx.$httpBackend.verifyNoOutstandingExpectation();
// });
//
// });
//
// });
//
describe('InfluxDatasource', function() {
var ctx = new helpers.ServiceTestContext();
beforeEach(module('grafana.services'));
beforeEach(ctx.providePhase(['templateSrv']));
beforeEach(ctx.createService('InfluxDatasource_08'));
beforeEach(function() {
ctx.ds = new ctx.service({ url: '', user: 'test', password: 'mupp' });
});
describe('When querying influxdb with one target using query editor target spec', function() {
var results;
var urlExpected = "/series?p=mupp&q=select+mean(value)+from+%22test%22"+
"+where+time+%3E+now()-1h+group+by+time(1s)+order+asc";
var query = {
range: { from: 'now-1h', to: 'now' },
targets: [{ series: 'test', column: 'value', function: 'mean' }],
interval: '1s'
};
var response = [{
columns: ["time", "sequence_nr", "value"],
name: 'test',
points: [[10, 1, 1]],
}];
beforeEach(function() {
ctx.$httpBackend.expect('GET', urlExpected).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.value');
});
});
describe('When querying influxdb with one raw query', function() {
var results;
var urlExpected = "/series?p=mupp&q=select+value+from+series"+
"+where+time+%3E+now()-1h";
var query = {
range: { from: 'now-1h', to: 'now' },
targets: [{ query: "select value from series where $timeFilter", rawQuery: true }]
};
var response = [];
beforeEach(function() {
ctx.$httpBackend.expect('GET', urlExpected).respond(response);
ctx.ds.query(query).then(function(data) { results = data; });
ctx.$httpBackend.flush();
});
it('should generate the correct query', function() {
ctx.$httpBackend.verifyNoOutstandingExpectation();
});
});
describe('When issuing annotation query', function() {
var results;
var urlExpected = "/series?p=mupp&q=select+title+from+events.backend_01"+
"+where+time+%3E+now()-1h";
var range = { from: 'now-1h', to: 'now' };
var annotation = { query: 'select title from events.$server where $timeFilter' };
var response = [];
beforeEach(function() {
ctx.templateSrv.replace = function(str) {
return str.replace('$server', 'backend_01');
};
ctx.$httpBackend.expect('GET', urlExpected).respond(response);
ctx.ds.annotationQuery(annotation, range).then(function(data) { results = data; });
ctx.$httpBackend.flush();
});
it('should generate the correct query', function() {
ctx.$httpBackend.verifyNoOutstandingExpectation();
});
});
});
});
......@@ -38,7 +38,7 @@ define([
scenario.setupFn();
var ds = {};
ds.metricFindQuery = sinon.stub().returns(ctx.$q.when(scenario.queryResult));
ctx.datasourceSrv.get = sinon.stub().returns(ds);
ctx.datasourceSrv.get = sinon.stub().returns(ctx.$q.when(ds));
ctx.service.updateOptions(scenario.variable);
ctx.$rootScope.$digest();
......
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