This is an automated email from the ASF dual-hosted git repository.

alexey pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/kudu.git

commit 7be030baee38ea971f5e3afddcff4c61cbe2acf3
Author: Attila Bukor <[email protected]>
AuthorDate: Thu Oct 26 15:35:15 2023 +0200

    KUDU-3519: List masters in /dump-entities
    
    Tablet servers are already listed on the /dump-entities master endpoint,
    but the masters are missing. To allow easily accessing master addresses
    and UUIDs in a parsable format, this commit adds the master info as
    well.
    
    Change-Id: I92ab8057c5bdae6e8b41afc8f19c0a72cfa329a2
    Reviewed-on: http://gerrit.cloudera.org:8080/20628
    Reviewed-by: Marton Greber <[email protected]>
    Tested-by: Kudu Jenkins
    Reviewed-by: Wang Xixu <[email protected]>
    Reviewed-by: Abhishek Chennaka <[email protected]>
---
 src/kudu/master/master-test.cc          | 28 +++++++++++++++----
 src/kudu/master/master_path_handlers.cc | 49 ++++++++++++++++++++++++++++++++-
 2 files changed, 71 insertions(+), 6 deletions(-)

diff --git a/src/kudu/master/master-test.cc b/src/kudu/master/master-test.cc
index 1b080a0bc..2554f3903 100644
--- a/src/kudu/master/master-test.cc
+++ b/src/kudu/master/master-test.cc
@@ -641,14 +641,13 @@ TEST_F(MasterTest, TestRegisterAndHeartbeat) {
     ASSERT_EQ(tablet_servers.Size(), 1);
     const rapidjson::Value& tablet_server = 
tablet_servers[rapidjson::SizeType(0)];
     ASSERT_STREQ("localhost:1000",
-        tablet_server["rpc_addrs"][rapidjson::SizeType(0)].GetString());
+                 
tablet_server["rpc_addrs"][rapidjson::SizeType(0)].GetString());
     ASSERT_STREQ("http://localhost:2000";,
-        tablet_server["http_addrs"][rapidjson::SizeType(0)].GetString());
+                 
tablet_server["http_addrs"][rapidjson::SizeType(0)].GetString());
     ASSERT_STREQ("my-ts-uuid", tablet_server["uuid"].GetString());
     ASSERT_TRUE(tablet_server["millis_since_heartbeat"].GetInt64() >= 0);
-    ASSERT_EQ(true, tablet_server["live"].GetBool());
-    ASSERT_STREQ(VersionInfo::GetVersionInfo().c_str(),
-        tablet_server["version"].GetString());
+    ASSERT_TRUE(tablet_server["live"].GetBool());
+    ASSERT_EQ(VersionInfo::GetVersionInfo(), 
tablet_server["version"].GetString());
     string start_time;
     StringAppendStrftime(&start_time, "%Y-%m-%d %H:%M:%S %Z", 
static_cast<time_t>(10000), true);
     ASSERT_STREQ(start_time.c_str(), tablet_server["start_time"].GetString());
@@ -3780,5 +3779,24 @@ TEST_F(MasterTest, GetTableStatesWithId) {
   }
 }
 
+TEST_F(MasterTest, TestMastersListedInDumpEndpoints) {
+  EasyCurl c;
+  faststring buf;
+  string addr = Substitute("http://$0";, 
mini_master_->bound_http_addr().ToString());
+  ASSERT_OK(c.FetchURL(Substitute("$0/dump-entities", addr), &buf));
+  rapidjson::Document doc;
+  doc.Parse<0>(buf.ToString().c_str());
+  const rapidjson::Value& masters = doc["masters"];
+  ASSERT_EQ(1, masters.Size());
+  const rapidjson::Value& master = masters[rapidjson::SizeType(0)];
+  ASSERT_EQ(mini_master_->bound_rpc_addr().ToString(),
+            master["rpc_addrs"][rapidjson::SizeType(0)].GetString());
+  ASSERT_EQ(addr, master["http_addrs"][rapidjson::SizeType(0)].GetString());
+  ASSERT_EQ(mini_master_->permanent_uuid(), master["uuid"].GetString());
+  ASSERT_EQ(VersionInfo::GetVersionInfo(), master["version"].GetString());
+  ASSERT_STREQ("LEADER", master["role"].GetString());
+  ASSERT_NE("", master["start_time"].GetString());
+}
+
 } // namespace master
 } // namespace kudu
diff --git a/src/kudu/master/master_path_handlers.cc 
b/src/kudu/master/master_path_handlers.cc
index 3bc817aef..f7ba11eec 100644
--- a/src/kudu/master/master_path_handlers.cc
+++ b/src/kudu/master/master_path_handlers.cc
@@ -747,7 +747,9 @@ void MasterPathHandlers::HandleDumpEntities(const 
Webserver::WebRequest& /*req*/
                                             Webserver::PrerenderedWebResponse* 
resp) {
   ostringstream* output = &resp->output;
   if (!master_->catalog_manager()->IsInitialized()) {
-    JsonError(Status::ServiceUnavailable("CatalogManager is not running"), 
output);
+    Status s = Status::ServiceUnavailable("CatalogManager is not running");
+    JsonError(s, output);
+    LOG(WARNING) << s.ToString();
     return;
   }
 
@@ -761,6 +763,7 @@ void MasterPathHandlers::HandleDumpEntities(const 
Webserver::WebRequest& /*req*/
   auto s = master_->catalog_manager()->sys_catalog()->VisitTables(&d);
   if (!s.ok()) {
     JsonError(s, output);
+    LOG(WARNING) << s.ToString();
     return;
   }
   jw.EndArray();
@@ -770,8 +773,52 @@ void MasterPathHandlers::HandleDumpEntities(const 
Webserver::WebRequest& /*req*/
   s = master_->catalog_manager()->sys_catalog()->VisitTablets(&d);
   if (!s.ok()) {
     JsonError(s, output);
+    LOG(WARNING) << s.ToString();
+    return;
+  }
+  jw.EndArray();
+
+  jw.String("masters");
+  jw.StartArray();
+  vector<ServerEntryPB> masters;
+  s = master_->ListMasters(&masters, /*use_external_addr=*/false);
+  if (!s.ok()) {
+    JsonError(s, output);
+    LOG(WARNING) << s.ToString();
     return;
   }
+
+  for (const auto& master : masters) {
+    jw.StartObject();
+    jw.String("uuid");
+    jw.String(master.instance_id().permanent_uuid());
+
+    jw.String("rpc_addrs");
+    jw.StartArray();
+    for (const HostPortPB& host_port : master.registration().rpc_addresses()) {
+      jw.String(Substitute("$0:$1", host_port.host(), host_port.port()));
+    }
+    jw.EndArray();
+
+    jw.String("http_addrs");
+    jw.StartArray();
+    for (const HostPortPB& host_port : master.registration().http_addresses()) 
{
+      jw.String(Substitute("$0://$1:$2", master.registration().https_enabled() 
? "https" : "http",
+                                         host_port.host(), host_port.port()));
+    }
+    jw.EndArray();
+
+    jw.String("role");
+    jw.String(RaftPeerPB_Role_Name(master.role()));
+
+    jw.String("version");
+    jw.String(master.registration().software_version());
+
+    jw.String("start_time");
+    jw.String(StartTimeToString(master.registration()));
+
+    jw.EndObject();
+  }
   jw.EndArray();
 
   jw.String("tablet_servers");

Reply via email to