From 07d250393d6ee736cd1e7bd656277013ffad3ead Mon Sep 17 00:00:00 2001
From: Georgy Moshkin <gmoshkin@picodata.io>
Date: Fri, 2 Feb 2024 20:39:35 +0300
Subject: [PATCH] fix: getting http & version info for webui

---
 src/http_server.lua | 17 ++++-------------
 src/info.rs         | 27 +++++++++++++++++++++++++++
 2 files changed, 31 insertions(+), 13 deletions(-)

diff --git a/src/http_server.lua b/src/http_server.lua
index bcae1ab76a..7f618f9b44 100644
--- a/src/http_server.lua
+++ b/src/http_server.lua
@@ -137,22 +137,13 @@ local function create_instance(instance, cluster_state)
     }
 
     local c = net.connect(instance_dto.binaryAddress, { fetch_schema = false })
-    local result = c:eval([[
-        return {
-            httpd = pico and pico.httpd and {
-                host = pico.httpd.host,
-                port = pico.httpd.port
-            },
-            version = pico.PICODATA_VERSION
-        }
-    ]])
+    local result = c:call('.proc_runtime_info')
 
     if result then
-        local httpAddress = result.httpd
-        if httpAddress then
-            instance_dto.httpAddress = string.format('%s:%d', httpAddress.host, httpAddress.port)
+        if result.http then
+            instance_dto.httpAddress = string.format('%s:%d', result.http.host, result.http.port)
         end
-        instance_dto.version = result.version
+        instance_dto.version = result.version_info.picodata_version
     end
 
     return instance_dto
diff --git a/src/info.rs b/src/info.rs
index 27c89fdf53..0de0ee4368 100644
--- a/src/info.rs
+++ b/src/info.rs
@@ -208,6 +208,14 @@ impl InternalInfo<'static> {
 // RuntimeInfo
 ////////////////////////////////////////////////////////////////////////////////
 
+#[derive(Clone, Debug, ::serde::Serialize, ::serde::Deserialize)]
+pub struct HttpServerInfo {
+    pub host: String,
+    pub port: u16,
+}
+
+impl tarantool::tuple::Encode for HttpServerInfo {}
+
 /// Info returned from [`.proc_runtime_info`].
 ///
 /// [`.proc_runtime_info`]: proc_runtime_info
@@ -215,15 +223,34 @@ impl InternalInfo<'static> {
 pub struct RuntimeInfo<'a> {
     pub raft: RaftInfo,
     pub internal: InternalInfo<'a>,
+    #[serde(skip_serializing_if = "Option::is_none")]
+    pub http: Option<HttpServerInfo>,
+    pub version_info: VersionInfo<'a>,
 }
 
 impl tarantool::tuple::Encode for RuntimeInfo<'_> {}
 
 impl RuntimeInfo<'static> {
     pub fn try_get(node: &node::Node) -> Result<Self, Error> {
+        let lua = tarantool::lua_state();
+        let host_port: Option<(String, String)> = lua.eval(
+            "if pico.httpd ~= nil then
+                return pico.httpd.host, pico.httpd.port
+            else
+                return nil
+            end",
+        )?;
+        let mut http = None;
+        if let Some((host, port)) = host_port {
+            let port = port.parse::<u16>().map_err(Error::other)?;
+            http = Some(HttpServerInfo { host, port });
+        }
+
         Ok(RuntimeInfo {
             raft: RaftInfo::get(node),
             internal: InternalInfo::get(node),
+            http,
+            version_info: VersionInfo::current(),
         })
     }
 }
-- 
GitLab