From 08d59ed325ab71721414dbf34ef5f8f7fbd5963a Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Mon, 5 Feb 2024 12:19:33 +0100 Subject: [PATCH 1/3] Graphql server status retuns now additional field -> commit hash --- priv/graphql/schemas/admin/server.gql | 2 ++ src/ejabberd_admin.erl | 2 +- .../admin/mongoose_graphql_server_admin_query.erl | 4 ++-- src/mongoose_server_api.erl | 12 ++++++++++-- 4 files changed, 15 insertions(+), 5 deletions(-) diff --git a/priv/graphql/schemas/admin/server.gql b/priv/graphql/schemas/admin/server.gql index 741ea84e353..19491401e83 100644 --- a/priv/graphql/schemas/admin/server.gql +++ b/priv/graphql/schemas/admin/server.gql @@ -48,6 +48,8 @@ type Status { message: String "MongooseIM version" version: String + "The hash of the commit that MongooseIM is running" + commitHash: String } "Specifies status of the server" diff --git a/src/ejabberd_admin.erl b/src/ejabberd_admin.erl index d52e8c07478..899e71ae2cf 100644 --- a/src/ejabberd_admin.erl +++ b/src/ejabberd_admin.erl @@ -46,7 +46,7 @@ %%% -spec status() -> {ok, {boolean(), iolist()}}. status() -> - {ok, {Status, Message, _}} = mongoose_server_api:status(), + {ok, {Status, Message, _, _}} = mongoose_server_api:status(), {ok, {Status, Message}}. %%% diff --git a/src/graphql/admin/mongoose_graphql_server_admin_query.erl b/src/graphql/admin/mongoose_graphql_server_admin_query.erl index eb6e84b6d99..e994800e82e 100644 --- a/src/graphql/admin/mongoose_graphql_server_admin_query.erl +++ b/src/graphql/admin/mongoose_graphql_server_admin_query.erl @@ -8,9 +8,9 @@ -include("../mongoose_graphql_types.hrl"). execute(_Ctx, server, <<"status">>, _) -> - {ok, {Status, Message, Version}} = mongoose_server_api:status(), + {ok, {Status, Message, Version, CommitHash}} = mongoose_server_api:status(), {ok, #{<<"statusCode">> => status_code(Status), <<"message">> => Message, - <<"version">> => Version}}; + <<"version">> => Version, <<"commitHash">> => CommitHash}}; execute(_Ctx, server, <<"getLoglevel">>, _) -> mongoose_server_api:get_loglevel(); execute(_Ctx, server, <<"getCookie">>, _) -> diff --git a/src/mongoose_server_api.erl b/src/mongoose_server_api.erl index 390ccac5b81..adfb72305a3 100644 --- a/src/mongoose_server_api.erl +++ b/src/mongoose_server_api.erl @@ -17,7 +17,7 @@ set_loglevel(Level) -> {invalid_level, io_lib:format("Log level ~p does not exist.", [Level])} end. --spec status() -> {ok, {boolean(), iolist(), iolist()}}. +-spec status() -> {ok, {boolean(), iolist(), iolist(), iolist()}}. status() -> {InternalStatus, ProvidedStatus} = init:get_status(), String1 = io_lib:format("The node ~p is ~p. Status: ~p.", @@ -28,9 +28,17 @@ status() -> {false, String1 ++ " MongooseIM is not running in that node.", "MongooseIM is not running in that node"}; {value, {_, _, Version}} -> + io:format("\n"), + io:format("--------------------------------------------------------\n"), + io:format("\n"), + io:format("~p", [string:tokens(Version, "-")]), + io:format("\n"), + io:format("--------------------------------------------------------\n"), + io:format("\n"), {true, String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version]), - lists:nth(1, string:split(Version, "-"))} + lists:nth(1, string:tokens(Version, "-")), + lists:nth(3, string:tokens(Version, "-"))} end, {ok, Result}. From b936ad4bd55e306b1a5d499f72e7c01ef545f227 Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Mon, 5 Feb 2024 13:21:38 +0100 Subject: [PATCH 2/3] Fixing graphql_server tests --- big_tests/tests/graphql_server_SUITE.erl | 5 +++-- src/mongoose_server_api.erl | 9 +-------- 2 files changed, 4 insertions(+), 10 deletions(-) diff --git a/big_tests/tests/graphql_server_SUITE.erl b/big_tests/tests/graphql_server_SUITE.erl index a068d28a89f..b48c53a5fbe 100644 --- a/big_tests/tests/graphql_server_SUITE.erl +++ b/big_tests/tests/graphql_server_SUITE.erl @@ -143,7 +143,8 @@ get_status_test(Config) -> Result = get_ok_value([data, server, status], get_status(Config)), ?assertEqual(<<"RUNNING">>, maps:get(<<"statusCode">>, Result)), ?assert(is_binary(maps:get(<<"message">>, Result))), - ?assert(is_binary(maps:get(<<"version">>, Result))). + ?assert(is_binary(maps:get(<<"version">>, Result))), + ?assert(is_binary(maps:get(<<"commitHash">>, Result))). join_successful(Config) -> @@ -292,7 +293,7 @@ ensure_node_started(Node) -> Timeout = timer:seconds(60), F = fun() -> case rpc(Node#{timeout => Timeout}, mongoose_server_api, status, []) of - {ok, {true, _, _}} -> true; + {ok, {true, _, _, _}} -> true; _Other -> false end end, diff --git a/src/mongoose_server_api.erl b/src/mongoose_server_api.erl index adfb72305a3..98d1d3bd886 100644 --- a/src/mongoose_server_api.erl +++ b/src/mongoose_server_api.erl @@ -26,15 +26,8 @@ status() -> case lists:keysearch(mongooseim, 1, application:which_applications()) of false -> {false, String1 ++ " MongooseIM is not running in that node.", - "MongooseIM is not running in that node"}; + "MongooseIM is not running in that node", "MongooseIM is not running in that node"}; {value, {_, _, Version}} -> - io:format("\n"), - io:format("--------------------------------------------------------\n"), - io:format("\n"), - io:format("~p", [string:tokens(Version, "-")]), - io:format("\n"), - io:format("--------------------------------------------------------\n"), - io:format("\n"), {true, String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version]), lists:nth(1, string:tokens(Version, "-")), From 4c96b6065fa0802aae2abbc23d51b7c4d045740f Mon Sep 17 00:00:00 2001 From: Janusz Jakubiec Date: Wed, 7 Feb 2024 07:47:59 +0100 Subject: [PATCH 3/3] CR comments fixes --- src/mongoose_server_api.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mongoose_server_api.erl b/src/mongoose_server_api.erl index 98d1d3bd886..187a9a772dc 100644 --- a/src/mongoose_server_api.erl +++ b/src/mongoose_server_api.erl @@ -31,7 +31,7 @@ status() -> {true, String1 ++ io_lib:format(" MongooseIM ~s is running in that node.", [Version]), lists:nth(1, string:tokens(Version, "-")), - lists:nth(3, string:tokens(Version, "-"))} + string:slice(lists:nth(3, string:tokens(Version, "-")), 1)} end, {ok, Result}.