Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
57 commits
Select commit Hold shift + click to select a range
3607b52
added hash check to specifier, started with cluster
drewsortega Sep 2, 2020
abadb7e
formatting fixes
drewsortega Sep 2, 2020
3d58e70
start setup for incremental changes to hds clusters
drewsortega Sep 2, 2020
0f55f8b
Kick CI
drewsortega Sep 3, 2020
abff735
move cluster config building into its own function
drewsortega Sep 3, 2020
a69ec54
add init check, break add and start HCs
drewsortega Sep 6, 2020
9ded2b3
set up for updating healthcheckers and hosts per cluster
drewsortega Sep 6, 2020
082fd05
add comment pseudocode
drewsortega Sep 6, 2020
f32ac32
update TODO comments
drewsortega Sep 6, 2020
20f069f
hash endpoints and health check lists to stop not needed updates
drewsortega Sep 6, 2020
d18e03d
finish health_checkers_ incremental updates
drewsortega Sep 7, 2020
a339771
remove cluster vector clear, use std::move instead
drewsortega Sep 7, 2020
28bc269
finish first implementation of dynamic endpoint/host updates
drewsortega Sep 7, 2020
1d2d07a
make maps not pointers, improve host map key
drewsortega Sep 7, 2020
a456e75
remove return from updateHdsCluster and rename function
drewsortega Sep 7, 2020
89d7043
unit test: repeated specifier
drewsortega Sep 9, 2020
635c220
Merge branch 'master' into hds_partial_updates
drewsortega Sep 9, 2020
7993f9f
unit test: change around Clusters, add/remove with reuse
drewsortega Sep 10, 2020
cdc019e
formatting fixes
drewsortega Sep 10, 2020
0f2fafc
fix: use correct cluster name map, hash correct endpoints list
drewsortega Sep 10, 2020
37a9bdf
priority_set_ bug fix, pass endpoints test
drewsortega Sep 11, 2020
63d8aa7
fix hcs using wrong hash, finish health checker update unit test
drewsortega Sep 11, 2020
c66236a
add better Endpoint hashing for map
drewsortega Sep 11, 2020
14011cd
formatting fix
drewsortega Sep 11, 2020
9a04a72
add more code comments for clarity
drewsortega Sep 11, 2020
2bd69ea
add alternative update function for PrioritySetImpl
drewsortega Sep 12, 2020
6d2440c
add missing proto dependency for locality_endpoint
drewsortega Sep 12, 2020
2108707
fix missing file content
drewsortega Sep 12, 2020
a3e2b46
update version history
drewsortega Sep 12, 2020
0226683
fix hosts_added building, reverted PrioritySetImpl changes
drewsortega Sep 12, 2020
51f5ec2
add newline to end of locality_endpoint.h
drewsortega Sep 12, 2020
ebef8af
use better keys for HealthChecker map
drewsortega Sep 12, 2020
60e7e65
move Eq checks and hashers to source/common/upstream
drewsortega Sep 15, 2020
7777e06
simplify LocalityEndpoint hashing
drewsortega Sep 15, 2020
b72feab
remove hash-key hash table and do hash compare inside of HdsCluster
drewsortega Sep 15, 2020
08552a1
remove redundant repeated field hashing, add updater to ClusterInfo
drewsortega Sep 15, 2020
2f74977
hash cluster_ instead of moved cluster
drewsortega Sep 15, 2020
cccf9d1
add bad cluster_name warnings, use dynamic not static cast
drewsortega Sep 16, 2020
b6dd5c2
use more const keywords where possible
drewsortega Sep 16, 2020
f4b1458
add log messages for repeated or empty cluster_names
drewsortega Sep 16, 2020
ba5a277
improve specifier change test
drewsortega Sep 16, 2020
7a231f1
add transport socket match update unit test, code cleanup
drewsortega Sep 16, 2020
68f6cc6
improve update socket unit test, that not always re-created.
drewsortega Sep 16, 2020
11c81a3
fix function name
drewsortega Sep 16, 2020
79200e7
intg test: remove cluster, add endpoint, reuse endpoint
drewsortega Sep 18, 2020
c6b69fa
remove complexity of updating info_ object
drewsortega Sep 18, 2020
187d103
minor comment changes
drewsortega Sep 18, 2020
e39cc33
test optimizations
drewsortega Sep 18, 2020
470be7b
comment fixes.
drewsortega Sep 18, 2020
45b2340
Merge branch 'master' into hds_partial_updates
drewsortega Sep 18, 2020
b6bc0ed
style fixes, add TODO comment.
drewsortega Sep 18, 2020
0430665
add more TODO comments.
drewsortega Sep 18, 2020
50bca5d
Merge remote-tracking branch 'upstream/master' into hds_partial_updates
drewsortega Oct 14, 2020
380c1ca
remove random from new unit test
drewsortega Oct 14, 2020
b39a2f6
fix version history merge problems
drewsortega Oct 14, 2020
ddef6e5
apply format fix patch from CI
drewsortega Oct 14, 2020
e0fb96a
fix version history alphabetical order
drewsortega Oct 14, 2020
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
1 change: 1 addition & 0 deletions docs/root/version_history/current.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Removed Config or Runtime
New Features
------------
* grpc: implemented header value syntax support when defining :ref:`initial metadata <envoy_v3_api_field_config.core.v3.GrpcService.initial_metadata>` for gRPC-based `ext_authz` :ref:`HTTP <envoy_v3_api_field_extensions.filters.http.ext_authz.v3.ExtAuthz.grpc_service>` and :ref:`network <envoy_v3_api_field_extensions.filters.network.ext_authz.v3.ExtAuthz.grpc_service>` filters, and :ref:`ratelimit <envoy_v3_api_field_config.ratelimit.v3.RateLimitServiceConfig.grpc_service>` filters.
* hds: added support for delta updates in the :ref:`HealthCheckSpecifier <envoy_v3_api_msg_service.health.v3.HealthCheckSpecifier>`, making only the Endpoints and Health Checkers that changed be reconstructed on receiving a new message, rather than the entire HDS.
* health_check: added option to use :ref:`no_traffic_healthy_interval <envoy_v3_api_field_config.core.v3.HealthCheck.no_traffic_healthy_interval>` which allows a different no traffic interval when the host is healthy.
* mongo_proxy: the list of commands to produce metrics for is now :ref:`configurable <envoy_v3_api_field_extensions.filters.network.mongo_proxy.v3.MongoProxy.commands>`.
* ratelimit: added :ref:`disable_x_envoy_ratelimited_header <envoy_v3_api_msg_extensions.filters.http.ratelimit.v3.RateLimit>` option to disable `X-Envoy-RateLimited` header.
Expand Down
11 changes: 11 additions & 0 deletions source/common/upstream/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -202,12 +202,23 @@ envoy_cc_library(
],
)

envoy_cc_library(
name = "locality_endpoint_lib",
hdrs = ["locality_endpoint.h"],
deps = [
"//source/common/protobuf:utility_lib",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/endpoint/v3:pkg_cc_proto",
],
)

envoy_cc_library(
name = "health_discovery_service_lib",
srcs = ["health_discovery_service.cc"],
hdrs = ["health_discovery_service.h"],
deps = [
":health_checker_lib",
":locality_endpoint_lib",
":upstream_includes",
"//include/envoy/api:api_interface",
"//include/envoy/event:dispatcher_interface",
Expand Down
17 changes: 17 additions & 0 deletions source/common/upstream/health_checker_base_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,23 @@ struct HealthCheckerStats {
ALL_HEALTH_CHECKER_STATS(GENERATE_COUNTER_STRUCT, GENERATE_GAUGE_STRUCT)
};

/**
* HealthCheckerHash and HealthCheckerEqualTo are used to allow the HealthCheck proto to be used as
* a flat_hash_map key.
*/
struct HealthCheckerHash {
size_t operator()(const envoy::config::core::v3::HealthCheck& health_check) const {
return MessageUtil::hash(health_check);
}
};

struct HealthCheckerEqualTo {
bool operator()(const envoy::config::core::v3::HealthCheck& lhs,
const envoy::config::core::v3::HealthCheck& rhs) const {
return Protobuf::util::MessageDifferencer::Equals(lhs, rhs);
}
};

/**
* Base implementation for all health checkers.
*/
Expand Down
348 changes: 285 additions & 63 deletions source/common/upstream/health_discovery_service.cc

Large diffs are not rendered by default.

56 changes: 46 additions & 10 deletions source/common/upstream/health_discovery_service.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,24 @@
#include "common/grpc/async_client_impl.h"
#include "common/network/resolver_impl.h"
#include "common/upstream/health_checker_impl.h"
#include "common/upstream/locality_endpoint.h"
#include "common/upstream/upstream_impl.h"

#include "server/transport_socket_config_impl.h"

#include "extensions/transport_sockets/well_known_names.h"

#include "absl/container/flat_hash_map.h"

namespace Envoy {
namespace Upstream {

using HostsMap = absl::flat_hash_map<LocalityEndpointTuple, HostSharedPtr, LocalityEndpointHash,
LocalityEndpointEqualTo>;
using HealthCheckerMap =
absl::flat_hash_map<envoy::config::core::v3::HealthCheck, Upstream::HealthCheckerSharedPtr,
HealthCheckerHash, HealthCheckerEqualTo>;

class ProdClusterInfoFactory : public ClusterInfoFactory, Logger::Loggable<Logger::Id::upstream> {
public:
ClusterInfoConstSharedPtr createClusterInfo(const CreateClusterInfoParams& params) override;
Expand Down Expand Up @@ -60,12 +69,19 @@ class HdsCluster : public Cluster, Logger::Loggable<Logger::Id::upstream> {
Outlier::Detector* outlierDetector() override { return outlier_detector_.get(); }
const Outlier::Detector* outlierDetector() const override { return outlier_detector_.get(); }
void initialize(std::function<void()> callback) override;

// Creates and starts healthcheckers to its endpoints
void startHealthchecks(AccessLog::AccessLogManager& access_log_manager, Runtime::Loader& runtime,
Event::Dispatcher& dispatcher, Api::Api& api);
// Compare changes in the cluster proto, and update parts of the cluster as needed.
void update(Server::Admin& admin, envoy::config::cluster::v3::Cluster cluster,
ClusterInfoFactory& info_factory, ClusterManager& cm,
const LocalInfo::LocalInfo& local_info, Event::Dispatcher& dispatcher,
Singleton::Manager& singleton_manager, ThreadLocal::SlotAllocator& tls,
ProtobufMessage::ValidationVisitor& validation_visitor, Api::Api& api,
AccessLog::AccessLogManager& access_log_manager, Runtime::Loader& runtime);
// Creates healthcheckers and adds them to the list, then does initial start.
void initHealthchecks(AccessLog::AccessLogManager& access_log_manager, Runtime::Loader& runtime,
Event::Dispatcher& dispatcher, Api::Api& api);

std::vector<Upstream::HealthCheckerSharedPtr> healthCheckers() { return health_checkers_; };
std::vector<HostSharedPtr> hosts() { return *hosts_; };

protected:
PrioritySetImpl priority_set_;
Expand All @@ -76,17 +92,31 @@ class HdsCluster : public Cluster, Logger::Loggable<Logger::Id::upstream> {
std::function<void()> initialization_complete_callback_;

Runtime::Loader& runtime_;
const envoy::config::cluster::v3::Cluster cluster_;
envoy::config::cluster::v3::Cluster cluster_;
const envoy::config::core::v3::BindConfig& bind_config_;
Stats::Store& stats_;
Ssl::ContextManager& ssl_context_manager_;
bool added_via_api_;
bool initialized_ = false;
uint64_t config_hash_;
uint64_t socket_match_hash_;

HostVectorSharedPtr initial_hosts_;
HostsPerLocalitySharedPtr initial_hosts_per_locality_;
HostVectorSharedPtr hosts_;
HostsPerLocalitySharedPtr hosts_per_locality_;
HostsMap hosts_map_;
ClusterInfoConstSharedPtr info_;
std::vector<Upstream::HealthCheckerSharedPtr> health_checkers_;
HealthCheckerMap health_checkers_map_;
ProtobufMessage::ValidationVisitor& validation_visitor_;

void updateHealthchecks(
const Protobuf::RepeatedPtrField<envoy::config::core::v3::HealthCheck>& health_checks,
AccessLog::AccessLogManager& access_log_manager, Runtime::Loader& runtime,
Event::Dispatcher& dispatcher, Api::Api& api);
void
updateHosts(const Protobuf::RepeatedPtrField<envoy::config::endpoint::v3::LocalityLbEndpoints>&
locality_endpoints,
bool update_socket_matches);
};

using HdsClusterPtr = std::shared_ptr<HdsCluster>;
Expand All @@ -97,7 +127,8 @@ using HdsClusterPtr = std::shared_ptr<HdsCluster>;
#define ALL_HDS_STATS(COUNTER) \
COUNTER(requests) \
COUNTER(responses) \
COUNTER(errors)
COUNTER(errors) \
COUNTER(updates)

/**
* Struct definition for all hds stats. @see stats_macros.h
Expand Down Expand Up @@ -145,7 +176,11 @@ class HdsDelegate : Grpc::AsyncStreamCallbacks<envoy::service::health::v3::Healt
// Establishes a connection with the management server
void establishNewStream();
void processMessage(std::unique_ptr<envoy::service::health::v3::HealthCheckSpecifier>&& message);

envoy::config::cluster::v3::Cluster
createClusterConfig(const envoy::service::health::v3::ClusterHealthCheck& cluster_health_check);
void updateHdsCluster(HdsClusterPtr cluster,
const envoy::config::cluster::v3::Cluster& cluster_health_check);
HdsClusterPtr createHdsCluster(const envoy::config::cluster::v3::Cluster& cluster_health_check);
HdsDelegateStats stats_;
const Protobuf::MethodDescriptor& service_method_;

Expand All @@ -168,10 +203,11 @@ class HdsDelegate : Grpc::AsyncStreamCallbacks<envoy::service::health::v3::Healt
ThreadLocal::SlotAllocator& tls_;

envoy::service::health::v3::HealthCheckRequestOrEndpointHealthResponse health_check_request_;
std::unique_ptr<envoy::service::health::v3::HealthCheckSpecifier> health_check_message_;
uint64_t specifier_hash_;

std::vector<std::string> clusters_;
std::vector<HdsClusterPtr> hds_clusters_;
absl::flat_hash_map<std::string, HdsClusterPtr> hds_clusters_name_map_;

Event::TimerPtr hds_stream_response_timer_;
Event::TimerPtr hds_retry_timer_;
Expand Down
29 changes: 29 additions & 0 deletions source/common/upstream/locality_endpoint.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#pragma once

#include "envoy/config/core/v3/base.pb.h"
#include "envoy/config/endpoint/v3/endpoint_components.pb.h"

#include "common/protobuf/utility.h"

namespace Envoy {
namespace Upstream {

using LocalityEndpointTuple = std::tuple<const envoy::config::core::v3::Locality&,
const envoy::config::endpoint::v3::LbEndpoint&>;
struct LocalityEndpointHash {
size_t operator()(const LocalityEndpointTuple& values) const {
const auto locality_hash = MessageUtil::hash(std::get<0>(values));
const auto endpoint_hash = MessageUtil::hash(std::get<1>(values));
return locality_hash ^ endpoint_hash;
}
};

struct LocalityEndpointEqualTo {
bool operator()(const LocalityEndpointTuple& lhs, const LocalityEndpointTuple& rhs) const {
return Protobuf::util::MessageDifferencer::Equals(std::get<0>(lhs), std::get<0>(rhs)) &&
Protobuf::util::MessageDifferencer::Equals(std::get<1>(lhs), std::get<1>(rhs));
}
};

} // namespace Upstream
} // namespace Envoy
Loading