-
Notifications
You must be signed in to change notification settings - Fork 4.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
formatter context: new method to provide extension data #38232
Open
wbpcode
wants to merge
2
commits into
envoyproxy:main
Choose a base branch
from
wbpcode:dev-new-extension-formatter-context
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Continuation of discussion from this comment.
I think this is what I'm missing. Why is there a need for an opaque data-structure?
Generally speaking one should prefer abstraction (interfaces) over opaque data-structures, as they define the contract of what is allowed/expected.
What I'm trying to get away from is having void* structures as we used to have in C, and improve a bit if possible.
You have more domain knowledge here, so apologies in advance if my suggestion is naive/non-possible.
It would be best if a strategy pattern can be used here, but it really depends on the details.
Can you point out some of the use-cases so we can try to see if there's a shared interface?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah. I know an explict interface is better. But at some scenarios, we still require an
any
. We have lots of similar cases in Envoy code base, for example, theFilterState::Ojbect
, theSingleton::Instance
.We cannot assume the structure/behavior of the data that will be stored in
FilterState
orSingleton::Manager
, so, we can only use a opaque interface forFilterState::Ojbect
andSingleton::Instance
.The formatter context extension is the same case: we cannot assume the structure/behavior, so, opaque is used and setter/getter will determine the specific type/structure/behavior.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Now, I have two scenarios will use the formatter context extension.
First, it is used to store the request/response metadata in the generic proxy. Here is its definition:
By this extension, the generic-proxy-specific formatter commands could convert the
Formatter::Context::Extension
to theGenericProxy::FormatterContextExtension
and access the meadata of request/response of generic proxy.Second, it is used to store the parsed JSON of HTTP request in a custom HTTP filter. Then, this filter will extend a custom formatter command
%BODY(xxx)%
to access the request body content. Here is its definition:You can see, they have no any shared point. Only the caller could know the type and usage of the data.