diff --git a/public/app/plugins/datasource/graphite/graphite_query.ts b/public/app/plugins/datasource/graphite/graphite_query.ts index 40a6b1d8543..6e863958b78 100644 --- a/public/app/plugins/datasource/graphite/graphite_query.ts +++ b/public/app/plugins/datasource/graphite/graphite_query.ts @@ -98,7 +98,7 @@ export default class GraphiteQuery { this.functions.push(innerFunc); break; case 'series-ref': - if (this.segments.length > 0) { + if (this.segments.length > 0 || this.getSeriesByTagFuncIndex() >= 0) { this.addFunctionParameter(func, astNode.value); } else { this.segments.push(astNode); diff --git a/public/app/plugins/datasource/graphite/specs/graphite_query.test.ts b/public/app/plugins/datasource/graphite/specs/graphite_query.test.ts index 2169db16c25..311dfec333a 100644 --- a/public/app/plugins/datasource/graphite/specs/graphite_query.test.ts +++ b/public/app/plugins/datasource/graphite/specs/graphite_query.test.ts @@ -44,4 +44,16 @@ describe('Graphite query model', () => { 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'); + }); + }); }); diff --git a/public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts b/public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts index 13ac2a48223..d69f5235832 100644 --- a/public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts +++ b/public/app/plugins/datasource/graphite/specs/query_ctrl.test.ts @@ -24,7 +24,6 @@ describe('GraphiteQueryCtrl', () => { beforeEach(() => { GraphiteQueryCtrl.prototype.target = ctx.target; GraphiteQueryCtrl.prototype.datasource = ctx.datasource; - GraphiteQueryCtrl.prototype.panelCtrl = ctx.panelCtrl; 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', () => { beforeEach(() => { ctx.ctrl.target.target = 'movingAverage(prod.count, $var)';