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
105 changes: 104 additions & 1 deletion envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,99 @@ struct BytesMeter {

using BytesMeterSharedPtr = std::shared_ptr<BytesMeter>;

// TODO(alyssawilk) after landing this, remove all the duplicate getters and
// setters from StreamInfo.
class UpstreamInfo {
public:
virtual ~UpstreamInfo() = default;

/**
* Dump the upstream info to the specified ostream.
*
* @param os the ostream to dump state to
* @param indent_level the depth, for pretty-printing.
*
* This function is called on Envoy fatal errors so should avoid memory allocation.
*/
virtual void dumpState(std::ostream& os, int indent_level = 0) 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 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;

/**
* 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;

/*
* @return the upstream timing for this stream
* */
virtual UpstreamTiming& upstreamTiming() PURE;
virtual const UpstreamTiming& upstreamTiming() 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;

/**
* @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 host the selected upstream host for the request.
*/
virtual void setUpstreamHost(Upstream::HostDescriptionConstSharedPtr host) PURE;

/**
* @return upstream host description.
*/
virtual Upstream::HostDescriptionConstSharedPtr upstreamHost() 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;
};

/**
* Additional information about a completed request for logging.
*/
Expand Down Expand Up @@ -422,13 +515,23 @@ class StreamInfo {
*/
virtual void setUpstreamTiming(const UpstreamTiming& upstream_timing) PURE;

/**
* Sets the upstream information for this stream.
*/
virtual void setUpstreamInfo(std::shared_ptr<UpstreamInfo>) PURE;

/**
* Returns the upstream information for this stream.
*/
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;
virtual const UpstreamTiming& upstreamTiming() const PURE;

/**
* @return the duration between the first byte of the request was sent upstream and the start of
Expand Down
10 changes: 6 additions & 4 deletions source/common/router/upstream_request.cc
Original file line number Diff line number Diff line change
Expand Up @@ -427,10 +427,12 @@ void UpstreamRequest::onPoolReady(
stream_info_.protocol(protocol.value());
}

upstream_timing_.upstream_connect_start_ = info.upstreamTiming().upstream_connect_start_;
upstream_timing_.upstream_connect_complete_ = info.upstreamTiming().upstream_connect_complete_;
upstream_timing_.upstream_handshake_complete_ =
info.upstreamTiming().upstream_handshake_complete_;
if (info.upstreamInfo().has_value()) {
auto& upstream_timing = info.upstreamInfo().value().get().upstreamTiming();
upstream_timing_.upstream_connect_start_ = upstream_timing.upstream_connect_start_;
upstream_timing_.upstream_connect_complete_ = upstream_timing.upstream_connect_complete_;
upstream_timing_.upstream_handshake_complete_ = upstream_timing.upstream_handshake_complete_;
}

stream_info_.setUpstreamFilterState(std::make_shared<StreamInfo::FilterStateImpl>(
info.filterState().parent()->parent(), StreamInfo::FilterState::LifeSpan::Request));
Expand Down
Loading