Skip to content

Commit

Permalink
Merge pull request #4221 from esl/adding-commit-hash-to-status
Browse files Browse the repository at this point in the history
Adding commit hash to graphql server status
  • Loading branch information
jacekwegr authored Feb 7, 2024
2 parents d2f609a + 4c96b60 commit fbd57db
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
5 changes: 3 additions & 2 deletions big_tests/tests/graphql_server_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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) ->
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions priv/graphql/schemas/admin/server.gql
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion src/ejabberd_admin.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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}}.

%%%
Expand Down
4 changes: 2 additions & 2 deletions src/graphql/admin/mongoose_graphql_server_admin_query.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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">>, _) ->
Expand Down
7 changes: 4 additions & 3 deletions src/mongoose_server_api.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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.",
Expand All @@ -26,11 +26,12 @@ 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}} ->
{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, "-")),
string:slice(lists:nth(3, string:tokens(Version, "-")), 1)}
end,
{ok, Result}.

Expand Down

0 comments on commit fbd57db

Please sign in to comment.