Merge pull request #8662 from lafirest/fix/health_check_api

fix(mgmt): remove the `/api/v5` prefix of status API
This commit is contained in:
lafirest 2022-08-09 14:18:14 +08:00 committed by GitHub
commit 38c771b581
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
8 changed files with 20 additions and 46 deletions

View File

@ -194,7 +194,7 @@ jobs:
./emqx/bin/emqx start || cat emqx/log/erlang.log.1 ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
ready='no' ready='no'
for i in {1..18}; do for i in {1..18}; do
if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then if curl -fs 127.0.0.1:18083/status > /dev/null; then
ready='yes' ready='yes'
break break
fi fi

View File

@ -178,7 +178,7 @@ jobs:
./emqx/bin/emqx start || cat emqx/log/erlang.log.1 ./emqx/bin/emqx start || cat emqx/log/erlang.log.1
ready='no' ready='no'
for i in {1..30}; do for i in {1..30}; do
if curl -fs 127.0.0.1:18083/api/v5/status > /dev/null; then if curl -fs 127.0.0.1:18083/status > /dev/null; then
ready='yes' ready='yes'
break break
fi fi

View File

@ -73,6 +73,7 @@ start_listeners(Listeners) ->
Dispatch = [ Dispatch = [
{"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}}, {"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}},
{"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}}, {"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}},
{emqx_mgmt_api_status:path(), emqx_mgmt_api_status, []},
{?BASE_PATH ++ "/[...]", emqx_dashboard_bad_api, []}, {?BASE_PATH ++ "/[...]", emqx_dashboard_bad_api, []},
{'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}} {'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}}
], ],

View File

@ -14,55 +14,25 @@
%% limitations under the License. %% limitations under the License.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
-module(emqx_mgmt_api_status). -module(emqx_mgmt_api_status).
%% API
-behaviour(minirest_api).
-export([ -export([
api_spec/0, init/2,
paths/0, path/0
schema/1
]). ]).
-export([running_status/2]). path() ->
"/status".
api_spec() -> init(Req0, State) ->
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). {Code, Headers, Body} = running_status(),
Req = cowboy_req:reply(Code, Headers, Body, Req0),
paths() -> {ok, Req, State}.
["/status"].
schema("/status") ->
#{
'operationId' => running_status,
get =>
#{
description => <<"Node running status">>,
tags => [<<"Status">>],
security => [],
responses =>
#{
200 =>
#{
description => <<"Node is running">>,
content =>
#{
'text/plain' =>
#{
schema => #{type => string},
example =>
<<"Node emqx@127.0.0.1 is started\nemqx is running">>
}
}
}
}
}
}.
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
%% API Handler funcs %% API Handler funcs
%%-------------------------------------------------------------------- %%--------------------------------------------------------------------
running_status(get, _Params) -> running_status() ->
BrokerStatus = BrokerStatus =
case emqx:is_running() of case emqx:is_running() of
true -> true ->

View File

@ -31,7 +31,7 @@ end_per_suite(_) ->
emqx_mgmt_api_test_util:end_suite(). emqx_mgmt_api_test_util:end_suite().
t_status(_Config) -> t_status(_Config) ->
Path = emqx_mgmt_api_test_util:api_path(["status"]), Path = emqx_mgmt_api_test_util:api_path_without_base_path(["/status"]),
Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), started, running]), Status = io_lib:format("Node ~ts is ~ts~nemqx is ~ts", [node(), started, running]),
{ok, Status} = emqx_mgmt_api_test_util:request_api(get, Path), {ok, Status} = emqx_mgmt_api_test_util:request_api(get, Path),
ok. ok.

View File

@ -110,6 +110,9 @@ build_http_header(X) ->
api_path(Parts) -> api_path(Parts) ->
?SERVER ++ filename:join([?BASE_PATH | Parts]). ?SERVER ++ filename:join([?BASE_PATH | Parts]).
api_path_without_base_path(Parts) ->
?SERVER ++ filename:join([Parts]).
%% Usage: %% Usage:
%% upload_request(<<"site.com/api/upload">>, <<"path/to/file.png">>, %% upload_request(<<"site.com/api/upload">>, <<"path/to/file.png">>,
%% <<"upload">>, <<"image/png">>, [], <<"some-token">>) %% <<"upload">>, <<"image/png">>, [], <<"some-token">>)

View File

@ -142,14 +142,14 @@ spec:
{{- end }} {{- end }}
readinessProbe: readinessProbe:
httpGet: httpGet:
path: /api/v5/status path: /status
port: {{ .Values.emqxConfig.EMQX_DASHBOARD__LISTENER__HTTP | default 18083 }} port: {{ .Values.emqxConfig.EMQX_DASHBOARD__LISTENER__HTTP | default 18083 }}
initialDelaySeconds: 10 initialDelaySeconds: 10
periodSeconds: 5 periodSeconds: 5
failureThreshold: 30 failureThreshold: 30
livenessProbe: livenessProbe:
httpGet: httpGet:
path: /api/v5/status path: /status
port: {{ .Values.emqxConfig.EMQX_DASHBOARD__LISTENER__HTTP | default 18083 }} port: {{ .Values.emqxConfig.EMQX_DASHBOARD__LISTENER__HTTP | default 18083 }}
initialDelaySeconds: 60 initialDelaySeconds: 60
periodSeconds: 30 periodSeconds: 30

View File

@ -103,7 +103,7 @@ emqx_test(){
exit 1 exit 1
fi fi
IDLE_TIME=0 IDLE_TIME=0
while ! curl http://127.0.0.1:18083/api/v5/status >/dev/null 2>&1; do while ! curl http://127.0.0.1:18083/status >/dev/null 2>&1; do
if [ $IDLE_TIME -gt 10 ] if [ $IDLE_TIME -gt 10 ]
then then
echo "emqx running error" echo "emqx running error"
@ -197,7 +197,7 @@ EOF
exit 1 exit 1
fi fi
IDLE_TIME=0 IDLE_TIME=0
while ! curl http://127.0.0.1:18083/api/v5/status >/dev/null 2>&1; do while ! curl http://127.0.0.1:18083/status >/dev/null 2>&1; do
if [ $IDLE_TIME -gt 10 ] if [ $IDLE_TIME -gt 10 ]
then then
echo "emqx running error" echo "emqx running error"