Skip to content

Commit

Permalink
comments
Browse files Browse the repository at this point in the history
Signed-off-by: Alyssa Wilk <alyssar@chromium.org>
  • Loading branch information
alyssawilk committed Oct 24, 2023
1 parent 182d595 commit 0b18640
Show file tree
Hide file tree
Showing 5 changed files with 174 additions and 60 deletions.
14 changes: 14 additions & 0 deletions envoy/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,20 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "router_filter_interface",
hdrs = ["router_filter_interface.h"],
external_deps = ["abseil_optional"],
deps = [
"//envoy/http:filter_interface",
"//envoy/http:header_map_interface",
"//envoy/stats:stats_interface",
"//envoy/stream_info:stream_info_interface",
"//envoy/upstream:cluster_manager_interface",
"//envoy/upstream:host_description_interface",
],
)

envoy_cc_library(
name = "router_interface",
hdrs = ["router.h"],
Expand Down
158 changes: 158 additions & 0 deletions envoy/router/router_filter_interface.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,158 @@
#pragma once

#include "envoy/http/filter.h"
#include "envoy/http/header_map.h"
#include "envoy/stats/scope.h"
#include "envoy/stats/stats_macros.h"
#include "envoy/stream_info/stream_info.h"
#include "envoy/upstream/cluster_manager.h"
#include "envoy/upstream/host_description.h"

namespace Envoy {
namespace Router {

class UpstreamRequest;

// This groups various per-stream timeouts conveniently together.
struct TimeoutData {
std::chrono::milliseconds global_timeout_{0};
std::chrono::milliseconds per_try_timeout_{0};
std::chrono::milliseconds per_try_idle_timeout_{0};
};

// The interface the UpstreamRequest has to interact with the router filter.
class RouterFilterInterface {
public:
virtual ~RouterFilterInterface() = default;

/**
* This will be called when upstream 1xx headers are ready to be processed by downstream code.
* @param headers contains the 1xx headers
* @param upstream_request inicates which UpstreamRequest the 1xx headers are from.
*
*/
virtual void onUpstream1xxHeaders(Http::ResponseHeaderMapPtr&& headers,
UpstreamRequest& upstream_request) PURE;
/**
* This will be called when upstream non-1xx headers are ready to be processed by downstream code.
* @param headers contains the headers
* @param upstream_request inicates which UpstreamRequest the headers are from.
* @param end_stream indicates if the response is complete.
*
*/
virtual void onUpstreamHeaders(uint64_t response_code, Http::ResponseHeaderMapPtr&& headers,
UpstreamRequest& upstream_request, bool end_stream) PURE;
/**
* This will be called when upstream data is ready to be processed by downstream code.
* @param data contains the data to process
* @param upstream_request inicates which UpstreamRequest the data is from.
* @param end_stream indicates if the response is complete.
*
*/
virtual void onUpstreamData(Buffer::Instance& data, UpstreamRequest& upstream_request,
bool end_stream) PURE;
/**
* This will be called when upstream trailers are ready to be processed by downstream code.
* @param trailers contains the trailers to process
* @param upstream_request inicates which UpstreamRequest the trailers are from.
*
*/
virtual void onUpstreamTrailers(Http::ResponseTrailerMapPtr&& trailers,
UpstreamRequest& upstream_request) PURE;
/**
* This will be called when upstream metadata is ready to be processed by downstream code.
* @param metadata contains the metadata to process
* @param upstream_request inicates which UpstreamRequest the metadata is from.
*
*/
virtual void onUpstreamMetadata(Http::MetadataMapPtr&& metadata_map) PURE;

/**
* This will be called when an upstream reset is ready to be processed by downstream code.
* @param reset_reason indicates the reason for the reset.
* @param transport_failure optionally indicates any transport failure.
* @param upstream_request inicates which UpstreamRequest the reset is from.
*
*/
virtual void onUpstreamReset(Http::StreamResetReason reset_reason,
absl::string_view transport_failure,
UpstreamRequest& upstream_request) PURE;

/**
* This will be called when an upstream host is selected. This is called both
* if the host can accomodate the stream and if the host is selected but unusable.
* @param host the host selected for the request
* @param pool_success indicates if the host can be used for the request.
*/
virtual void onUpstreamHostSelected(Upstream::HostDescriptionConstSharedPtr host,
bool pool_success) PURE;
/*
* This will be called if a per-try timeout fails.
* @param upstream_request inicates which UpstreamRequest which timed out
*/
virtual void onPerTryTimeout(UpstreamRequest& upstream_request) PURE;

/*
* This will be called if a per-try idle timeout fails.
* @param upstream_request inicates which UpstreamRequest which timed out
*/
virtual void onPerTryIdleTimeout(UpstreamRequest& upstream_request) PURE;

/*
* This will be called if the max stream duration was reached.
* @param upstream_request inicates which UpstreamRequest which timed out
*/
virtual void onStreamMaxDurationReached(UpstreamRequest& upstream_request) PURE;

/*
* @returns the Router filter's StreamDecoderFilterCallbacks.
*/
virtual Http::StreamDecoderFilterCallbacks* callbacks() PURE;
/*
* @returns the cluster for this stream.
*/
virtual Upstream::ClusterInfoConstSharedPtr cluster() PURE;

/*
* @returns the FilterConfig for this stream
*/
virtual FilterConfig& config() PURE;

/*
* @returns the various timeouts for this stream.
*/
virtual TimeoutData timeout() PURE;

/*
* @returns the dynamic max stream duraration for this stream, if set.
*/
virtual absl::optional<std::chrono::milliseconds> dynamicMaxStreamDuration() const PURE;

/*
* @returns the request headers for the stream.
*/
virtual Http::RequestHeaderMap* downstreamHeaders() PURE;

/*
* @returns the request trailers for the stream.
*/
virtual Http::RequestTrailerMap* downstreamTrailers() PURE;

/*
* @returns true if the downstream response has started.
*/
virtual bool downstreamResponseStarted() const PURE;

/*
* @returns true if end_stream has been sent from the upstream side to the downstream side.
*/
virtual bool downstreamEndStream() const PURE;

/*
* @returns the number of attempts (e.g. retries) performed for this stream.
*/
virtual uint32_t attemptCount() const PURE;
};

} // namespace Router
} // namespace Envoy
2 changes: 1 addition & 1 deletion source/common/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -280,7 +280,6 @@ envoy_cc_library(
],
hdrs = [
"router.h",
"router_filter_interface.h",
"upstream_request.h",
],
deps = [
Expand All @@ -300,6 +299,7 @@ envoy_cc_library(
"//envoy/http:filter_interface",
"//envoy/http:stateful_session_interface",
"//envoy/local_info:local_info_interface",
"//envoy/router:router_filter_interface",
"//envoy/router:shadow_writer_interface",
"//envoy/runtime:runtime_interface",
"//envoy/server:factory_context_interface",
Expand Down
2 changes: 1 addition & 1 deletion source/common/router/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
#include "envoy/http/hash_policy.h"
#include "envoy/http/stateful_session.h"
#include "envoy/local_info/local_info.h"
#include "envoy/router/router_filter_interface.h"
#include "envoy/router/shadow_writer.h"
#include "envoy/runtime/runtime.h"
#include "envoy/server/factory_context.h"
Expand All @@ -38,7 +39,6 @@
#include "source/common/http/utility.h"
#include "source/common/router/config_impl.h"
#include "source/common/router/context_impl.h"
#include "source/common/router/router_filter_interface.h"
#include "source/common/router/upstream_request.h"
#include "source/common/stats/symbol_table.h"
#include "source/common/stream_info/stream_info_impl.h"
Expand Down
58 changes: 0 additions & 58 deletions source/common/router/router_filter_interface.h

This file was deleted.

0 comments on commit 0b18640

Please sign in to comment.