You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ji...@apache.org on 2025/01/23 15:55:40 UTC

(couchdb) branch extract-versions-response created (now c42e1eb9d)

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

jiahuili430 pushed a change to branch extract-versions-response
in repository https://gitbox.apache.org/repos/asf/couchdb.git


      at c42e1eb9d Extract the response of the "_versions" endpoint

This branch includes the following new commits:

     new c42e1eb9d Extract the response of the "_versions" endpoint

The 1 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails.  The revisions
listed as "add" were already present in the repository and have only
been added to this reference.



(couchdb) 01/01: Extract the response of the "_versions" endpoint

Posted by ji...@apache.org.
This is an automated email from the ASF dual-hosted git repository.

jiahuili430 pushed a commit to branch extract-versions-response
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit c42e1eb9df4e2e63cc9789e1db86b5f8ddc03222
Author: Jiahui Li <li...@gmail.com>
AuthorDate: Thu Jan 23 09:54:25 2025 -0600

    Extract the response of the "_versions" endpoint
---
 src/chttpd/src/chttpd_node.erl | 89 ++++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 42 deletions(-)

diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 2a8bc6cea..2a67da9e3 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -16,6 +16,7 @@
 -export([
     handle_node_req/1,
     get_stats/0,
+    get_versions/0,
     run_queues/0,
     message_queues/0,
     db_pid_stats/0
@@ -46,48 +47,10 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_smoosh">>, <<
 handle_node_req(#httpd{path_parts = [_, _Node, <<"_smoosh">>, <<"status">>]} = Req) ->
     send_method_not_allowed(Req, "GET");
 % GET /_node/$node/_versions
-handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_versions">>]} = Req) ->
-    IcuVer = couch_ejson_compare:get_icu_version(),
-    UcaVer = couch_ejson_compare:get_uca_version(),
-    ColVer = couch_ejson_compare:get_collator_version(),
-    Hashes = crypto:supports(hashs),
-    EngineName = couch_server:get_js_engine(),
-    JsEngine =
-        case EngineName of
-            <<"spidermonkey">> ->
-                #{
-                    name => EngineName,
-                    version => couch_server:get_spidermonkey_version()
-                };
-            _Other ->
-                #{name => EngineName}
-        end,
-    ClouseauResponse =
-        case clouseau_rpc:version() of
-            {ok, Version} ->
-                #{
-                    clouseau => #{
-                        version => Version
-                    }
-                };
-            _ ->
-                #{}
-        end,
-    BaseResponse = #{
-        erlang => #{
-            version => ?l2b(?COUCHDB_ERLANG_VERSION),
-            supported_hashes => Hashes
-        },
-        collation_driver => #{
-            name => <<"libicu">>,
-            library_version => couch_util:version_to_binary(IcuVer),
-            collation_algorithm_version => couch_util:version_to_binary(UcaVer),
-            collator_version => couch_util:version_to_binary(ColVer)
-        },
-        javascript_engine => JsEngine
-    },
-    Response = maps:merge(BaseResponse, ClouseauResponse),
-    send_json(Req, 200, Response);
+handle_node_req(#httpd{method = 'GET', path_parts = [_, Node, <<"_versions">>]} = Req) ->
+    Versions = call_node(Node, chttpd_node, get_versions, []),
+    EJSON = couch_stats_httpd:to_ejson(Versions),
+    send_json(Req, EJSON);
 handle_node_req(#httpd{path_parts = [_, _Node, <<"_versions">>]} = Req) ->
     send_method_not_allowed(Req, "GET");
 % GET /_node/$node/_config
@@ -339,6 +302,48 @@ get_stats() ->
         {distribution_events, mem3_distribution:events()}
     ].
 
+get_versions() ->
+    IcuVer = couch_ejson_compare:get_icu_version(),
+    UcaVer = couch_ejson_compare:get_uca_version(),
+    ColVer = couch_ejson_compare:get_collator_version(),
+    Hashes = crypto:supports(hashs),
+    EngineName = couch_server:get_js_engine(),
+    JsEngine =
+        case EngineName of
+            <<"spidermonkey">> ->
+                #{
+                    name => EngineName,
+                    version => couch_server:get_spidermonkey_version()
+                };
+            _Other ->
+                #{name => EngineName}
+        end,
+    ClouseauResponse =
+        case clouseau_rpc:version() of
+            {ok, Version} when is_binary(Version) ->
+                #{
+                    clouseau => #{
+                        version => Version
+                    }
+                };
+            _ ->
+                #{}
+        end,
+    BaseResponse = #{
+        erlang => #{
+            version => ?l2b(?COUCHDB_ERLANG_VERSION),
+            supported_hashes => Hashes
+        },
+        collation_driver => #{
+            name => <<"libicu">>,
+            library_version => couch_util:version_to_binary(IcuVer),
+            collation_algorithm_version => couch_util:version_to_binary(UcaVer),
+            collator_version => couch_util:version_to_binary(ColVer)
+        },
+        javascript_engine => JsEngine
+    },
+    maps:merge(BaseResponse, ClouseauResponse).
+
 db_pid_stats_formatted() ->
     {CF, CDU} = db_pid_stats(),
     {format_pid_stats(CF), format_pid_stats(CDU)}.