Repository navigation
parser: Allow parsing arbitrary functions - #12170
Conversation
In Thanos we would like to start experimenting with custom functions that are currently not part of the PromQL spec. We would do this by adding an implementation for those functions in the Thanos engine: https://github.com/thanos-community/promql-engine and allow users to decide which engine they want to use on a per-query basis. Since we use the PromQL parser from Prometheus, injecting functions in the global `Functions` variable would mean they also become available for the Prometheus engine. To avoid this side-effect, this commit exposes a Parser interface in which the supported functions can be injected as an option. If not functions are injected, the parser implementation will default to the functions defined in the global Functions variable. Signed-off-by: Filip Petkovski <[email protected]>
75d0b4b to
97c7fff
Compare
Signed-off-by: Filip Petkovski <[email protected]>
|
While I appreciate your efforts, I cannot accept this pull request as we aim to maintain a consistent PromQL experience across the ecosystem. I would like to inquire about the types of functions that are not suitable for Prometheus upstream and whether they can be implemented (maybe even behind a feature flag). (Additionally, some users have already been overriding the exposed |
|
Thank you for the feedback. We wanted to experiment with the There are several forks out there that already add support for these functions, but I don't think Prometheus has made a decision yet on whether they make sense in prometheus/prometheus. |
|
In my opinion, we should move forward with implementing them in Prometheus behind a feature flag. Since the design document has stalled, with Alin commenting last, this is definitely something worth implementing and discussing upstream. |
|
Thanks for the feedback, and I am glad that Prometheus is willing to consider adding these functions under a feature flag. I will close this PR now and we will try to get ourselves unblocked in the short term. Maybe it's worth starting a discussion on this topic during a dev summit? |
|
Personally, I'm still not convinced adding However, coming from a very different angle, I am pretty convinced that we need to offer some way of injecting non-standard functions or aggregators into PromQL. This is mostly coming from the many discussions we had about adding specific statistical functions. There are just so many of them that we cannot simply add all, and it's really hard to make the call which ones are generally useful enough to make them "built-ins". We had discussed this at a dev-summit, and even contemplated adding some kind of scripting interface (embedded Lua, Python, R? 🤯 ), but maybe it has to be a simple way of adding functions at compile time. In any case, once there is a way of "loading custom libraries of PromQL functions", it would also be a way to offer something like |
|
It is possible to add fonctions at compile time. Some users do it already.
Functions is public for that reason. But you can't change per engine if you
have multiple engines running.
Le lun. 27 mars 2023, 15:44, Björn Rabenstein ***@***.***> a
écrit :
… Personally, I'm still not convinced adding xrate and friends to standard
PromQL is a net gain for the community.
However, coming from a very different angle, I am pretty convinced that we
need to offer *some* way of injecting non-standard functions or
aggregators into PromQL. This is mostly coming from the many discussions we
had about adding specific statistical functions. There are just so many of
them that we cannot simply add all, and it's really hard to make the call
which ones are generally useful enough to make them "built-ins". We had
discussed this at a dev-summit, and even contemplated adding some kind of
scripting interface (embedded Lua, Python, R? 🤯 ), but maybe it has to
be a simple way of adding functions at compile time. In any case, once
there is a way of "loading custom libraries of PromQL functions", it would
also be a way to offer something like xrate as a custom thing while still
clearly communicating that it is not a standard "built-in" function yet.
—
Reply to this email directly, view it on GitHub
<#12170 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AACHHJUPFSCKBGF62EI24RTW6GKTJANCNFSM6AAAAAAWDQ7G5M>
.
You are receiving this because your review was requested.Message ID:
***@***.***>
|
|
Thanks for your contribution, we have decided during our bug scrub to enable this change. |
|
Thank you, much appreciated ! |
#17977 replaced the package-level parser flags with parser.Options and, in doing so, removed parser.WithFunctions (added in #12170). Since then the only way for a downstream PromQL engine to parse its own functions is to add them to the global parser.Functions map, which also makes them parseable by every other parser in the process, including the one used by the Prometheus engine. Add a Functions field to parser.Options. When set, it replaces the default function set for that parser, as WithFunctions did; when nil, the default parser.Functions set is used. NewParser copies the map so later changes by the caller cannot affect or race with parsing, and RegisterFeatures now reports the functions the parser actually accepts. TestParseCustomFunctions used the internal newParserWithFunctions helper and added its function to the global Functions map, leaking it into the other tests of the package. It now uses the public API with its own map, and the helper is removed. Signed-off-by: Sandy Chen <[email protected]>
In Thanos we would like to start experimenting with custom functions that are currently not part of the PromQL spec. We would do this by adding an implementation for those functions to the Thanos engine and allow users to decide which engine they want to use on a per-query basis.
Since we use the PromQL parser from Prometheus, injecting functions in the global
Functionsvariable would mean they also become available for the Prometheus engine. To avoid this side-effect, this commit exposes a Parser interface in which the supported functions can be injected as an option. If no functions are injected, the parser implementation will default to the functions defined in the global Functions variable.