Merge pull request #16111 from grafana/graphite-series-by-tag-issue

Graphite: Fixed issue with using series ref and series by tag
This commit is contained in:
Torkel Ödegaard 2019-03-22 12:24:40 +01:00 committed by GitHub
commit 31dc3cfcf4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 18 deletions

View File

@ -98,7 +98,7 @@ export default class GraphiteQuery {
this.functions.push(innerFunc); this.functions.push(innerFunc);
break; break;
case 'series-ref': case 'series-ref':
if (this.segments.length > 0) { if (this.segments.length > 0 || this.getSeriesByTagFuncIndex() >= 0) {
this.addFunctionParameter(func, astNode.value); this.addFunctionParameter(func, astNode.value);
} else { } else {
this.segments.push(astNode); this.segments.push(astNode);

View File

@ -44,4 +44,16 @@ describe('Graphite query model', () => {
expect(ctx.queryModel.target.targetFull).toBeDefined(); expect(ctx.queryModel.target.targetFull).toBeDefined();
}); });
}); });
describe('when query seriesByTag and series ref', () => {
beforeEach(() => {
ctx.target = { refId: 'A', target: `group(seriesByTag('namespace=asd'), #A)` };
ctx.targets = [ctx.target];
ctx.queryModel = new GraphiteQuery(ctx.datasource, ctx.target, ctx.templateSrv);
});
it('should keep group function series ref', () => {
expect(ctx.queryModel.functions[1].params[0]).toBe('#A');
});
});
}); });

View File

@ -24,7 +24,6 @@ describe('GraphiteQueryCtrl', () => {
beforeEach(() => { beforeEach(() => {
GraphiteQueryCtrl.prototype.target = ctx.target; GraphiteQueryCtrl.prototype.target = ctx.target;
GraphiteQueryCtrl.prototype.datasource = ctx.datasource; GraphiteQueryCtrl.prototype.datasource = ctx.datasource;
GraphiteQueryCtrl.prototype.panelCtrl = ctx.panelCtrl; GraphiteQueryCtrl.prototype.panelCtrl = ctx.panelCtrl;
ctx.ctrl = new GraphiteQueryCtrl( ctx.ctrl = new GraphiteQueryCtrl(
@ -84,22 +83,6 @@ describe('GraphiteQueryCtrl', () => {
}); });
}); });
describe('when initializing target without metric expression and only function', () => {
beforeEach(() => {
ctx.ctrl.target.target = 'asPercent(#A, #B)';
ctx.ctrl.datasource.metricFindQuery = () => Promise.resolve([]);
ctx.ctrl.parseTarget();
});
it('should not add select metric segment', () => {
expect(ctx.ctrl.segments.length).toBe(1);
});
it('should add second series ref as param', () => {
expect(ctx.ctrl.queryModel.functions[0].params.length).toBe(1);
});
});
describe('when initializing a target with single param func using variable', () => { describe('when initializing a target with single param func using variable', () => {
beforeEach(() => { beforeEach(() => {
ctx.ctrl.target.target = 'movingAverage(prod.count, $var)'; ctx.ctrl.target.target = 'movingAverage(prod.count, $var)';