From a9992b2accb4972d6f310c249d24dd900f0ba6f9 Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Sun, 21 Jan 2024 20:06:31 -0800 Subject: [PATCH 1/9] access log: support %UPSTREAM_CONNECTION_ID% Signed-off-by: deveshkandpal1224 --- changelogs/current.yaml | 3 +++ source/common/formatter/stream_info_formatter.cc | 8 ++++++++ test/common/formatter/substitution_formatter_test.cc | 9 ++++++++- 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/changelogs/current.yaml b/changelogs/current.yaml index a31b4d7a2a08..b4964a41a10d 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -24,5 +24,8 @@ 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 ``%UPSTREAM_CONNECTION_ID%`` to access log formatting. deprecated: diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index 7d72800f3aaa..b1e50d02fda1 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -884,6 +884,14 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide return nullptr; }); }}}, + {"UPSTREAM_CONNECTION_ID", + {CommandSyntaxChecker::COMMAND_ONLY, + [](const std::string&, absl::optional) { + return std::make_unique( + [](const StreamInfo::StreamInfo& stream_info) { + return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + }); + }}}, {"UPSTREAM_CLUSTER", {CommandSyntaxChecker::COMMAND_ONLY, [](const std::string&, absl::optional) { diff --git a/test/common/formatter/substitution_formatter_test.cc b/test/common/formatter/substitution_formatter_test.cc index 8d32a486dfad..8c81e21544f2 100644 --- a/test/common/formatter/substitution_formatter_test.cc +++ b/test/common/formatter/substitution_formatter_test.cc @@ -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"); From 73805686269b2e7f6bc8a2cbb1093ba210fdd423 Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Sun, 21 Jan 2024 20:36:58 -0800 Subject: [PATCH 2/9] update docs Signed-off-by: deveshkandpal1224 --- changelogs/current.yaml | 3 ++- docs/root/configuration/observability/access_log/usage.rst | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/changelogs/current.yaml b/changelogs/current.yaml index b4964a41a10d..270d71804254 100644 --- a/changelogs/current.yaml +++ b/changelogs/current.yaml @@ -26,6 +26,7 @@ new_features: ``envoy.reloadable_features.grpc_http1_reverse_bridge_change_http_status`` to false. - area: access log change: | - added support for ``%UPSTREAM_CONNECTION_ID%`` to access log formatting. + added support for :ref:`%UPSTREAM_CONNECTION_ID% ` for the upstream connection + identifier. deprecated: diff --git a/docs/root/configuration/observability/access_log/usage.rst b/docs/root/configuration/observability/access_log/usage.rst index 498fc923e0e3..09ad034f9622 100644 --- a/docs/root/configuration/observability/access_log/usage.rst +++ b/docs/root/configuration/observability/access_log/usage.rst @@ -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. + .. _config_access_log_format_stream_id: %STREAM_ID% From 773e7d47b54c7aebe8538268ce035e2768dd4b84 Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Sun, 21 Jan 2024 22:29:01 -0800 Subject: [PATCH 3/9] fix formatter Signed-off-by: deveshkandpal1224 --- source/common/formatter/stream_info_formatter.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index b1e50d02fda1..a1707943e052 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -891,7 +891,7 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide [](const StreamInfo::StreamInfo& stream_info) { return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); }); - }}}, + }}}, {"UPSTREAM_CLUSTER", {CommandSyntaxChecker::COMMAND_ONLY, [](const std::string&, absl::optional) { From a1aee96786fb86dbf230c8209f5875f6311e211b Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Mon, 22 Jan 2024 22:27:55 -0800 Subject: [PATCH 4/9] refactor code Signed-off-by: deveshkandpal1224 --- source/common/formatter/stream_info_formatter.cc | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index a1707943e052..3762a45d34ec 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -889,7 +889,11 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide [](const std::string&, absl::optional) { return std::make_unique( [](const StreamInfo::StreamInfo& stream_info) { - return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + unsigned long result = 0; + if (stream_info.upstreamInfo().has_value()) { + result = stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + } + return result; }); }}}, {"UPSTREAM_CLUSTER", From ce45becb747ea87aed32d43d7727a8c41d6ca404 Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Mon, 22 Jan 2024 22:35:16 -0800 Subject: [PATCH 5/9] minor change Signed-off-by: deveshkandpal1224 --- source/common/formatter/stream_info_formatter.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index 3762a45d34ec..12137c3e780b 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -889,11 +889,10 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide [](const std::string&, absl::optional) { return std::make_unique( [](const StreamInfo::StreamInfo& stream_info) { - unsigned long result = 0; if (stream_info.upstreamInfo().has_value()) { - result = stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); } - return result; + return 0UL; }); }}}, {"UPSTREAM_CLUSTER", From e887f8a81c26ab12ef0e0e519713787e7580b0e1 Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Tue, 23 Jan 2024 06:35:42 -0800 Subject: [PATCH 6/9] switch from UL to uint64_t Signed-off-by: deveshkandpal1224 --- source/common/formatter/stream_info_formatter.cc | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index 12137c3e780b..26f23a13ff89 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -889,10 +889,11 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide [](const std::string&, absl::optional) { return std::make_unique( [](const StreamInfo::StreamInfo& stream_info) { + uint64_t result = 0; if (stream_info.upstreamInfo().has_value()) { - return stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + result = stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); } - return 0UL; + return result; }); }}}, {"UPSTREAM_CLUSTER", From 8c563a0e5268559ce9331bd8f825411ae64a4af9 Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Tue, 23 Jan 2024 09:40:21 -0800 Subject: [PATCH 7/9] dummy change Signed-off-by: deveshkandpal1224 --- source/common/formatter/stream_info_formatter.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index 26f23a13ff89..d68378bb8a35 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -889,11 +889,11 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide [](const std::string&, absl::optional) { return std::make_unique( [](const StreamInfo::StreamInfo& stream_info) { - uint64_t result = 0; + uint64_t upstream_connection_id = 0; if (stream_info.upstreamInfo().has_value()) { - result = stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + upstream_connection_id = stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); } - return result; + return upstream_connection_id; }); }}}, {"UPSTREAM_CLUSTER", From 66a8842ca04ed646e55de3ec9b62f87bf975fa4e Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Tue, 23 Jan 2024 11:27:42 -0800 Subject: [PATCH 8/9] fix formatting Signed-off-by: deveshkandpal1224 --- source/common/formatter/stream_info_formatter.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/source/common/formatter/stream_info_formatter.cc b/source/common/formatter/stream_info_formatter.cc index d68378bb8a35..29003ab607f4 100644 --- a/source/common/formatter/stream_info_formatter.cc +++ b/source/common/formatter/stream_info_formatter.cc @@ -891,7 +891,8 @@ const StreamInfoFormatterProviderLookupTable& getKnownStreamInfoFormatterProvide [](const StreamInfo::StreamInfo& stream_info) { uint64_t upstream_connection_id = 0; if (stream_info.upstreamInfo().has_value()) { - upstream_connection_id = stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); + upstream_connection_id = + stream_info.upstreamInfo()->upstreamConnectionId().value_or(0); } return upstream_connection_id; }); From 87cad0a19a5237223c24631436c0d574c75f260b Mon Sep 17 00:00:00 2001 From: deveshkandpal1224 Date: Tue, 23 Jan 2024 18:56:50 -0800 Subject: [PATCH 9/9] update usage.rst Signed-off-by: deveshkandpal1224 --- docs/root/configuration/observability/access_log/usage.rst | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/docs/root/configuration/observability/access_log/usage.rst b/docs/root/configuration/observability/access_log/usage.rst index 09ad034f9622..30ea630e5b19 100644 --- a/docs/root/configuration/observability/access_log/usage.rst +++ b/docs/root/configuration/observability/access_log/usage.rst @@ -682,7 +682,11 @@ UDP .. _config_access_log_format_upstream_connection_id: %UPSTREAM_CONNECTION_ID% - An identifier for the upstream connection. + An identifier for the upstream connection. It can be used to + cross-reference TCP access logs across multiple log sinks, or to + cross-reference timer-based reports for the same connection. The identifier + is unique with high likelihood within an execution, but can duplicate across + multiple instances or between restarts. .. _config_access_log_format_stream_id: