-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: add support for setting degraded through LoadAssignment #5649
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
d8d4aa3
upstream: add support for setting degraded through EDS
5f6fe9a
add admin output for new flag
c980745
PR feedback naming changes, remove std::cerrs
8f413f5
Merge remote-tracking branch 'origin/master' into degraded-eds
0071ab8
clean up merge
aa99b0e
specify FALLTHRU and add integration test coverage
5cb9477
Merge remote-tracking branch 'origin/master' into degraded-eds
198eb6e
fix bad merge
3626ea7
move setEdsFlag to HostImpl ctor, add test description
44015a1
fix load balancer simulation
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -170,6 +170,30 @@ parseExtensionProtocolOptions(const envoy::api::v2::Cluster& config) { | |
| return options; | ||
| } | ||
|
|
||
| // Updates the health flags for an existing host to match the new host. | ||
| // @param updated_host the new host to read health flag values from. | ||
| // @param existing_host the host to update. | ||
| // @param flag the health flag to update. | ||
| // @return bool whether the flag update caused the host health to change. | ||
| bool updateHealthFlag(const Host& updated_host, Host& existing_host, Host::HealthFlag flag) { | ||
| // Check if the health flag has changed. | ||
| if (existing_host.healthFlagGet(flag) != updated_host.healthFlagGet(flag)) { | ||
| // Keep track of the previous health value of the host. | ||
| const auto previous_health = existing_host.health(); | ||
|
|
||
| if (updated_host.healthFlagGet(flag)) { | ||
| existing_host.healthFlagSet(flag); | ||
| } else { | ||
| existing_host.healthFlagClear(flag); | ||
| } | ||
|
|
||
| // Rebuild if changing the flag affected the host health. | ||
| return previous_health != existing_host.health(); | ||
| } | ||
|
|
||
| return false; | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| Host::CreateConnectionData HostImpl::createConnection( | ||
|
|
@@ -179,6 +203,24 @@ Host::CreateConnectionData HostImpl::createConnection( | |
| shared_from_this()}; | ||
| } | ||
|
|
||
| void HostImpl::setEdsHealthFlag(envoy::api::v2::core::HealthStatus health_status) { | ||
| switch (health_status) { | ||
| case envoy::api::v2::core::HealthStatus::UNHEALTHY: | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit: Maybe add fall-thru annotations or comments here. |
||
| FALLTHRU; | ||
| case envoy::api::v2::core::HealthStatus::DRAINING: | ||
| FALLTHRU; | ||
| case envoy::api::v2::core::HealthStatus::TIMEOUT: | ||
| healthFlagSet(Host::HealthFlag::FAILED_EDS_HEALTH); | ||
| break; | ||
| case envoy::api::v2::core::HealthStatus::DEGRADED: | ||
| healthFlagSet(Host::HealthFlag::DEGRADED_EDS_HEALTH); | ||
| break; | ||
| default:; | ||
| break; | ||
| // No health flags should be set. | ||
| } | ||
| } | ||
|
|
||
| Host::CreateConnectionData | ||
| HostImpl::createHealthCheckConnection(Event::Dispatcher& dispatcher) const { | ||
| return {createConnection(dispatcher, *cluster_, healthCheckAddress(), nullptr, nullptr), | ||
|
|
@@ -863,32 +905,22 @@ void PriorityStateManager::initializePriorityFor( | |
| void PriorityStateManager::registerHostForPriority( | ||
| const std::string& hostname, Network::Address::InstanceConstSharedPtr address, | ||
| const envoy::api::v2::endpoint::LocalityLbEndpoints& locality_lb_endpoint, | ||
| const envoy::api::v2::endpoint::LbEndpoint& lb_endpoint, | ||
| const absl::optional<Upstream::Host::HealthFlag> health_checker_flag) { | ||
| const envoy::api::v2::endpoint::LbEndpoint& lb_endpoint) { | ||
| const HostSharedPtr host( | ||
| new HostImpl(parent_.info(), hostname, address, lb_endpoint.metadata(), | ||
| lb_endpoint.load_balancing_weight().value(), locality_lb_endpoint.locality(), | ||
| lb_endpoint.endpoint().health_check_config(), locality_lb_endpoint.priority())); | ||
| registerHostForPriority(host, locality_lb_endpoint, lb_endpoint, health_checker_flag); | ||
| lb_endpoint.endpoint().health_check_config(), locality_lb_endpoint.priority(), | ||
| lb_endpoint.health_status())); | ||
| registerHostForPriority(host, locality_lb_endpoint); | ||
| } | ||
|
|
||
| void PriorityStateManager::registerHostForPriority( | ||
| const HostSharedPtr& host, | ||
| const envoy::api::v2::endpoint::LocalityLbEndpoints& locality_lb_endpoint, | ||
| const envoy::api::v2::endpoint::LbEndpoint& lb_endpoint, | ||
| const absl::optional<Upstream::Host::HealthFlag> health_checker_flag) { | ||
| const envoy::api::v2::endpoint::LocalityLbEndpoints& locality_lb_endpoint) { | ||
| const uint32_t priority = locality_lb_endpoint.priority(); | ||
| // Should be called after initializePriorityFor. | ||
| ASSERT(priority_state_[priority].first); | ||
| priority_state_[priority].first->emplace_back(host); | ||
| if (health_checker_flag.has_value()) { | ||
| const auto& health_status = lb_endpoint.health_status(); | ||
| if (health_status == envoy::api::v2::core::HealthStatus::UNHEALTHY || | ||
| health_status == envoy::api::v2::core::HealthStatus::DRAINING || | ||
| health_status == envoy::api::v2::core::HealthStatus::TIMEOUT) { | ||
| priority_state_[priority].first->back()->healthFlagSet(health_checker_flag.value()); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| void PriorityStateManager::updateClusterPrioritySet( | ||
|
|
@@ -982,7 +1014,7 @@ StaticClusterImpl::StaticClusterImpl( | |
| for (const auto& lb_endpoint : locality_lb_endpoint.lb_endpoints()) { | ||
| priority_state_manager_->registerHostForPriority( | ||
| "", resolveProtoAddress(lb_endpoint.endpoint().address()), locality_lb_endpoint, | ||
| lb_endpoint, absl::nullopt); | ||
| lb_endpoint); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1069,24 +1101,10 @@ bool BaseDynamicClusterImpl::updateDynamicHostList(const HostVector& new_hosts, | |
| max_host_weight = host->weight(); | ||
| } | ||
|
|
||
| if (existing_host->second->healthFlagGet(Host::HealthFlag::FAILED_EDS_HEALTH) != | ||
| host->healthFlagGet(Host::HealthFlag::FAILED_EDS_HEALTH)) { | ||
| // TODO(snowp): To accommodate degraded, this bit should be checking for any changes | ||
| // to the health flag, not just healthy vs not healthy. | ||
| const bool previously_healthy = existing_host->second->health() == Host::Health::Healthy; | ||
| if (host->healthFlagGet(Host::HealthFlag::FAILED_EDS_HEALTH)) { | ||
| existing_host->second->healthFlagSet(Host::HealthFlag::FAILED_EDS_HEALTH); | ||
| // If the host was previously healthy and we're now unhealthy, we need to | ||
| // rebuild. | ||
| hosts_changed |= previously_healthy; | ||
| } else { | ||
| existing_host->second->healthFlagClear(Host::HealthFlag::FAILED_EDS_HEALTH); | ||
| // If the host was previously unhealthy and now healthy, we need to | ||
| // rebuild. | ||
| hosts_changed |= | ||
| !previously_healthy && existing_host->second->health() == Host::Health::Healthy; | ||
| } | ||
| } | ||
| hosts_changed |= | ||
| updateHealthFlag(*host, *existing_host->second, Host::HealthFlag::FAILED_EDS_HEALTH); | ||
| hosts_changed |= | ||
| updateHealthFlag(*host, *existing_host->second, Host::HealthFlag::DEGRADED_EDS_HEALTH); | ||
|
|
||
| // Did metadata change? | ||
| const bool metadata_changed = !Protobuf::util::MessageDifferencer::Equivalent( | ||
|
|
@@ -1259,8 +1277,7 @@ void StrictDnsClusterImpl::updateAllHosts(const HostVector& hosts_added, | |
| priority_state_manager.initializePriorityFor(target->locality_lb_endpoint_); | ||
| for (const HostSharedPtr& host : target->hosts_) { | ||
| if (target->locality_lb_endpoint_.priority() == current_priority) { | ||
| priority_state_manager.registerHostForPriority(host, target->locality_lb_endpoint_, | ||
| target->lb_endpoint_, absl::nullopt); | ||
| priority_state_manager.registerHostForPriority(host, target->locality_lb_endpoint_); | ||
| } | ||
| } | ||
| } | ||
|
|
@@ -1309,7 +1326,7 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() { | |
| parent_.info_, dns_address_, Network::Utility::getAddressWithPort(*address, port_), | ||
| lb_endpoint_.metadata(), lb_endpoint_.load_balancing_weight().value(), | ||
| locality_lb_endpoint_.locality(), lb_endpoint_.endpoint().health_check_config(), | ||
| locality_lb_endpoint_.priority())); | ||
| locality_lb_endpoint_.priority(), lb_endpoint_.health_status())); | ||
| } | ||
|
|
||
| HostVector hosts_added; | ||
|
|
@@ -1337,4 +1354,4 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() { | |
| } | ||
|
|
||
| } // namespace Upstream | ||
| } // namespace Envoy | ||
| } // namespace Envoy | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you remind me why we can't just use
FAILED_EDS_HEALTHfor this use case? AFAICT it fits the bill, and looking at the underlying issue being fixed, it seemed we just needed some plumbing around that.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because this is for degrading an endpoint, not marking it as unhealthy. The new value is necessary to differentiate it here https://github.com/envoyproxy/envoy/pull/5649/files#diff-583237ddb4e16f38ccda2e9affdb0ad8R210 from the host being marked as unhealthy.
Degraded docs if you're not familiar: https://www.envoyproxy.io/docs/envoy/latest/intro/arch_overview/load_balancing/degraded
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe it wasn't super clear, but this PR adds support for marking endpoints as degraded, and while I was in here I also made sure to fix #5637
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, that clarifies.