Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c0e451b
access_log: Added new command operator %VIRTUAL_CLUSTER_NAME% to retr…
agrawroh Nov 9, 2021
338e117
Fixed Tests
agrawroh Nov 9, 2021
2afee97
Merge branch 'main' into add-vc-name-to-access-logs
agrawroh Nov 10, 2021
6aa15e8
Fixed Formatter Test
agrawroh Nov 10, 2021
ef45a22
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 15, 2021
2037455
Addressed Comments From @lambdai
agrawroh Nov 15, 2021
70e6cdf
Merge branch 'main' into add-vc-name-to-access-logs
agrawroh Nov 16, 2021
6735c98
Resolved Merge Conflicts
agrawroh Nov 16, 2021
258a0ff
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 17, 2021
d7d782c
Addressed Comments From @jmarantz
agrawroh Nov 17, 2021
18b19f0
Remove Unwanted Fields
agrawroh Nov 17, 2021
1d01999
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 17, 2021
67e84df
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 18, 2021
6a47aff
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 18, 2021
73bb998
Addressed Comments From @jmarantz
agrawroh Nov 18, 2021
341aaf7
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 18, 2021
fb141c1
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 19, 2021
073fdb6
Addressed Comments From @jmarantz
agrawroh Nov 19, 2021
a3342e7
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 20, 2021
d4eb829
Fix Syntax
agrawroh Nov 20, 2021
0dee63c
Addressed Comments From @jmarantz
agrawroh Nov 21, 2021
ad17748
Merge branch 'main' of github.com:envoyproxy/envoy into add-vc-name-t…
agrawroh Nov 29, 2021
325cf76
Addressed Comments From @zuercher
agrawroh Nov 29, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions docs/root/configuration/observability/access_log/usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -384,6 +384,9 @@ The following command operators are supported:
%ROUTE_NAME%
Name of the route.

%VIRTUAL_CLUSTER_NAME%
Name of the matched Virtual Cluster (if any).

Comment thread
agrawroh marked this conversation as resolved.
%UPSTREAM_HOST%
Upstream host URL (e.g., tcp://ip:port for TCP connections).

Expand Down
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ Removed Config or Runtime
New Features
------------
* access log: added :ref:`grpc_stream_retry_policy <envoy_v3_api_field_extensions.access_loggers.grpc.v3.CommonGrpcAccessLogConfig.grpc_stream_retry_policy>` to the gRPC logger to reconnect when a connection fails to be established.
* access_log: added new access_log command operator ``%VIRTUAL_CLUSTER_NAME%`` to retrieve the matched Virtual Cluster name.
* api: added support for *xds.type.v3.TypedStruct* in addition to the now-deprecated *udpa.type.v1.TypedStruct* proto message, which is a wrapper proto used to encode typed JSON data in a *google.protobuf.Any* field.
* bootstrap: added :ref:`typed_dns_resolver_config <envoy_v3_api_field_config.bootstrap.v3.Bootstrap.typed_dns_resolver_config>` in the bootstrap to support DNS resolver as an extension.
* cluster: added :ref:`typed_dns_resolver_config <envoy_v3_api_field_config.cluster.v3.Cluster.typed_dns_resolver_config>` in the cluster to support DNS resolver as an extension.
Expand Down
10 changes: 10 additions & 0 deletions envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,16 @@ class StreamInfo {
*/
virtual const std::string& getRouteName() const PURE;

/**
* @param std::string name denotes the name of the virtual cluster.
*/
virtual void setVirtualClusterName(const std::string& name) PURE;

/**
* @return std::string& the name of the virtual cluster which got matched.
*/
virtual const std::string& getVirtualClusterName() const PURE;
Comment thread
agrawroh marked this conversation as resolved.
Outdated

/**
* @param bytes_received denotes number of bytes to add to total received bytes.
*/
Expand Down
10 changes: 10 additions & 0 deletions source/common/formatter/substitution_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,16 @@ StreamInfoFormatter::StreamInfoFormatter(const std::string& field_name) {
}
return absl::nullopt;
});
} else if (field_name == "VIRTUAL_CLUSTER_NAME") {
Comment thread
agrawroh marked this conversation as resolved.
field_extractor_ = std::make_unique<StreamInfoStringFieldExtractor>(
[](const StreamInfo::StreamInfo& stream_info) {
absl::optional<std::string> result;
std::string virtual_cluster_name = stream_info.getVirtualClusterName();
Comment thread
agrawroh marked this conversation as resolved.
Outdated
if (!virtual_cluster_name.empty()) {
result = virtual_cluster_name;
}
return result;
});
} else {
throw EnvoyException(fmt::format("Not supported field in StreamInfo: {}", field_name));
}
Expand Down
4 changes: 4 additions & 0 deletions source/common/router/router.cc
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,10 @@ Http::FilterHeadersStatus Filter::decodeHeaders(Http::RequestHeaderMap& headers,

// Set up stat prefixes, etc.
request_vcluster_ = route_entry_->virtualCluster(headers);
if (request_vcluster_) {
Comment thread
agrawroh marked this conversation as resolved.
Outdated
std::string vc_name = config_.scope_.symbolTable().toString(request_vcluster_->statName());
Comment thread
agrawroh marked this conversation as resolved.
Outdated
callbacks_->streamInfo().setVirtualClusterName(vc_name);
Comment thread
agrawroh marked this conversation as resolved.
Outdated
}
ENVOY_STREAM_LOG(debug, "cluster '{}' match for URL '{}'", *callbacks_,
route_entry_->clusterName(), headers.getPathValue());

Expand Down
7 changes: 7 additions & 0 deletions source/common/stream_info/stream_info_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,12 @@ struct StreamInfoImpl : public StreamInfo {

const std::string& getRouteName() const override { return route_name_; }

void setVirtualClusterName(const std::string& virtual_cluster_name) override {
virtual_cluster_name_ = virtual_cluster_name;
}

const std::string& getVirtualClusterName() const override { return virtual_cluster_name_; }

void setUpstreamLocalAddress(
const Network::Address::InstanceConstSharedPtr& upstream_local_address) override {
upstream_local_address_ = upstream_local_address;
Expand Down Expand Up @@ -332,6 +338,7 @@ struct StreamInfoImpl : public StreamInfo {
std::string route_name_;
absl::optional<uint64_t> upstream_connection_id_;
absl::optional<uint32_t> attempt_count_;
std::string virtual_cluster_name_;
Comment thread
agrawroh marked this conversation as resolved.
Outdated

private:
static Network::ConnectionInfoProviderSharedPtr emptyDownstreamAddressProvider() {
Expand Down
9 changes: 9 additions & 0 deletions test/common/formatter/substitution_formatter_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -752,6 +752,15 @@ TEST(SubstitutionFormatterTest, streamInfoFormatterWithSsl) {
Http::TestResponseTrailerMapImpl response_trailers;
std::string body;

{
NiceMock<StreamInfo::MockStreamInfo> stream_info;
StreamInfoFormatter upstream_format("VIRTUAL_CLUSTER_NAME");
std::string virtual_cluster_name = "authN";
stream_info.setVirtualClusterName(virtual_cluster_name);
EXPECT_EQ("authN", upstream_format.format(request_headers, response_headers, response_trailers,
stream_info, body));
}

{
// Use a local stream info for these tests as as setSslConnection can only be called once.
NiceMock<StreamInfo::MockStreamInfo> stream_info;
Expand Down
2 changes: 2 additions & 0 deletions test/common/router/router_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -5912,6 +5912,7 @@ TEST_F(RouterTest, CanaryStatusTrue) {
Http::TestRequestHeaderMapImpl headers{{"x-envoy-upstream-alt-stat-name", "alt_stat"},
{"x-envoy-internal", "true"}};
HttpTestUtility::addDefaultHeaders(headers);
EXPECT_CALL(callbacks_.stream_info_, setVirtualClusterName("fake_virtual_cluster"));
router_.decodeHeaders(headers, true);
EXPECT_EQ(1U,
callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());
Expand Down Expand Up @@ -5949,6 +5950,7 @@ TEST_F(RouterTest, CanaryStatusFalse) {
Http::TestRequestHeaderMapImpl headers{{"x-envoy-upstream-alt-stat-name", "alt_stat"},
{"x-envoy-internal", "true"}};
HttpTestUtility::addDefaultHeaders(headers);
EXPECT_CALL(callbacks_.stream_info_, setVirtualClusterName("fake_virtual_cluster"));
router_.decodeHeaders(headers, true);
EXPECT_EQ(1U,
callbacks_.route_->route_entry_.virtual_cluster_.stats().upstream_rq_total_.value());
Expand Down
6 changes: 6 additions & 0 deletions test/common/stream_info/test_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,11 @@ class TestStreamInfo : public StreamInfo::StreamInfo {
}
const std::string& getRouteName() const override { return route_name_; }

void setVirtualClusterName(const std::string& virtual_cluster_name) override {
virtual_cluster_name_ = virtual_cluster_name;
}
const std::string& getVirtualClusterName() const override { return virtual_cluster_name_; }

Router::RouteConstSharedPtr route() const override { return route_; }

absl::optional<std::chrono::nanoseconds>
Expand Down Expand Up @@ -258,6 +263,7 @@ class TestStreamInfo : public StreamInfo::StreamInfo {
Upstream::HostDescriptionConstSharedPtr upstream_host_{};
bool health_check_request_{};
std::string route_name_;
std::string virtual_cluster_name_;
Network::Address::InstanceConstSharedPtr upstream_local_address_;
Network::ConnectionInfoSetterSharedPtr downstream_connection_info_provider_{
std::make_shared<Network::ConnectionInfoSetterImpl>(nullptr, nullptr)};
Expand Down
5 changes: 5 additions & 0 deletions test/mocks/stream_info/mocks.cc
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,12 @@ MockStreamInfo::MockStreamInfo()
ON_CALL(*this, setRouteName(_)).WillByDefault(Invoke([this](const absl::string_view route_name) {
route_name_ = std::string(route_name);
}));
ON_CALL(*this, setVirtualClusterName(_))
.WillByDefault(Invoke([this](const std::string& virtual_cluster_name) {
virtual_cluster_name_ = std::string(virtual_cluster_name);
}));
ON_CALL(*this, getRouteName()).WillByDefault(ReturnRef(route_name_));
ON_CALL(*this, getVirtualClusterName()).WillByDefault(ReturnRef(virtual_cluster_name_));
ON_CALL(*this, upstreamTransportFailureReason())
.WillByDefault(ReturnRef(upstream_transport_failure_reason_));
ON_CALL(*this, setConnectionID(_)).WillByDefault(Invoke([this](uint64_t id) {
Expand Down
3 changes: 3 additions & 0 deletions test/mocks/stream_info/mocks.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ class MockStreamInfo : public StreamInfo {
MOCK_METHOD(void, addWireBytesReceived, (uint64_t));
MOCK_METHOD(uint64_t, wireBytesReceived, (), (const));
MOCK_METHOD(void, setRouteName, (absl::string_view route_name));
MOCK_METHOD(void, setVirtualClusterName, (const std::string& virtual_cluster_name));
MOCK_METHOD(const std::string&, getRouteName, (), (const));
MOCK_METHOD(const std::string&, getVirtualClusterName, (), (const));
MOCK_METHOD(absl::optional<Http::Protocol>, protocol, (), (const));
MOCK_METHOD(void, protocol, (Http::Protocol protocol));
MOCK_METHOD(absl::optional<uint32_t>, responseCode, (), (const));
Expand Down Expand Up @@ -141,6 +143,7 @@ class MockStreamInfo : public StreamInfo {
std::string filter_chain_name_;
absl::optional<uint64_t> upstream_connection_id_;
absl::optional<uint32_t> attempt_count_;
std::string virtual_cluster_name_;
};

} // namespace StreamInfo
Expand Down