Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
128 changes: 1 addition & 127 deletions envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,13 +358,6 @@ class UpstreamInfo {
*/
virtual Ssl::ConnectionInfoConstSharedPtr upstreamSslConnection() const PURE;

/**
* Sets the upstream timing information for this stream. This is useful for
* when multiple upstream requests are issued and we want to save timing
* information for the one that "wins".
*/
virtual void setUpstreamTiming(const UpstreamTiming& upstream_timing) PURE;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This PR seems quite similar to #19118? Does this PR replace that one?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

yeah, theoretically. there's 2 issues with that one - the clang tidy which I have fixed locally (not pushed) and the windows build failure, which I could not figure out. I was hoping removing the getters would remove the build failure but left it assigned my way until I was sure.

if it's too big to combine getter and setter clean up, I can likely submit removing getters first, but didn't want to break it up until 1) I knew it fixed the problem and 2) checking to see if you wanted it split or were OK with the one large PR

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This approach seems totally fine. No need to split. It's a lot of movement but it's largely mechanical/straightforward. It's not like there's lots of complex interactions which are changing, I think.

/*
* @return the upstream timing for this stream
* */
Expand Down Expand Up @@ -451,11 +444,6 @@ class StreamInfo {
*/
virtual bool intersectResponseFlags(uint64_t response_flags) const PURE;

/**
* @param host the selected upstream host for the request.
*/
virtual void onUpstreamHostSelected(Upstream::HostDescriptionConstSharedPtr host) PURE;

/**
* @param std::string name denotes the name of the route.
*/
Expand Down Expand Up @@ -522,19 +510,6 @@ class StreamInfo {
*/
virtual MonotonicTime startTimeMonotonic() const PURE;

/**
* @return the duration between the last byte of the request was received and the start of the
* request.
*/
virtual absl::optional<std::chrono::nanoseconds> lastDownstreamRxByteReceived() const PURE;

/**
* Sets the upstream timing information for this stream. This is useful for
* when multiple upstream requests are issued and we want to save timing
* information for the one that "wins".
*/
virtual void setUpstreamTiming(const UpstreamTiming& upstream_timing) PURE;

/**
* Sets the upstream information for this stream.
*/
Expand All @@ -546,50 +521,6 @@ class StreamInfo {
virtual std::shared_ptr<UpstreamInfo> upstreamInfo() PURE;
virtual OptRef<const UpstreamInfo> upstreamInfo() const PURE;

/**
* Returns the upstream timing information for this stream.
* It is not expected that the fields in upstreamTiming() will be set until
* the upstream request is complete.
*/
virtual UpstreamTiming& upstreamTiming() PURE;

/**
* @return the duration between the first byte of the request was sent upstream and the start of
* the request. There may be a considerable delta between lastDownstreamByteReceived and this
* value due to filters.
*/
virtual absl::optional<std::chrono::nanoseconds> firstUpstreamTxByteSent() const PURE;

/**
* @return the duration between the last byte of the request was sent upstream and the start of
* the request.
*/
virtual absl::optional<std::chrono::nanoseconds> lastUpstreamTxByteSent() const PURE;

/**
* @return the duration between the first byte of the response is received from upstream and the
* start of the request.
*/
virtual absl::optional<std::chrono::nanoseconds> firstUpstreamRxByteReceived() const PURE;

/**
* @return the duration between the last byte of the response is received from upstream and the
* start of the request.
*/
virtual absl::optional<std::chrono::nanoseconds> lastUpstreamRxByteReceived() const PURE;
/**
* @return the duration between the first byte of the response is sent downstream and the start of
* the request. There may be a considerable delta between lastUpstreamByteReceived and this value
* due to filters.
*/
virtual absl::optional<std::chrono::nanoseconds> firstDownstreamTxByteSent() const PURE;

/**
* @return the duration between the last byte of the response is sent downstream and the start of
* the request.
*/
virtual absl::optional<std::chrono::nanoseconds> lastDownstreamTxByteSent() const PURE;

/**
* @return the total duration of the request (i.e., when the request's ActiveStream is destroyed)
* and may be longer than lastDownstreamTxByteSent.
Expand All @@ -606,6 +537,7 @@ class StreamInfo {
* @return the downstream timing information.
*/
virtual DownstreamTiming& downstreamTiming() PURE;
virtual OptRef<const DownstreamTiming> downstreamTiming() const PURE;

/**
* @param bytes_sent denotes the number of bytes to add to total sent bytes.
Expand All @@ -632,23 +564,6 @@ class StreamInfo {
*/
virtual uint64_t responseFlags() const PURE;

/**
* @return upstream host description.
*/
virtual Upstream::HostDescriptionConstSharedPtr upstreamHost() const PURE;

/**
* @param upstream_local_address sets the local address of the upstream connection. Note that it
* can be different than the local address of the downstream connection.
*/
virtual void setUpstreamLocalAddress(
const Network::Address::InstanceConstSharedPtr& upstream_local_address) PURE;

/**
* @return the upstream local address.
*/
virtual const Network::Address::InstanceConstSharedPtr& upstreamLocalAddress() const PURE;

/**
* @return whether the request is a health check request or not.
*/
Expand All @@ -664,18 +579,6 @@ class StreamInfo {
*/
virtual const Network::ConnectionInfoProvider& downstreamAddressProvider() const PURE;

/**
* @param connection_info sets the upstream ssl connection.
*/
virtual void
setUpstreamSslConnection(const Ssl::ConnectionInfoConstSharedPtr& ssl_connection_info) PURE;

/**
* @return the upstream SSL connection. This will be nullptr if the upstream
* connection does not use SSL.
*/
virtual Ssl::ConnectionInfoConstSharedPtr upstreamSslConnection() const PURE;

/**
* @return const Router::RouteConstSharedPtr Get the route selected for this request.
*/
Expand Down Expand Up @@ -705,25 +608,6 @@ class StreamInfo {
virtual const FilterStateSharedPtr& filterState() PURE;
virtual const FilterState& filterState() const PURE;

/**
* Filter State object to be shared between upstream and downstream filters.
* @param pointer to upstream connections filter state.
* @return pointer to filter state to be used by upstream connections.
*/
virtual const FilterStateSharedPtr& upstreamFilterState() const PURE;
virtual void setUpstreamFilterState(const FilterStateSharedPtr& filter_state) PURE;

/**
* @param failure_reason the upstream transport failure reason.
*/
virtual void setUpstreamTransportFailureReason(absl::string_view failure_reason) PURE;

/**
* @return const std::string& the upstream transport failure reason, e.g. certificate validation
* failed.
*/
virtual const std::string& upstreamTransportFailureReason() const PURE;

/**
* @param headers request headers.
*/
Expand Down Expand Up @@ -778,16 +662,6 @@ class StreamInfo {
*/
virtual const std::string& filterChainName() const PURE;

/**
* @param connection ID of the upstream connection.
*/
virtual void setUpstreamConnectionId(uint64_t id) PURE;

/**
* @return the ID of the upstream connection, or absl::nullopt if not available.
*/
virtual absl::optional<uint64_t> upstreamConnectionId() const PURE;

/**
* @param attempt_count, the number of times the request was attempted upstream.
*/
Expand Down
39 changes: 26 additions & 13 deletions source/common/formatter/substitution_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -690,23 +690,27 @@ StreamInfoFormatter::StreamInfoFormatter(const std::string& field_name) {
if (field_name == "REQUEST_DURATION") {
field_extractor_ = std::make_unique<StreamInfoDurationFieldExtractor>(
[](const StreamInfo::StreamInfo& stream_info) {
return stream_info.lastDownstreamRxByteReceived();
StreamInfo::TimingUtility timing(stream_info);
return timing.lastDownstreamRxByteReceived();
});
} else if (field_name == "REQUEST_TX_DURATION") {
field_extractor_ = std::make_unique<StreamInfoDurationFieldExtractor>(
[](const StreamInfo::StreamInfo& stream_info) {
return stream_info.lastUpstreamTxByteSent();
StreamInfo::TimingUtility timing(stream_info);
return timing.lastUpstreamTxByteSent();
});
} else if (field_name == "RESPONSE_DURATION") {
field_extractor_ = std::make_unique<StreamInfoDurationFieldExtractor>(
[](const StreamInfo::StreamInfo& stream_info) {
return stream_info.firstUpstreamRxByteReceived();
StreamInfo::TimingUtility timing(stream_info);
return timing.firstUpstreamRxByteReceived();
});
} else if (field_name == "RESPONSE_TX_DURATION") {
field_extractor_ = std::make_unique<StreamInfoDurationFieldExtractor>(
[](const StreamInfo::StreamInfo& stream_info) {
auto downstream = stream_info.lastDownstreamTxByteSent();
auto upstream = stream_info.firstUpstreamRxByteReceived();
StreamInfo::TimingUtility timing(stream_info);
auto downstream = timing.lastDownstreamTxByteSent();
auto upstream = timing.firstUpstreamRxByteReceived();

absl::optional<std::chrono::nanoseconds> result;
if (downstream && upstream) {
Expand Down Expand Up @@ -790,9 +794,13 @@ StreamInfoFormatter::StreamInfoFormatter(const std::string& field_name) {
return StreamInfo::ResponseFlagUtils::toShortString(stream_info);
});
} else if (field_name == "UPSTREAM_HOST") {
field_extractor_ =
StreamInfoAddressFieldExtractor::withPort([](const StreamInfo::StreamInfo& stream_info) {
return stream_info.upstreamHost() ? stream_info.upstreamHost()->address() : nullptr;
field_extractor_ = StreamInfoAddressFieldExtractor::withPort(
[](const StreamInfo::StreamInfo& stream_info)
-> std::shared_ptr<const Envoy::Network::Address::Instance> {
if (stream_info.upstreamInfo() && stream_info.upstreamInfo()->upstreamHost()) {
return stream_info.upstreamInfo()->upstreamHost()->address();
}
return nullptr;
});
} else if (field_name == "UPSTREAM_CLUSTER") {
field_extractor_ = std::make_unique<StreamInfoStringFieldExtractor>(
Expand All @@ -814,9 +822,13 @@ StreamInfoFormatter::StreamInfoFormatter(const std::string& field_name) {
: absl::make_optional<std::string>(upstream_cluster_name);
});
} else if (field_name == "UPSTREAM_LOCAL_ADDRESS") {
field_extractor_ =
StreamInfoAddressFieldExtractor::withPort([](const StreamInfo::StreamInfo& stream_info) {
return stream_info.upstreamLocalAddress();
field_extractor_ = StreamInfoAddressFieldExtractor::withPort(
[](const StreamInfo::StreamInfo& stream_info)
-> std::shared_ptr<const Envoy::Network::Address::Instance> {
if (stream_info.upstreamInfo().has_value()) {
return stream_info.upstreamInfo().value().get().upstreamLocalAddress();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Nit: small simplification, since OptRef already has a method for this chain of calls.

Suggested change
return stream_info.upstreamInfo().value().get().upstreamLocalAddress();
return stream_info.upstreamInfo().ref().upstreamLocalAddress();

}
return nullptr;
});
} else if (field_name == "UPSTREAM_REQUEST_ATTEMPT_COUNT") {
field_extractor_ = std::make_unique<StreamInfoUInt64FieldExtractor>(
Expand Down Expand Up @@ -942,8 +954,9 @@ StreamInfoFormatter::StreamInfoFormatter(const std::string& field_name) {
field_extractor_ = std::make_unique<StreamInfoStringFieldExtractor>(
[](const StreamInfo::StreamInfo& stream_info) {
absl::optional<std::string> result;
if (!stream_info.upstreamTransportFailureReason().empty()) {
result = stream_info.upstreamTransportFailureReason();
if (stream_info.upstreamInfo().has_value() &&
!stream_info.upstreamInfo().value().get().upstreamTransportFailureReason().empty()) {
result = stream_info.upstreamInfo().value().get().upstreamTransportFailureReason();
}
return result;
});
Expand Down
3 changes: 0 additions & 3 deletions source/common/http/filter_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,9 +631,6 @@ class OverridableRemoteConnectionInfoSetterStreamInfo : public StreamInfo::Strea
Ssl::ConnectionInfoConstSharedPtr sslConnection() const override {
return StreamInfoImpl::downstreamAddressProvider().sslConnection();
}
Ssl::ConnectionInfoConstSharedPtr upstreamSslConnection() const override {
return StreamInfoImpl::upstreamSslConnection();
}
void dumpState(std::ostream& os, int indent_level) const override {
StreamInfoImpl::dumpState(os, indent_level);

Expand Down
5 changes: 3 additions & 2 deletions source/common/network/connection_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -848,6 +848,7 @@ ClientConnectionImpl::ClientConnectionImpl(
false),
stream_info_(dispatcher_.timeSource(), socket_->connectionInfoProviderSharedPtr()) {

stream_info_.setUpstreamInfo(std::make_shared<StreamInfo::UpstreamInfoImpl>());
// There are no meaningful socket options or source address semantics for
// non-IP sockets, so skip.
if (socket_->connectionInfoProviderSharedPtr()->remoteAddress()->ip() == nullptr) {
Expand Down Expand Up @@ -891,7 +892,7 @@ void ClientConnectionImpl::connect() {
socket_->connectionInfoProvider().remoteAddress()->asString());
const Api::SysCallIntResult result =
socket_->connect(socket_->connectionInfoProvider().remoteAddress());
stream_info_.upstreamTiming().onUpstreamConnectStart(dispatcher_.timeSource());
stream_info_.upstreamInfo()->upstreamTiming().onUpstreamConnectStart(dispatcher_.timeSource());
if (result.return_value_ == 0) {
// write will become ready.
ASSERT(connecting_);
Expand Down Expand Up @@ -921,7 +922,7 @@ void ClientConnectionImpl::connect() {
}

void ClientConnectionImpl::onConnected() {
stream_info_.upstreamTiming().onUpstreamConnectComplete(dispatcher_.timeSource());
stream_info_.upstreamInfo()->upstreamTiming().onUpstreamConnectComplete(dispatcher_.timeSource());
ConnectionImpl::onConnected();
}

Expand Down
11 changes: 7 additions & 4 deletions source/common/quic/envoy_quic_client_session.cc
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ EnvoyQuicClientSession::EnvoyQuicClientSession(
quic::QuicSpdyClientSession(config, supported_versions, connection.release(), server_id,
crypto_config.get(), push_promise_index),
crypto_config_(crypto_config), crypto_stream_factory_(crypto_stream_factory),
quic_stat_names_(quic_stat_names), scope_(scope) {}
quic_stat_names_(quic_stat_names), scope_(scope) {
streamInfo().setUpstreamInfo(std::make_shared<StreamInfo::UpstreamInfoImpl>());
}

EnvoyQuicClientSession::~EnvoyQuicClientSession() {
ASSERT(!connection()->connected());
Expand All @@ -31,7 +33,7 @@ EnvoyQuicClientSession::~EnvoyQuicClientSession() {
absl::string_view EnvoyQuicClientSession::requestedServerName() const { return server_id().host(); }

void EnvoyQuicClientSession::connect() {
streamInfo().upstreamTiming().onUpstreamConnectStart(dispatcher_.timeSource());
streamInfo().upstreamInfo()->upstreamTiming().onUpstreamConnectStart(dispatcher_.timeSource());
dynamic_cast<EnvoyQuicClientConnection*>(network_connection_)
->setUpConnectionSocket(
*static_cast<EnvoyQuicClientConnection*>(connection())->connectionSocket(), *this);
Expand Down Expand Up @@ -133,8 +135,9 @@ void EnvoyQuicClientSession::OnTlsHandshakeComplete() {
// before use. This may result in OnCanCreateNewOutgoingStream with zero
// available streams.
OnCanCreateNewOutgoingStream(false);
streamInfo().upstreamTiming().onUpstreamConnectComplete(dispatcher_.timeSource());
streamInfo().upstreamTiming().onUpstreamHandshakeComplete(dispatcher_.timeSource());
streamInfo().upstreamInfo()->upstreamTiming().onUpstreamConnectComplete(dispatcher_.timeSource());
streamInfo().upstreamInfo()->upstreamTiming().onUpstreamHandshakeComplete(
dispatcher_.timeSource());

raiseConnectionEvent(Network::ConnectionEvent::Connected);
}
Expand Down
8 changes: 4 additions & 4 deletions source/common/router/header_formatter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,8 @@ parseMetadataField(absl::string_view params_str, bool upstream = true) {

return [upstream, params](const Envoy::StreamInfo::StreamInfo& stream_info) -> std::string {
const envoy::config::core::v3::Metadata* metadata = nullptr;
if (upstream) {
Upstream::HostDescriptionConstSharedPtr host = stream_info.upstreamHost();
if (upstream && stream_info.upstreamInfo()) {
Upstream::HostDescriptionConstSharedPtr host = stream_info.upstreamInfo()->upstreamHost();
if (!host) {
return std::string();
}
Expand Down Expand Up @@ -330,8 +330,8 @@ StreamInfoHeaderFormatter::StreamInfoHeaderFormatter(absl::string_view field_nam
field_extractor_ = parseSubstitutionFormatField(field_name, formatter_map_);
} else if (field_name == "UPSTREAM_REMOTE_ADDRESS") {
field_extractor_ = [](const Envoy::StreamInfo::StreamInfo& stream_info) -> std::string {
if (stream_info.upstreamHost()) {
return stream_info.upstreamHost()->address()->asString();
if (stream_info.upstreamInfo() && stream_info.upstreamInfo()->upstreamHost()) {
return stream_info.upstreamInfo()->upstreamHost()->address()->asString();
}
return "";
};
Expand Down
Loading