-
Notifications
You must be signed in to change notification settings - Fork 5k
route: keep the matched virtual host in the stream info #40065
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
Conversation
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Hi, @kyessenov , could you give first pass when you get some free time because seem you have some context of #39391. Thanks. |
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
…eep-virtualhost
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
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.
Some initial thoughts...
@@ -299,6 +299,13 @@ struct StreamInfoImpl : public StreamInfo { | |||
return *downstream_connection_info_provider_; | |||
} | |||
|
|||
const Router::VHostConstSharedPtr& vhost() const override { | |||
// TODO(wbpcode): There is an edge case where the route and virtual host be override | |||
// by the setRoute() of HTTP filter callbacks. But in that case the virtual host stored |
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.
That seems problematic? Filters can reprogram a route AFAIR?
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.
Basically, there should no developer will override the virtualhost in practices (although they could). This is an edge case that may never happen. So, I left a TODO here.
I actually think we can remove the reference of vhost in the route in the next PR. Then the one who override virtualhost will encounter a compile error. Then he could create a issue to require new solution for virtulhost override if there is an actual scenario.
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.
I refactor the implmentation, so we can get the vhost from the route if the setRoute() method is called. This resolve the problem the comment referred.
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
/retest |
…eep-virtualhost
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
/retest |
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.
Pull Request Overview
This PR updates the routing code to preserve and expose the matched virtual host in StreamInfo
, even when no route entry is found. Key changes include:
- Introducing a new
vhost()
accessor andVHostRoute
struct to carry both virtual host and route pointers through routing APIs. - Updating all call sites, mocks, and tests to use the new
virtualHost()->...
andstream_info.vhost()
. - Adjusting
METADATA
andCEL
formatters to pull metadata fromvhost()
when present, and adding an integration test for logging vhost metadata on unmatched routes.
Reviewed Changes
Copilot reviewed 44 out of 44 changed files in this pull request and generated no comments.
Show a summary per file
File | Description |
---|---|
envoy/stream_info/stream_info.h | Add pure-virtual vhost() to StreamInfo API |
source/common/stream_info/stream_info_impl.h | Implement and store vhost_ in stream info |
envoy/router/router.h | Introduce VHostRoute struct and change Config::route API |
source/common/router/* | Update internal routing to return and propagate vhost() |
source/extensions/formatter/metadata/* | Switch metadata formatter to use vhost() |
test/* | Update dozens of mocks and test assertions to reflect new API |
Comments suppressed due to low confidence (3)
test/extensions/formatter/metadata/metadata_test.cc:183
- [nitpick] Consider adding a unit test for the scenario where the route lookup fails but a virtual host is still matched (i.e.
route()==nullptr
butvhost()!=nullptr
) to ensure the formatter returns the vhost metadata as expected.
TEST_F(MetadataFormatterTest, VirtualHostMetadataNoVirtualHost) {
envoy/router/router.h:1374
- Add a brief comment above this struct explaining that it carries both the matched virtual host and the route pointer, and that consumers should check
.route
before dereferencing.
struct VHostRoute {
envoy/stream_info/stream_info.h:850
- Update the doc comment to note that
vhost()
may benullptr
if no virtual host was matched, so callers should guard accordingly.
virtual const Router::VHostConstSharedPtr& vhost() const PURE;
// The method cannot return the vhost_ directly because the vhost_ has different type with | ||
// the VHostConstSharedPtr and will create a temporary copy implicitly and result in error | ||
// of returning reference to local temporary object. | ||
return vhost_copy_; |
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.
Did we change signature to be able to store vhost shared ptr in stream info?
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.
Sorry, I missed this comment. Yeah, this change is necessary to ensure the vhost pointer in the stream info is always correct even when the setRoute
is used.
It's possible that the developers re-program the route in a custom filter and override the virtual host. This method ensure we can get a shared point from the route that provided by the custom filter.
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.
Oooof, this is a quite a large refactor, but I think the interface for stream info / route looks clean, and that's where most of the changes come from.
/assign-from @envoyproxy/senior-maintainers |
@envoyproxy/senior-maintainers assignee is @phlax |
/assign-from @envoyproxy/senior-maintainers |
@envoyproxy/senior-maintainers assignee is @RyanTheOptimist |
Thanks for the review!!! Most changes are test code to adapt to new interfaces. The actual core code changes are limited. |
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
The latest commit do following changes after @kyessenov 's approval:
|
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com>
/retest |
…0065) Commit Message: route: keep the matched virtual host in the stream info Additional Description: Now the virtual host will also be kept in the stream info. This is useful if there is a partial match. Then although the route is not found, we still could log some virtual host related metadata in the log. To close envoyproxy#39391 Risk Level: low. The core code change is very minor. Testing: unit/intergation. Docs Changes: n/a. Release Notes: added. Platform Specific Features: n/a. --------- Signed-off-by: wangbaiping(wbpcode) <wbphub@gmail.com> Signed-off-by: Anirban Nandi <anirbannandi@google.com>
Commit Message: route: keep the matched virtual host in the stream info
Additional Description:
Now the virtual host will also be kept in the stream info. This is useful if there is a partial match. Then although the route is not found, we still could log some virtual host related metadata in the log.
To close #39391
Risk Level: low. The core code change is very minor.
Testing: unit/intergation.
Docs Changes: n/a.
Release Notes: added.
Platform Specific Features: n/a.