You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ja...@apache.org on 2024/12/05 04:39:35 UTC

(couchdb) 01/01: Expose Clouseau version in `/_node` endpoint

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

jaydoane pushed a commit to branch expose-search-version
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit bdee411114c3c1a16bdb29531e11fe8c4f22364f
Author: Jay Doane <ja...@apache.org>
AuthorDate: Wed Dec 4 20:39:06 2024 -0800

    Expose Clouseau version in `/_node` endpoint
    
    When a running Clouseau node is detected, expose a top level `search`
    field containing the version and search engine name in the
    `/_node/{node_name|/_versions` endpoint.
    
    Note that Clouseau version < 3.0 only returns a non-`null` value when
    run from a `.jar` file, as is typically done in a development
    environment, so approximate the version as `2.x-dev` in that case.
---
 src/chttpd/src/chttpd_node.erl | 24 ++++++++++++++++++++++--
 1 file changed, 22 insertions(+), 2 deletions(-)

diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index 859d96bd6..dbe29a28e 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -62,7 +62,25 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_versions">>]}
             _Other ->
                 #{name => EngineName}
         end,
-    send_json(Req, 200, #{
+    ClouseauVer =
+        case clouseau_rpc:version() of
+            {ok, null} -> <<"2.x-dev">>;
+            {ok, V} -> V;
+            _ -> undefined
+        end,
+    SearchResponse =
+        case ClouseauVer of
+            undefined ->
+                #{};
+            Version ->
+                #{
+                    search => #{
+                        name => clouseau,
+                        version => Version
+                    }
+                }
+        end,
+    BaseResponse = #{
         erlang => #{
             version => ?l2b(?COUCHDB_ERLANG_VERSION),
             supported_hashes => Hashes
@@ -74,7 +92,9 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, _Node, <<"_versions">>]}
             collator_version => couch_util:version_to_binary(ColVer)
         },
         javascript_engine => JsEngine
-    });
+    },
+    Response = maps:merge(BaseResponse, SearchResponse),
+    send_json(Req, 200, Response);
 handle_node_req(#httpd{path_parts = [_, _Node, <<"_versions">>]} = Req) ->
     send_method_not_allowed(Req, "GET");
 % GET /_node/$node/_config