mirror of
https://github.com/prometheus/prometheus.git
synced 2025-09-21 22:01:01 +02:00
* fix(parser): wrong end position aggregate expression Fixes: https://github.com/prometheus/prometheus/issues/16053 The position range of nested aggregate expression was wrong, for the expression "(sum(foo))" the position of "sum(foo)" should be 1-9, but the parser could not decide the end of the expression on pos 9, instead it read ahead to pos 10 and then emitted the aggregate. But we only kept the last closing position (10) and wrote that into the aggregate. The reason for this is that the parser cannot know from "(sum(foo)" alone if the aggregate is finished. It could be finished as in "(sum(foo))" but equally it could continue with group modifier as "(sum(foo) by (bar))". Previous fix in #16041 tried to keep track of parenthesis, but that is complicated because the error happens after closing two parenthesis. That fix introduced new bugs. This fix now addresses the issue directly. Since we have to step outside the parser state machine anyway, we can just add an algorithm to detect and fix the issue. That's Lexer.findPrevRightParen(). Signed-off-by: György Krajcsovits <gyorgy.krajcsovits@grafana.com>