From b1c03b814cbcfc22afd417f7999da73f07e717c8 Mon Sep 17 00:00:00 2001 From: Tom Zhang Date: Mon, 18 Oct 2021 16:42:20 -0400 Subject: [PATCH 1/7] Partial Envoy import. Does not include resolving tests for changes in function signatures. --- .bazelrc | 17 +++-------------- .bazelversion | 2 +- bazel/repositories.bzl | 4 ++-- include/nighthawk/client/BUILD | 2 +- include/nighthawk/common/uri.h | 4 +++- source/client/BUILD | 4 ++-- source/client/process_bootstrap.cc | 8 +++++--- source/client/process_bootstrap.h | 4 ++-- source/client/process_impl.cc | 12 +++++++++--- source/common/uri_impl.cc | 12 +++++++++--- source/common/uri_impl.h | 4 +++- source/common/utility.h | 2 +- test/process_bootstrap_test.cc | 1 + test/utility_test.cc | 6 +++--- 14 files changed, 45 insertions(+), 37 deletions(-) diff --git a/.bazelrc b/.bazelrc index 6bdcd4a8b..deaa2699a 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,12 +1,3 @@ -# The following .bazelrc content is forked from the main Envoy repository. # unique -# This is necessary since this needs to be available before we can access # unique -# the Envoy repository contents via Bazel. # unique - # unique -build:clang-asan --test_timeout=900 # unique -build:clang-tsan --test_timeout=900 # unique -# See https://github.com/envoyproxy/nighthawk/issues/405 # unique -build:macos --copt -UDEBUG # unique - # unique # Envoy specific Bazel build/test options. # Bazel doesn't need more than 200MB of memory for local build based on memory profiling: @@ -68,10 +59,8 @@ build:asan --config=sanitizer # ASAN install its signal handler, disable ours so the stacktrace will be printed by ASAN build:asan --define signal_trace=disabled build:asan --define ENVOY_CONFIG_ASAN=1 -# The following two lines were manually edited due to #593. # unique -# Flag undefined was dropped from both the lines to allow CI/ASAN to pass. # unique -build:asan --copt -fsanitize=address # unique -build:asan --linkopt -fsanitize=address # unique +build:asan --copt -fsanitize=address,undefined +build:asan --linkopt -fsanitize=address,undefined # vptr and function sanitizer are enabled in clang-asan if it is set up via bazel/setup_clang.sh. build:asan --copt -fno-sanitize=vptr,function build:asan --linkopt -fno-sanitize=vptr,function @@ -169,7 +158,7 @@ build:coverage --strategy=CoverageReport=sandboxed,local build:coverage --experimental_use_llvm_covmap build:coverage --collect_code_coverage build:coverage --test_tag_filters=-nocoverage -build:coverage --instrumentation_filter="//source(?!/common/chromium_url|/common/quic/platform)[/:],//include[/:]" +build:coverage --instrumentation_filter="//source(?!/common/quic/platform)[/:],//include[/:]" build:test-coverage --test_arg="-l trace" build:fuzz-coverage --config=plain-fuzzer build:fuzz-coverage --run_under=@envoy//bazel/coverage:fuzz_coverage_wrapper.sh diff --git a/.bazelversion b/.bazelversion index ee74734aa..fae6e3d04 100644 --- a/.bazelversion +++ b/.bazelversion @@ -1 +1 @@ -4.1.0 +4.2.1 diff --git a/bazel/repositories.bzl b/bazel/repositories.bzl index 36f302663..d1eefc666 100644 --- a/bazel/repositories.bzl +++ b/bazel/repositories.bzl @@ -1,7 +1,7 @@ load("@bazel_tools//tools/build_defs/repo:http.bzl", "http_archive") -ENVOY_COMMIT = "9d476a1563ab8acc244bad3246d2b13368d5552a" # Oct 11, 2021 -ENVOY_SHA = "05d52ba9660963d5d495227b2650979b38d3bb04322a614d689aa16b02b8a9f5" +ENVOY_COMMIT = "592868adfefacf1afae6e41c6ee25e4a059aa089" # Oct 18, 2021 +ENVOY_SHA = "674a6d802d934596ac6373612c40398ce8e37ec91aa5cc1dd1873b780ef15f68" HDR_HISTOGRAM_C_VERSION = "0.11.2" # October 12th, 2020 HDR_HISTOGRAM_C_SHA = "637f28b5f64de2e268131e4e34e6eef0b91cf5ff99167db447d9b2825eae6bad" diff --git a/include/nighthawk/client/BUILD b/include/nighthawk/client/BUILD index 7ec0b6869..507de214e 100644 --- a/include/nighthawk/client/BUILD +++ b/include/nighthawk/client/BUILD @@ -46,9 +46,9 @@ envoy_basic_cc_library( "@envoy//source/common/api:api_lib_with_external_headers", "@envoy//source/common/common:minimal_logger_lib_with_external_headers", "@envoy//source/common/common:non_copyable_with_external_headers", - "@envoy//source/common/network:dns_lib_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", "@envoy//source/common/runtime:runtime_lib_with_external_headers", + "@envoy//source/extensions/network/dns_resolver/cares:config_with_external_headers", "@envoy_api//envoy/api/v2:pkg_cc_proto", "@envoy_api//envoy/config/metrics/v3:pkg_cc_proto", ], diff --git a/include/nighthawk/common/uri.h b/include/nighthawk/common/uri.h index 820b917ab..b1e746cc8 100644 --- a/include/nighthawk/common/uri.h +++ b/include/nighthawk/common/uri.h @@ -4,8 +4,8 @@ #include "nighthawk/common/exception.h" -#include "external/envoy/source/common/network/dns_impl.h" #include "external/envoy/source/common/network/utility.h" +#include "external/envoy/source/extensions/network/dns_resolver/cares/dns_impl.h" #include "absl/strings/string_view.h" @@ -58,12 +58,14 @@ class Uri { /** * Synchronously resolves the parsed host from the uri to an ip-address. * @param dispatcher Dispatcher to use for resolving. + * @param api Api to use for resolving. * @param dns_lookup_family Allows specifying Ipv4, Ipv6, or Auto as the preferred returned * address family. * @return Envoy::Network::Address::InstanceConstSharedPtr the resolved address. */ virtual Envoy::Network::Address::InstanceConstSharedPtr resolve(Envoy::Event::Dispatcher& dispatcher, + Envoy::Api::Api& api, const Envoy::Network::DnsLookupFamily dns_lookup_family) PURE; /** diff --git a/source/client/BUILD b/source/client/BUILD index 9d81e538a..c437ae1f7 100644 --- a/source/client/BUILD +++ b/source/client/BUILD @@ -106,11 +106,10 @@ envoy_cc_library( "@envoy//source/common/http:header_map_lib_with_external_headers", "@envoy//source/common/http:headers_lib_with_external_headers", "@envoy//source/common/http/http1:codec_lib_with_external_headers", - "@envoy//source/common/http/http1:conn_pool_lib_with_external_headers", + "@envoy//source/common/http/http1:conn_pool_lib_with_external_headers", "@envoy//source/common/http/http2:conn_pool_lib_with_external_headers", "@envoy//source/common/init:manager_lib_with_external_headers", "@envoy//source/common/local_info:local_info_lib_with_external_headers", - "@envoy//source/common/network:dns_lib_with_external_headers", "@envoy//source/common/network:address_lib_with_external_headers", "@envoy//source/common/protobuf:message_validator_lib_with_external_headers", "@envoy//source/common/protobuf:utility_lib_with_external_headers", @@ -128,6 +127,7 @@ envoy_cc_library( "@envoy//source/exe:platform_header_lib_with_external_headers", "@envoy//source/exe:platform_impl_lib", "@envoy//source/exe:process_wide_lib_with_external_headers", + "@envoy//source/extensions/network/dns_resolver/cares:config_with_external_headers", "@envoy//source/extensions/request_id/uuid:config_with_external_headers", "@envoy//source/extensions/transport_sockets/tls:context_lib_with_external_headers", "@envoy//source/server:server_lib_with_external_headers", diff --git a/source/client/process_bootstrap.cc b/source/client/process_bootstrap.cc index 7ef789eff..9364cf65c 100644 --- a/source/client/process_bootstrap.cc +++ b/source/client/process_bootstrap.cc @@ -181,6 +181,7 @@ Cluster createNighthawkClusterForWorker(const Client::Options& options, // Nighthawk options. // Resolves all the extracted URIs. absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatcher, + Envoy::Api::Api& api, const Client::Options& options, std::vector* uris, UriPtr* request_source_uri) { @@ -196,12 +197,12 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch } } for (const UriPtr& uri : *uris) { - uri->resolve(dispatcher, Utility::translateFamilyOptionString(options.addressFamily())); + uri->resolve(dispatcher, api, Utility::translateFamilyOptionString(options.addressFamily())); } if (options.requestSource() != "") { *request_source_uri = std::make_unique(options.requestSource()); (*request_source_uri) - ->resolve(dispatcher, Utility::translateFamilyOptionString(options.addressFamily())); + ->resolve(dispatcher, api, Utility::translateFamilyOptionString(options.addressFamily())); } } catch (const UriException& ex) { return absl::InvalidArgumentError( @@ -215,12 +216,13 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch } // namespace absl::StatusOr createBootstrapConfiguration(Envoy::Event::Dispatcher& dispatcher, + Envoy::Api::Api& api, const Client::Options& options, int number_of_workers) { std::vector uris; UriPtr request_source_uri; absl::Status uri_status = - extractAndResolveUrisFromOptions(dispatcher, options, &uris, &request_source_uri); + extractAndResolveUrisFromOptions(dispatcher, api, options, &uris, &request_source_uri); if (!uri_status.ok()) { return uri_status; } diff --git a/source/client/process_bootstrap.h b/source/client/process_bootstrap.h index 6a7554371..26d37a250 100644 --- a/source/client/process_bootstrap.h +++ b/source/client/process_bootstrap.h @@ -24,7 +24,7 @@ namespace Nighthawk { * @return the created bootstrap configuration. */ absl::StatusOr -createBootstrapConfiguration(Envoy::Event::Dispatcher& dispatcher, const Client::Options& options, - int number_of_workers); +createBootstrapConfiguration(Envoy::Event::Dispatcher& dispatcher, Envoy::Api::Api& api, + const Client::Options& options, int number_of_workers); } // namespace Nighthawk diff --git a/source/client/process_impl.cc b/source/client/process_impl.cc index 26fe16112..6aa36558a 100644 --- a/source/client/process_impl.cc +++ b/source/client/process_impl.cc @@ -24,6 +24,7 @@ #include "external/envoy/source/common/event/real_time_system.h" #include "external/envoy/source/common/init/manager_impl.h" #include "external/envoy/source/common/local_info/local_info_impl.h" +#include "external/envoy/source/common/network/dns_resolver/dns_factory.h" #include "external/envoy/source/common/network/utility.h" #include "external/envoy/source/common/runtime/runtime_impl.h" #include "external/envoy/source/common/singleton/manager_impl.h" @@ -197,7 +198,7 @@ ProcessImpl::CreateProcessImpl(const Options& options, Envoy::Event::TimeSystem& std::unique_ptr process(new ProcessImpl(options, time_system, process_wide)); absl::StatusOr bootstrap = createBootstrapConfiguration( - *process->dispatcher_, process->options_, process->number_of_workers_); + *process->dispatcher_, *process->api_, process->options_, process->number_of_workers_); if (!bootstrap.ok()) { ENVOY_LOG(error, "Failed to create bootstrap configuration: {}", bootstrap.status().message()); process->shutdown(); @@ -465,10 +466,14 @@ bool ProcessImpl::runInternal(OutputCollector& collector, const UriPtr& tracing_ }; const Envoy::OptionsImpl envoy_options( /* args = */ {"process_impl"}, hot_restart_version_cb, spdlog::level::info); - envoy::config::core::v3::DnsResolverOptions dns_resolver_options; + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + auto dns_resolver = dns_resolver_factory.createDnsResolver(*dispatcher_, *api_, typed_dns_resolver_config); cluster_manager_factory_ = std::make_unique( admin_, Envoy::Runtime::LoaderSingleton::get(), store_root_, tls_, - dispatcher_->createDnsResolver({}, dns_resolver_options), *ssl_context_manager_, + dns_resolver, *ssl_context_manager_, *dispatcher_, *local_info_, secret_manager_, validation_context_, *api_, http_context_, grpc_context_, router_context_, access_log_manager_, *singleton_manager_, envoy_options, quic_stat_names_); @@ -579,6 +584,7 @@ bool ProcessImpl::run(OutputCollector& collector) { if (options_.trace() != "") { tracing_uri = std::make_unique(options_.trace()); tracing_uri->resolve(*dispatcher_, + *api_, Utility::translateFamilyOptionString(options_.addressFamily())); } } catch (const UriException& ex) { diff --git a/source/common/uri_impl.cc b/source/common/uri_impl.cc index 82960f823..ea923cfe5 100644 --- a/source/common/uri_impl.cc +++ b/source/common/uri_impl.cc @@ -1,6 +1,7 @@ #include "source/common/uri_impl.h" #include "external/envoy/source/common/http/utility.h" +#include "external/envoy/source/common/network/dns_resolver/dns_factory.h" #include "external/envoy/source/common/network/utility.h" #include "external/envoy_api/envoy/config/core/v3/resolver.pb.h" @@ -62,9 +63,13 @@ UriImpl::UriImpl(absl::string_view uri, absl::string_view default_scheme) } bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, + Envoy::Api::Api& api, const Envoy::Network::DnsLookupFamily dns_lookup_family) { - envoy::config::core::v3::DnsResolverOptions dns_resolver_options; - auto dns_resolver = dispatcher.createDnsResolver({}, dns_resolver_options); + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + auto dns_resolver = dns_resolver_factory.createDnsResolver(dispatcher, api, typed_dns_resolver_config); std::string hostname = std::string(hostWithoutPort()); if (!hostname.empty() && hostname[0] == '[' && hostname[hostname.size() - 1] == ']') { @@ -93,13 +98,14 @@ bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::Address::InstanceConstSharedPtr UriImpl::resolve(Envoy::Event::Dispatcher& dispatcher, + Envoy::Api::Api& api, const Envoy::Network::DnsLookupFamily dns_lookup_family) { if (resolve_attempted_) { return address_; } resolve_attempted_ = true; - bool ok = performDnsLookup(dispatcher, dns_lookup_family); + bool ok = performDnsLookup(dispatcher, api, dns_lookup_family); // Ensure that we figured out a fitting match for the requested dns lookup family. ok = ok && !((dns_lookup_family == Envoy::Network::DnsLookupFamily::V6Only && diff --git a/source/common/uri_impl.h b/source/common/uri_impl.h index 2a9a0bb4a..393cbe458 100644 --- a/source/common/uri_impl.h +++ b/source/common/uri_impl.h @@ -8,8 +8,8 @@ #include "nighthawk/common/uri.h" #include "external/envoy/source/common/common/logger.h" -#include "external/envoy/source/common/network/dns_impl.h" #include "external/envoy/source/common/network/utility.h" +#include "external/envoy/source/extensions/network/dns_resolver/cares/dns_impl.h" #include "absl/strings/string_view.h" @@ -25,6 +25,7 @@ class UriImpl : public Uri, public Envoy::Logger::LoggableallocateDispatcher("uri_resolution_thread"); auto u = UriImpl(uri); - return u.resolve(*dispatcher, address_family); + return u.resolve(*dispatcher, *api, address_family); } }; @@ -145,8 +145,8 @@ TEST_P(UtilityAddressResolutionTest, ResolveTwiceReturnsCached) { auto dispatcher = api->allocateDispatcher("test_thread"); auto u = UriImpl("localhost"); - EXPECT_EQ(u.resolve(*dispatcher, address_family).get(), - u.resolve(*dispatcher, address_family).get()); + EXPECT_EQ(u.resolve(*dispatcher, *api, address_family).get(), + u.resolve(*dispatcher, *api, address_family).get()); } TEST_F(UtilityTest, TranslateAddressFamilyGoodValues) { From a12a3a67d7edc2abf633aa025798e3c603b8041f Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 01:39:30 -0400 Subject: [PATCH 2/7] preserve bzl comments, inject DNS resolver factory and config Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- .bazelrc | 11 ++++++ include/nighthawk/common/uri.h | 7 ++-- source/client/BUILD | 2 +- source/client/client.cc | 8 +++- source/client/process_bootstrap.cc | 23 ++++++----- source/client/process_bootstrap.h | 14 +++++-- source/client/process_impl.cc | 41 ++++++++++--------- source/client/process_impl.h | 18 ++++++++- source/client/service_impl.cc | 8 +++- source/common/uri_impl.cc | 11 ++---- source/common/uri_impl.h | 7 ++-- test/BUILD | 1 + test/process_bootstrap_test.cc | 63 ++++++++++++++++++++++-------- test/process_test.cc | 16 ++++++-- test/utility_test.cc | 17 ++++++-- 15 files changed, 169 insertions(+), 78 deletions(-) diff --git a/.bazelrc b/.bazelrc index deaa2699a..5bfbbd9e1 100644 --- a/.bazelrc +++ b/.bazelrc @@ -1,3 +1,12 @@ +# The following .bazelrc content is forked from the main Envoy repository. # unique +# This is necessary since this needs to be available before we can access # unique +# the Envoy repository contents via Bazel. # unique + # unique +build:clang-asan --test_timeout=900 # unique +build:clang-tsan --test_timeout=900 # unique +# See https://github.com/envoyproxy/nighthawk/issues/405 # unique +build:macos --copt -UDEBUG # unique + # unique # Envoy specific Bazel build/test options. # Bazel doesn't need more than 200MB of memory for local build based on memory profiling: @@ -59,6 +68,8 @@ build:asan --config=sanitizer # ASAN install its signal handler, disable ours so the stacktrace will be printed by ASAN build:asan --define signal_trace=disabled build:asan --define ENVOY_CONFIG_ASAN=1 +# The following two lines were manually edited due to #593. # unique +# Flag undefined was dropped from both the lines to allow CI/ASAN to pass. # unique build:asan --copt -fsanitize=address,undefined build:asan --linkopt -fsanitize=address,undefined # vptr and function sanitizer are enabled in clang-asan if it is set up via bazel/setup_clang.sh. diff --git a/include/nighthawk/common/uri.h b/include/nighthawk/common/uri.h index b1e746cc8..46e59790e 100644 --- a/include/nighthawk/common/uri.h +++ b/include/nighthawk/common/uri.h @@ -4,8 +4,8 @@ #include "nighthawk/common/exception.h" +#include "external/envoy/envoy/network/dns.h" #include "external/envoy/source/common/network/utility.h" -#include "external/envoy/source/extensions/network/dns_resolver/cares/dns_impl.h" #include "absl/strings/string_view.h" @@ -58,14 +58,13 @@ class Uri { /** * Synchronously resolves the parsed host from the uri to an ip-address. * @param dispatcher Dispatcher to use for resolving. - * @param api Api to use for resolving. + * @param dns_resolver DNS resolver to use for resolving. * @param dns_lookup_family Allows specifying Ipv4, Ipv6, or Auto as the preferred returned * address family. * @return Envoy::Network::Address::InstanceConstSharedPtr the resolved address. */ virtual Envoy::Network::Address::InstanceConstSharedPtr - resolve(Envoy::Event::Dispatcher& dispatcher, - Envoy::Api::Api& api, + resolve(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::DnsResolverSharedPtr dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) PURE; /** diff --git a/source/client/BUILD b/source/client/BUILD index c437ae1f7..3b06a0ff4 100644 --- a/source/client/BUILD +++ b/source/client/BUILD @@ -106,7 +106,7 @@ envoy_cc_library( "@envoy//source/common/http:header_map_lib_with_external_headers", "@envoy//source/common/http:headers_lib_with_external_headers", "@envoy//source/common/http/http1:codec_lib_with_external_headers", - "@envoy//source/common/http/http1:conn_pool_lib_with_external_headers", + "@envoy//source/common/http/http1:conn_pool_lib_with_external_headers", "@envoy//source/common/http/http2:conn_pool_lib_with_external_headers", "@envoy//source/common/init:manager_lib_with_external_headers", "@envoy//source/common/local_info:local_info_lib_with_external_headers", diff --git a/source/client/client.cc b/source/client/client.cc index b6c4847ca..081cb18bd 100644 --- a/source/client/client.cc +++ b/source/client/client.cc @@ -72,8 +72,12 @@ bool Main::run() { stub = std::make_unique(channel); process = std::make_unique(*options_, *stub); } else { - absl::StatusOr process_or_status = - ProcessImpl::CreateProcessImpl(*options_, time_system); + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *options_, dns_resolver_factory, typed_dns_resolver_config, time_system); if (!process_or_status.ok()) { ENVOY_LOG(error, "Unable to create ProcessImpl: {}", process_or_status.status().ToString()); return false; diff --git a/source/client/process_bootstrap.cc b/source/client/process_bootstrap.cc index 9364cf65c..5c21ae3cd 100644 --- a/source/client/process_bootstrap.cc +++ b/source/client/process_bootstrap.cc @@ -181,8 +181,8 @@ Cluster createNighthawkClusterForWorker(const Client::Options& options, // Nighthawk options. // Resolves all the extracted URIs. absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatcher, - Envoy::Api::Api& api, const Client::Options& options, + Envoy::Network::DnsResolverSharedPtr dns_resolver, std::vector* uris, UriPtr* request_source_uri) { try { @@ -197,12 +197,14 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch } } for (const UriPtr& uri : *uris) { - uri->resolve(dispatcher, api, Utility::translateFamilyOptionString(options.addressFamily())); + uri->resolve(dispatcher, dns_resolver, + Utility::translateFamilyOptionString(options.addressFamily())); } if (options.requestSource() != "") { *request_source_uri = std::make_unique(options.requestSource()); (*request_source_uri) - ->resolve(dispatcher, api, Utility::translateFamilyOptionString(options.addressFamily())); + ->resolve(dispatcher, dns_resolver, + Utility::translateFamilyOptionString(options.addressFamily())); } } catch (const UriException& ex) { return absl::InvalidArgumentError( @@ -215,14 +217,17 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch } // namespace -absl::StatusOr createBootstrapConfiguration(Envoy::Event::Dispatcher& dispatcher, - Envoy::Api::Api& api, - const Client::Options& options, - int number_of_workers) { +absl::StatusOr createBootstrapConfiguration( + Envoy::Event::Dispatcher& dispatcher, Envoy::Api::Api& api, const Client::Options& options, + Envoy::Network::DnsResolverFactory& dns_resolver_factory, + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, + int number_of_workers) { + Envoy::Network::DnsResolverSharedPtr dns_resolver = + dns_resolver_factory.createDnsResolver(dispatcher, api, typed_dns_resolver_config); std::vector uris; UriPtr request_source_uri; - absl::Status uri_status = - extractAndResolveUrisFromOptions(dispatcher, api, options, &uris, &request_source_uri); + absl::Status uri_status = extractAndResolveUrisFromOptions(dispatcher, options, dns_resolver, + &uris, &request_source_uri); if (!uri_status.ok()) { return uri_status; } diff --git a/source/client/process_bootstrap.h b/source/client/process_bootstrap.h index 26d37a250..8b9a84f3f 100644 --- a/source/client/process_bootstrap.h +++ b/source/client/process_bootstrap.h @@ -5,6 +5,7 @@ #include "external/envoy/source/common/common/statusor.h" #include "external/envoy/source/common/event/dispatcher_impl.h" +#include "external/envoy/source/common/network/dns_resolver/dns_factory.h" #include "external/envoy_api/envoy/config/bootstrap/v3/bootstrap.pb.h" namespace Nighthawk { @@ -16,15 +17,20 @@ namespace Nighthawk { * specified uris. * * @param dispatcher is used when resolving hostnames to IP addresses in the - bootstrap. + * bootstrap. * @param options are the options this Nighthawk execution was triggered with. + * @param dns_resolver_factory used to create a DNS resolver to resolve hostnames + * in the bootstrap. + * @param typed_dns_resolver_config config used when creating dns_resolver_factory, + * also needed when creating the resolver. * @param number_of_workers indicates how many Nighthawk workers will be * upstreaming requests. A separate cluster is generated for each worker. * * @return the created bootstrap configuration. */ -absl::StatusOr -createBootstrapConfiguration(Envoy::Event::Dispatcher& dispatcher, Envoy::Api::Api& api, - const Client::Options& options, int number_of_workers); +absl::StatusOr createBootstrapConfiguration( + Envoy::Event::Dispatcher& dispatcher, Envoy::Api::Api& api, const Client::Options& options, + Envoy::Network::DnsResolverFactory& dns_resolver_factory, + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, int number_of_workers); } // namespace Nighthawk diff --git a/source/client/process_impl.cc b/source/client/process_impl.cc index 6aa36558a..c78ad055d 100644 --- a/source/client/process_impl.cc +++ b/source/client/process_impl.cc @@ -161,6 +161,8 @@ class ClusterManagerFactory : public Envoy::Upstream::ProdClusterManagerFactory }; ProcessImpl::ProcessImpl(const Options& options, Envoy::Event::TimeSystem& time_system, + Envoy::Network::DnsResolverFactory& dns_resolver_factory, + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, const std::shared_ptr& process_wide) : options_(options), number_of_workers_(BootstrapFactory::determineConcurrency(options_)), process_wide_(process_wide == nullptr ? std::make_shared() @@ -182,6 +184,8 @@ ProcessImpl::ProcessImpl(const Options& options, Envoy::Event::TimeSystem& time_ singleton_manager_(std::make_unique(api_->threadFactory())), access_log_manager_(std::chrono::milliseconds(1000), *api_, *dispatcher_, access_log_lock_, store_root_), + dns_resolver_factory_(dns_resolver_factory), + typed_dns_resolver_config_(std::move(typed_dns_resolver_config)), init_watcher_("Nighthawk", []() {}), admin_(Envoy::Network::Address::InstanceConstSharedPtr()), validation_context_(false, false, false), router_context_(store_root_.symbolTable()) { @@ -192,13 +196,17 @@ ProcessImpl::ProcessImpl(const Options& options, Envoy::Event::TimeSystem& time_ configureComponentLogLevels(spdlog::level::from_str(lower)); } -absl::StatusOr -ProcessImpl::CreateProcessImpl(const Options& options, Envoy::Event::TimeSystem& time_system, - const std::shared_ptr& process_wide) { - std::unique_ptr process(new ProcessImpl(options, time_system, process_wide)); +absl::StatusOr ProcessImpl::CreateProcessImpl( + const Options& options, Envoy::Network::DnsResolverFactory& dns_resolver_factory, + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, + Envoy::Event::TimeSystem& time_system, + const std::shared_ptr& process_wide) { + std::unique_ptr process(new ProcessImpl(options, time_system, dns_resolver_factory, + typed_dns_resolver_config, process_wide)); absl::StatusOr bootstrap = createBootstrapConfiguration( - *process->dispatcher_, *process->api_, process->options_, process->number_of_workers_); + *process->dispatcher_, *process->api_, process->options_, process->dns_resolver_factory_, + process->typed_dns_resolver_config_, process->number_of_workers_); if (!bootstrap.ok()) { ENVOY_LOG(error, "Failed to create bootstrap configuration: {}", bootstrap.status().message()); process->shutdown(); @@ -430,6 +438,7 @@ void ProcessImpl::setupStatsSinks(const envoy::config::bootstrap::v3::Bootstrap& } bool ProcessImpl::runInternal(OutputCollector& collector, const UriPtr& tracing_uri, + Envoy::Network::DnsResolverSharedPtr dns_resolver, const absl::optional& scheduled_start) { const Envoy::SystemTime now = time_system_.systemTime(); if (scheduled_start.value_or(now) < now) { @@ -460,23 +469,16 @@ bool ProcessImpl::runInternal(OutputCollector& collector, const UriPtr& tracing_ std::make_unique( time_system_); - ::envoy::config::core::v3::DnsResolverOptions dns_options; const Envoy::OptionsImpl::HotRestartVersionCb hot_restart_version_cb = [](bool) { return "hot restart is disabled"; }; const Envoy::OptionsImpl envoy_options( /* args = */ {"process_impl"}, hot_restart_version_cb, spdlog::level::info); - envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; - Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); - Envoy::Network::DnsResolverFactory& dns_resolver_factory = - Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); - auto dns_resolver = dns_resolver_factory.createDnsResolver(*dispatcher_, *api_, typed_dns_resolver_config); cluster_manager_factory_ = std::make_unique( - admin_, Envoy::Runtime::LoaderSingleton::get(), store_root_, tls_, - dns_resolver, *ssl_context_manager_, - *dispatcher_, *local_info_, secret_manager_, validation_context_, *api_, http_context_, - grpc_context_, router_context_, access_log_manager_, *singleton_manager_, envoy_options, - quic_stat_names_); + admin_, Envoy::Runtime::LoaderSingleton::get(), store_root_, tls_, dns_resolver, + *ssl_context_manager_, *dispatcher_, *local_info_, secret_manager_, validation_context_, + *api_, http_context_, grpc_context_, router_context_, access_log_manager_, + *singleton_manager_, envoy_options, quic_stat_names_); cluster_manager_factory_->setConnectionReuseStrategy( options_.h1ConnectionReuseStrategy() == nighthawk::client::H1ConnectionReuseStrategy::LRU ? Http1PoolImpl::ConnectionReuseStrategy::LRU @@ -580,11 +582,12 @@ bool ProcessImpl::runInternal(OutputCollector& collector, const UriPtr& tracing_ bool ProcessImpl::run(OutputCollector& collector) { UriPtr tracing_uri; + Envoy::Network::DnsResolverSharedPtr dns_resolver = + dns_resolver_factory_.createDnsResolver(*dispatcher_, *api_, typed_dns_resolver_config_); try { if (options_.trace() != "") { tracing_uri = std::make_unique(options_.trace()); - tracing_uri->resolve(*dispatcher_, - *api_, + tracing_uri->resolve(*dispatcher_, dns_resolver, Utility::translateFamilyOptionString(options_.addressFamily())); } } catch (const UriException& ex) { @@ -596,7 +599,7 @@ bool ProcessImpl::run(OutputCollector& collector) { } try { - return runInternal(collector, tracing_uri, options_.scheduled_start()); + return runInternal(collector, tracing_uri, dns_resolver, options_.scheduled_start()); } catch (Envoy::EnvoyException& ex) { ENVOY_LOG(error, "Fatal exception: {}", ex.what()); throw; diff --git a/source/client/process_impl.h b/source/client/process_impl.h index 7ae191d89..1a9e14f43 100644 --- a/source/client/process_impl.h +++ b/source/client/process_impl.h @@ -21,6 +21,7 @@ #include "external/envoy/source/common/event/real_time_system.h" #include "external/envoy/source/common/grpc/context_impl.h" #include "external/envoy/source/common/http/context_impl.h" +#include "external/envoy/source/common/network/dns_resolver/dns_factory.h" #include "external/envoy/source/common/protobuf/message_validator_impl.h" #include "external/envoy/source/common/quic/quic_stat_names.h" #include "external/envoy/source/common/router/context_impl.h" @@ -55,6 +56,10 @@ class ProcessImpl : public Process, public Envoy::Logger::Loggable - CreateProcessImpl(const Options& options, Envoy::Event::TimeSystem& time_system, + CreateProcessImpl(const Options& options, + Envoy::Network::DnsResolverFactory& dns_resolver_factory, + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, + Envoy::Event::TimeSystem& time_system, const std::shared_ptr& process_wide = nullptr); ~ProcessImpl() override; @@ -87,6 +95,8 @@ class ProcessImpl : public Process, public Envoy::Logger::Loggable& process_wide = nullptr); void addTracingCluster(envoy::config::bootstrap::v3::Bootstrap& bootstrap, const Uri& uri) const; @@ -115,6 +125,7 @@ class ProcessImpl : public Process, public Envoy::Logger::Loggable>& stats_sinks); bool runInternal(OutputCollector& collector, const UriPtr& tracing_uri, + Envoy::Network::DnsResolverSharedPtr dns_resolver, const absl::optional& schedule); /** @@ -169,7 +180,6 @@ class ProcessImpl : public Process, public Envoy::Logger::Loggable ssl_context_manager_; diff --git a/source/client/service_impl.cc b/source/client/service_impl.cc index a2093d16d..7168299a6 100644 --- a/source/client/service_impl.cc +++ b/source/client/service_impl.cc @@ -33,9 +33,13 @@ void ServiceImpl::handleExecutionRequest(const nighthawk::client::ExecutionReque writeResponse(response); return; } + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); - absl::StatusOr process_or_status = - ProcessImpl::CreateProcessImpl(*options, time_system_, process_wide_); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *options, dns_resolver_factory, typed_dns_resolver_config, time_system_, process_wide_); if (!process_or_status.ok()) { response.mutable_error_detail()->set_code(grpc::StatusCode::INTERNAL); response.mutable_error_detail()->set_message( diff --git a/source/common/uri_impl.cc b/source/common/uri_impl.cc index ea923cfe5..660d3583a 100644 --- a/source/common/uri_impl.cc +++ b/source/common/uri_impl.cc @@ -63,13 +63,8 @@ UriImpl::UriImpl(absl::string_view uri, absl::string_view default_scheme) } bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, - Envoy::Api::Api& api, + Envoy::Network::DnsResolverSharedPtr dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) { - envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; - Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); - Envoy::Network::DnsResolverFactory& dns_resolver_factory = - Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); - auto dns_resolver = dns_resolver_factory.createDnsResolver(dispatcher, api, typed_dns_resolver_config); std::string hostname = std::string(hostWithoutPort()); if (!hostname.empty() && hostname[0] == '[' && hostname[hostname.size() - 1] == ']') { @@ -98,14 +93,14 @@ bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::Address::InstanceConstSharedPtr UriImpl::resolve(Envoy::Event::Dispatcher& dispatcher, - Envoy::Api::Api& api, + Envoy::Network::DnsResolverSharedPtr dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) { if (resolve_attempted_) { return address_; } resolve_attempted_ = true; - bool ok = performDnsLookup(dispatcher, api, dns_lookup_family); + bool ok = performDnsLookup(dispatcher, dns_resolver, dns_lookup_family); // Ensure that we figured out a fitting match for the requested dns lookup family. ok = ok && !((dns_lookup_family == Envoy::Network::DnsLookupFamily::V6Only && diff --git a/source/common/uri_impl.h b/source/common/uri_impl.h index 393cbe458..e0b941e52 100644 --- a/source/common/uri_impl.h +++ b/source/common/uri_impl.h @@ -7,9 +7,9 @@ #include "nighthawk/common/exception.h" #include "nighthawk/common/uri.h" +#include "external/envoy/envoy/network/dns.h" #include "external/envoy/source/common/common/logger.h" #include "external/envoy/source/common/network/utility.h" -#include "external/envoy/source/extensions/network/dns_resolver/cares/dns_impl.h" #include "absl/strings/string_view.h" @@ -24,8 +24,7 @@ class UriImpl : public Uri, public Envoy::Logger::Loggable()}; NiceMock mock_dispatcher_; int number_of_workers_{1}; + NiceMock mock_dns_resolver_factory_; + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config_; }; TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH1) { @@ -139,8 +142,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH1) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -216,8 +221,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH1RespectingPortInUr )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -304,8 +311,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH1WithMultipleTarget )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -392,8 +401,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH1WithTls) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -522,8 +533,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH1AndMultipleWorkers )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, /* number_of_workers = */ 2); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, /* number_of_workers = */ 2); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -602,8 +615,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH2) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -693,8 +708,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH2WithTls) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -788,8 +805,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapForH3) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -898,8 +917,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapWithRequestSourceAndCus )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -1094,8 +1115,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapWithRequestSourceAndMul )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, /* number_of_workers = */ 2); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, /* number_of_workers = */ 2); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -1207,8 +1230,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapWithCustomOptions) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -1286,8 +1311,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapSetsMaxRequestToAtLeast )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -1385,8 +1412,10 @@ TEST_F(CreateBootstrapConfigurationTest, CreatesBootstrapWithCustomTransportSock )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); @@ -1475,8 +1504,10 @@ TEST_F(CreateBootstrapConfigurationTest, DeterminesSniFromRequestHeader) { )pb"); ASSERT_THAT(expected_bootstrap, StatusIs(absl::StatusCode::kOk)); + NiceMock api; absl::StatusOr bootstrap = - createBootstrapConfiguration(mock_dispatcher_, *options, number_of_workers_); + createBootstrapConfiguration(mock_dispatcher_, api, *options, mock_dns_resolver_factory_, + typed_dns_resolver_config_, number_of_workers_); ASSERT_THAT(bootstrap, StatusIs(absl::StatusCode::kOk)); EXPECT_THAT(*bootstrap, EqualsProto(*expected_bootstrap)); diff --git a/test/process_test.cc b/test/process_test.cc index 4cea04e51..37c3088f2 100644 --- a/test/process_test.cc +++ b/test/process_test.cc @@ -74,8 +74,12 @@ class ProcessTest : public TestWithParam { absl::Status runProcess(RunExpectation expectation, bool do_cancel = false, bool terminate_right_away = false) { - absl::StatusOr process_or_status = - ProcessImpl::CreateProcessImpl(*options_, time_system_); + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *options_, dns_resolver_factory, typed_dns_resolver_config, time_system_); if (!process_or_status.ok()) { return process_or_status.status(); } @@ -209,8 +213,12 @@ class ProcessTestWithSimTime : public Envoy::Event::TestUsingSimulatedTime, absl::Status process_status; auto run_thread = std::thread([this, &verify_callback, &process_status] { - absl::StatusOr process_or_status = - ProcessImpl::CreateProcessImpl(*options_, simTime()); + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *options_, dns_resolver_factory, typed_dns_resolver_config, simTime()); if (!process_or_status.ok()) { process_status = process_or_status.status(); return; diff --git a/test/utility_test.cc b/test/utility_test.cc index 191829d4f..6b3376836 100644 --- a/test/utility_test.cc +++ b/test/utility_test.cc @@ -1,5 +1,6 @@ #include +#include "external/envoy/source/common/network/dns_resolver/dns_factory.h" #include "external/envoy/source/common/network/utility.h" #include "external/envoy/source/common/stats/isolated_store_impl.h" #include "external/envoy/test/test_common/utility.h" @@ -94,8 +95,13 @@ class UtilityAddressResolutionTest : public TestWithParamallocateDispatcher("uri_resolution_thread"); + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + Envoy::Network::DnsResolverSharedPtr dns_resolver = + dns_resolver_factory.createDnsResolver(*dispatcher, *api, typed_dns_resolver_config); auto u = UriImpl(uri); - return u.resolve(*dispatcher, *api, address_family); + return u.resolve(*dispatcher, dns_resolver, address_family); } }; @@ -143,10 +149,15 @@ TEST_P(UtilityAddressResolutionTest, ResolveTwiceReturnsCached) { Envoy::Api::ApiPtr api = Envoy::Api::createApiForTest(); auto dispatcher = api->allocateDispatcher("test_thread"); + envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; + Envoy::Network::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + Envoy::Network::DnsResolverSharedPtr dns_resolver = + dns_resolver_factory.createDnsResolver(*dispatcher, *api, typed_dns_resolver_config); auto u = UriImpl("localhost"); - EXPECT_EQ(u.resolve(*dispatcher, *api, address_family).get(), - u.resolve(*dispatcher, *api, address_family).get()); + EXPECT_EQ(u.resolve(*dispatcher, dns_resolver, address_family).get(), + u.resolve(*dispatcher, dns_resolver, address_family).get()); } TEST_F(UtilityTest, TranslateAddressFamilyGoodValues) { From db769991557224072bcfff770b217d5e545a8b92 Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 01:45:33 -0400 Subject: [PATCH 3/7] fix bazelrc Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- .bazelrc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.bazelrc b/.bazelrc index 5bfbbd9e1..a0e8139a4 100644 --- a/.bazelrc +++ b/.bazelrc @@ -70,8 +70,8 @@ build:asan --define signal_trace=disabled build:asan --define ENVOY_CONFIG_ASAN=1 # The following two lines were manually edited due to #593. # unique # Flag undefined was dropped from both the lines to allow CI/ASAN to pass. # unique -build:asan --copt -fsanitize=address,undefined -build:asan --linkopt -fsanitize=address,undefined +build:asan --copt -fsanitize=address # unique +build:asan --linkopt -fsanitize=address # unique # vptr and function sanitizer are enabled in clang-asan if it is set up via bazel/setup_clang.sh. build:asan --copt -fno-sanitize=vptr,function build:asan --linkopt -fno-sanitize=vptr,function From 0c76e5761aef77d0bc100faae50eb8ed982f281a Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 01:58:48 -0400 Subject: [PATCH 4/7] fix dns includes Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- include/nighthawk/client/BUILD | 1 - source/client/BUILD | 1 - source/common/utility.h | 2 +- 3 files changed, 1 insertion(+), 3 deletions(-) diff --git a/include/nighthawk/client/BUILD b/include/nighthawk/client/BUILD index 507de214e..49dd108be 100644 --- a/include/nighthawk/client/BUILD +++ b/include/nighthawk/client/BUILD @@ -48,7 +48,6 @@ envoy_basic_cc_library( "@envoy//source/common/common:non_copyable_with_external_headers", "@envoy//source/common/protobuf:protobuf_with_external_headers", "@envoy//source/common/runtime:runtime_lib_with_external_headers", - "@envoy//source/extensions/network/dns_resolver/cares:config_with_external_headers", "@envoy_api//envoy/api/v2:pkg_cc_proto", "@envoy_api//envoy/config/metrics/v3:pkg_cc_proto", ], diff --git a/source/client/BUILD b/source/client/BUILD index 3b06a0ff4..bee064852 100644 --- a/source/client/BUILD +++ b/source/client/BUILD @@ -127,7 +127,6 @@ envoy_cc_library( "@envoy//source/exe:platform_header_lib_with_external_headers", "@envoy//source/exe:platform_impl_lib", "@envoy//source/exe:process_wide_lib_with_external_headers", - "@envoy//source/extensions/network/dns_resolver/cares:config_with_external_headers", "@envoy//source/extensions/request_id/uuid:config_with_external_headers", "@envoy//source/extensions/transport_sockets/tls:context_lib_with_external_headers", "@envoy//source/server:server_lib_with_external_headers", diff --git a/source/common/utility.h b/source/common/utility.h index f1c755450..94342b8ba 100644 --- a/source/common/utility.h +++ b/source/common/utility.h @@ -6,7 +6,7 @@ #include "nighthawk/common/exception.h" -#include "external/envoy/source/extensions/network/dns_resolver/cares/dns_impl.h" +#include "external/envoy/envoy/network/dns.h" #include "api/client/options.pb.h" From cb8f664a8858c314474c782dfba38c200d43adde Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 02:03:10 -0400 Subject: [PATCH 5/7] remove c-ares initialization which is clobbered by the default Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- source/client/client.cc | 1 - source/client/service_impl.cc | 1 - test/process_test.cc | 2 -- 3 files changed, 4 deletions(-) diff --git a/source/client/client.cc b/source/client/client.cc index 081cb18bd..0cfe099ce 100644 --- a/source/client/client.cc +++ b/source/client/client.cc @@ -73,7 +73,6 @@ bool Main::run() { process = std::make_unique(*options_, *stub); } else { envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; - Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( diff --git a/source/client/service_impl.cc b/source/client/service_impl.cc index 7168299a6..21074e798 100644 --- a/source/client/service_impl.cc +++ b/source/client/service_impl.cc @@ -34,7 +34,6 @@ void ServiceImpl::handleExecutionRequest(const nighthawk::client::ExecutionReque return; } envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; - Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); diff --git a/test/process_test.cc b/test/process_test.cc index 37c3088f2..bd8ba498d 100644 --- a/test/process_test.cc +++ b/test/process_test.cc @@ -75,7 +75,6 @@ class ProcessTest : public TestWithParam { absl::Status runProcess(RunExpectation expectation, bool do_cancel = false, bool terminate_right_away = false) { envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; - Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( @@ -214,7 +213,6 @@ class ProcessTestWithSimTime : public Envoy::Event::TestUsingSimulatedTime, auto run_thread = std::thread([this, &verify_callback, &process_status] { envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config; - Envoy::Network::makeDefaultCaresDnsResolverConfig(typed_dns_resolver_config); Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( From 32be032061d3b2af0e05246fa28aa93ce64c87ef Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 02:12:49 -0400 Subject: [PATCH 6/7] move typed_dns_resolver_config Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- source/client/process_bootstrap.cc | 2 +- source/client/process_bootstrap.h | 3 ++- source/client/process_impl.cc | 3 ++- source/client/service_impl.cc | 3 ++- test/process_test.cc | 4 ++-- 5 files changed, 9 insertions(+), 6 deletions(-) diff --git a/source/client/process_bootstrap.cc b/source/client/process_bootstrap.cc index 5c21ae3cd..468f233f6 100644 --- a/source/client/process_bootstrap.cc +++ b/source/client/process_bootstrap.cc @@ -220,7 +220,7 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch absl::StatusOr createBootstrapConfiguration( Envoy::Event::Dispatcher& dispatcher, Envoy::Api::Api& api, const Client::Options& options, Envoy::Network::DnsResolverFactory& dns_resolver_factory, - envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, + const envoy::config::core::v3::TypedExtensionConfig& typed_dns_resolver_config, int number_of_workers) { Envoy::Network::DnsResolverSharedPtr dns_resolver = dns_resolver_factory.createDnsResolver(dispatcher, api, typed_dns_resolver_config); diff --git a/source/client/process_bootstrap.h b/source/client/process_bootstrap.h index 8b9a84f3f..ff732a3a1 100644 --- a/source/client/process_bootstrap.h +++ b/source/client/process_bootstrap.h @@ -31,6 +31,7 @@ namespace Nighthawk { absl::StatusOr createBootstrapConfiguration( Envoy::Event::Dispatcher& dispatcher, Envoy::Api::Api& api, const Client::Options& options, Envoy::Network::DnsResolverFactory& dns_resolver_factory, - envoy::config::core::v3::TypedExtensionConfig typed_dns_resolver_config, int number_of_workers); + const envoy::config::core::v3::TypedExtensionConfig& typed_dns_resolver_config, + int number_of_workers); } // namespace Nighthawk diff --git a/source/client/process_impl.cc b/source/client/process_impl.cc index c78ad055d..5bf053cc0 100644 --- a/source/client/process_impl.cc +++ b/source/client/process_impl.cc @@ -202,7 +202,8 @@ absl::StatusOr ProcessImpl::CreateProcessImpl( Envoy::Event::TimeSystem& time_system, const std::shared_ptr& process_wide) { std::unique_ptr process(new ProcessImpl(options, time_system, dns_resolver_factory, - typed_dns_resolver_config, process_wide)); + std::move(typed_dns_resolver_config), + process_wide)); absl::StatusOr bootstrap = createBootstrapConfiguration( *process->dispatcher_, *process->api_, process->options_, process->dns_resolver_factory_, diff --git a/source/client/service_impl.cc b/source/client/service_impl.cc index 21074e798..669545b8e 100644 --- a/source/client/service_impl.cc +++ b/source/client/service_impl.cc @@ -38,7 +38,8 @@ void ServiceImpl::handleExecutionRequest(const nighthawk::client::ExecutionReque Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( - *options, dns_resolver_factory, typed_dns_resolver_config, time_system_, process_wide_); + *options, dns_resolver_factory, std::move(typed_dns_resolver_config), time_system_, + process_wide_); if (!process_or_status.ok()) { response.mutable_error_detail()->set_code(grpc::StatusCode::INTERNAL); response.mutable_error_detail()->set_message( diff --git a/test/process_test.cc b/test/process_test.cc index bd8ba498d..08224915d 100644 --- a/test/process_test.cc +++ b/test/process_test.cc @@ -78,7 +78,7 @@ class ProcessTest : public TestWithParam { Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( - *options_, dns_resolver_factory, typed_dns_resolver_config, time_system_); + *options_, dns_resolver_factory, std::move(typed_dns_resolver_config), time_system_); if (!process_or_status.ok()) { return process_or_status.status(); } @@ -216,7 +216,7 @@ class ProcessTestWithSimTime : public Envoy::Event::TestUsingSimulatedTime, Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( - *options_, dns_resolver_factory, typed_dns_resolver_config, simTime()); + *options_, dns_resolver_factory, std::move(typed_dns_resolver_config), simTime()); if (!process_or_status.ok()) { process_status = process_or_status.status(); return; From 267114097343f6e766d8e217e9b54b2280a4ea31 Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 02:33:21 -0400 Subject: [PATCH 7/7] DnsResolverSharedPtr -> DnsResolver& where possible Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- include/nighthawk/common/uri.h | 2 +- source/client/client.cc | 2 +- source/client/process_bootstrap.cc | 4 ++-- source/client/process_impl.cc | 2 +- source/common/uri_impl.cc | 7 +++---- source/common/uri_impl.h | 4 ++-- test/utility_test.cc | 6 +++--- 7 files changed, 13 insertions(+), 14 deletions(-) diff --git a/include/nighthawk/common/uri.h b/include/nighthawk/common/uri.h index 46e59790e..a153e2435 100644 --- a/include/nighthawk/common/uri.h +++ b/include/nighthawk/common/uri.h @@ -64,7 +64,7 @@ class Uri { * @return Envoy::Network::Address::InstanceConstSharedPtr the resolved address. */ virtual Envoy::Network::Address::InstanceConstSharedPtr - resolve(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::DnsResolverSharedPtr dns_resolver, + resolve(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::DnsResolver& dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) PURE; /** diff --git a/source/client/client.cc b/source/client/client.cc index 0cfe099ce..a02b38d76 100644 --- a/source/client/client.cc +++ b/source/client/client.cc @@ -76,7 +76,7 @@ bool Main::run() { Envoy::Network::DnsResolverFactory& dns_resolver_factory = Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( - *options_, dns_resolver_factory, typed_dns_resolver_config, time_system); + *options_, dns_resolver_factory, std::move(typed_dns_resolver_config), time_system); if (!process_or_status.ok()) { ENVOY_LOG(error, "Unable to create ProcessImpl: {}", process_or_status.status().ToString()); return false; diff --git a/source/client/process_bootstrap.cc b/source/client/process_bootstrap.cc index 468f233f6..58f1c224b 100644 --- a/source/client/process_bootstrap.cc +++ b/source/client/process_bootstrap.cc @@ -182,7 +182,7 @@ Cluster createNighthawkClusterForWorker(const Client::Options& options, // Resolves all the extracted URIs. absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatcher, const Client::Options& options, - Envoy::Network::DnsResolverSharedPtr dns_resolver, + Envoy::Network::DnsResolver& dns_resolver, std::vector* uris, UriPtr* request_source_uri) { try { @@ -226,7 +226,7 @@ absl::StatusOr createBootstrapConfiguration( dns_resolver_factory.createDnsResolver(dispatcher, api, typed_dns_resolver_config); std::vector uris; UriPtr request_source_uri; - absl::Status uri_status = extractAndResolveUrisFromOptions(dispatcher, options, dns_resolver, + absl::Status uri_status = extractAndResolveUrisFromOptions(dispatcher, options, *dns_resolver, &uris, &request_source_uri); if (!uri_status.ok()) { return uri_status; diff --git a/source/client/process_impl.cc b/source/client/process_impl.cc index 5bf053cc0..040da23ae 100644 --- a/source/client/process_impl.cc +++ b/source/client/process_impl.cc @@ -588,7 +588,7 @@ bool ProcessImpl::run(OutputCollector& collector) { try { if (options_.trace() != "") { tracing_uri = std::make_unique(options_.trace()); - tracing_uri->resolve(*dispatcher_, dns_resolver, + tracing_uri->resolve(*dispatcher_, *dns_resolver, Utility::translateFamilyOptionString(options_.addressFamily())); } } catch (const UriException& ex) { diff --git a/source/common/uri_impl.cc b/source/common/uri_impl.cc index 660d3583a..fe52d8cfc 100644 --- a/source/common/uri_impl.cc +++ b/source/common/uri_impl.cc @@ -63,7 +63,7 @@ UriImpl::UriImpl(absl::string_view uri, absl::string_view default_scheme) } bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, - Envoy::Network::DnsResolverSharedPtr dns_resolver, + Envoy::Network::DnsResolver& dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) { std::string hostname = std::string(hostWithoutPort()); @@ -71,7 +71,7 @@ bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, hostname = absl::StrReplaceAll(hostname, {{"[", ""}, {"]", ""}}); } - Envoy::Network::ActiveDnsQuery* active_dns_query_ = dns_resolver->resolve( + Envoy::Network::ActiveDnsQuery* active_dns_query_ = dns_resolver.resolve( hostname, dns_lookup_family, [this, &dispatcher, &active_dns_query_](Envoy::Network::DnsResolver::ResolutionStatus status, @@ -92,8 +92,7 @@ bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, } Envoy::Network::Address::InstanceConstSharedPtr -UriImpl::resolve(Envoy::Event::Dispatcher& dispatcher, - Envoy::Network::DnsResolverSharedPtr dns_resolver, +UriImpl::resolve(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::DnsResolver& dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) { if (resolve_attempted_) { return address_; diff --git a/source/common/uri_impl.h b/source/common/uri_impl.h index e0b941e52..cabfff860 100644 --- a/source/common/uri_impl.h +++ b/source/common/uri_impl.h @@ -24,7 +24,7 @@ class UriImpl : public Uri, public Envoy::Logger::Loggable