Skip to content

4.x: register routing in weighted order of Server and HTTP Features #8826

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

Merged
merged 5 commits into from
Jun 4, 2024

Conversation

tomas-langer
Copy link
Member

@tomas-langer tomas-langer commented May 31, 2024

Resolves: #8816

Description

Correctly handle order of Server Features and HTTP Features when registering non-HTTP Feature elements to the routing.

With the updated version, all elements (filters, routes, services) are ordered depending on the feature's weight. This is achieved by creating a new HttpFeature for each Server Feature with the same weight, that collects all registrations and applies them once the HTTP Features are ordered by weight. HttpFeature registered from a Server Feature is left intact and applied on the real builder (as this already works as it should)

Documentation

This aligns with the internal documentation of feature weights.

I have added update of WebServer documentation in the latest commit.

…stering non-HTTP Feature elements to the routing.

With the updated version, all elements (filters, routes, services) are ordered depending on the feature's weight.
This is achieved by creating a new HttpFeature for each Server Feature with the same weight, that collects all registrations and applies them once the HTTP Features are ordered by weight.
HttpFeature registered from a Server Feature is left intact and applied on the real builder (as this already works as it should)
@tomas-langer tomas-langer added bug Something isn't working webserver 4.x Version 4.x labels May 31, 2024
@tomas-langer tomas-langer added this to the 4.0.10 milestone May 31, 2024
@tomas-langer tomas-langer self-assigned this May 31, 2024
@oracle-contributor-agreement oracle-contributor-agreement bot added the OCA Verified All contributors have signed the Oracle Contributor Agreement. label May 31, 2024
@tjquinno
Copy link
Member

The coding changes look OK to me, although I do not know this area of the system.

The user whose questions raised our awareness of this issue has specifically asked for public documentation explaining, first, the ordering of filters vs. handlers (maybe we think it should be intuitive but we can at least state what that ordering is) and, second, how weighting affects that ordering.

Ideally such a doc update should be part of this PR...maybe a brief section on the webserver page in the request handling section?

@RickyFrost
Copy link

RickyFrost commented May 31, 2024

Tim, I was also asking about the ordering of filters vs filters from features. It seems like an undue burden to create a ServerFeature, and an HttpFeature, just so I can correctly weight my filter, don't you think? Seems like that would be buried too deep in uptake, and be subject to unnecessary brittleness for each new release... Sounds like a good argument for a "standard" feature where you can plug in your filter (with a weight, and a name maybe?).

@tomas-langer
Copy link
Member Author

tomas-langer commented Jun 3, 2024

Tim, I was also asking about the ordering of filters vs filters from features. It seems like an undue burden to create a ServerFeature, and an HttpFeature, just so I can correctly weight my filter, don't you think? Seems like that would be buried too deep in uptake, and be subject to unnecessary brittleness for each new release... Sounds like a good argument for a "standard" feature where you can plug in your filter (with a weight, and a name maybe?).

After this PR, you can either create an HttpFeature or a ServerFeature - depending on your use case.
The filters registered directly in routing are always ordered by insertion order.

So the ordering is:

- filters, routes, `HttpService` from features (server or HTTP) that have higher than default weight
- filters, routes, `HttpService` from routing ordered by insertion
- filters, routes, `HttpService` from features that have lower than default weight

Routing is "just" another HTTP feature that has default weight (except for the capability to register HttpFeatures), that is why you cannot register a filter outside of its scope.
We could add a method addFilter(Filter filter, double weight) and wrap it in an HttpFeature ourself, if you think this would improve your use case a lot.
Or would you prefer to analyze the filter instance, and if it is weighted, use its weight?

@tomas-langer
Copy link
Member Author

After a discussion with @RickyFrost, I still think we should require a feature to have filter/routing weighted. Otherwise we may end up with confusing behavior

Added documentation for Context feature.
Reorganized webserver.adoc, as some sections were within wrong chapters; updated TOC
@tomas-langer tomas-langer requested a review from ljamen June 4, 2024 10:54
@tomas-langer
Copy link
Member Author

Updated documentation of WebServer

danielkec
danielkec previously approved these changes Jun 4, 2024
Copy link
Contributor

@danielkec danielkec left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just a typo

Co-authored-by: Daniel Kec <[email protected]>
Copy link
Member

@tjquinno tjquinno left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The doc updates do help. The coding changes LGTM but this is not an area of the system I know well.

@tomas-langer tomas-langer merged commit 2ff288b into helidon-io:main Jun 4, 2024
12 checks passed
@tomas-langer tomas-langer deleted the 8816-feature-ordering branch June 4, 2024 18:42
barchetta pushed a commit to barchetta/helidon that referenced this pull request Jun 4, 2024
…elidon-io#8826)

* Correctly handle order of Server Features and HTTP Features when registering non-HTTP Feature elements to the routing.
With the updated version, all elements (filters, routes, services) are ordered depending on the feature's weight.
This is achieved by creating a new HttpFeature for each Server Feature with the same weight, that collects all registrations and applies them once the HTTP Features are ordered by weight.
HttpFeature registered from a Server Feature is left intact and applied on the real builder (as this already works as it should)
* Updated CORS weight to 850 to align with the documented (and intended) ordering
* Added documentation for server features.
* Added documentation for Context feature.
* Reorganized webserver.adoc, as some sections were within wrong chapters; updated TOC
* Added `HttpFeature` documentation.

---------

Co-authored-by: Daniel Kec <[email protected]>
barchetta added a commit that referenced this pull request Jun 5, 2024
…8826) (#8840)

* Correctly handle order of Server Features and HTTP Features when registering non-HTTP Feature elements to the routing.
With the updated version, all elements (filters, routes, services) are ordered depending on the feature's weight.
This is achieved by creating a new HttpFeature for each Server Feature with the same weight, that collects all registrations and applies them once the HTTP Features are ordered by weight.
HttpFeature registered from a Server Feature is left intact and applied on the real builder (as this already works as it should)
* Updated CORS weight to 850 to align with the documented (and intended) ordering
* Added documentation for server features.
* Added documentation for Context feature.
* Reorganized webserver.adoc, as some sections were within wrong chapters; updated TOC
* Added `HttpFeature` documentation.

---------

Co-authored-by: Tomas Langer <[email protected]>
Co-authored-by: Daniel Kec <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
4.x Version 4.x bug Something isn't working docs OCA Verified All contributors have signed the Oracle Contributor Agreement. webserver
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4:x: Filter ordering should honor feature weight
4 participants