-
Notifications
You must be signed in to change notification settings - Fork 5.5k
upstream: implement Cluster's load_assignment field #3864
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
Changes from 5 commits
8adcf53
d0c9760
18e98f4
f72f279
a7c9ec9
75a1537
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,6 +18,7 @@ namespace Upstream { | |
| LogicalDnsCluster::LogicalDnsCluster(const envoy::api::v2::Cluster& cluster, | ||
| Runtime::Loader& runtime, Stats::Store& stats, | ||
| Ssl::ContextManager& ssl_context_manager, | ||
| const LocalInfo::LocalInfo& local_info, | ||
| Network::DnsResolverSharedPtr dns_resolver, | ||
| ThreadLocal::SlotAllocator& tls, ClusterManager& cm, | ||
| Event::Dispatcher& dispatcher, bool added_via_api) | ||
|
|
@@ -27,10 +28,17 @@ LogicalDnsCluster::LogicalDnsCluster(const envoy::api::v2::Cluster& cluster, | |
| dns_refresh_rate_ms_( | ||
| std::chrono::milliseconds(PROTOBUF_GET_MS_OR_DEFAULT(cluster, dns_refresh_rate, 5000))), | ||
| tls_(tls.allocateSlot()), | ||
| resolve_timer_(dispatcher.createTimer([this]() -> void { startResolve(); })) { | ||
| const auto& hosts = cluster.hosts(); | ||
| if (hosts.size() != 1) { | ||
| throw EnvoyException("logical_dns clusters must have a single host"); | ||
| resolve_timer_(dispatcher.createTimer([this]() -> void { startResolve(); })), | ||
| local_info_(local_info), | ||
| load_assignment_(cluster.has_load_assignment() | ||
| ? cluster.load_assignment() | ||
| : Config::Utility::translateClusterHosts(cluster.hosts())) { | ||
| const auto& locality_lb_endpoints = load_assignment_.endpoints(); | ||
| if (locality_lb_endpoints.size() != 1 || locality_lb_endpoints[0].lb_endpoints().size() != 1) { | ||
| throw EnvoyException(fmt::format("LOGICAL_DNS clusters must have {}", | ||
|
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: just (it'll be easier to search for the error string, but I don't feel strongly)
Member
Author
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. 👍 updated 75a1537. |
||
| cluster.has_load_assignment() | ||
| ? "a single locality_lb_endpoint and a single lb_endpoint" | ||
| : "a single host")); | ||
| } | ||
|
|
||
| switch (cluster.dns_lookup_family()) { | ||
|
|
@@ -47,7 +55,8 @@ LogicalDnsCluster::LogicalDnsCluster(const envoy::api::v2::Cluster& cluster, | |
| NOT_REACHED_GCOVR_EXCL_LINE; | ||
| } | ||
|
|
||
| const auto& socket_address = hosts[0].socket_address(); | ||
| const envoy::api::v2::core::SocketAddress& socket_address = | ||
| lbEndpoint().endpoint().address().socket_address(); | ||
| dns_url_ = fmt::format("tcp://{}:{}", socket_address.address(), socket_address.port_value()); | ||
| hostname_ = Network::Utility::hostFromTcpUrl(dns_url_); | ||
| Network::Utility::portFromTcpUrl(dns_url_); | ||
|
|
@@ -88,7 +97,8 @@ void LogicalDnsCluster::startResolve() { | |
| current_resolved_address_ = new_address; | ||
| // Capture URL to avoid a race with another update. | ||
| tls_->runOnAllThreads([this, new_address]() -> void { | ||
| tls_->getTyped<PerThreadCurrentHostData>().current_resolved_address_ = new_address; | ||
| PerThreadCurrentHostData& data = tls_->getTyped<PerThreadCurrentHostData>(); | ||
| data.current_resolved_address_ = new_address; | ||
| }); | ||
| } | ||
|
|
||
|
|
@@ -107,14 +117,16 @@ void LogicalDnsCluster::startResolve() { | |
| new LogicalHost(info_, hostname_, Network::Utility::getIpv6AnyAddress(), *this)); | ||
| break; | ||
| } | ||
| HostVectorSharedPtr new_hosts(new HostVector()); | ||
| new_hosts->emplace_back(logical_host_); | ||
| // Given the current config, only EDS clusters support multiple priorities. | ||
| ASSERT(priority_set_.hostSetsPerPriority().size() == 1); | ||
| auto& first_host_set = priority_set_.getOrCreateHostSet(0); | ||
| first_host_set.updateHosts(new_hosts, createHealthyHostList(*new_hosts), | ||
| HostsPerLocalityImpl::empty(), HostsPerLocalityImpl::empty(), | ||
| {}, *new_hosts, {}); | ||
| const auto& locality_lb_endpoint = localityLbEndpoint(); | ||
| PriorityStateManager priority_state_manager(*this, local_info_); | ||
| priority_state_manager.initializePriorityFor(locality_lb_endpoint); | ||
| priority_state_manager.registerHostForPriority(logical_host_, locality_lb_endpoint, | ||
| lbEndpoint(), absl::nullopt); | ||
|
|
||
| const uint32_t priority = locality_lb_endpoint.priority(); | ||
| priority_state_manager.updateClusterPrioritySet( | ||
| priority, std::move(priority_state_manager.priorityState()[priority].first), | ||
| absl::nullopt, absl::nullopt, absl::nullopt); | ||
| } | ||
| } | ||
|
|
||
|
|
@@ -131,7 +143,8 @@ Upstream::Host::CreateConnectionData LogicalDnsCluster::LogicalHost::createConne | |
| return {HostImpl::createConnection(dispatcher, *parent_.info_, data.current_resolved_address_, | ||
| options), | ||
| HostDescriptionConstSharedPtr{ | ||
| new RealHostDescription(data.current_resolved_address_, shared_from_this())}}; | ||
| new RealHostDescription(data.current_resolved_address_, parent_.localityLbEndpoint(), | ||
| parent_.lbEndpoint(), shared_from_this())}}; | ||
| } | ||
|
|
||
| } // namespace Upstream | ||
|
|
||
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.
While we're here, it should read "When an Envoy instance loses..."
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, @zuercher! This is addressed in 75a1537.