Skip to content

router: unified header formatters#21932

Merged
mattklein123 merged 77 commits intoenvoyproxy:mainfrom
cpakulski:issue/20389
Sep 22, 2022
Merged

router: unified header formatters#21932
mattklein123 merged 77 commits intoenvoyproxy:mainfrom
cpakulski:issue/20389

Conversation

@cpakulski
Copy link
Copy Markdown
Contributor

@cpakulski cpakulski commented Jun 28, 2022

Commit Message:
unified formatters for access log and header

Additional Description:
At the core of this PR are changes to signature of just two methods:
HeaderFormatter::evaluateHeader - it used to take only stream_info as param. Now it also takes RequestHeaderMap and ResponseHeaderMap. This is required to directly map parameters to access log substitution formatters.
Router::ResponseEntry::finalizeResponseHeaders - added RequestHeaderMap to the parameters.
Remaining changes are around changes to those two methods.

Header formatters used to have internal parser and its own set of formatters. Now parsing is done by access log's parser and header formatting is done via access log's substitution formatters.
Runtime guard envoy_reloadable_features_unified_header_formatter was added to allow using the previous implementation of parser and formatters.

New changes are fully backward compatible. However, header formatters for DYNAMIC_METADATA, UPSTREAM_METADATA and PER_REQUEST_STATE had a different format than access log's equivalent. Temporary translators have been added for those 3 formatters and will be removed when old format is deprecated.

All substitution formatters are allowed to be used. Some usage does not make sense though. For example, it is possible to modify request headers using a formatter which needs response headers, like ,%RESP(X-SERVED-BY)%. At the moment of modifying request headers, the response headers are not present yet and formatter produces empty string. It is left up for the administrator to select only formatters which make sense to use. This behaviour could be modified by adding attribute flags to each formatter indicating where formatters can be used (for example only in request headers, only in response headers or both), but it would come at some code complexity.

Risk Level: Med
Testing: Added unit tests. Manual testing with runtime guard on and off.
Docs Changes: Yes.
Release Notes: Yes
Platform Specific Features:
Runtime guard: envoy.reloadable_features.unified_header_formatter
Fixes #20389
Fixes #15036

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Fixed all unit tests.
Added translators for backwards compatibility.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
…_utils.cc.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@repokitteh-read-only
Copy link
Copy Markdown

As a reminder, PRs marked as draft will not be automatically assigned reviewers,
or be handled by maintainer-oncall triage.

Please mark your PR as ready when you want it to be reviewed!

🐱

Caused by: #21932 was opened by cpakulski.

see: more, trace.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #21932 (comment) was created by @cpakulski.

see: more, trace.

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
@cpakulski
Copy link
Copy Markdown
Contributor Author

/retest

@repokitteh-read-only
Copy link
Copy Markdown

Retrying Azure Pipelines:
Retried failed jobs in: envoy-presubmit

🐱

Caused by: a #21932 (comment) was created by @cpakulski.

see: more, trace.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Sep 20, 2022

Thanks. Great.

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Sep 20, 2022

cc @mattklein123 I think this is ready for a final review.

Some background: according to previous discussion, this PR will not change the method signature as far as possible to reduce impact to exist code tree (except some unavoidable updates). We will have a dedicated PR to unify all these interfaces after the runtime guard is expired.

Comment on lines -579 to -587
%DOWNSTREAM_REMOTE_ADDRESS%
Remote address of the downstream connection. If the address is an IP address it includes both
address and port.

.. note::

This may not be the physical remote address of the peer if the address has been inferred from
:ref:`Proxy Protocol filter <config_listener_filters_proxy_protocol>` or :ref:`x-forwarded-for
<config_http_conn_man_headers_x-forwarded-for>`.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

nit: should we just keep these old docs for now and removed after the runtime guard is expired? 🤔

@wbpcode
Copy link
Copy Markdown
Member

wbpcode commented Sep 20, 2022

/assign @mattklein123

Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Sweet! A few small comments, thank you.

/wait

Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Signed-off-by: Christoph Pakulski <christoph@tetrate.io>
Copy link
Copy Markdown
Member

@mattklein123 mattklein123 left a comment

Choose a reason for hiding this comment

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

Thanks!

wbpcode added a commit that referenced this pull request Sep 24, 2025
Commit Message: formatter: removed legacy router formatter support
Additional Description:

Three yeas ago, at #21932, we unified all the formatters to the
substitution formatter. And we add a warn log for the legacy
UPSTREAM_METADATA and DYNAMIC_METADATA.

Now, I think it's time to remove it finally. This PR Removed legacy
header formatter support for `%DYNAMIC_METADATA(["namespace", "key",
...])%` and `%UPSTREAM_METADATA(["namespace", "key", ...])%`. Please use
`%DYNAMIC_METADATA(namespace:key:...])%` and
`%UPSTREAM_METADATA(namespace:key:...])%` as alternatives.
This change can be reverted temporarily by setting the runtime guard
`envoy.reloadable_features.remove_legacy_route_formatter` to `false`.

Risk Level: low.
Testing: unit.
Docs Changes: n/a.
Release Notes: added.

---------

Signed-off-by: WangBaiping <wbphub@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

unified header formatter and substitution formatter Add RESP(header-name) header formatter

8 participants