Skip to content

Commit

Permalink
feat: show erlang and spidermonkey version in /_node/_local/_versions
Browse files Browse the repository at this point in the history
The endpoint is admin-only.

Closes #3298
  • Loading branch information
janl committed Jul 11, 2021
1 parent ca86ae1 commit d953d2d
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 3 deletions.
3 changes: 1 addition & 2 deletions rebar.config.script
Expand Up @@ -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]),
Expand Down Expand Up @@ -200,7 +199,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, [
Expand Down
12 changes: 12 additions & 0 deletions src/chttpd/src/chttpd_node.erl
Expand Up @@ -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) ->
Expand Down
1 change: 1 addition & 0 deletions src/couch/rebar.config.script
Expand Up @@ -215,6 +215,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},
Expand Down
4 changes: 3 additions & 1 deletion src/couch/src/couch_server.erl
Expand Up @@ -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]).
Expand Down Expand Up @@ -84,6 +84,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], []).

Expand Down

0 comments on commit d953d2d

Please sign in to comment.