envoyproxy / envoy

Cloud-native high-performance edge/middle/service proxy
https://www.envoyproxy.io
Apache License 2.0
24.31k stars 4.7k forks source link

New CEL convenience function: random() #34805

Open wtzhang23 opened 3 weeks ago

wtzhang23 commented 3 weeks ago

Title: New CEL convenience function: random()

Description:

Questions:

message CelRandomFunction { }

...

tyxia commented 3 weeks ago

@wtzhang23

Is this issue for sampling in access log OR for general random purpose? This is ongoing effort https://github.com/envoyproxy/envoy/pull/34611 for former.

Also, that will be great to introduce random feature in general rather than limiting to accessLog

wtzhang23 commented 3 weeks ago

Intended specifically for only using the CEL access log filter. I know it is possible to compose multiple access log filters together but I'd like to use CEL by itself for convenience sake. Especially should the expression change frequently.

I agree random is one of those features that would be useful everywhere, but it might be a good idea to not set the expectation that functions should be available everywhere. I also think that there is all sorts of functions that people would like and it would make sense to provide them the extensibility to compile in their own helper functions. Though we could probably keep it simple for this issue.

tyxia commented 3 weeks ago

If you are adding a CEL convenience function, it seems that it should not only be tied with access log, even if it is not available everywhere Limiting the scope to CEL SGTM

tyxia commented 3 weeks ago

cced @kyessenov as well

wtzhang23 commented 3 weeks ago

Will try to add it everywhere I can once I open a PR

wtzhang23 commented 3 days ago

Seems like x-request-id is already present so it may be better to simply use that? As in, in addition to the request.id attribute, we can add another attribute that converts it into a uint that can be used for randomness (e.g. use the request id extension's getInteger function)?

Anyways, I'm almost done with the function; just need to write unit tests.