Skip to content
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

access log: add support for %UPSTREAM_CONNECTION_ID% #31920

Merged
4 changes: 4 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,5 +24,9 @@ new_features:
Change HTTP status to 200 to respect the gRPC protocol. This may cause problems for incorrect gRPC clients expecting the filter
to preserve HTTP 1.1 responses. This behavioral change can be temporarily reverted by setting runtime guard
``envoy.reloadable_features.grpc_http1_reverse_bridge_change_http_status`` to false.
- area: access log
change: |
added support for :ref:`%UPSTREAM_CONNECTION_ID% <config_access_log_format_upstream_connection_id>` for the upstream connection
identifier.

deprecated:
5 changes: 5 additions & 0 deletions docs/root/configuration/observability/access_log/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -679,6 +679,11 @@ UDP
is unique with high likelihood within an execution, but can duplicate across
multiple instances or between restarts.

.. _config_access_log_format_upstream_connection_id:

%UPSTREAM_CONNECTION_ID%
An identifier for the upstream connection.

Copy link
Member

Choose a reason for hiding this comment

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

Thanks for you in timely update 😄 . This LGTM overall. Please supplement more context about the new command in the docs. I think this description should almost same with the CONNECTION_ID except it's used to tell the upstream connection id.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done :)

.. _config_access_log_format_stream_id:

%STREAM_ID%
Expand Down
8 changes: 8 additions & 0 deletions source/common/formatter/stream_info_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -884,6 +884,14 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide
return nullptr;
});
}}},
{"UPSTREAM_CONNECTION_ID",
{CommandSyntaxChecker::COMMAND_ONLY,
[](const std::string&, absl::optional<size_t>) {
return std::make_unique<StreamInfoUInt64FormatterProvider>(
[](const StreamInfo::StreamInfo& stream_info) {
return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0);
Copy link
Member

Choose a reason for hiding this comment

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

                    if (stream_info.upstreamInfo().has_value()) {
                      return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0);
                    }
                    return 0;

});
}}},
{"UPSTREAM_CLUSTER",
{CommandSyntaxChecker::COMMAND_ONLY,
[](const std::string&, absl::optional<size_t>) {
Expand Down
9 changes: 8 additions & 1 deletion test/common/formatter/substitution_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -796,7 +796,14 @@ TEST(SubstitutionFormatterTest, streamInfoFormatter) {
EXPECT_THAT(upstream_format.formatValueWithContext({}, stream_info),
ProtoEq(ValueUtil::numberValue(id)));
}

{
StreamInfoFormatter upstream_format("UPSTREAM_CONNECTION_ID");
uint64_t id = 1234;
stream_info.upstreamInfo()->setUpstreamConnectionId(id);
EXPECT_EQ("1234", upstream_format.formatWithContext({}, stream_info));
EXPECT_THAT(upstream_format.formatValueWithContext({}, stream_info),
ProtoEq(ValueUtil::numberValue(id)));
}
{
StreamInfoFormatter upstream_format("STREAM_ID");

Expand Down
Loading