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


The following commit(s) were added to refs/heads/master by this push:
     new 05ae60a  [web-server] add http api, get version info
05ae60a is described below

commit 05ae60adc6d16e8d63a41ec62bd8edaf5f5967c5
Author: shenxingwuying <[email protected]>
AuthorDate: Sat Jul 31 11:52:03 2021 +0800

    [web-server] add http api, get version info
    
    Applications may need some kudu function, that just support from some 
version.
    So it need a method to check when installing or upgrading.
    Of course, footer or `kudu --version` has included the infomation,
    but it's not convenience for users. The commit is a syntax sugar.
    
    You can use it by `curl http://x.x.x.x:8050/version` will directly
    return json info including the version info, that's convenience.
    
    Change-Id: Ic25b08b3d3f9bb74e2a877c733ffcaf45f5ece46
    Reviewed-on: http://gerrit.cloudera.org:8080/17745
    Tested-by: Kudu Jenkins
    Reviewed-by: Yingchun Lai <[email protected]>
    Reviewed-by: Andrew Wong <[email protected]>
---
 src/kudu/server/default_path_handlers.cc | 21 +++++++++++++++++++++
 src/kudu/server/webserver-test.cc        |  4 ++++
 2 files changed, 25 insertions(+)

diff --git a/src/kudu/server/default_path_handlers.cc 
b/src/kudu/server/default_path_handlers.cc
index b167017..0da303f 100644
--- a/src/kudu/server/default_path_handlers.cc
+++ b/src/kudu/server/default_path_handlers.cc
@@ -30,6 +30,8 @@
 
 #include <gflags/gflags.h>
 #include <glog/logging.h>
+#include "kudu/util/version_info.h"
+#include "kudu/util/version_info.pb.h"
 
 #ifdef TCMALLOC_ENABLED
 #include <boost/algorithm/string/replace.hpp>
@@ -210,6 +212,22 @@ static void StacksHandler(const Webserver::WebRequest& 
/*req*/,
     });
 }
 
+// Registered to handle "/version"
+//
+// Prints out the current version info
+static void VersionInfoHandler(const Webserver::WebRequest& /*req*/,
+                               Webserver::PrerenderedWebResponse* resp) {
+  JsonWriter writer(&resp->output, JsonWriter::PRETTY);
+  writer.StartObject();
+  writer.String("version_info");
+
+  kudu::VersionInfoPB version_info;
+  VersionInfo::GetVersionInfoPB(&version_info);
+
+  writer.Protobuf(version_info);
+  writer.EndObject();
+}
+
 // Registered to handle "/memz", and prints out memory allocation statistics.
 static void MemUsageHandler(const Webserver::WebRequest& req,
                             Webserver::PrerenderedWebResponse* resp) {
@@ -422,6 +440,9 @@ void AddDefaultPathHandlers(Webserver* webserver) {
   webserver->RegisterPrerenderedPathHandler("/stacks", "Stacks", StacksHandler,
                                             /*is_styled=*/false,
                                             /*is_on_nav_bar=*/true);
+  webserver->RegisterPrerenderedPathHandler("/version", "VersionInfo", 
VersionInfoHandler,
+                                            /*is_styled=*/false,
+                                            /*is_on_nav_bar*/false);
   AddPprofPathHandlers(webserver);
 }
 
diff --git a/src/kudu/server/webserver-test.cc 
b/src/kudu/server/webserver-test.cc
index 3b4c724..27847a7 100644
--- a/src/kudu/server/webserver-test.cc
+++ b/src/kudu/server/webserver-test.cc
@@ -427,6 +427,10 @@ TEST_F(WebserverTest, TestDefaultPaths) {
   // Test varz -- check for one of the built-in gflags flags.
   ASSERT_OK(curl_.FetchURL(Substitute("$0/varz?raw=1", url_), &buf_));
   ASSERT_STR_CONTAINS(buf_.ToString(), "--v=");
+
+  // Test version -- check for version information
+  ASSERT_OK(curl_.FetchURL(Substitute("$0/version", url_), &buf_));
+  ASSERT_STR_CONTAINS(buf_.ToString(), "version_info");
 }
 
 TEST_F(WebserverTest, TestRedactFlagsDump) {

Reply via email to