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

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

commit cc4d0a58ead986dbbc8db7c95e52399f34bd9072
Author: Yida Wu <[email protected]>
AuthorDate: Thu Apr 11 22:59:24 2024 -0700

    IMPALA-12874: Identify active and standby catalog and statestore in the web 
debug endpoint
    
    This patch adds support to display the HA status of catalog and
    statestore on the root web page. The status will be presented
    as "Catalog Status: Active" or "Statestore Status: Standby"
    based on the values retrieved from the metrics
    catalogd-server.active-status and statestore.active-status.
    
    If the catalog or statestore is standalone, it will show active as
    the status, which is same as the metric.
    
    Tests:
    Ran core tests.
    Manually tests the web page, and verified the status display is
    correct. Also checked the situation when the failover happens,
    the current 'standby' status can be changed to 'active'.
    
    Change-Id: Ie9435ba7a9549ea56f9d080a9315aecbcc630cd2
    Reviewed-on: http://gerrit.cloudera.org:8080/21294
    Reviewed-by: Impala Public Jenkins <[email protected]>
    Tested-by: Impala Public Jenkins <[email protected]>
---
 be/src/common/daemon-env.h           |  1 +
 be/src/util/default-path-handlers.cc | 65 ++++++++++++++++++++++++++++++++----
 be/src/util/default-path-handlers.h  |  3 +-
 www/root.tmpl                        |  8 +++++
 4 files changed, 69 insertions(+), 8 deletions(-)

diff --git a/be/src/common/daemon-env.h b/be/src/common/daemon-env.h
index efb5140b5..542772e8e 100644
--- a/be/src/common/daemon-env.h
+++ b/be/src/common/daemon-env.h
@@ -46,6 +46,7 @@ class DaemonEnv {
   MetricGroup* metrics() { return metrics_.get(); }
   Webserver* webserver() { return webserver_.get(); }
   Webserver* metrics_webserver() { return metrics_webserver_.get(); }
+  std::string name() { return name_; }
 
  private:
   static DaemonEnv* daemon_env_;
diff --git a/be/src/util/default-path-handlers.cc 
b/be/src/util/default-path-handlers.cc
index 6ee358cc3..f5429cc87 100644
--- a/be/src/util/default-path-handlers.cc
+++ b/be/src/util/default-path-handlers.cc
@@ -17,14 +17,15 @@
 
 #include "util/default-path-handlers.h"
 
-#include <sstream>
 #include <fstream>
-#include <sys/stat.h>
+#include <sstream>
 #include <boost/algorithm/string.hpp>
 #include <boost/bind.hpp>
 #include <gutil/strings/substitute.h>
 #include <gnu/libc-version.h>
+#include <sys/stat.h>
 
+#include "common/daemon-env.h"
 #include "common/logging.h"
 #include "kudu/util/flags.h"
 #include "rpc/jni-thrift-util.h"
@@ -220,7 +221,56 @@ void AddBuildFlag(const std::string& flag_name, const 
std::string& flag_value,
 
 namespace impala {
 
-void RootHandler(const Webserver::WebRequest& req, Document* document) {
+// Add active or standby status for catalog or statestore.
+void AddActiveStatus(Document* document, MetricGroup* metric_group) {
+  DaemonEnv* d_env = DaemonEnv::GetInstance();
+  bool is_statestore = false;
+  bool is_catalog = false;
+  if (d_env != nullptr) {
+    if (d_env->name() == "statestore") {
+      is_statestore = true;
+    } else if (d_env->name() == "catalog") {
+      is_catalog = true;
+    } else {
+      // Only deal with the status of catalog or statestore.
+      return;
+    }
+    document->AddMember("is_statestore", is_statestore, 
document->GetAllocator());
+    document->AddMember("is_catalog", is_catalog, document->GetAllocator());
+  }
+
+  if (metric_group != nullptr) {
+    if (is_catalog) {
+      BooleanProperty* metric = 
metric_group->FindMetricForTesting<BooleanProperty>(
+          "catalog-server.active-status");
+      if (metric != nullptr) {
+        if (metric->GetValue()) {
+          document->AddMember(
+              "catalogd_active_status", "Active", document->GetAllocator());
+        } else {
+          document->AddMember(
+              "catalogd_active_status", "Standby", document->GetAllocator());
+        }
+      }
+    }
+    if (is_statestore) {
+      BooleanProperty* metric =
+          
metric_group->FindMetricForTesting<BooleanProperty>("statestore.active-status");
+      if (metric != nullptr) {
+        if (metric->GetValue()) {
+          document->AddMember(
+              "statestore_active_status", "Active", document->GetAllocator());
+        } else {
+          document->AddMember(
+              "statestore_active_status", "Standby", document->GetAllocator());
+        }
+      }
+    }
+  }
+}
+
+void RootHandler(
+    const Webserver::WebRequest& req, Document* document, MetricGroup* 
metric_group) {
   Value version(GetVersionString().c_str(), document->GetAllocator());
   document->AddMember("version", version, document->GetAllocator());
 
@@ -264,6 +314,8 @@ void RootHandler(const Webserver::WebRequest& req, 
Document* document) {
         "process_start_time", process_start_time, document->GetAllocator());
   }
 
+  AddActiveStatus(document, metric_group);
+
   ExecEnv* env = ExecEnv::GetInstance();
   if (env == nullptr || env->impala_server() == nullptr) return;
   ImpalaServer* impala_server = env->impala_server();
@@ -307,10 +359,9 @@ void AddDefaultUrlCallbacks(Webserver* webserver, 
MetricGroup* metric_group,
   }
 #endif
 
-  auto root_handler =
-    [](const Webserver::WebRequest& req, Document* doc) {
-      RootHandler(req, doc);
-    };
+  auto root_handler = [metric_group](const Webserver::WebRequest& req, 
Document* doc) {
+    RootHandler(req, doc, metric_group);
+  };
   webserver->RegisterUrlCallback("/", "root.tmpl", root_handler, true);
 }
 
diff --git a/be/src/util/default-path-handlers.h 
b/be/src/util/default-path-handlers.h
index 2483319b2..c0d9b1d17 100644
--- a/be/src/util/default-path-handlers.h
+++ b/be/src/util/default-path-handlers.h
@@ -36,7 +36,8 @@ void AddDefaultUrlCallbacks(Webserver* webserver, 
MetricGroup* metric_group = NU
 
 /// Registered to handle "/"
 /// Populates document with various system-wide information.
-void RootHandler(const Webserver::WebRequest& req, rapidjson::Document* 
document);
+void RootHandler(const Webserver::WebRequest& req, rapidjson::Document* 
document,
+    MetricGroup* metric_group);
 }
 
 #endif // IMPALA_UTIL_DEFAULT_PATH_HANDLERS_H
diff --git a/www/root.tmpl b/www/root.tmpl
index da779917d..cf073ee8e 100644
--- a/www/root.tmpl
+++ b/www/root.tmpl
@@ -32,6 +32,14 @@ under the License.
     {{?is_executor}}Executor{{/is_executor}}</h2>
   {{/impala_server_mode}}
 
+  {{?catalogd_active_status}}
+  <h2> Catalog Status: {{catalogd_active_status}} </h2>
+  {{/catalogd_active_status}}
+
+  {{?statestore_active_status}}
+  <h2> Statestore Status: {{statestore_active_status}} </h2>
+  {{/statestore_active_status}}
+
   <h2>Vers<span id="v">i</span>on</h2>
   <pre id="version_pre">{{version}}
 Build Flags: {{#build_flags}}{{flag_name}}={{flag_value}}  
{{/build_flags}}</pre>

Reply via email to