Commit 8fcc370f by Torkel Ödegaard Committed by GitHub

Graphite: Fixes issue with seriesByTag & function with variable param (#17795)

Fixes #17696
parent 3045daed
......@@ -29,6 +29,7 @@ export default class GraphiteQuery {
this.functions = [];
this.segments = [];
this.tags = [];
this.seriesByTagUsed = false;
this.error = null;
if (this.target.textEditor) {
......@@ -57,17 +58,6 @@ export default class GraphiteQuery {
}
this.checkOtherSegmentsIndex = this.segments.length - 1;
this.checkForSeriesByTag();
}
checkForSeriesByTag() {
const seriesByTagFunc: any = _.find(this.functions, func => func.def.name === 'seriesByTag');
if (seriesByTagFunc) {
this.seriesByTagUsed = true;
seriesByTagFunc.hidden = true;
const tags = this.splitSeriesByTagParams(seriesByTagFunc);
this.tags = tags;
}
}
getSegmentPathUpTo(index) {
......@@ -98,6 +88,14 @@ export default class GraphiteQuery {
innerFunc.updateText();
this.functions.push(innerFunc);
// extract tags from seriesByTag function and hide function
if (innerFunc.def.name === 'seriesByTag' && !this.seriesByTagUsed) {
this.seriesByTagUsed = true;
innerFunc.hidden = true;
this.tags = this.splitSeriesByTagParams(innerFunc);
}
break;
case 'series-ref':
if (this.segments.length > 0 || this.getSeriesByTagFuncIndex() >= 0) {
......@@ -112,7 +110,7 @@ export default class GraphiteQuery {
this.addFunctionParameter(func, astNode.value);
break;
case 'metric':
if (this.segments.length > 0) {
if (this.segments.length || this.tags.length) {
this.addFunctionParameter(func, _.join(_.map(astNode.segments, 'value'), '.'));
} else {
this.segments = astNode.segments;
......
......@@ -57,4 +57,17 @@ describe('Graphite query model', () => {
expect(ctx.queryModel.functions[1].params[0]).toBe('#A');
});
});
describe('when query has seriesByTag and highestMax with variable param', () => {
beforeEach(() => {
ctx.target = { refId: 'A', target: `highestMax(seriesByTag('namespace=asd'), $limit)` };
ctx.targets = [ctx.target];
ctx.queryModel = new GraphiteQuery(ctx.datasource, ctx.target, ctx.templateSrv);
});
it('should add $limit to highestMax function param', () => {
expect(ctx.queryModel.segments.length).toBe(0);
expect(ctx.queryModel.functions[1].params[0]).toBe('$limit');
});
});
});
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