Skip to content

Commit

Permalink
Format
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Jin Xuan <[email protected]>
  • Loading branch information
Stevenjin8 committed Oct 10, 2024
1 parent c944d7e commit 8ed51ae
Show file tree
Hide file tree
Showing 13 changed files with 26 additions and 112 deletions.
49 changes: 3 additions & 46 deletions api/envoy/extensions/clusters/dns/v3/dns_cluster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -28,35 +28,6 @@ option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#next-free-field: 7]
message DnsCluster {
// When V4_ONLY is selected, the DNS resolver will only perform a lookup for
// addresses in the IPv4 family. If V6_ONLY is selected, the DNS resolver will
// only perform a lookup for addresses in the IPv6 family. If AUTO is
// specified, the DNS resolver will first perform a lookup for addresses in
// the IPv6 family and fallback to a lookup for addresses in the IPv4 family.
// This is semantically equivalent to a non-existent V6_PREFERRED option.
// AUTO is a legacy name that is more opaque than
// necessary and will be deprecated in favor of V6_PREFERRED in a future major version of the API.
// If V4_PREFERRED is specified, the DNS resolver will first perform a lookup for addresses in the
// IPv4 family and fallback to a lookup for addresses in the IPv6 family. i.e., the callback
// target will only get v6 addresses if there were NO v4 addresses to return.
// If ALL is specified, the DNS resolver will perform a lookup for both IPv4 and IPv6 families,
// and return all resolved addresses. When this is used, Happy Eyeballs will be enabled for
// upstream connections. Refer to :ref:`Happy Eyeballs Support <arch_overview_happy_eyeballs>`
// for more information.
// For cluster types other than
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>` and
// :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>`,
// this setting is
// ignored.
// [#next-major-version: deprecate AUTO in favor of a V6_PREFERRED option.]
// enum DnsLookupFamily {
// UNSPECIFIED = 0;
// AUTO = 1;
// V4_ONLY = 2;
// V6_ONLY = 3;
// V4_PREFERRED = 4;
// ALL = 5;
// }

message RefreshRate {
// Specifies the base interval between refreshes. This parameter is required and must be greater
Expand All @@ -77,36 +48,22 @@ message DnsCluster {
// This value is the cluster’s DNS refresh rate. The value configured must be at least 1ms.
// If this setting is not specified, the
// value defaults to 5000ms.
google.protobuf.Duration dns_refresh_rate = 1 [(validate.rules).duration = {gt {nanos: 1000000}}];
google.protobuf.Duration dns_refresh_rate = 3 [(validate.rules).duration = {gt {nanos: 1000000}}];

// this is the cluster’s DNS refresh rate when requests are failing. If this setting is
// not specified, the failure refresh rate defaults to the DNS refresh rate.
RefreshRate dns_failure_refresh_rate = 2;
RefreshRate dns_failure_refresh_rate = 4;

// Optional configuration for setting cluster's DNS refresh rate. If the value is set to true,
// cluster's DNS refresh rate will be set to resource record's TTL which comes from DNS
// resolution.
google.protobuf.BoolValue respect_dns_ttl = 3;
google.protobuf.BoolValue respect_dns_ttl = 5;

// The DNS IP address resolution policy. If this setting is not specified, the
// value defaults to
// :ref:`AUTO<envoy_v3_api_enum_value_extensions.clusters.dns.v3.DnsConfig.DnsLookupFamily.AUTO>`.
// DnsLookupFamily dns_lookup_family = 4 [(validate.rules).enum = {defined_only: true}];

// DNS resolver type configuration extension. This extension can be used to configure c-ares, apple,
// or any other DNS resolver types and the related parameters.
// For example, an object of
// :ref:`CaresDnsResolverConfig <envoy_v3_api_msg_extensions.network.dns_resolver.cares.v3.CaresDnsResolverConfig>`
// can be packed into this ``typed_dns_resolver_config``. This configuration replaces the
// :ref:`dns_resolution_config <envoy_v3_api_field_config.cluster.v3.Cluster.dns_resolution_config>`
// configuration.
// During the transition period when both ``dns_resolution_config`` and ``typed_dns_resolver_config`` exists,
// when ``typed_dns_resolver_config`` is in place, Envoy will use it and ignore ``dns_resolution_config``.
// When ``typed_dns_resolver_config`` is missing, the default behavior is in place.
// [#extension-category: envoy.network.dns_resolver]
// Fixme docs
// config.core.v3.TypedExtensionConfig typed_dns_resolver_config = 5;

// DNS jitter causes the cluster to refresh DNS entries later by a random amount of time to avoid a
// stampede of DNS requests. This value sets the upper bound (exclusive) for the random amount.
// There will be no jitter if this value is omitted.
Expand Down
4 changes: 2 additions & 2 deletions source/common/common/dns_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ getDnsLookupFamilyFromCluster(const envoy::config::cluster::v3::Cluster& cluster
return getDnsLookupFamilyFromEnum(cluster.dns_lookup_family());
}

Network::DnsLookupFamily getDnsLookupFamilyFromEnum(
envoy::config::cluster::v3::Cluster::DnsLookupFamily family) {
Network::DnsLookupFamily
getDnsLookupFamilyFromEnum(envoy::config::cluster::v3::Cluster::DnsLookupFamily family) {
switch (family) {
PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
case envoy::config::cluster::v3::Cluster::V6_ONLY:
Expand Down
14 changes: 0 additions & 14 deletions source/common/network/dns_resolver/dns_factory_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,27 +46,13 @@ bool tryUseAppleApiForDnsLookups(
return false;
}

//bool checkDnsResolutionConfigExist(
// [[maybe_unused]] const envoy::extensions::clusters::dns::v3::DnsConfig& config,
// [[maybe_unused]] envoy::config::core::v3::TypedExtensionConfig& typed_dns_resolver_config) {
// return false;
//}

// Overloading the template function for DnsFilterConfig type, which doesn't need to copy anything.
void handleLegacyDnsResolverData(
const envoy::extensions::filters::udp::dns_filter::v3::DnsFilterConfig::ClientContextConfig&,
envoy::config::core::v3::TypedExtensionConfig& typed_dns_resolver_config) {
makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config);
}

//void handleLegacyDnsResolverData(
// [[maybe_unused]] const envoy::extensions::clusters::dns::v3::DnsConfig config,
// envoy::config::core::v3::TypedExtensionConfig& typed_dns_resolver_config) {
// envoy::extensions::network::dns_resolver::cares::v3::CaresDnsResolverConfig cares;
// typed_dns_resolver_config.mutable_typed_config()->PackFrom(cares);
// typed_dns_resolver_config.set_name(std::string(CaresDnsResolver));
//}

// Overloading the template function for Cluster config type, which need to copy
// both use_tcp_for_dns_lookups and dns_resolvers.
void handleLegacyDnsResolverData(
Expand Down
5 changes: 0 additions & 5 deletions source/common/network/dns_resolver/dns_factory_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,6 @@ bool checkDnsResolutionConfigExist(
return false;
}

// Overloading the template funciton for DnsConfig because DnsConfig has no dns_resolution_config.
// bool checkDnsResolutionConfigExist(
// const envoy::extensions::clusters::dns::v3::DnsConfig& config,
// envoy::config::core::v3::TypedExtensionConfig& typed_dns_resolver_config);

// For backward compatibility, copy over use_tcp_for_dns_lookups from config, and create
// a CaresDnsResolverConfig typed config. This logic fit for bootstrap, and dns_cache config types.
template <class ConfigType>
Expand Down
17 changes: 3 additions & 14 deletions source/common/upstream/cluster_factory_impl.cc
Original file line number Diff line number Diff line change
Expand Up @@ -65,26 +65,15 @@ ClusterFactoryImplBase::create(const envoy::config::cluster::v3::Cluster& cluste
return factory->create(cluster, context);
}

absl::StatusOr<Network::DnsResolverSharedPtr> ClusterFactoryImplBase::selectDnsResolver(
const envoy::config::cluster::v3::Cluster& cluster,
ClusterFactoryContext& context) {
absl::StatusOr<Network::DnsResolverSharedPtr>
ClusterFactoryImplBase::selectDnsResolver(const envoy::config::cluster::v3::Cluster& cluster,
ClusterFactoryContext& context) {
// We make this a shared pointer to deal with the distinct ownership
// scenarios that can exist: in one case, we pass in the "default"
// DNS resolver that is owned by the Server::Instance. In the case
// where 'dns_resolvers' is specified, we have per-cluster DNS
// resolvers that are created here but ownership resides with
// StrictDnsClusterImpl/LogicalDnsCluster.
// if ((cluster.has_dns_config() && cluster.dns_config().has_typed_dns_resolver_config() &&
// !(cluster.dns_config().typed_dns_resolver_config().typed_config().type_url().empty()))) {
// envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config;
// Network::DnsResolverFactory& dns_resolver_factory =
// Network::createDnsResolverFactoryFromProto(cluster.dns_config(),
// typed_dns_resolver_config);
// auto& server_context = context.serverFactoryContext();
// return dns_resolver_factory.createDnsResolver(server_context.mainThreadDispatcher(),
// server_context.api(),
// typed_dns_resolver_config);
//}

if ((cluster.has_typed_dns_resolver_config() &&
!(cluster.typed_dns_resolver_config().typed_config().type_url().empty())) ||
Expand Down
4 changes: 2 additions & 2 deletions source/extensions/clusters/common/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ envoy_cc_library(
deps = [
"//source/common/upstream:cluster_factory_includes",
"//source/common/upstream:upstream_includes",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/endpoint/v3:pkg_cc_proto",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/clusters/dns/v3:pkg_cc_proto",
],
)
15 changes: 3 additions & 12 deletions source/extensions/clusters/common/backcompat_dns.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "source/extensions/clusters/common/backcompat_dns.h"

#include "envoy/config/cluster/v3/cluster.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.h"
#include "source/extensions/clusters/common/backcompat_dns.h"

namespace Envoy {
namespace Upstream {
Expand All @@ -24,20 +25,10 @@ void mergeClusterAndProtoConfig(
new_proto_config.mutable_respect_dns_ttl()->set_value(cluster.respect_dns_ttl());
}

// if (new_proto_config.dns_lookup_family() ==
// envoy::extensions::clusters::dns::v3::DnsCluster::UNSPECIFIED) {
// new_proto_config.set_dns_lookup_family(translateLookupFamily(cluster.dns_lookup_family()));
// }

// if (cluster.has_typed_dns_resolver_config() &&
// !new_proto_config.has_typed_dns_resolver_config()) {
// new_proto_config.mutable_typed_dns_resolver_config()->CopyFrom(
// cluster.typed_dns_resolver_config());
// }

if (cluster.has_dns_jitter() && !new_proto_config.has_dns_jitter()) {
new_proto_config.mutable_dns_jitter()->CopyFrom(cluster.dns_jitter());
}
}

} // namespace Upstream
} // namespace Envoy
1 change: 1 addition & 0 deletions source/extensions/clusters/logical_dns/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,6 @@ envoy_cc_extension(
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/config/core/v3:pkg_cc_proto",
"@envoy_api//envoy/config/endpoint/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/clusters/dns/v3:pkg_cc_proto",
],
)
8 changes: 3 additions & 5 deletions source/extensions/clusters/logical_dns/logical_dns_cluster.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "source/extensions/clusters/logical_dns/logical_dns_cluster.h"
#include "source/extensions/clusters/common/backcompat_dns.h"

#include <chrono>
#include <list>
Expand All @@ -21,6 +20,7 @@
#include "source/common/network/utility.h"
#include "source/common/protobuf/protobuf.h"
#include "source/common/protobuf/utility.h"
#include "source/extensions/clusters/common/backcompat_dns.h"

namespace Envoy {
namespace Upstream {
Expand Down Expand Up @@ -216,10 +216,8 @@ LogicalDnsClusterFactory::createClusterWithConfig(
THROW_IF_NOT_OK(dns_resolver_or_error.status());

auto cluster_or_error = LogicalDnsCluster::create(cluster, proto_config, context,
std::move(dns_resolver_or_error.value()));
return std::make_pair(std::shared_ptr<LogicalDnsCluster>(std::move(*cluster_or_error)),
nullptr);

std::move(dns_resolver_or_error.value()));
return std::make_pair(std::shared_ptr<LogicalDnsCluster>(std::move(*cluster_or_error)), nullptr);
}

/**
Expand Down
11 changes: 4 additions & 7 deletions source/extensions/clusters/logical_dns/logical_dns_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "envoy/config/endpoint/v3/endpoint_components.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.validate.h"

#include "envoy/stats/scope.h"

#include "source/common/common/empty_string.h"
Expand Down Expand Up @@ -41,11 +40,10 @@ class LogicalDnsCluster : public ClusterImplBase {
public:
~LogicalDnsCluster() override;

absl::StatusOr<std::unique_ptr<LogicalDnsCluster>>
static create(const envoy::config::cluster::v3::Cluster& cluster,
const envoy::extensions::clusters::dns::v3::DnsCluster& dns_cluster,
ClusterFactoryContext& context,
Network::DnsResolverSharedPtr dns_resolver);
absl::StatusOr<std::unique_ptr<LogicalDnsCluster>> static create(
const envoy::config::cluster::v3::Cluster& cluster,
const envoy::extensions::clusters::dns::v3::DnsCluster& dns_cluster,
ClusterFactoryContext& context, Network::DnsResolverSharedPtr dns_resolver);

// Upstream::Cluster
InitializePhase initializePhase() const override { return InitializePhase::Primary; }
Expand Down Expand Up @@ -100,7 +98,6 @@ class LogicalDnsClusterFactory : public Upstream::ConfigurableClusterFactoryBase
public:
LogicalDnsClusterFactory() : ConfigurableClusterFactoryBase("envoy.cluster.logical_dns") {}


private:
friend class LogicalDnsClusterTest;
absl::StatusOr<std::pair<ClusterImplBaseSharedPtr, ThreadAwareLoadBalancerPtr>>
Expand Down
1 change: 1 addition & 0 deletions source/extensions/clusters/strict_dns/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ envoy_cc_extension(
"//source/extensions/clusters/common:backcompat_dns_lib",
"@envoy_api//envoy/config/cluster/v3:pkg_cc_proto",
"@envoy_api//envoy/config/endpoint/v3:pkg_cc_proto",
"@envoy_api//envoy/extensions/clusters/dns/v3:pkg_cc_proto",
],
)
8 changes: 4 additions & 4 deletions source/extensions/clusters/strict_dns/strict_dns_cluster.cc
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
#include "source/extensions/clusters/strict_dns/strict_dns_cluster.h"
#include "source/extensions/clusters/common/backcompat_dns.h"

#include <chrono>

Expand All @@ -9,6 +8,8 @@
#include "envoy/config/endpoint/v3/endpoint_components.pb.h"
#include "envoy/extensions/clusters/dns/v3/dns_cluster.pb.h"

#include "source/extensions/clusters/common/backcompat_dns.h"

namespace Envoy {
namespace Upstream {

Expand All @@ -24,9 +25,8 @@ StrictDnsClusterImpl::create(const envoy::config::cluster::v3::Cluster& cluster,
merged_dns_cluster.MergeFrom(dns_cluster);
mergeClusterAndProtoConfig(cluster, merged_dns_cluster);


auto ret = std::unique_ptr<StrictDnsClusterImpl>(
new StrictDnsClusterImpl(cluster, merged_dns_cluster, context, dns_resolver, creation_status));
auto ret = std::unique_ptr<StrictDnsClusterImpl>(new StrictDnsClusterImpl(
cluster, merged_dns_cluster, context, dns_resolver, creation_status));

RETURN_IF_NOT_OK(creation_status);
return ret;
Expand Down
1 change: 0 additions & 1 deletion source/extensions/clusters/strict_dns/strict_dns_cluster.h
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,6 @@ class StrictDnsClusterFactory : public Upstream::ConfigurableClusterFactoryBase<
Upstream::ClusterFactoryContext& context) override;
};


DECLARE_FACTORY(StrictDnsClusterFactory);

} // namespace Upstream
Expand Down

0 comments on commit 8ed51ae

Please sign in to comment.