diff --git a/.github/workflows/build_packages.yaml b/.github/workflows/build_packages.yaml index 6877b25d7..a7fb86aa9 100644 --- a/.github/workflows/build_packages.yaml +++ b/.github/workflows/build_packages.yaml @@ -194,7 +194,7 @@ jobs: ./emqx/bin/emqx start || cat emqx/log/erlang.log.1 ready='no' 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' break fi diff --git a/.github/workflows/build_slim_packages.yaml b/.github/workflows/build_slim_packages.yaml index 27f43d0ea..56d2a6394 100644 --- a/.github/workflows/build_slim_packages.yaml +++ b/.github/workflows/build_slim_packages.yaml @@ -178,7 +178,7 @@ jobs: ./emqx/bin/emqx start || cat emqx/log/erlang.log.1 ready='no' 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' break fi diff --git a/apps/emqx_dashboard/src/emqx_dashboard.erl b/apps/emqx_dashboard/src/emqx_dashboard.erl index 9bf981323..6c2a02e47 100644 --- a/apps/emqx_dashboard/src/emqx_dashboard.erl +++ b/apps/emqx_dashboard/src/emqx_dashboard.erl @@ -73,6 +73,7 @@ start_listeners(Listeners) -> Dispatch = [ {"/", cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}}, {"/static/[...]", cowboy_static, {priv_dir, emqx_dashboard, "www/static"}}, + {emqx_mgmt_api_status:path(), emqx_mgmt_api_status, []}, {?BASE_PATH ++ "/[...]", emqx_dashboard_bad_api, []}, {'_', cowboy_static, {priv_file, emqx_dashboard, "www/index.html"}} ], diff --git a/apps/emqx_management/src/emqx_mgmt_api_status.erl b/apps/emqx_management/src/emqx_mgmt_api_status.erl index 5ece0bda4..70ff98988 100644 --- a/apps/emqx_management/src/emqx_mgmt_api_status.erl +++ b/apps/emqx_management/src/emqx_mgmt_api_status.erl @@ -14,55 +14,25 @@ %% limitations under the License. %%-------------------------------------------------------------------- -module(emqx_mgmt_api_status). -%% API --behaviour(minirest_api). -export([ - api_spec/0, - paths/0, - schema/1 + init/2, + path/0 ]). --export([running_status/2]). +path() -> + "/status". -api_spec() -> - emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}). - -paths() -> - ["/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">> - } - } - } - } - } - }. +init(Req0, State) -> + {Code, Headers, Body} = running_status(), + Req = cowboy_req:reply(Code, Headers, Body, Req0), + {ok, Req, State}. %%-------------------------------------------------------------------- %% API Handler funcs %%-------------------------------------------------------------------- -running_status(get, _Params) -> +running_status() -> BrokerStatus = case emqx:is_running() of true -> diff --git a/apps/emqx_management/test/emqx_mgmt_api_status_SUITE.erl b/apps/emqx_management/test/emqx_mgmt_api_status_SUITE.erl index 3e7f77a31..b725e37b2 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_status_SUITE.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_status_SUITE.erl @@ -31,7 +31,7 @@ end_per_suite(_) -> emqx_mgmt_api_test_util:end_suite(). 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]), {ok, Status} = emqx_mgmt_api_test_util:request_api(get, Path), ok. diff --git a/apps/emqx_management/test/emqx_mgmt_api_test_util.erl b/apps/emqx_management/test/emqx_mgmt_api_test_util.erl index 1bdf584e5..a8b04dc80 100644 --- a/apps/emqx_management/test/emqx_mgmt_api_test_util.erl +++ b/apps/emqx_management/test/emqx_mgmt_api_test_util.erl @@ -110,6 +110,9 @@ build_http_header(X) -> api_path(Parts) -> ?SERVER ++ filename:join([?BASE_PATH | Parts]). +api_path_without_base_path(Parts) -> + ?SERVER ++ filename:join([Parts]). + %% Usage: %% upload_request(<<"site.com/api/upload">>, <<"path/to/file.png">>, %% <<"upload">>, <<"image/png">>, [], <<"some-token">>) diff --git a/deploy/charts/emqx/templates/StatefulSet.yaml b/deploy/charts/emqx/templates/StatefulSet.yaml index d44c88a86..3af9fd62d 100644 --- a/deploy/charts/emqx/templates/StatefulSet.yaml +++ b/deploy/charts/emqx/templates/StatefulSet.yaml @@ -142,14 +142,14 @@ spec: {{- end }} readinessProbe: httpGet: - path: /api/v5/status + path: /status port: {{ .Values.emqxConfig.EMQX_DASHBOARD__LISTENER__HTTP | default 18083 }} initialDelaySeconds: 10 periodSeconds: 5 failureThreshold: 30 livenessProbe: httpGet: - path: /api/v5/status + path: /status port: {{ .Values.emqxConfig.EMQX_DASHBOARD__LISTENER__HTTP | default 18083 }} initialDelaySeconds: 60 periodSeconds: 30 diff --git a/scripts/pkg-tests.sh b/scripts/pkg-tests.sh index ec3c115b0..9f3e4d7bd 100755 --- a/scripts/pkg-tests.sh +++ b/scripts/pkg-tests.sh @@ -103,7 +103,7 @@ emqx_test(){ exit 1 fi 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 ] then echo "emqx running error" @@ -197,7 +197,7 @@ EOF exit 1 fi 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 ] then echo "emqx running error"