From 08f5f885a2d632c2feafe8873bae6cb664190cc0 Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 03:01:38 -0400 Subject: [PATCH 1/5] update instrumentation_filter and clang version in .bazelrc, update .bazelversion, commit id and SHA Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- .bazelrc | 4 ++-- .bazelversion | 2 +- bazel/repositories.bzl | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.bazelrc b/.bazelrc index 6bdcd4a8b..cd297d4e3 100644 --- a/.bazelrc +++ b/.bazelrc @@ -169,7 +169,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 @@ -200,7 +200,7 @@ build:rbe-toolchain-asan --linkopt -fuse-ld=lld build:rbe-toolchain-asan --action_env=ENVOY_UBSAN_VPTR=1 build:rbe-toolchain-asan --copt=-fsanitize=vptr,function build:rbe-toolchain-asan --linkopt=-fsanitize=vptr,function -build:rbe-toolchain-asan --linkopt=-L/opt/llvm/lib/clang/11.0.1/lib/linux +build:rbe-toolchain-asan --linkopt=-L/opt/llvm/lib/clang/12.0.1/lib/linux build:rbe-toolchain-asan --linkopt=-l:libclang_rt.ubsan_standalone-x86_64.a build:rbe-toolchain-asan --linkopt=-l:libclang_rt.ubsan_standalone_cxx-x86_64.a 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..0da10c82b 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 = "5d4a457615cf19294dc077b1f7123c480ffdaa94" # Oct 19, 2021 +ENVOY_SHA = "f2b77817f724f351b24ad2c28dbfeda6eba86f6d344bdf7db11d87a9174cbf51" HDR_HISTOGRAM_C_VERSION = "0.11.2" # October 12th, 2020 HDR_HISTOGRAM_C_SHA = "637f28b5f64de2e268131e4e34e6eef0b91cf5ff99167db447d9b2825eae6bad" From 040083fb551e79d31f7e27fcc376d17ca7385a28 Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 03:05:24 -0400 Subject: [PATCH 2/5] update to new Envoy DNS resolver factory Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- include/nighthawk/client/BUILD | 1 - include/nighthawk/common/uri.h | 5 ++- source/client/BUILD | 1 - source/client/client.cc | 7 +++- source/client/process_bootstrap.cc | 21 ++++++---- source/client/process_bootstrap.h | 15 ++++++-- source/client/process_impl.cc | 38 +++++++++++------- source/client/process_impl.h | 18 ++++++++- source/client/service_impl.cc | 8 +++- source/common/uri_impl.cc | 10 ++--- source/common/uri_impl.h | 5 ++- source/common/utility.h | 2 +- test/BUILD | 1 + test/process_bootstrap_test.cc | 62 ++++++++++++++++++++++-------- test/process_test.cc | 14 +++++-- test/utility_test.cc | 17 ++++++-- 16 files changed, 160 insertions(+), 65 deletions(-) diff --git a/include/nighthawk/client/BUILD b/include/nighthawk/client/BUILD index 7ec0b6869..49dd108be 100644 --- a/include/nighthawk/client/BUILD +++ b/include/nighthawk/client/BUILD @@ -46,7 +46,6 @@ 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_api//envoy/api/v2:pkg_cc_proto", diff --git a/include/nighthawk/common/uri.h b/include/nighthawk/common/uri.h index 820b917ab..a153e2435 100644 --- a/include/nighthawk/common/uri.h +++ b/include/nighthawk/common/uri.h @@ -4,7 +4,7 @@ #include "nighthawk/common/exception.h" -#include "external/envoy/source/common/network/dns_impl.h" +#include "external/envoy/envoy/network/dns.h" #include "external/envoy/source/common/network/utility.h" #include "absl/strings/string_view.h" @@ -58,12 +58,13 @@ class Uri { /** * Synchronously resolves the parsed host from the uri to an ip-address. * @param dispatcher Dispatcher 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, + resolve(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::DnsResolver& dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) PURE; /** diff --git a/source/client/BUILD b/source/client/BUILD index 9d81e538a..bee064852 100644 --- a/source/client/BUILD +++ b/source/client/BUILD @@ -110,7 +110,6 @@ envoy_cc_library( "@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", diff --git a/source/client/client.cc b/source/client/client.cc index b6c4847ca..a02b38d76 100644 --- a/source/client/client.cc +++ b/source/client/client.cc @@ -72,8 +72,11 @@ 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::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *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 7ef789eff..58f1c224b 100644 --- a/source/client/process_bootstrap.cc +++ b/source/client/process_bootstrap.cc @@ -182,6 +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::DnsResolver& dns_resolver, std::vector* uris, UriPtr* request_source_uri) { try { @@ -196,12 +197,14 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch } } for (const UriPtr& uri : *uris) { - uri->resolve(dispatcher, 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, Utility::translateFamilyOptionString(options.addressFamily())); + ->resolve(dispatcher, dns_resolver, + Utility::translateFamilyOptionString(options.addressFamily())); } } catch (const UriException& ex) { return absl::InvalidArgumentError( @@ -214,13 +217,17 @@ absl::Status extractAndResolveUrisFromOptions(Envoy::Event::Dispatcher& dispatch } // namespace -absl::StatusOr createBootstrapConfiguration(Envoy::Event::Dispatcher& dispatcher, - 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, + 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); std::vector uris; UriPtr request_source_uri; - absl::Status uri_status = - extractAndResolveUrisFromOptions(dispatcher, 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 6a7554371..ff732a3a1 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,21 @@ 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, 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, + 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 26fe16112..040da23ae 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" @@ -160,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() @@ -181,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()) { @@ -191,13 +196,18 @@ 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, + std::move(typed_dns_resolver_config), + process_wide)); absl::StatusOr bootstrap = createBootstrapConfiguration( - *process->dispatcher_, 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(); @@ -429,6 +439,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) { @@ -459,19 +470,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::DnsResolverOptions dns_resolver_options; cluster_manager_factory_ = std::make_unique( - admin_, Envoy::Runtime::LoaderSingleton::get(), store_root_, tls_, - dispatcher_->createDnsResolver({}, dns_resolver_options), *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 @@ -575,10 +583,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_, + tracing_uri->resolve(*dispatcher_, *dns_resolver, Utility::translateFamilyOptionString(options_.addressFamily())); } } catch (const UriException& ex) { @@ -590,7 +600,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..669545b8e 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::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, 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/source/common/uri_impl.cc b/source/common/uri_impl.cc index 82960f823..fe52d8cfc 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,16 +63,15 @@ UriImpl::UriImpl(absl::string_view uri, absl::string_view default_scheme) } bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, + Envoy::Network::DnsResolver& dns_resolver, const Envoy::Network::DnsLookupFamily dns_lookup_family) { - envoy::config::core::v3::DnsResolverOptions dns_resolver_options; - auto dns_resolver = dispatcher.createDnsResolver({}, dns_resolver_options); std::string hostname = std::string(hostWithoutPort()); if (!hostname.empty() && hostname[0] == '[' && hostname[hostname.size() - 1] == ']') { 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,14 +92,14 @@ bool UriImpl::performDnsLookup(Envoy::Event::Dispatcher& dispatcher, } Envoy::Network::Address::InstanceConstSharedPtr -UriImpl::resolve(Envoy::Event::Dispatcher& dispatcher, +UriImpl::resolve(Envoy::Event::Dispatcher& dispatcher, Envoy::Network::DnsResolver& dns_resolver, 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, 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 2a9a0bb4a..cabfff860 100644 --- a/source/common/uri_impl.h +++ b/source/common/uri_impl.h @@ -7,8 +7,8 @@ #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/dns_impl.h" #include "external/envoy/source/common/network/utility.h" #include "absl/strings/string_view.h" @@ -24,7 +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) { @@ -138,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)); @@ -215,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)); @@ -303,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)); @@ -391,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)); @@ -521,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)); @@ -601,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)); @@ -692,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)); @@ -787,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)); @@ -897,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)); @@ -1093,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)); @@ -1206,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)); @@ -1285,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)); @@ -1384,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)); @@ -1474,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..08224915d 100644 --- a/test/process_test.cc +++ b/test/process_test.cc @@ -74,8 +74,11 @@ 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::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *options_, dns_resolver_factory, std::move(typed_dns_resolver_config), time_system_); if (!process_or_status.ok()) { return process_or_status.status(); } @@ -209,8 +212,11 @@ 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::DnsResolverFactory& dns_resolver_factory = + Envoy::Network::createDefaultDnsResolverFactory(typed_dns_resolver_config); + absl::StatusOr process_or_status = ProcessImpl::CreateProcessImpl( + *options_, dns_resolver_factory, std::move(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 e9f1a1d13..a8c1ed5a2 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, 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, address_family).get(), - u.resolve(*dispatcher, 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 8cb3871be2edaba97726a26c883db93569212056 Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 03:21:33 -0400 Subject: [PATCH 3/5] improve CreateProcessImpl comment Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- source/client/process_impl.h | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/source/client/process_impl.h b/source/client/process_impl.h index 1a9e14f43..df8e57c70 100644 --- a/source/client/process_impl.h +++ b/source/client/process_impl.h @@ -56,10 +56,10 @@ class ProcessImpl : public Process, public Envoy::Logger::Loggable Date: Tue, 19 Oct 2021 03:23:56 -0400 Subject: [PATCH 4/5] improve typed_dns_resolver_config_ comment Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- source/client/process_impl.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/source/client/process_impl.h b/source/client/process_impl.h index df8e57c70..3301e5906 100644 --- a/source/client/process_impl.h +++ b/source/client/process_impl.h @@ -191,8 +191,8 @@ class ProcessImpl : public Process, public Envoy::Logger::Loggable From c84ec355702e4f0898e054921c2eee3a8e6ae1e5 Mon Sep 17 00:00:00 2001 From: eric846 <56563761+eric846@users.noreply.github.com> Date: Tue, 19 Oct 2021 10:14:59 -0400 Subject: [PATCH 5/5] clang-tidy DnsResolverSharedPtr& Signed-off-by: eric846 <56563761+eric846@users.noreply.github.com> --- source/client/process_impl.cc | 2 +- source/client/process_impl.h | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/source/client/process_impl.cc b/source/client/process_impl.cc index 040da23ae..7bd8ab664 100644 --- a/source/client/process_impl.cc +++ b/source/client/process_impl.cc @@ -439,7 +439,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 Envoy::Network::DnsResolverSharedPtr& dns_resolver, const absl::optional& scheduled_start) { const Envoy::SystemTime now = time_system_.systemTime(); if (scheduled_start.value_or(now) < now) { diff --git a/source/client/process_impl.h b/source/client/process_impl.h index 3301e5906..849329e46 100644 --- a/source/client/process_impl.h +++ b/source/client/process_impl.h @@ -125,7 +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 Envoy::Network::DnsResolverSharedPtr& dns_resolver, const absl::optional& schedule); /**