Repository navigation
Conversation
Signed-off-by: Shriram Rajagopalan <[email protected]>
| namespace StreamInfo { | ||
|
|
||
| // Mutable filter state wrapping metadata object. State within this | ||
| // metadata should still be namespaced per usual reverse dns naming |
There was a problem hiding this comment.
What's the tradeoff here between having the namespacing at the FilterState level and just embedding a Struct here? Shouldn't it be possible to still preserve the existing semantics this way?
There was a problem hiding this comment.
Existing code also relies on directly accessing the map inside the Metadata, something that FilterState does not offer. All of this can be fixed, but its a lot of work across the code. Redirecting dynamic metadata calls to the state stored in filter state offers a compromise in that we still get to store this in a quarantined manner
There was a problem hiding this comment.
I'm less concerned about the churn to existing code as with getting the right long term abstraction in place. I do realize though that it's a bit unfair to make this statement without skin in the game, as I'm not doing the refactoring work. Would be interested in hearing from other folks like this, such as @mattklein123.
There was a problem hiding this comment.
Yeah tough call. What about one of these two options:
- Mark
dynamicMetadata()as deprecated and subject to removal in a future version. No new code should use it. - More aggressively, change the name to
deprecatedDynamicMetadata()to really make sure people understand they shouldn't be using it? This would require some find/replace across the code and some trivial breakage to third party filters, but with some comments on the deprecated functions on how people should migrate away I think this would be a good thing? We could also open issues on all the existing call sites within the repo to be cleaned up as tech debt?
There was a problem hiding this comment.
That sounds good by me. That said, I would still propose to keep the well known FilterState called envoy.streaminfo.dynamicMetadata around. Allows people to pile stuff into envoy.streaminfo.dynamicmetadata filter State, where they still have to use soem well defined namespaces to put things in. At the same time, it allows consumers to inspect whats been stored in this dynamic filter state (map semantics), without needing to add all those interfaces to FilterState.
From that point of view, would it make sense to rename this to wellKnownDynamicFilterState() ? Its still the same find/replace operation with no tech debt
There was a problem hiding this comment.
OK, I just chatted with @mattklein123 offline. I'm happy with a combination of #4873 (comment), adding a well known envoy.streaminfo.dynamicmetadata for those who really want it and a personal request to provide some well-throught out guidance on the pros and cons of using a global grab bag vs. namespaced data. I'm happy to sign-off if we have all three.
There was a problem hiding this comment.
I just talked to @htuch offline and I agree we should deprecate it, and file follow up tech debt issues to fix both access logging and Lua to specify both a namespace and item when access the struct.
Beyond this, if people want to use a grab bag in a well known namespace that is up to them.
Is that fair?
There was a problem hiding this comment.
What to do about all the users of metadata match thats is a common user of the metadata struct obtained from Dynamic metadata? Provide it with full access to the internal state in the map? Even then, its going to be full of exception catch code if the FilterState doesn't match the Struct object type.
There was a problem hiding this comment.
I think for this case we can avoid exception catch by allowing code to test to see if the map contains a struct type.
There was a problem hiding this comment.
Yeah, but I am not sure Randy and co would be happy with that given that they wanted super strict semantics on how data can be accessed across filters
Signed-off-by: Shriram Rajagopalan <[email protected]>
…adata_in_fs Signed-off-by: Shriram Rajagopalan <[email protected]>
| * @return a map of data names and their corresponding objects. | ||
| */ | ||
| const std::map<std::string, std::unique_ptr<FilterObject> getRawState() const PURE; | ||
|
|
There was a problem hiding this comment.
So in the absence of a well known namespace, given that we have things like MetadataMatcher etc that rely on iterating through the map, I hope this interface is okay. If this is too much of a blasphemy for the filter state's strict write-once semantics, then I can split the write-many store out into a separate map inside filter state and return that map directly.
|
Having had some time to think about this, the root of the problem is the introduction of this internal typed filterState::Object, which prevents things like dumping the entire filter state on the wire, or allowing end users to abstractions like metadata matcher to match on the filter state. What we need is namespaced filter state wrapping generic Structs so that we can do things like #4862 (that the Google folks themselves wanted), as well as metadata matchers in RBAC or other places. Something like #4862 is exactly what I am looking for in Istio as well. these are properties that dynamic metadata supports today. It has nothing to do with a global dumping ground, nor does dynamic metadata allow such a thing anyway. If we can preserve these two properties (ability to dump the entire state on the wire and allowing end users to match on the state - which requires a flexible object, aka (sadly) struct -- then I am happy. There are two ways to go about this:
|
|
Either way, I would like some resolution asap as I have been on this for over a month, but still made no progress on the actual internal use case that requires access to all the info generated by all filters. |
|
@rshriram can't we have some kind of |
|
I am not the C++ expert here. So I leave those bits to you guys. But here are example snippets of code that need to be supported: access_log: metadata matchers: The entire set of functions here take envoy::api::core::metadata as argument. We could make it such that they take FilterState also as argument, and repeat the logic in metadataValue() in some other function.. I think the key is being able to get the entire dynamic state map (string, structs) and dumping it on the wire as is. I dont know how to achieve this with a map of custom types (filter state object or subtypes) without adding a lot of intermediaries, and custom iterators, on the fly map creations, etc. |
|
@rshriram if you really are wanting to support existing Struct semantics with little change, then you are forced to embed a If you want to be a bit more abstract, you could create an |
|
to clarify, streamInfo.dynamicMetadata returns envoy.api.v2.core.metadata which is a The fact that both sides are aware of this well defined proto makes it alluring when you want to dump the filter state on the wire. This has little to do with Struct, and more to do with protos, and the map semantics. Neither of which are offered by FilterState today (it requires typed C++ objects, and doesn't allow grabbing the entire map of <string, Struct> to be dumped on the wire). |
|
@rshriram @htuch what if we have a read-only iterator type function which will iterate through filter filter state map and return objects that are of a specific type using RTTI? Something like this: Where the callback is called with each namespace that has an object of a specific type? Then I think everything else could be implemented on top of this from an iteration/matching perspective? |
|
This was exactly my point. What is the trade off here? in the name of efficiency for a select set of internal use cases (needing to access typed filter state object), we are forcing all others (access logs, metadata matchers, etc.) to create maps on the fly, and populate them with strings, and structs so that they can serialize them on the wire. We have documented use of the |
|
Also keep in mind that metadataMatcher is used by other parts of envoy (ones dealing with statically defined metadata), and not just rbac which uses dynamic metadata. So, if we are to use that code as is, then we have to collect and create a metadata proto object before using metadata matcher. Or change the function signatures and impose this tax on all other users of metadata. This was also my point earlier -- as to how strongly do we feel about needing to ONLY use typed filter objects (not protos) and the code/perf overhead imposed on everybody else. If we separate the filter state into two maps, then we can allow the second map to be map<string, struct> and maintain the existing semantics. |
|
@rshriram why would it suffer? My point is we can offer the existing interface on top of the new interface without any major change to callers who want the map<string, struct> paradigm? |
|
You would have to allocate the map on the fly right? How would code like this get transformed? dynamicMetadata returns map<string, struct> (pre-allocated) |
|
@rshriram it would be an iterator, returning references as it moves over the |
|
https://github.com/envoyproxy/envoy/blob/master/source/common/config/metadata.cc#L6 is used by https://github.com/envoyproxy/envoy/blob/master/source/extensions/filters/common/rbac/engine_impl.cc#L20 called by https://github.com/envoyproxy/envoy/blob/master/source/extensions/filters/http/rbac/rbac_filter.cc#L100 which requires a metadata Object (map<string, struct>) where the query is determined by user input. and then this: this can be fixed through the iterator but the former is not. |
|
@rshriram yes, if you want to preserve the exact current implementation, you'll need to use |
|
+1 to what @htuch is saying, but TBH at this point I think we are splitting hairs here and it doesn't really matter. |
|
Metadata matcher is being used by other parts of envoy, not just RBAC. RBAC is simply piggy backing on it. So, yes its what I stated earlier. We duplicate the entire metadata match logic but without the metadata proto stuff, to decouple RBAC from metadata. This seems like way too much work to preserve the typed C++ object stuff in filter state. I am going to have to close this PR as its more work than I originally estimated. I am happy to give pointers to someone interested in rewriting the code. |
Since dynamic metadata is being used everywhere, there is a non trivial amount of code that needs to be rewired to use the FilterState abstractions. Existing code also relies on directly accessing the map inside the Metadata, something that FilterState does not offer.
So, as a temporary measure, I have re-routed all dynamic metadata calls to a well known mutable FilterState object (envoy.streaminfo.dynamicmetadata). Note that state inside this filter state object is still namespaced per usual conventions (reverse dns filter name, etc.). This redirection preserves the existing setDynamicMetadata(), and dynamicMetadata() interfaces, while still using the unified state management abstractions (aka filter state).
Thoughts @mattklein123 / @htuch before making this code compile?
Signed-off-by: Shriram Rajagopalan [email protected]