Skip to content
Closed
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
11 changes: 10 additions & 1 deletion include/envoy/router/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ envoy_cc_library(
hdrs = ["router.h"],
external_deps = ["abseil_optional"],
deps = [
":upstream_endpoint_interface",
"//include/envoy/access_log:access_log_interface",
"//include/envoy/common:matchers_interface",
"//include/envoy/config:typed_metadata_interface",
Expand All @@ -64,12 +65,20 @@ envoy_cc_library(
"//include/envoy/upstream:resource_manager_interface",
"//include/envoy/upstream:retry_interface",
"//source/common/protobuf",
"//source/common/protobuf:utility_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/type/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "upstream_endpoint_interface",
hdrs = ["upstream_endpoint_info.h"],
deps = [
"//source/common/protobuf",
"//source/common/protobuf:protobuf_utility_lib",
],
)

envoy_cc_library(
name = "scopes_interface",
hdrs = ["scopes.h"],
Expand Down
70 changes: 3 additions & 67 deletions include/envoy/router/router.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,13 @@
#include "envoy/http/codes.h"
#include "envoy/http/hash_policy.h"
#include "envoy/http/header_map.h"
#include "envoy/router/upstream_endpoint_info.h"
#include "envoy/tracing/http_tracer.h"
#include "envoy/type/v3/percent.pb.h"
#include "envoy/upstream/resource_manager.h"
#include "envoy/upstream/retry.h"

#include "common/protobuf/protobuf.h"
#include "common/protobuf/utility.h"

#include "absl/types/optional.h"

Expand Down Expand Up @@ -487,59 +487,6 @@ class HedgePolicy {
virtual bool hedgeOnPerTryTimeout() const PURE;
};

class MetadataMatchCriterion {
public:
virtual ~MetadataMatchCriterion() = default;

/*
* @return const std::string& the name of the metadata key
*/
virtual const std::string& name() const PURE;

/*
* @return const Envoy::HashedValue& the value for the metadata key
*/
virtual const HashedValue& value() const PURE;
};

using MetadataMatchCriterionConstSharedPtr = std::shared_ptr<const MetadataMatchCriterion>;

class MetadataMatchCriteria;
using MetadataMatchCriteriaConstPtr = std::unique_ptr<const MetadataMatchCriteria>;

class MetadataMatchCriteria {
public:
virtual ~MetadataMatchCriteria() = default;

/*
* @return std::vector<MetadataMatchCriterionConstSharedPtr>& a vector of
* metadata to be matched against upstream endpoints when load
* balancing, sorted lexically by name.
*/
virtual const std::vector<MetadataMatchCriterionConstSharedPtr>&
metadataMatchCriteria() const PURE;

/**
* Creates a new MetadataMatchCriteria, merging existing
* metadata criteria with the provided criteria. The result criteria is the
* combination of both sets of criteria, with those from the metadata_matches
* ProtobufWkt::Struct taking precedence.
* @param metadata_matches supplies the new criteria.
* @return MetadataMatchCriteriaConstPtr the result criteria.
*/
virtual MetadataMatchCriteriaConstPtr
mergeMatchCriteria(const ProtobufWkt::Struct& metadata_matches) const PURE;

/**
* Creates a new MetadataMatchCriteria with criteria vector reduced to given names
* @param names names of metadata keys to preserve
* @return MetadataMatchCriteriaConstPtr the result criteria. Returns nullptr if the result
* criteria are empty.
*/
virtual MetadataMatchCriteriaConstPtr
filterMatchCriteria(const std::set<std::string>& names) const PURE;
};

/**
* Criterion that a route entry uses for matching TLS connection context.
*/
Expand Down Expand Up @@ -597,15 +544,10 @@ class HttpRouteTypedMetadataFactory : public Envoy::Config::TypedMetadataFactory
/**
* An individual resolved route entry.
*/
class RouteEntry : public ResponseEntry {
class RouteEntry : public ResponseEntry, public UpstreamEndpointInfo {
public:
~RouteEntry() override = default;

/**
* @return const std::string& the upstream cluster that owns the route.
*/
virtual const std::string& clusterName() const PURE;

/**
* Returns the HTTP status code to use when configured cluster is not found.
* @return Http::Code to use when configured cluster is not found.
Expand Down Expand Up @@ -713,12 +655,6 @@ class RouteEntry : public ResponseEntry {
*/
virtual bool autoHostRewrite() const PURE;

/**
* @return MetadataMatchCriteria* the metadata that a subset load balancer should match when
* selecting an upstream host
*/
virtual const MetadataMatchCriteria* metadataMatchCriteria() const PURE;

/**
* @return const std::multimap<std::string, std::string> the opaque configuration associated
* with the route
Expand Down Expand Up @@ -893,7 +829,7 @@ class Route {
/**
* @return the route entry or nullptr if there is no matching route for the request.
*/
virtual const RouteEntry* routeEntry() const PURE;
virtual const std::shared_ptr<const RouteEntry> routeEntry() const PURE;

/**
* @return the decorator or nullptr if not defined for the request.
Expand Down
88 changes: 88 additions & 0 deletions include/envoy/router/upstream_endpoint_info.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
#pragma once

#include <chrono>
#include <cstdint>
#include <functional>
#include <list>
#include <map>
#include <memory>
#include <string>

#include "common/protobuf/protobuf.h"
#include "common/protobuf/protobuf_utility.h"

namespace Envoy {
namespace Router {

class MetadataMatchCriterion {
public:
virtual ~MetadataMatchCriterion() = default;

/*
* @return const std::string& the name of the metadata key
*/
virtual const std::string& name() const PURE;

/*
* @return const Envoy::HashedValue& the value for the metadata key
*/
virtual const HashedValue& value() const PURE;
};

using MetadataMatchCriterionConstSharedPtr = std::shared_ptr<const MetadataMatchCriterion>;

class MetadataMatchCriteria;
using MetadataMatchCriteriaConstPtr = std::unique_ptr<const MetadataMatchCriteria>;

class MetadataMatchCriteria {
public:
virtual ~MetadataMatchCriteria() = default;

/*
* @return std::vector<MetadataMatchCriterionConstSharedPtr>& a vector of
* metadata to be matched against upstream endpoints when load
* balancing, sorted lexically by name.
*/
virtual const std::vector<MetadataMatchCriterionConstSharedPtr>&
metadataMatchCriteria() const PURE;

/**
* Creates a new MetadataMatchCriteria, merging existing
* metadata criteria with the provided criteria. The result criteria is the
* combination of both sets of criteria, with those from the metadata_matches
* ProtobufWkt::Struct taking precedence.
* @param metadata_matches supplies the new criteria.
* @return MetadataMatchCriteriaConstPtr the result criteria.
*/
virtual MetadataMatchCriteriaConstPtr
mergeMatchCriteria(const ProtobufWkt::Struct& metadata_matches) const PURE;

/**
* Creates a new MetadataMatchCriteria with criteria vector reduced to given names
* @param names names of metadata keys to preserve
* @return MetadataMatchCriteriaConstPtr the result criteria. Returns nullptr if the result
* criteria are empty.
*/
virtual MetadataMatchCriteriaConstPtr
filterMatchCriteria(const std::set<std::string>& names) const PURE;
};

class UpstreamEndpointInfo {
public:
virtual ~UpstreamEndpointInfo() = default;

/**
* @return const std::string& the upstream cluster that owns the route.
*/
virtual const std::string& clusterName() const PURE;

/**
* @return MetadataMatchCriteria* the metadata that a subset load balancer should match when
* selecting an upstream host
*/
virtual const MetadataMatchCriteria* metadataMatchCriteria() const PURE;
};

using UpstreamEndpointInfoConstSharedPtr = std::shared_ptr<const UpstreamEndpointInfo>;
} // namespace Router
} // namespace Envoy
1 change: 1 addition & 0 deletions include/envoy/stream_info/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ envoy_cc_library(
"//include/envoy/common:time_interface",
"//include/envoy/http:header_map_interface",
"//include/envoy/http:protocol_interface",
"//include/envoy/router:upstream_endpoint_interface",
"//include/envoy/ssl:connection_interface",
"//include/envoy/upstream:host_description_interface",
"//source/common/common:assert_lib",
Expand Down
17 changes: 17 additions & 0 deletions include/envoy/stream_info/stream_info.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include "envoy/config/core/v3/base.pb.h"
#include "envoy/http/header_map.h"
#include "envoy/http/protocol.h"
#include "envoy/router/upstream_endpoint_info.h"
#include "envoy/ssl/connection.h"
#include "envoy/stream_info/filter_state.h"
#include "envoy/upstream/host_description.h"
Expand Down Expand Up @@ -453,6 +454,22 @@ class StreamInfo {
*/
virtual Ssl::ConnectionInfoConstSharedPtr upstreamSslConnection() const PURE;

/**
* @param upstream_endpoint_info sets the upstream endpoint info like cluster_name.
*/
virtual void setUpstreamEndpointInfo(
const Router::UpstreamEndpointInfoConstSharedPtr& upstream_endpoint_info) PURE;
/**
* @return const Router::UpstreamEndpointInfo* Get the upstream endpoint info selected for this
* request. Note: this will be nullptr if no route was selected.
*/
virtual const Router::UpstreamEndpointInfo* upstreamEndpointInfo() const PURE;

/**
* @param route_entry sets the RouteEntry for HTTP and UpstreamEndpointInfo for TCP.
*/
virtual void setRouteEntry(const std::shared_ptr<const Router::RouteEntry>& route_entry) PURE;

/**
* @return const Router::RouteEntry* Get the route entry selected for this request. Note: this
* will be nullptr if no route was selected.
Expand Down
1 change: 1 addition & 0 deletions include/envoy/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ envoy_cc_library(
hdrs = ["retry.h"],
deps = [
"//include/envoy/config:typed_config_interface",
"//include/envoy/protobuf:message_validator_interface",
"//include/envoy/upstream:types_interface",
"//include/envoy/upstream:upstream_interface",
],
Expand Down
1 change: 1 addition & 0 deletions include/envoy/upstream/retry.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#pragma once

#include "envoy/config/typed_config.h"
#include "envoy/protobuf/message_validator.h"
#include "envoy/upstream/types.h"
#include "envoy/upstream/upstream.h"

Expand Down
8 changes: 5 additions & 3 deletions source/common/http/async_client_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -300,18 +300,20 @@ class AsyncStreamImpl : public AsyncClient::Stream,
const absl::optional<std::chrono::milliseconds>& timeout,
const Protobuf::RepeatedPtrField<envoy::config::route::v3::RouteAction::HashPolicy>&
hash_policy)
: route_entry_(cluster_name, timeout, hash_policy) {}
: route_entry_(std::make_shared<RouteEntryImpl>(cluster_name, timeout, hash_policy)) {}

// Router::Route
const Router::DirectResponseEntry* directResponseEntry() const override { return nullptr; }
const Router::RouteEntry* routeEntry() const override { return &route_entry_; }
const std::shared_ptr<const Router::RouteEntry> routeEntry() const override {
return route_entry_;
}
const Router::Decorator* decorator() const override { return nullptr; }
const Router::RouteTracing* tracingConfig() const override { return nullptr; }
const Router::RouteSpecificFilterConfig* perFilterConfig(const std::string&) const override {
return nullptr;
}

RouteEntryImpl route_entry_;
std::shared_ptr<RouteEntryImpl> route_entry_;
};

void cleanup();
Expand Down
7 changes: 5 additions & 2 deletions source/common/http/conn_manager_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ void ConnectionManagerImpl::ActiveStream::decodeHeaders(RequestHeaderMapPtr&& he
}

if (hasCachedRoute()) {
const Router::RouteEntry* route_entry = cached_route_.value()->routeEntry();
const auto route_entry = cached_route_.value()->routeEntry();
if (route_entry != nullptr && route_entry->idleTimeout()) {
idle_timeout_ms_ = route_entry->idleTimeout().value();
if (idle_timeout_ms_.count()) {
Expand Down Expand Up @@ -1396,7 +1396,10 @@ void ConnectionManagerImpl::ActiveStream::refreshCachedRoute() {
route = snapped_route_config_->route(*request_headers_, stream_info_, stream_id_);
}
}
stream_info_.route_entry_ = route ? route->routeEntry() : nullptr;
stream_info_.setRouteEntry(route ? route->routeEntry() : nullptr);
stream_info_.setUpstreamEndpointInfo(
route ? std::dynamic_pointer_cast<const Router::UpstreamEndpointInfo>(route->routeEntry())
: nullptr);
cached_route_ = std::move(route);
if (nullptr == stream_info_.route_entry_) {
cached_cluster_info_ = nullptr;
Expand Down
2 changes: 1 addition & 1 deletion source/common/http/utility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ void Utility::traversePerFilterConfigGeneric(
return;
}

const Router::RouteEntry* routeEntry = route->routeEntry();
const std::shared_ptr<const Router::RouteEntry> routeEntry = route->routeEntry();

if (routeEntry != nullptr) {
auto maybe_vhost_config = routeEntry->virtualHost().perFilterConfig(filter_name);
Expand Down
15 changes: 14 additions & 1 deletion source/common/protobuf/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ envoy_cc_library(
"//include/envoy/protobuf:message_validator_interface",
"//include/envoy/stats:stats_interface",
"//source/common/common:hash_lib",
"//source/common/common:logger_lib",
"//source/common/common:macros",
"//source/common/common:minimal_logger_lib",
],
)

Expand All @@ -48,6 +48,18 @@ envoy_cc_library(
deps = [":cc_wkt_protos"],
)

envoy_cc_library(
name = "protobuf_utility_lib",
hdrs = ["protobuf_utility.h"],
external_deps = [
"protobuf",
],
deps = [
":protobuf",
"//source/common/common:hash_lib",
],
)

envoy_cc_library(
name = "utility_lib",
srcs = ["utility.cc"],
Expand All @@ -59,6 +71,7 @@ envoy_cc_library(
deps = [
":message_validator_lib",
":protobuf",
":protobuf_utility_lib",
":well_known_lib",
"//include/envoy/api:api_interface",
"//include/envoy/protobuf:message_validator_interface",
Expand Down
Loading