From 794f3c42bdd8af672082cfb76eafd9cc0e27ab74 Mon Sep 17 00:00:00 2001 From: Dan Manjarres Date: Mon, 24 Jul 2023 10:51:04 -0700 Subject: [PATCH] ALlow overriding hostname for node manager. --- distbench_busybox.cc | 4 ++++ distbench_node_manager.cc | 11 +++++++---- distbench_node_manager.h | 4 ++++ distbench_test_sequencer_tester.cc | 1 + 4 files changed, 16 insertions(+), 4 deletions(-) diff --git a/distbench_busybox.cc b/distbench_busybox.cc index 8d6a35ca..a1310003 100644 --- a/distbench_busybox.cc +++ b/distbench_busybox.cc @@ -57,6 +57,8 @@ ABSL_FLAG(std::string, service_address, "", "Incoming RPC address for the node_manager to report to the " "test_sequencer. Useful if DNS cannot resolve the hostname. " "Must include gRPC protocol host and port e.g. ipv4:///1.2.3.4:5678"); +ABSL_FLAG(std::string, service_hostname, "", + "Hostname for the node_manager to use. Useful for multi-homed hosts"); int main(int argc, char** argv, char** envp) { std::vector remaining_arguments = absl::ParseCommandLine(argc, argv); @@ -348,6 +350,7 @@ int MainTestSequencer(std::vector& arguments) { absl::GetFlag(FLAGS_default_data_plane_device), .control_plane_device = absl::GetFlag(FLAGS_control_plane_device), .port = &new_port, + .service_hostname = absl::GetFlag(FLAGS_service_hostname), }; nodes.push_back(std::make_unique()); absl::Status status = nodes.back()->Initialize(opts); @@ -413,6 +416,7 @@ int MainNodeManager(std::vector& arguments) { .port = &port, .attributes = attributes, .service_address = absl::GetFlag(FLAGS_service_address), + .service_hostname = absl::GetFlag(FLAGS_service_hostname), }; distbench::NodeManager node_manager; absl::Status status = node_manager.Initialize(opts); diff --git a/distbench_node_manager.cc b/distbench_node_manager.cc index 0bfcf54e..577b45b0 100644 --- a/distbench_node_manager.cc +++ b/distbench_node_manager.cc @@ -83,7 +83,7 @@ grpc::Status NodeManager::ConfigureNode(grpc::ServerContext* context, } auto& service_entry = service_map[service_name]; service_entry.set_endpoint_address(maybe_address.value()); - service_entry.set_hostname(Hostname()); + service_entry.set_hostname(opts_.service_hostname); *service_entry.mutable_attributes() = registration_info_.attributes(); int dimensions = std::count(service_name.begin(), service_name.end(), '/'); Attribute* attribute; @@ -277,6 +277,9 @@ NodeManager::~NodeManager() { absl::Status NodeManager::Initialize(const NodeManagerOpts& opts) { opts_ = opts; + if (opts_.service_hostname.empty()) { + opts_.service_hostname = Hostname(); + } if (opts_.test_sequencer_service_address.empty()) { Shutdown(); return absl::InvalidArgumentError( @@ -312,7 +315,7 @@ absl::Status NodeManager::Initialize(const NodeManagerOpts& opts) { if (opts_.service_address.empty()) { if (!registration_info_.has_control_ip()) { opts_.service_address = - absl::StrCat("dns:///", Hostname(), ":", *opts_.port); + absl::StrCat("dns:///", opts_.service_hostname, ":", *opts_.port); } else if (listening_address[0] == '[') { opts_.service_address = absl::StrCat("ipv6:///", listening_address); @@ -327,10 +330,10 @@ absl::Status NodeManager::Initialize(const NodeManagerOpts& opts) { return absl::UnknownError("NodeManager service failed to start"); } LOG(INFO) << "NodeManager server listening on " << opts_.service_address - << " on " << Hostname(); + << " on " << opts_.service_hostname; registration_info_.set_preassigned_node_id(opts_.preassigned_node_id); - registration_info_.set_hostname(Hostname()); + registration_info_.set_hostname(opts_.service_hostname); registration_info_.set_control_port(*opts_.port); for (const auto& attr : opts_.attributes) { auto new_attr = registration_info_.add_attributes(); diff --git a/distbench_node_manager.h b/distbench_node_manager.h index ce888b8d..0ac49802 100644 --- a/distbench_node_manager.h +++ b/distbench_node_manager.h @@ -34,6 +34,10 @@ struct NodeManagerOpts { // resolve the hostname). This is passed to gRPC unmodified, so it must be // a valid "target" (I.e. it must include a protocol, host and port). std::string service_address; + + // If the hostname reported by gethostname is unresolvable this will override + // it for node manager registrations: + std::string service_hostname; }; class NodeManager final : public DistBenchNodeManager::Service { diff --git a/distbench_test_sequencer_tester.cc b/distbench_test_sequencer_tester.cc index 607eaa32..3daaa0b6 100644 --- a/distbench_test_sequencer_tester.cc +++ b/distbench_test_sequencer_tester.cc @@ -67,6 +67,7 @@ absl::Status DistBenchTester::Resize(size_t num_nodes) { nm_opts.port = &port; nm_opts.test_sequencer_service_address = test_sequencer->service_address(); nm_opts.control_plane_device = "lo"; + nm_opts.service_hostname = "localhost"; nodes[i] = std::make_unique(); auto ret = nodes[i]->Initialize(nm_opts); if (!ret.ok()) return ret;