fix: return 404 for /telemetry/data in case it's disabled
This commit is contained in:
parent
cfd792add4
commit
2443500884
|
@ -1,7 +1,7 @@
|
||||||
%% -*- mode: erlang -*-
|
%% -*- mode: erlang -*-
|
||||||
{application, emqx_modules, [
|
{application, emqx_modules, [
|
||||||
{description, "EMQX Modules"},
|
{description, "EMQX Modules"},
|
||||||
{vsn, "5.0.7"},
|
{vsn, "5.0.8"},
|
||||||
{modules, []},
|
{modules, []},
|
||||||
{applications, [kernel, stdlib, emqx]},
|
{applications, [kernel, stdlib, emqx]},
|
||||||
{mod, {emqx_modules_app, []}},
|
{mod, {emqx_modules_app, []}},
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
]).
|
]).
|
||||||
|
|
||||||
-define(BAD_REQUEST, 'BAD_REQUEST').
|
-define(BAD_REQUEST, 'BAD_REQUEST').
|
||||||
|
-define(NOT_FOUND, 'NOT_FOUND').
|
||||||
|
|
||||||
api_spec() ->
|
api_spec() ->
|
||||||
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).
|
emqx_dashboard_swagger:spec(?MODULE, #{check_schema => true}).
|
||||||
|
@ -63,7 +64,8 @@ schema("/telemetry/status") ->
|
||||||
'requestBody' => status_schema(?DESC(update_telemetry_status_api)),
|
'requestBody' => status_schema(?DESC(update_telemetry_status_api)),
|
||||||
responses =>
|
responses =>
|
||||||
#{
|
#{
|
||||||
200 => status_schema(?DESC(update_telemetry_status_api))
|
200 => status_schema(?DESC(update_telemetry_status_api)),
|
||||||
|
400 => emqx_dashboard_swagger:error_codes([?BAD_REQUEST], <<"Bad Request">>)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -75,7 +77,12 @@ schema("/telemetry/data") ->
|
||||||
description => ?DESC(get_telemetry_data_api),
|
description => ?DESC(get_telemetry_data_api),
|
||||||
tags => [<<"Telemetry">>],
|
tags => [<<"Telemetry">>],
|
||||||
responses =>
|
responses =>
|
||||||
#{200 => mk(ref(?MODULE, telemetry), #{desc => ?DESC(get_telemetry_data_api)})}
|
#{
|
||||||
|
200 => mk(ref(?MODULE, telemetry), #{desc => ?DESC(get_telemetry_data_api)}),
|
||||||
|
404 => emqx_dashboard_swagger:error_codes(
|
||||||
|
[?NOT_FOUND], <<"Telemetry is not enabled">>
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}.
|
}.
|
||||||
|
|
||||||
|
@ -220,21 +227,29 @@ status(put, #{body := Body}) ->
|
||||||
true -> <<"Telemetry status is already enabled">>;
|
true -> <<"Telemetry status is already enabled">>;
|
||||||
false -> <<"Telemetry status is already disabled">>
|
false -> <<"Telemetry status is already disabled">>
|
||||||
end,
|
end,
|
||||||
{400, #{code => 'BAD_REQUEST', message => Reason}};
|
{400, #{code => ?BAD_REQUEST, message => Reason}};
|
||||||
false ->
|
false ->
|
||||||
case enable_telemetry(Enable) of
|
case enable_telemetry(Enable) of
|
||||||
ok ->
|
ok ->
|
||||||
{200, get_telemetry_status()};
|
{200, get_telemetry_status()};
|
||||||
{error, Reason} ->
|
{error, Reason} ->
|
||||||
{400, #{
|
{400, #{
|
||||||
code => 'BAD_REQUEST',
|
code => ?BAD_REQUEST,
|
||||||
message => Reason
|
message => Reason
|
||||||
}}
|
}}
|
||||||
end
|
end
|
||||||
end.
|
end.
|
||||||
|
|
||||||
data(get, _Request) ->
|
data(get, _Request) ->
|
||||||
{200, emqx_json:encode(get_telemetry_data())}.
|
case emqx_modules_conf:is_telemetry_enabled() of
|
||||||
|
true ->
|
||||||
|
{200, emqx_json:encode(get_telemetry_data())};
|
||||||
|
false ->
|
||||||
|
{404, #{
|
||||||
|
code => ?NOT_FOUND,
|
||||||
|
message => <<"Telemetry is not enabled">>
|
||||||
|
}}
|
||||||
|
end.
|
||||||
|
|
||||||
%%--------------------------------------------------------------------
|
%%--------------------------------------------------------------------
|
||||||
%% Internal functions
|
%% Internal functions
|
||||||
|
|
|
@ -61,8 +61,20 @@ init_per_testcase(t_status_non_official, Config) ->
|
||||||
init_per_testcase(t_status, Config) ->
|
init_per_testcase(t_status, Config) ->
|
||||||
meck:new(emqx_telemetry, [non_strict, passthrough]),
|
meck:new(emqx_telemetry, [non_strict, passthrough]),
|
||||||
meck:expect(emqx_telemetry, enable, fun() -> ok end),
|
meck:expect(emqx_telemetry, enable, fun() -> ok end),
|
||||||
|
{ok, _, _} =
|
||||||
|
request(
|
||||||
|
put,
|
||||||
|
uri(["telemetry", "status"]),
|
||||||
|
#{<<"enable">> => true}
|
||||||
|
),
|
||||||
Config;
|
Config;
|
||||||
init_per_testcase(_TestCase, Config) ->
|
init_per_testcase(_TestCase, Config) ->
|
||||||
|
{ok, _, _} =
|
||||||
|
request(
|
||||||
|
put,
|
||||||
|
uri(["telemetry", "status"]),
|
||||||
|
#{<<"enable">> => true}
|
||||||
|
),
|
||||||
Config.
|
Config.
|
||||||
|
|
||||||
end_per_testcase(t_status_non_official, _Config) ->
|
end_per_testcase(t_status_non_official, _Config) ->
|
||||||
|
@ -169,4 +181,16 @@ t_data(_) ->
|
||||||
<<"vm_specs">> := _
|
<<"vm_specs">> := _
|
||||||
},
|
},
|
||||||
jsx:decode(Result)
|
jsx:decode(Result)
|
||||||
).
|
),
|
||||||
|
|
||||||
|
{ok, 200, _} =
|
||||||
|
request(
|
||||||
|
put,
|
||||||
|
uri(["telemetry", "status"]),
|
||||||
|
#{<<"enable">> => false}
|
||||||
|
),
|
||||||
|
|
||||||
|
{ok, 404, _} =
|
||||||
|
request(get, uri(["telemetry", "data"])),
|
||||||
|
|
||||||
|
ok.
|
||||||
|
|
|
@ -21,3 +21,5 @@
|
||||||
- Fix that the obsolete SSL files aren't deleted after the ExHook config update [#9432](https://github.com/emqx/emqx/pull/9432).
|
- Fix that the obsolete SSL files aren't deleted after the ExHook config update [#9432](https://github.com/emqx/emqx/pull/9432).
|
||||||
|
|
||||||
- Fix doc and schema for `/trace` API [#9468](https://github.com/emqx/emqx/pull/9468).
|
- Fix doc and schema for `/trace` API [#9468](https://github.com/emqx/emqx/pull/9468).
|
||||||
|
|
||||||
|
- Return `404` for `/telemetry/data` in case it's disabled [#9464](https://github.com/emqx/emqx/pull/9464).
|
||||||
|
|
|
@ -20,3 +20,5 @@
|
||||||
- 修复 ExHook 更新 SSL 相关配置后,过时的 SSL 文件没有被删除的问题 [#9432](https://github.com/emqx/emqx/pull/9432)。
|
- 修复 ExHook 更新 SSL 相关配置后,过时的 SSL 文件没有被删除的问题 [#9432](https://github.com/emqx/emqx/pull/9432)。
|
||||||
|
|
||||||
- 修复 /trace API 的返回值格式和相关文档 [#9468](https://github.com/emqx/emqx/pull/9468)。
|
- 修复 /trace API 的返回值格式和相关文档 [#9468](https://github.com/emqx/emqx/pull/9468)。
|
||||||
|
|
||||||
|
- 在遥测功能未开启时,通过 /telemetry/data 请求其数据,将会返回 404 [#9464](https://github.com/emqx/emqx/pull/9464)。
|
||||||
|
|
Loading…
Reference in New Issue