Skip to content
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

upstream: add load_assigment field to Cluster #3261

Closed
wants to merge 43 commits into from
Closed
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
0c95fab
upstream cluster: introduce endpoints to allow specifying per cluster…
dio May 1, 2018
a974b87
Update version history
dio May 1, 2018
036a319
review: update DEPRECATED.md
dio May 3, 2018
88090ed
review: update cds.proto doc
dio May 3, 2018
8da2c60
review: add discussion about HealthCheckConfig
dio May 3, 2018
ed08cd2
review: add deprecation note
dio May 3, 2018
9ba78d3
review: translate hosts to endpoints
dio May 3, 2018
14b0d23
review: remove TODO
dio May 3, 2018
bd6ac42
Fix version history entry
dio May 3, 2018
8b2ee7f
review: use LocalityLbEndpoints instead of Endpoints
dio May 3, 2018
e92c5e5
review: implement Cluster.endpoints as LocalityLbEndpoints
dio May 3, 2018
1626fab
Fix logical dns cluster test
dio May 3, 2018
3213dd1
Use ClusterLoadAssignment instead
dio May 8, 2018
d887de6
Merge remote-tracking branch 'upstream/master'
dio May 8, 2018
8629c7b
Back to square 1
dio May 8, 2018
11c77b3
Merge remote-tracking branch 'upstream/master'
dio May 8, 2018
f2bbd12
Merge remote-tracking branch 'upstream/master'
dio May 9, 2018
cf34a06
Refactor static cluster
dio May 9, 2018
c019448
Merge remote-tracking branch 'upstream/master'
dio May 11, 2018
df77682
review: add load_assignment
dio May 11, 2018
2708782
review: health check docs update
dio May 11, 2018
c5db329
Translate cluster hosts to load_assignment
dio May 11, 2018
fc8251e
Update DEPRECATED.md
dio May 11, 2018
675bb90
Fix build api
dio May 11, 2018
5879fd5
review: remove const for translateClusterHosts
dio May 11, 2018
4bfd57e
Locality-aware StrictDnsCluster
dio May 12, 2018
1a48994
Use common function for STATIC and STRICT_DNS
dio May 12, 2018
a34c195
review: update docs
dio May 12, 2018
669fa63
Local info for LOGICAL_DNS
dio May 12, 2018
cb69f92
Add simple tests using load_assignment
dio May 12, 2018
307e247
Fix comments breakpoints
dio May 12, 2018
c724f2a
Context namespacing
dio May 13, 2018
37c6c72
Introduce priority state manager
dio May 13, 2018
81fc59d
Remove initializePrioritySet
dio May 13, 2018
9c6254f
review: reword DEPRECATED.md
dio May 15, 2018
1a2f404
review: update health checking config doc
dio May 15, 2018
572cf12
review: update CDS doc
dio May 15, 2018
decca86
review: NiceMock-ing LocalInfo
dio May 15, 2018
d3ed76e
review: remove context
dio May 15, 2018
b79ddbe
Copy the temporary
dio May 15, 2018
af559be
Fix unnecessary additions and removals
dio May 15, 2018
b88200c
Remove more unnecessary additions and removals
dio May 15, 2018
3cc11be
Update cds.proto next free field
dio May 15, 2018
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
3 changes: 3 additions & 0 deletions DEPRECATED.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@ A logged warning is expected for each deprecated item that is in deprecation win
* `SAN` is replaced by `URI` in the `x-forwarded-client-cert` header.
* The `endpoint` field in the http health check filter is deprecated in favor of the `headers`
field where one can specify HeaderMatch objects to match on.
* The `hosts` field in the `Cluster` is deprecated in favor of the `endpoints` field to accomodate
specifying `HealthCheckConfig` for each cluster member.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's quite a bit more than just the health check config, even if this was the original rationale :) Might be worth pointing out that CDS assignments can now contained embedded EDS equivalent endpoint assignments.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch yes, In general, I haven't touched the locality yet. Still trying to group some functionalities.



## Version 1.6.0 (March 20, 2018)

Expand Down
2 changes: 2 additions & 0 deletions api/envoy/api/v2/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ api_proto_library(
"//envoy/api/v2/core:config_source",
"//envoy/api/v2/core:health_check",
"//envoy/api/v2/core:protocol",
"//envoy/api/v2/endpoint",
"//envoy/type:percent",
],
)
Expand All @@ -86,6 +87,7 @@ api_go_grpc_library(
"//envoy/api/v2/core:config_source_go_proto",
"//envoy/api/v2/core:health_check_go_proto",
"//envoy/api/v2/core:protocol_go_proto",
"//envoy/api/v2/endpoint:endpoint_go_proto",
"//envoy/type:percent_go_proto",
],
)
Expand Down
21 changes: 17 additions & 4 deletions api/envoy/api/v2/cds.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "envoy/api/v2/core/health_check.proto";
import "envoy/api/v2/core/protocol.proto";
import "envoy/api/v2/cluster/circuit_breaker.proto";
import "envoy/api/v2/cluster/outlier_detection.proto";
import "envoy/api/v2/endpoint/endpoint.proto";
import "envoy/type/percent.proto";

import "google/api/annotations.proto";
Expand Down Expand Up @@ -150,12 +151,24 @@ message Cluster {
// when picking a host in the cluster.
LbPolicy lb_policy = 6 [(validate.rules).enum.defined_only = true];

// If the service discovery type is
// Setting this as a requirement for clusters with discovery type
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: s/as/is/

// :ref:`STATIC<envoy_api_enum_value_Cluster.DiscoveryType.STATIC>`,
// :ref:`STRICT_DNS<envoy_api_enum_value_Cluster.DiscoveryType.STRICT_DNS>`
// or :ref:`LOGICAL_DNS<envoy_api_enum_value_Cluster.DiscoveryType.LOGICAL_DNS>`,
// then hosts is required.
repeated core.Address hosts = 7;
// or :ref:`LOGICAL_DNS<envoy_api_enum_value_Cluster.DiscoveryType.LOGICAL_DNS>`
// is deprecated. Set the :ref:`endpoints<envoy_api_field_Cluster.endpoints>` field
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

End the sentence after the LOGICAL_DNS reference. And then just "This field is deprecated. Set..."

// instead.
repeated core.Address hosts = 7 [deprecated = true];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch what's our policy on docs and deprecation? I'd be inclined to say when we deprecate a field we should update the relevant docs (i.e. updating use of hosts in v2_overview.html) so folks cribbing configuration will be cribbing the new way of doing things and not the deprecated way of doing things.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ideally, yes.


// Setting this is required for specifying members of
// :ref:`STATIC<envoy_api_enum_value_Cluster.DiscoveryType.STATIC>`,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you update

// The upstream host address.
to indicate that the interpretation of the Address depends on the cluster type. For static, it will be expected to be a direct IP address (or something resolvable by the specified resolver in the Address). For logical/static DNS, it will be expected to be a hostname, resolved via DNS.

This is actually a bit more complicated thinking about it. See the wording at

// hostname to be resolved via DNS. If it is a hostname, :ref:`resolver_name
. I think we should try and get clear in the API (with some implementation TODOs) what the final relationship is going to be between the custom resolvers (which can apply to listener addresses as well, and act on port values/names) and the DNS resolvers for Clusters. @mattklein123 WDYT on this? Seems a rough edge in the API.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I don't know. That's a good question. Should we just say that custom resolvers can't be used at all with DNS discovery types and block it? I don't think it really makes sense and is confusing. If we do that, I think we can have error checking / error messages to guide people in the right direction...

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would be reasonable. I think if we had the custom resolvers able to operate async, and some hooks to detect DNS changes, we could replace the hardcoded DNS cluster types with just resolver extensions. But, moving the resolver extension model to be expressive enough and then plumbing this would be a fair chunk of work.

// :ref:`STRICT_DNS<envoy_api_enum_value_Cluster.DiscoveryType.STRICT_DNS>`
// or :ref:`LOGICAL_DNS<envoy_api_enum_value_Cluster.DiscoveryType.LOGICAL_DNS>` clusters.
// This field supersedes :ref:`hosts<envoy_api_field_Cluster.hosts>` field.
//
// .. attention::
//
// Setting this overrides :ref:`hosts<envoy_api_field_Cluster.hosts>` values.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have a higher level API issue I'd like to raise if we're going to add this. From time-to-time, folks wonder if we can provide the full set of EDS capabilities embedded in a CDS response (i.e. in a Cluster). To do this, we would effectively need to have a LocalityLbEndpoints here, rather than repeated Endpoint. It would close one weird inconsistency in the Envoy API, where you can basically get all the behaviors with a static bootstrap config except for some EDS special ones (e.g. locality balancing). @mattklein123 for thoughts as well.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch @mattklein123 could we keep both of them ((core.Address) hosts and (endpoint.LocalityLbEndpoints) endpoints)?

Reason is, I'm not sure if it makes sense: by having hosts will be easier to digest for e.g. a newcomer like me. It's simple and the depth of the config is shallow for specifying cluster members "statically".

A config accommodating endpoint.LocalityLbEndpoints will be something like:

    endpoints:
      lb_endpoints:
      - endpoint:
          address:
            socket_address:
              address: localhost1
              port_value: 11001
          health_check_config:
            port_value: 8000

Which is not only deep but it also has that lb_endpoints. IMO, not super obvious at the first glance for defining cluster members statically.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree with @htuch that this is a good opportunity to fix this inconsistency. In general, I agree with @dio that the lb_endpoints construct is more confusing, however, we also optimize for machine generated config. My feeling is to support lb_endpoints, and just have a good example in the docs of a sample configuration. I think with that it should be pretty straightforward for people to use.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to LocalityLbEndpoints in e92c5e5.

About the docs (e.g. example in getting started etc), should I update it together in this PR or I can do that later?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch/@mattklein123 should it be repeated LocalityLbEndpoints as in eds?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch can we consider this, in EDS context, as a config update (onConfigUpdate)?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dio not sure if I fully grok the question. Are you asking if we can use onConfigUpdate to process the ClusterLoadAssignment when embedded in a Cluster? If so, I don't think you use exactly that method, but you can factor out the logic to somewhere shared between EDS and Cluster load, sure, it's the same code in both cases.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@htuch yes, I meant to take out the logic from eds and use that for other clusters.

I have another question, while refactoring the StaticClusterImpl, I failed to satisfy these conditions: https://github.com/envoyproxy/envoy/blob/master/test/common/upstream/upstream_impl_test.cc#L646-L648. Could you enlight me about those assertions a bit more (why they have to be zero)? Thanks!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dio those assertions are just an artifact of the old code not supporting localities. If you add support the expectations are likely to change.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An interesting aspect of this PR is that we now support logical DNS in embedded ClusterLoadAssignments. This didn't use to work, we had a number of questions about this IIRC.

endpoint.LocalityLbEndpoints endpoints = 31;

// Optional :ref:`active health checking <arch_overview_health_checking>`
// configuration for the cluster. If no
Expand Down
6 changes: 3 additions & 3 deletions api/envoy/api/v2/endpoint/endpoint.proto
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ message Endpoint {
// The upstream host address.
core.Address address = 1;

// [#not-implemented-hide:] The optional health check configuration.
// The optional health check configuration.
message HealthCheckConfig {
// Optional alternative health check port value.
//
Expand All @@ -32,8 +32,8 @@ message Endpoint {
uint32 port_value = 1;
}

// [#not-implemented-hide:] The optional health check configuration is used as
// configuration for the health checker to contact the health checked host.
// The optional health check configuration is used as configuration for the health checker
// to contact the health checked host.
//
// .. attention::
//
Expand Down
8 changes: 8 additions & 0 deletions docs/root/intro/arch_overview/health_checking.rst
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,14 @@ unhealthy, successes required before marking a host healthy, etc.):
maintenance by setting the specified key to any value and waiting for traffic to drain. See
:ref:`redis_key <config_cluster_manager_cluster_hc_redis_key>`.

Per cluster member health checking config
-----------------------------------------

If the active health checking is configured for an upstream cluster, a specific additional configuration
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove the

for each registered member in that cluster's :ref:`endpoints<envoy_api_field_Cluster.endpoints>` can be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think just "in the cluster can be" -- the HealtchCheckConfig applies to cluster members obtained via EDS as well.

specified by setting the :ref:`health check config<envoy_api_msg_endpoint.Endpoint.HealthCheckConfig>`
of each of them.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: remove "of each of them"


Passive health checking
-----------------------

Expand Down
2 changes: 2 additions & 0 deletions docs/root/intro/version_history.rst
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ Version history
<envoy_api_field_Listener.transparent>`.
* sockets: added `SO_KEEPALIVE` socket option for upstream connections
:ref:`per cluster <envoy_api_field_Cluster.upstream_connection_options>`.
* upstream: added a new :ref:`endpoints<envoy_api_field_Cluster.endpoints>` field to allow specifying
health check config for each cluster member. Deprecated the :ref:`hosts<envoy_api_field_Cluster.hosts>` field.
* tracing: the sampling decision is now delegated to the tracers, allowing the tracer to decide when and if
to use it. For example, if the :ref:`x-b3-sampled <config_http_conn_man_headers_x-b3-sampled>` header
is supplied with the client request, its value will override any sampling decision made by the Envoy proxy.
Expand Down
16 changes: 10 additions & 6 deletions source/common/upstream/logical_dns_cluster.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,7 @@ LogicalDnsCluster::LogicalDnsCluster(const envoy::api::v2::Cluster& cluster,
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) {
if (endpoints_.size() != 1) {
throw EnvoyException("logical_dns clusters must have a single host");
}

Expand All @@ -46,11 +45,14 @@ LogicalDnsCluster::LogicalDnsCluster(const envoy::api::v2::Cluster& cluster,
NOT_REACHED;
}

const auto& socket_address = hosts[0].socket_address();
const envoy::api::v2::endpoint::Endpoint& endpoint = endpoints_[0].endpoint();
const envoy::api::v2::core::SocketAddress& socket_address = 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_);

health_check_config_ = endpoint.health_check_config();

tls_->set([](Event::Dispatcher&) -> ThreadLocal::ThreadLocalObjectSharedPtr {
return std::make_shared<PerThreadCurrentHostData>();
});
Expand Down Expand Up @@ -87,7 +89,9 @@ 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;
data.health_check_config_ = health_check_config_;
});
}

Expand Down Expand Up @@ -129,8 +133,8 @@ Upstream::Host::CreateConnectionData LogicalDnsCluster::LogicalHost::createConne
ASSERT(data.current_resolved_address_);
return {HostImpl::createConnection(dispatcher, *parent_.info_, data.current_resolved_address_,
options),
HostDescriptionConstSharedPtr{
new RealHostDescription(data.current_resolved_address_, shared_from_this())}};
HostDescriptionConstSharedPtr{new RealHostDescription(
data.current_resolved_address_, data.health_check_config_, shared_from_this())}};
}

} // namespace Upstream
Expand Down
19 changes: 14 additions & 5 deletions source/common/upstream/logical_dns_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,16 @@ class LogicalDnsCluster : public ClusterImplBase {
};

struct RealHostDescription : public HostDescription {
RealHostDescription(Network::Address::InstanceConstSharedPtr address,
HostConstSharedPtr logical_host)
: address_(address), logical_host_(logical_host) {}
RealHostDescription(
Network::Address::InstanceConstSharedPtr address,
const envoy::api::v2::endpoint::Endpoint::HealthCheckConfig& health_check_config,
HostConstSharedPtr logical_host)
: address_(address),
health_check_address_(health_check_config.port_value() == 0
? address
: Network::Utility::getAddressWithPort(
*address, health_check_config.port_value())),
logical_host_(logical_host) {}

// Upstream:HostDescription
bool canary() const override { return false; }
Expand All @@ -78,16 +85,17 @@ class LogicalDnsCluster : public ClusterImplBase {
const envoy::api::v2::core::Locality& locality() const override {
return envoy::api::v2::core::Locality().default_instance();
}
// TODO(dio): To support different address port.
Network::Address::InstanceConstSharedPtr healthCheckAddress() const override {
return address_;
return health_check_address_;
}
Network::Address::InstanceConstSharedPtr address_;
Network::Address::InstanceConstSharedPtr health_check_address_;
HostConstSharedPtr logical_host_;
};

struct PerThreadCurrentHostData : public ThreadLocal::ThreadLocalObject {
Network::Address::InstanceConstSharedPtr current_resolved_address_;
envoy::api::v2::endpoint::Endpoint::HealthCheckConfig health_check_config_;
};

void startResolve();
Expand All @@ -105,6 +113,7 @@ class LogicalDnsCluster : public ClusterImplBase {
Network::Address::InstanceConstSharedPtr current_resolved_address_;
HostSharedPtr logical_host_;
Network::ActiveDnsQuery* active_dns_query_{};
envoy::api::v2::endpoint::Endpoint::HealthCheckConfig health_check_config_;
};

} // namespace Upstream
Expand Down
53 changes: 36 additions & 17 deletions source/common/upstream/upstream_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ ClusterImplBase::ClusterImplBase(const envoy::api::v2::Cluster& cluster,
Runtime::Loader& runtime, Stats::Store& stats,
Ssl::ContextManager& ssl_context_manager, bool added_via_api)
: runtime_(runtime), info_(new ClusterInfoImpl(cluster, bind_config, runtime, stats,
ssl_context_manager, added_via_api)) {
ssl_context_manager, added_via_api)),
endpoints_(cluster.endpoints().lb_endpoints()) {
// Create the default (empty) priority set before registering callbacks to
// avoid getting an update the first time it is accessed.
priority_set_.getOrCreateHostSet(0);
Expand All @@ -433,6 +434,22 @@ ClusterImplBase::ClusterImplBase(const envoy::api::v2::Cluster& cluster,
info_->stats().membership_total_.set(hosts);
info_->stats().membership_healthy_.set(healthy_hosts);
});

// The cluster's hosts field is deprecated, this translates cluster hosts to endpoints.
translateClusterHosts(cluster.hosts());
}

void ClusterImplBase::translateClusterHosts(
const Protobuf::RepeatedPtrField<envoy::api::v2::core::Address>& hosts) {
if (!endpoints_.empty()) {
return;
}

endpoints_.Reserve(hosts.size());
for (const envoy::api::v2::core::Address& host : hosts) {
envoy::api::v2::endpoint::LbEndpoint* lb_endpoint = endpoints_.Add();
lb_endpoint->mutable_endpoint()->mutable_address()->CopyFrom(host);
}
}

HostVectorConstSharedPtr ClusterImplBase::createHealthyHostList(const HostVector& hosts) {
Expand Down Expand Up @@ -624,12 +641,12 @@ StaticClusterImpl::StaticClusterImpl(const envoy::api::v2::Cluster& cluster,
bool added_via_api)
: ClusterImplBase(cluster, cm.bindConfig(), runtime, stats, ssl_context_manager, added_via_api),
initial_hosts_(new HostVector()) {

for (const auto& host : cluster.hosts()) {
for (const envoy::api::v2::endpoint::LbEndpoint& lb_endpoint : endpoints_) {
const envoy::api::v2::endpoint::Endpoint& endpoint = lb_endpoint.endpoint();
initial_hosts_->emplace_back(HostSharedPtr{new HostImpl(
info_, "", resolveProtoAddress(host), envoy::api::v2::core::Metadata::default_instance(), 1,
envoy::api::v2::core::Locality().default_instance(),
envoy::api::v2::endpoint::Endpoint::HealthCheckConfig().default_instance())});
info_, EMPTY_STRING, resolveProtoAddress(endpoint.address()),
envoy::api::v2::core::Metadata::default_instance(), 1,
envoy::api::v2::core::Locality().default_instance(), endpoint.health_check_config())});
}
}

Expand Down Expand Up @@ -791,11 +808,13 @@ StrictDnsClusterImpl::StrictDnsClusterImpl(const envoy::api::v2::Cluster& cluste
NOT_REACHED;
}

for (const auto& host : cluster.hosts()) {
resolve_targets_.emplace_back(
new ResolveTarget(*this, dispatcher,
fmt::format("tcp://{}:{}", host.socket_address().address(),
host.socket_address().port_value())));
for (const envoy::api::v2::endpoint::LbEndpoint& lb_endpoint : endpoints_) {
const envoy::api::v2::core::SocketAddress& socket_address =
lb_endpoint.endpoint().address().socket_address();
resolve_targets_.emplace_back(new ResolveTarget(
*this, dispatcher,
fmt::format("tcp://{}:{}", socket_address.address(), socket_address.port_value()),
lb_endpoint.endpoint().health_check_config()));
}
}

Expand Down Expand Up @@ -823,12 +842,13 @@ void StrictDnsClusterImpl::updateAllHosts(const HostVector& hosts_added,
hosts_added, hosts_removed);
}

StrictDnsClusterImpl::ResolveTarget::ResolveTarget(StrictDnsClusterImpl& parent,
Event::Dispatcher& dispatcher,
const std::string& url)
StrictDnsClusterImpl::ResolveTarget::ResolveTarget(
StrictDnsClusterImpl& parent, Event::Dispatcher& dispatcher, const std::string& url,
const envoy::api::v2::endpoint::Endpoint::HealthCheckConfig& health_check_config)
: parent_(parent), dns_address_(Network::Utility::hostFromTcpUrl(url)),
port_(Network::Utility::portFromTcpUrl(url)),
resolve_timer_(dispatcher.createTimer([this]() -> void { startResolve(); })) {}
resolve_timer_(dispatcher.createTimer([this]() -> void { startResolve(); })),
health_check_config_(health_check_config) {}

StrictDnsClusterImpl::ResolveTarget::~ResolveTarget() {
if (active_query_) {
Expand Down Expand Up @@ -856,8 +876,7 @@ void StrictDnsClusterImpl::ResolveTarget::startResolve() {
new_hosts.emplace_back(new HostImpl(
parent_.info_, dns_address_, Network::Utility::getAddressWithPort(*address, port_),
envoy::api::v2::core::Metadata::default_instance(), 1,
envoy::api::v2::core::Locality().default_instance(),
envoy::api::v2::endpoint::Endpoint::HealthCheckConfig().default_instance()));
envoy::api::v2::core::Locality().default_instance(), health_check_config_));
}

HostVector hosts_added;
Expand Down
7 changes: 6 additions & 1 deletion source/common/upstream/upstream_impl.h
Original file line number Diff line number Diff line change
Expand Up @@ -477,10 +477,13 @@ class ClusterImplBase : public Cluster, protected Logger::Loggable<Logger::Id::u

protected:
PrioritySetImpl priority_set_;
Protobuf::RepeatedPtrField<envoy::api::v2::endpoint::LbEndpoint> endpoints_;

private:
void finishInitialization();
void reloadHealthyHosts();
void
translateClusterHosts(const Protobuf::RepeatedPtrField<envoy::api::v2::core::Address>& hosts);

bool initialization_started_{};
std::function<void()> initialization_complete_callback_;
Expand Down Expand Up @@ -535,7 +538,8 @@ class StrictDnsClusterImpl : public BaseDynamicClusterImpl {
private:
struct ResolveTarget {
ResolveTarget(StrictDnsClusterImpl& parent, Event::Dispatcher& dispatcher,
const std::string& url);
const std::string& url,
const envoy::api::v2::endpoint::Endpoint::HealthCheckConfig& health_check_config);
~ResolveTarget();
void startResolve();

Expand All @@ -545,6 +549,7 @@ class StrictDnsClusterImpl : public BaseDynamicClusterImpl {
uint32_t port_;
Event::TimerPtr resolve_timer_;
HostVector hosts_;
const envoy::api::v2::endpoint::Endpoint::HealthCheckConfig health_check_config_;
};

typedef std::unique_ptr<ResolveTarget> ResolveTargetPtr;
Expand Down
Loading