diff --git a/public/app/plugins/datasource/graphite/graphite_query.ts b/public/app/plugins/datasource/graphite/graphite_query.ts index 2a70667fdac..c97cf725459 100644 --- a/public/app/plugins/datasource/graphite/graphite_query.ts +++ b/public/app/plugins/datasource/graphite/graphite_query.ts @@ -91,27 +91,25 @@ export default class GraphiteQuery { this.functions.push(innerFunc); break; case 'series-ref': - this.addFunctionParameter(func, astNode.value, index, this.segments.length > 0); + if (this.segments.length > 0) { + this.addFunctionParameter(func, astNode.value, index, true); + } else { + this.segments.push(astNode); + } break; case 'bool': case 'string': case 'number': - if ((index-1) >= func.def.params.length) { - throw { message: 'invalid number of parameters to method ' + func.def.name }; - } var shiftBack = this.isShiftParamsBack(func); this.addFunctionParameter(func, astNode.value, index, shiftBack); - break; + break; case 'metric': if (this.segments.length > 0) { - if (astNode.segments.length !== 1) { - throw { message: 'Multiple metric params not supported, use text editor.' }; + this.addFunctionParameter(func, _.join(_.map(astNode.segments, 'value'), '.'), index, true); + } else { + this.segments = astNode.segments; } - this.addFunctionParameter(func, astNode.segments[0].value, index, true); break; - } - - this.segments = astNode.segments; } } @@ -149,6 +147,9 @@ export default class GraphiteQuery { if (shiftBack) { index = Math.max(index - 1, 0); } + if (index > func.def.params.length) { + throw { message: 'too many parameters for function ' + func.def.name }; + } func.params[index] = value; } diff --git a/public/app/plugins/datasource/graphite/query_ctrl.ts b/public/app/plugins/datasource/graphite/query_ctrl.ts index c14836b4bdd..f5daf01f7cc 100644 --- a/public/app/plugins/datasource/graphite/query_ctrl.ts +++ b/public/app/plugins/datasource/graphite/query_ctrl.ts @@ -62,6 +62,10 @@ export class GraphiteQueryCtrl extends QueryCtrl { } checkOtherSegments(fromIndex) { + if (this.queryModel.segments.length === 1 && this.queryModel.segments[0].type === 'series-ref') { + return; + } + if (fromIndex === 0) { this.addSelectMetricSegment(); return; @@ -108,8 +112,23 @@ export class GraphiteQueryCtrl extends QueryCtrl { if (altSegments.length === 0) { return altSegments; } + // add query references + if (index === 0) { + _.eachRight(this.panelCtrl.panel.targets, target => { + if (target.refId === this.queryModel.target.refId) { + return; + } + + altSegments.unshift(this.uiSegmentSrv.newSegment({ + type: 'series-ref', + value: '#' + target.refId, + expandable: false, + })); + }); + } + // add template variables - _.each(this.templateSrv.variables, variable => { + _.eachRight(this.templateSrv.variables, variable => { altSegments.unshift(this.uiSegmentSrv.newSegment({ type: 'template', value: '$' + variable.name, diff --git a/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts b/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts index 22d93976043..86c32c3c018 100644 --- a/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts +++ b/public/app/plugins/datasource/graphite/specs/query_ctrl_specs.ts @@ -95,11 +95,11 @@ describe('GraphiteQueryCtrl', function() { }); it('should not add select metric segment', function() { - expect(ctx.ctrl.segments.length).to.be(0); + expect(ctx.ctrl.segments.length).to.be(1); }); - it('should add both series refs as params', function() { - expect(ctx.ctrl.queryModel.functions[0].params.length).to.be(2); + it('should add second series ref as param', function() { + expect(ctx.ctrl.queryModel.functions[0].params.length).to.be(1); }); });