Title: Expose stats api to lua filter scripts
Description: It would be great if lua filter scripts could somehow hook into the envoy stats infrastructure so that, for instance, they could increment custom counters based on conditions encountered during filtering. We're doing auth and some other operations via lua filters, and we need stats on things like how many requests are blocked. We currently get around this by using the httpCall functionality to hit a sidecar service that then increments the appropriate metrics.
/assign @venilnoronha
@venilnoronha any update on this feature? This feature would be very useful for us.
@jmarantz if one wants to implement this, what stats infra/API should be called today?
@dio you can look at how envoy-wasm repo is doing it.
The api today is very constraining but works.
@mandarjog awesome! Thank you. I'll take a look.
I haven't looked at the Lua filter implementation, but I'm assuming there's some mechanism to create and persist C++ objects in the context of a Lua extension. On the C++ side I'm assuming there's a (potentially bidirectional) map between various C++ objects and integer handles passed to Lua. I think the Wasm one keeps distinct integer ranges for each type of C++ object.
You can then get a Counter handle by string name, but just like in C++ this will acquire a global lock, so it's only appropriate to do so during some kind of init or load phase for the filter.
So if you are composing stat names at runtime I'd expose some sort of interface to create StatName so you can collect up the tokens you want to compose names from at init-time, and then you can join them at runtime and find and increment stats without taking locks.
Feel free to request a review from me on any PR.
@preethi29 I have a WIP branch but I haven't been actively working on it. I'm going to unassign myself, therefore.
/unassign @venilnoronha
/subscribe
Don't suppose this feature is in anyone's radar? We would like to add extra stats also to keep track of specific failed policies.
Same here. Such an API would be highly appreciated. @venilnoronha where can I find your branch?
@bobvanderlinden it was a local branch with everything hacked up, so I didn't push it.