summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJan Lehnardt <jan@apache.org>2021-03-14 19:54:04 +0100
committerJan Lehnardt <jan@apache.org>2021-07-13 10:12:40 +0200
commitc42d5b93cadd64e11170d89b06f7f60ad6c765a9 (patch)
tree061949bf096a2178ab9933d11059b0b4fa4ceb45
parent95d49bc6846280b312944ec6c0da94cccf5e9fff (diff)
downloadcouchdb-c42d5b93cadd64e11170d89b06f7f60ad6c765a9.tar.gz
feat: show erlang and spidermonkey version in /_node/_local/_versions
The endpoint is admin-only. Closes #3298
-rw-r--r--rebar.config.script3
-rw-r--r--src/chttpd/src/chttpd_node.erl12
-rw-r--r--src/couch/rebar.config.script1
-rw-r--r--src/couch/src/couch_server.erl4
4 files changed, 17 insertions, 3 deletions
diff --git a/rebar.config.script b/rebar.config.script
index 8267fc13e..e3743ad9d 100644
--- a/rebar.config.script
+++ b/rebar.config.script
@@ -27,7 +27,6 @@ end.
VerList = lists:map(fun(X) -> {Int, _} = string:to_integer(X), Int end,
string:tokens(VerString, ".")).
-
DisplayMsg = fun(Msg, Args) ->
Base = iolist_to_binary(io_lib:format(Msg, Args)),
Lines = binary:split(Base, <<"\n">>, [global]),
@@ -202,7 +201,7 @@ AddConfig = [
{deps, lists:map(MakeDep, DepDescs ++ OptionalDeps)},
{sub_dirs, SubDirs},
{lib_dirs, ["src"]},
- {erl_opts, [{i, "../"}] ++ ErlOpts},
+ {erl_opts, [{i, "../"}] ++ [{d, 'COUCHDB_ERLANG_VERSION', VerString}] ++ ErlOpts},
{eunit_opts, [verbose, {report,{eunit_surefire,[{dir,"."}]}}]},
{plugins, [eunit_plugin]},
{dialyzer, [
diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl
index d3d3ff7f8..feabcb9c2 100644
--- a/src/chttpd/src/chttpd_node.erl
+++ b/src/chttpd/src/chttpd_node.erl
@@ -31,6 +31,18 @@ handle_node_req(#httpd{path_parts=[_, <<"_local">>]}=Req) ->
send_json(Req, 200, {[{name, node()}]});
handle_node_req(#httpd{path_parts=[A, <<"_local">>|Rest]}=Req) ->
handle_node_req(Req#httpd{path_parts=[A, node()] ++ Rest});
+% GET /_node/$node/_versions
+handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_versions">>]}=Req) ->
+ send_json(Req, 200, {[
+ {erlang_version, ?l2b(?COUCHDB_ERLANG_VERSION)},
+ {javascript_engine, {[
+ {name, <<"spidermonkey">>},
+ {version, couch_server:get_spidermonkey_version()}
+ ]}}
+ ]});
+handle_node_req(#httpd{path_parts=[_, _Node, <<"_versions">>]}=Req) ->
+ send_method_not_allowed(Req, "GET");
+
% GET /_node/$node/_config
handle_node_req(#httpd{method='GET', path_parts=[_, Node, <<"_config">>]}=Req) ->
Grouped = lists:foldl(fun({{Section, Key}, Value}, Acc) ->
diff --git a/src/couch/rebar.config.script b/src/couch/rebar.config.script
index a6d700518..b03d70d5c 100644
--- a/src/couch/rebar.config.script
+++ b/src/couch/rebar.config.script
@@ -228,6 +228,7 @@ AddConfig = [
{erl_opts, PlatformDefines ++ [
{d, 'COUCHDB_VERSION', Version},
{d, 'COUCHDB_GIT_SHA', GitSha},
+ {d, 'COUCHDB_SPIDERMONKEY_VERSION', SMVsn},
{i, "../"}
] ++ MD5Config ++ ProperConfig},
{port_env, PortEnvOverrides},
diff --git a/src/couch/src/couch_server.erl b/src/couch/src/couch_server.erl
index 04e8c6cf9..5dc0a05f0 100644
--- a/src/couch/src/couch_server.erl
+++ b/src/couch/src/couch_server.erl
@@ -28,7 +28,7 @@
-export([lock/2, unlock/1]).
-export([db_updated/1]).
-export([num_servers/0, couch_server/1, couch_dbs_pid_to_name/1, couch_dbs/1]).
--export([aggregate_queue_len/0]).
+-export([aggregate_queue_len/0,get_spidermonkey_version/0]).
% config_listener api
-export([handle_config_change/5, handle_config_terminate/3]).
@@ -85,6 +85,8 @@ get_stats() ->
lists:foldl(Fun, {0, 0}, lists:seq(1, num_servers())),
[{start_time, ?l2b(Time)}, {dbs_open, Open}].
+get_spidermonkey_version() -> list_to_binary(?COUCHDB_SPIDERMONKEY_VERSION).
+
sup_start_link(N) ->
gen_server:start_link({local, couch_server(N)}, couch_server, [N], []).