Skip to content

Commit

Permalink
access log: add support for %UPSTREAM_CONNECTION_ID% (envoyproxy#31920)
Browse files Browse the repository at this point in the history
* access log: support %UPSTREAM_CONNECTION_ID%

Signed-off-by: deveshkandpal1224 <[email protected]>

* update docs

Signed-off-by: deveshkandpal1224 <[email protected]>

* fix formatter

Signed-off-by: deveshkandpal1224 <[email protected]>

* refactor code

Signed-off-by: deveshkandpal1224 <[email protected]>

* minor change

Signed-off-by: deveshkandpal1224 <[email protected]>

* switch from UL to uint64_t

Signed-off-by: deveshkandpal1224 <[email protected]>

* dummy change

Signed-off-by: deveshkandpal1224 <[email protected]>

* fix formatting

Signed-off-by: deveshkandpal1224 <[email protected]>

* update usage.rst

Signed-off-by: deveshkandpal1224 <[email protected]>

---------

Signed-off-by: deveshkandpal1224 <[email protected]>
  • Loading branch information
deveshkandpal1224 authored Jan 24, 2024
1 parent 6952f54 commit 282ff3a
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 1 deletion.
4 changes: 4 additions & 0 deletions changelogs/current.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,5 +34,9 @@ new_features:
and
:ref:`response_attributes <envoy_v3_api_field_extensions.filters.http.ext_proc.v3.ExternalProcessor.response_attributes>`
config APIs to enable sending and receiving attributes to/from the external processing server.
- area: access log
change: |
added support for :ref:`%UPSTREAM_CONNECTION_ID% <config_access_log_format_upstream_connection_id>` for the upstream connection
identifier.
deprecated:
9 changes: 9 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,15 @@ 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. 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:

%STREAM_ID%
Expand Down
13 changes: 13 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,19 @@ 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) {
uint64_t upstream_connection_id = 0;
if (stream_info.upstreamInfo().has_value()) {
upstream_connection_id =
stream_info.upstreamInfo()->upstreamConnectionId().value_or(0);
}
return upstream_connection_id;
});
}}},
{"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

0 comments on commit 282ff3a

Please sign in to comment.