Skip to content

Commit

Permalink
Move cluster dns config and validate in strict dns clusters
Browse files Browse the repository at this point in the history
Signed-off-by: Steven Jin Xuan <sjinxuan@microsoft.com>
  • Loading branch information
Stevenjin8 committed Oct 2, 2024
1 parent cfbc830 commit 9048a69
Show file tree
Hide file tree
Showing 22 changed files with 274 additions and 67 deletions.
1 change: 1 addition & 0 deletions api/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ proto_library(
"//envoy/extensions/access_loggers/wasm/v3:pkg",
"//envoy/extensions/bootstrap/internal_listener/v3:pkg",
"//envoy/extensions/clusters/aggregate/v3:pkg",
"//envoy/extensions/clusters/dns/v3:pkg",
"//envoy/extensions/clusters/dynamic_forward_proxy/v3:pkg",
"//envoy/extensions/clusters/redis/v3:pkg",
"//envoy/extensions/common/async_files/v3:pkg",
Expand Down
1 change: 1 addition & 0 deletions api/envoy/config/cluster/v3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ api_proto_package(
"//envoy/annotations:pkg",
"//envoy/config/core/v3:pkg",
"//envoy/config/endpoint/v3:pkg",
"//envoy/extensions/clusters/dns/v3:pkg",
"//envoy/type/metadata/v3:pkg",
"//envoy/type/v3:pkg",
"@com_github_cncf_xds//udpa/annotations:pkg",
Expand Down
62 changes: 30 additions & 32 deletions api/envoy/config/cluster/v3/cluster.proto
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import "envoy/config/core/v3/health_check.proto";
import "envoy/config/core/v3/protocol.proto";
import "envoy/config/core/v3/resolver.proto";
import "envoy/config/endpoint/v3/endpoint.proto";
import "envoy/extensions/clusters/dns/v3/cluster.proto";
import "envoy/type/metadata/v3/metadata.proto";
import "envoy/type/v3/percent.proto";

Expand Down Expand Up @@ -45,7 +46,7 @@ message ClusterCollection {
}

// Configuration for a single upstream cluster.
// [#next-free-field: 59]
// [#next-free-field: 60]
message Cluster {
option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.Cluster";

Expand Down Expand Up @@ -141,13 +142,6 @@ message Cluster {
// this setting is
// ignored.
// [#next-major-version: deprecate AUTO in favor of a V6_PREFERRED option.]
enum DnsLookupFamily {
AUTO = 0;
V4_ONLY = 1;
V6_ONLY = 2;
V4_PREFERRED = 3;
ALL = 4;
}

enum ClusterProtocolSelection {
// Cluster can only operate on one of the possible upstream protocols (HTTP1.1, HTTP2).
Expand Down Expand Up @@ -678,24 +672,6 @@ message Cluster {
core.v3.HealthStatusSet override_host_status = 8;
}

message RefreshRate {
option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.Cluster.RefreshRate";

// Specifies the base interval between refreshes. This parameter is required and must be greater
// than zero and less than
// :ref:`max_interval <envoy_v3_api_field_config.cluster.v3.Cluster.RefreshRate.max_interval>`.
google.protobuf.Duration base_interval = 1 [(validate.rules).duration = {
required: true
gt {nanos: 1000000}
}];

// Specifies the maximum interval between refreshes. This parameter is optional, but must be
// greater than or equal to the
// :ref:`base_interval <envoy_v3_api_field_config.cluster.v3.Cluster.RefreshRate.base_interval>` if set. The default
// is 10 times the :ref:`base_interval <envoy_v3_api_field_config.cluster.v3.Cluster.RefreshRate.base_interval>`.
google.protobuf.Duration max_interval = 2 [(validate.rules).duration = {gt {nanos: 1000000}}];
}

message PreconnectPolicy {
// Indicates how many streams (rounded up) can be anticipated per-upstream for each
// incoming stream. This is useful for high-QPS or latency-sensitive services. Preconnecting
Expand Down Expand Up @@ -944,6 +920,9 @@ message Cluster {
// [#next-major-version: make this a list of typed extensions.]
map<string, google.protobuf.Any> typed_extension_protocol_options = 36;

// [#extension-category: envoy.clusters.dns]
envoy.extensions.clusters.dns.v3.DnsConfig dns_config = 59;

// If the DNS refresh rate is specified and the cluster type is either
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
// or :ref:`LOGICAL_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.LOGICAL_DNS>`,
Expand All @@ -953,8 +932,13 @@ message Cluster {
// :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.
google.protobuf.Duration dns_refresh_rate = 16
[(validate.rules).duration = {gt {nanos: 1000000}}];
// This field is deprecated in favor of ``dns_config``
// which aggregates all of the DNS configuration in a single message.
google.protobuf.Duration dns_refresh_rate = 16 [
deprecated = true,
(validate.rules).duration = {gt {nanos: 1000000}},
(envoy.annotations.deprecated_at_minor_version) = "3.0"
];

// DNS jitter can be optionally specified if the cluster type is either
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
Expand All @@ -965,7 +949,10 @@ message Cluster {
// :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.
google.protobuf.Duration dns_jitter = 58;
// This field is deprecated in favor of ``dns_config``
// which aggregates all of the DNS configuration in a single message.
google.protobuf.Duration dns_jitter = 58
[deprecated = true, (envoy.annotations.deprecated_at_minor_version) = "3.0"];

// If the DNS failure refresh rate is specified and the cluster type is either
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
Expand All @@ -975,17 +962,27 @@ message Cluster {
// 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.
RefreshRate dns_failure_refresh_rate = 44;
// This field is deprecated in favor of ``dns_config``
// which aggregates all of the DNS configuration in a single message.
envoy.extensions.clusters.dns.v3.DnsConfig.RefreshRate dns_failure_refresh_rate = 44
[deprecated = true, (envoy.annotations.deprecated_at_minor_version) = "3.0"];

// 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.
bool respect_dns_ttl = 39;
// This field is deprecated in favor of ``dns_config``
// which aggregates all of the DNS configuration in a single message.
bool respect_dns_ttl = 39
[deprecated = true, (envoy.annotations.deprecated_at_minor_version) = "3.0"];

// The DNS IP address resolution policy. If this setting is not specified, the
// value defaults to
// :ref:`AUTO<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DnsLookupFamily.AUTO>`.
DnsLookupFamily dns_lookup_family = 17 [(validate.rules).enum = {defined_only: true}];
envoy.extensions.clusters.dns.v3.DnsConfig.DnsLookupFamily dns_lookup_family = 17 [
deprecated = true,
(validate.rules).enum = {defined_only: true},
(envoy.annotations.deprecated_at_minor_version) = "3.0"
];

// If DNS resolvers are specified and the cluster type is either
// :ref:`STRICT_DNS<envoy_v3_api_enum_value_config.cluster.v3.Cluster.DiscoveryType.STRICT_DNS>`,
Expand Down Expand Up @@ -1025,6 +1022,7 @@ message Cluster {
// 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 do we also want to move this one?
core.v3.TypedExtensionConfig typed_dns_resolver_config = 55;

// Optional configuration for having cluster readiness block on warm-up. Currently, only applicable for
Expand Down
12 changes: 12 additions & 0 deletions api/envoy/extensions/clusters/dns/v3/BUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# DO NOT EDIT. This file is generated by tools/proto_format/proto_sync.py.

load("@envoy_api//bazel:api_build_system.bzl", "api_proto_package")

licenses(["notice"]) # Apache 2

api_proto_package(
deps = [
"//envoy/config/core/v3:pkg",
"@com_github_cncf_xds//udpa/annotations:pkg",
],
)
116 changes: 116 additions & 0 deletions api/envoy/extensions/clusters/dns/v3/cluster.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
syntax = "proto3";

package envoy.extensions.clusters.dns.v3;

import "envoy/config/core/v3/extension.proto";

import "google/protobuf/any.proto";
import "google/protobuf/duration.proto";
import "google/protobuf/struct.proto";
import "google/protobuf/wrappers.proto";

import "udpa/annotations/migrate.proto";
import "udpa/annotations/security.proto";
import "udpa/annotations/status.proto";
import "udpa/annotations/versioning.proto";
import "validate/validate.proto";

option java_package = "io.envoyproxy.envoy.extensions.clusters.dns.v3";
option java_outer_classname = "ClusterProto";
option java_multiple_files = true;
option go_package = "github.com/envoyproxy/go-control-plane/envoy/extensions/clusters/dns/v3;dnsv3";
option (udpa.annotations.file_status).package_version_status = ACTIVE;

// [#protodoc-title: DNS cluster configuration]

// Configuration for the dynamic forward proxy cluster. See the :ref:`architecture overview
// <arch_overview_http_dynamic_forward_proxy>` for more information.
// [#extension: envoy.clusters.dns]

// [#next-free-field: 7]
message DnsConfig {
// 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 {
AUTO = 0;
V4_ONLY = 1;
V6_ONLY = 2;
V4_PREFERRED = 3;
ALL = 4;
}

message RefreshRate {
option (udpa.annotations.versioning).previous_message_type = "envoy.api.v2.Cluster.RefreshRate";

// Specifies the base interval between refreshes. This parameter is required and must be greater
// than zero and less than
// :ref:`max_interval <envoy_v3_api_field_extensions.clusters.dns.v3.DnsConfig.RefreshRate.max_interval>`.
google.protobuf.Duration base_interval = 1 [(validate.rules).duration = {
required: true
gt {nanos: 1000000}
}];

// Specifies the maximum interval between refreshes. This parameter is optional, but must be
// greater than or equal to the
// :ref:`base_interval <envoy_v3_api_field_extensions.clusters.dns.v3.DnsConfig.RefreshRate.max_interval>` if set. The default
// is 10 times the :ref:`base_interval <envoy_v3_api_field_extensions.clusters.dns.v3.DnsConfig.RefreshRate.max_interval>`.
google.protobuf.Duration max_interval = 2 [(validate.rules).duration = {gt {nanos: 1000000}}];
}

// 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}}];

// 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;

// 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.
bool respect_dns_ttl = 3;

// 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.
google.protobuf.Duration dns_jitter = 6;
}
2 changes: 1 addition & 1 deletion api/envoy/extensions/common/dynamic_forward_proxy/v3/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ licenses(["notice"]) # Apache 2
api_proto_package(
deps = [
"//envoy/annotations:pkg",
"//envoy/config/cluster/v3:pkg",
"//envoy/config/common/key_value/v3:pkg",
"//envoy/config/core/v3:pkg",
"//envoy/extensions/clusters/dns/v3:pkg",
"@com_github_cncf_xds//udpa/annotations:pkg",
],
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ syntax = "proto3";

package envoy.extensions.common.dynamic_forward_proxy.v3;

import "envoy/config/cluster/v3/cluster.proto";
import "envoy/config/common/key_value/v3/config.proto";
import "envoy/config/core/v3/address.proto";
import "envoy/config/core/v3/extension.proto";
import "envoy/config/core/v3/resolver.proto";
import "envoy/extensions/clusters/dns/v3/cluster.proto";

import "google/protobuf/duration.proto";
import "google/protobuf/wrappers.proto";
Expand Down Expand Up @@ -53,7 +53,7 @@ message DnsCacheConfig {
// likely build a "happy eyeballs" connection pool which would race the primary / fall back
// address and return the one that wins. This same method could potentially also be used for
// QUIC to TCP fall back.]
config.cluster.v3.Cluster.DnsLookupFamily dns_lookup_family = 2
clusters.dns.v3.DnsConfig.DnsLookupFamily dns_lookup_family = 2
[(validate.rules).enum = {defined_only: true}];

// The DNS refresh rate for unresolved DNS hosts. If not specified defaults to 60s.
Expand Down Expand Up @@ -97,7 +97,7 @@ message DnsCacheConfig {
// If the DNS failure refresh rate is specified,
// this is used as the cache's DNS refresh rate when DNS requests are failing. If this setting is
// not specified, the failure refresh rate defaults to the dns_refresh_rate.
config.cluster.v3.Cluster.RefreshRate dns_failure_refresh_rate = 6;
clusters.dns.v3.DnsConfig.RefreshRate dns_failure_refresh_rate = 6;

// The config of circuit breakers for resolver. It provides a configurable threshold.
// Envoy will use dns cache circuit breakers with default settings even if this value is not set.
Expand Down
1 change: 1 addition & 0 deletions api/versioning/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ proto_library(
"//envoy/extensions/access_loggers/wasm/v3:pkg",
"//envoy/extensions/bootstrap/internal_listener/v3:pkg",
"//envoy/extensions/clusters/aggregate/v3:pkg",
"//envoy/extensions/clusters/dns/v3:pkg",
"//envoy/extensions/clusters/dynamic_forward_proxy/v3:pkg",
"//envoy/extensions/clusters/redis/v3:pkg",
"//envoy/extensions/common/async_files/v3:pkg",
Expand Down
14 changes: 7 additions & 7 deletions source/common/common/dns_utils.cc
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,19 @@ 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::extensions::clusters::dns::v3::DnsConfig::DnsLookupFamily family) {
switch (family) {
PANIC_ON_PROTO_ENUM_SENTINEL_VALUES;
case envoy::config::cluster::v3::Cluster::V6_ONLY:
case envoy::extensions::clusters::dns::v3::DnsConfig::V6_ONLY:
return Network::DnsLookupFamily::V6Only;
case envoy::config::cluster::v3::Cluster::V4_ONLY:
case envoy::extensions::clusters::dns::v3::DnsConfig::V4_ONLY:
return Network::DnsLookupFamily::V4Only;
case envoy::config::cluster::v3::Cluster::AUTO:
case envoy::extensions::clusters::dns::v3::DnsConfig::AUTO:
return Network::DnsLookupFamily::Auto;
case envoy::config::cluster::v3::Cluster::V4_PREFERRED:
case envoy::extensions::clusters::dns::v3::DnsConfig::V4_PREFERRED:
return Network::DnsLookupFamily::V4Preferred;
case envoy::config::cluster::v3::Cluster::ALL:
case envoy::extensions::clusters::dns::v3::DnsConfig::ALL:
return Network::DnsLookupFamily::All;
}
IS_ENVOY_BUG("unexpected dns lookup family enum");
Expand Down
2 changes: 1 addition & 1 deletion source/common/common/dns_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace DnsUtils {
Network::DnsLookupFamily
getDnsLookupFamilyFromCluster(const envoy::config::cluster::v3::Cluster& cluster);
Network::DnsLookupFamily
getDnsLookupFamilyFromEnum(envoy::config::cluster::v3::Cluster::DnsLookupFamily family);
getDnsLookupFamilyFromEnum(envoy::extensions::clusters::dns::v3::DnsConfig::DnsLookupFamily family);

// Generates a list of InstanceConstSharedPtr from the DNS responses provided.
std::vector<Network::Address::InstanceConstSharedPtr>
Expand Down
14 changes: 14 additions & 0 deletions source/common/network/dns_resolver/dns_factory_util.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,27 @@ 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
Loading

0 comments on commit 9048a69

Please sign in to comment.