Skip to content

Commit

Permalink
pass timerange in meta data queries
Browse files Browse the repository at this point in the history
  • Loading branch information
svenklemm committed Aug 31, 2018
1 parent cd708d6 commit bcfb841
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
5 changes: 4 additions & 1 deletion public/app/plugins/datasource/mysql/datasource.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export class MysqlDatasource {
queryModel: MysqlQuery;

/** @ngInject **/
constructor(instanceSettings, private backendSrv, private $q, private templateSrv) {
constructor(instanceSettings, private backendSrv, private $q, private templateSrv, private timeSrv) {
this.name = instanceSettings.name;
this.id = instanceSettings.id;
this.responseParser = new ResponseParser(this.$q);
Expand Down Expand Up @@ -108,8 +108,11 @@ export class MysqlDatasource {
format: 'table',
};

const range = this.timeSrv.timeRange();
const data = {
queries: [interpolatedQuery],
from: range.from.valueOf().toString(),
to: range.to.valueOf().toString(),
};

if (optionalOptions && optionalOptions.range && optionalOptions.range.from) {
Expand Down
13 changes: 12 additions & 1 deletion public/app/plugins/datasource/mysql/specs/datasource.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,23 @@ describe('MySQLDatasource', function() {
replace: jest.fn(text => text),
};

const raw = {
from: moment.utc('2018-04-25 10:00'),
to: moment.utc('2018-04-25 11:00'),
};
const ctx = <any>{
backendSrv,
timeSrvMock: {
timeRange: () => ({
from: raw.from,
to: raw.to,
raw: raw,
}),
},
};

beforeEach(() => {
ctx.ds = new MysqlDatasource(instanceSettings, backendSrv, {}, templateSrv);
ctx.ds = new MysqlDatasource(instanceSettings, backendSrv, {}, templateSrv, ctx.timeSrvMock);
});

describe('When performing annotationQuery', function() {
Expand Down

0 comments on commit bcfb841

Please sign in to comment.