From 4afae79be93f25c607c71d472d5c5742dd3b2a48 Mon Sep 17 00:00:00 2001 From: Turtle Date: Thu, 29 Jul 2021 09:48:59 +0800 Subject: [PATCH] chore(statsd): update statsd conf root --- apps/emqx/src/emqx_schema.erl | 4 ++-- apps/emqx_authz/test/emqx_authz_api_SUITE.erl | 1 + apps/emqx_authz/test/emqx_authz_http_SUITE.erl | 1 + apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl | 1 + apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl | 1 + apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl | 1 + apps/emqx_authz/test/emqx_authz_redis_SUITE.erl | 1 + apps/emqx_statsd/etc/emqx_statsd.conf | 2 +- apps/emqx_statsd/src/emqx_statsd.app.src | 1 - apps/emqx_statsd/src/emqx_statsd_api.erl | 8 ++++---- apps/emqx_statsd/src/emqx_statsd_app.erl | 4 ++-- apps/emqx_statsd/src/emqx_statsd_schema.erl | 4 ++-- extension_schemas.config | 2 +- rebar.config.erl | 5 +++-- 14 files changed, 21 insertions(+), 15 deletions(-) diff --git a/apps/emqx/src/emqx_schema.erl b/apps/emqx/src/emqx_schema.erl index 3650df6ca..bf1e4cf51 100644 --- a/apps/emqx/src/emqx_schema.erl +++ b/apps/emqx/src/emqx_schema.erl @@ -72,7 +72,7 @@ -export([ssl/1]). %% will be used by emqx_ct_helper to find the dependent apps --export([includes/0]). +-export([includes/0, extra_schema_fields/1]). structs() -> ["cluster", "node", "rpc", "log", "zones", "listeners", "broker", @@ -485,7 +485,7 @@ fields("alarm") -> ]; fields(FieldName) -> - extra_schema_fields(FieldName). + ?MODULE:extra_schema_fields(FieldName). -ifndef(EMQX_EXT_SCHEMAS). %% Function extra_schema_fields/1 only terminates with explicit exception diff --git a/apps/emqx_authz/test/emqx_authz_api_SUITE.erl b/apps/emqx_authz/test/emqx_authz_api_SUITE.erl index 81dcfb0d2..3ae019e36 100644 --- a/apps/emqx_authz/test/emqx_authz_api_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_api_SUITE.erl @@ -46,6 +46,7 @@ init_per_suite(Config) -> %% important! let emqx_schema include the current app! meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), + meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), ok = emqx_ct_helpers:start_apps([emqx_authz]), %create_default_app(), diff --git a/apps/emqx_authz/test/emqx_authz_http_SUITE.erl b/apps/emqx_authz/test/emqx_authz_http_SUITE.erl index 405f216ff..0a68dd06a 100644 --- a/apps/emqx_authz/test/emqx_authz_http_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_http_SUITE.erl @@ -32,6 +32,7 @@ init_per_suite(Config) -> %% important! let emqx_schema include the current app! meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), + meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), diff --git a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl index 81a95e9a5..803979eb6 100644 --- a/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mongo_SUITE.erl @@ -35,6 +35,7 @@ init_per_suite(Config) -> %% important! let emqx_schema include the current app! meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), + meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), ok = emqx_ct_helpers:start_apps([emqx_authz]), ct:pal("---- emqx_hooks: ~p", [ets:tab2list(emqx_hooks)]), diff --git a/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl b/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl index 6426cbe4d..9a57a69f7 100644 --- a/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_mysql_SUITE.erl @@ -32,6 +32,7 @@ init_per_suite(Config) -> %% important! let emqx_schema include the current app! meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), + meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), diff --git a/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl b/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl index dfad14ca4..aee01e38b 100644 --- a/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_pgsql_SUITE.erl @@ -32,6 +32,7 @@ init_per_suite(Config) -> %% important! let emqx_schema include the current app! meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), + meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), diff --git a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl index b34e538fe..42429624e 100644 --- a/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl +++ b/apps/emqx_authz/test/emqx_authz_redis_SUITE.erl @@ -32,6 +32,7 @@ init_per_suite(Config) -> %% important! let emqx_schema include the current app! meck:new(emqx_schema, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_schema, includes, fun() -> ["emqx_authz"] end ), + meck:expect(emqx_schema, extra_schema_fields, fun(FieldName) -> emqx_authz_schema:fields(FieldName) end), meck:new(emqx_resource, [non_strict, passthrough, no_history, no_link]), meck:expect(emqx_resource, create, fun(_, _, _) -> {ok, meck_data} end ), diff --git a/apps/emqx_statsd/etc/emqx_statsd.conf b/apps/emqx_statsd/etc/emqx_statsd.conf index e7c293282..2bb6014a4 100644 --- a/apps/emqx_statsd/etc/emqx_statsd.conf +++ b/apps/emqx_statsd/etc/emqx_statsd.conf @@ -2,7 +2,7 @@ ## Statsd for EMQ X ##-------------------------------------------------------------------- -emqx_statsd:{ +statsd:{ enable: true server: "127.0.0.1:8125" sample_time_interval: "10s" diff --git a/apps/emqx_statsd/src/emqx_statsd.app.src b/apps/emqx_statsd/src/emqx_statsd.app.src index 2885f4dc9..44f5c6192 100644 --- a/apps/emqx_statsd/src/emqx_statsd.app.src +++ b/apps/emqx_statsd/src/emqx_statsd.app.src @@ -10,7 +10,6 @@ ]}, {env,[]}, {modules, []}, - {licenses, ["Apache 2.0"]}, {links, []} ]}. diff --git a/apps/emqx_statsd/src/emqx_statsd_api.erl b/apps/emqx_statsd/src/emqx_statsd_api.erl index b10dfdca9..c16bc9a61 100644 --- a/apps/emqx_statsd/src/emqx_statsd_api.erl +++ b/apps/emqx_statsd/src/emqx_statsd_api.erl @@ -84,23 +84,23 @@ statsd_api() -> [{"/statsd", Metadata, statsd}]. statsd(get, _Request) -> - Response = emqx_config:get_raw([<<"emqx_statsd">>], #{}), + Response = emqx_config:get_raw([<<"statsd">>], #{}), {200, Response}; statsd(put, Request) -> {ok, Body, _} = cowboy_req:read_body(Request), Params = emqx_json:decode(Body, [return_maps]), Enable = maps:get(<<"enable">>, Params), - ok = emqx_config:update([emqx_statsd], Params), + ok = emqx_config:update([statsd], Params), enable_statsd(Enable). enable_statsd(true) -> ok = emqx_statsd_sup:stop_child(?APP), - emqx_statsd_sup:start_child(?APP, emqx_config:get([?APP], #{})), + emqx_statsd_sup:start_child(?APP, emqx_config:get([statsd], #{})), {200}; enable_statsd(false) -> _ = emqx_statsd_sup:stop_child(?APP), {200}. get_raw(Key, Def) -> - emqx_config:get_raw([<<"emqx_statsd">>]++ [Key], Def). + emqx_config:get_raw([<<"statsd">>]++ [Key], Def). diff --git a/apps/emqx_statsd/src/emqx_statsd_app.erl b/apps/emqx_statsd/src/emqx_statsd_app.erl index 4764c04e1..6dd9dc5c7 100644 --- a/apps/emqx_statsd/src/emqx_statsd_app.erl +++ b/apps/emqx_statsd/src/emqx_statsd_app.erl @@ -32,9 +32,9 @@ stop(_) -> ok. maybe_enable_statsd() -> - case emqx_config:get([?APP, enable], false) of + case emqx_config:get([statsd, enable], false) of true -> - emqx_statsd_sup:start_child(?APP, emqx_config:get([?APP], #{})); + emqx_statsd_sup:start_child(?APP, emqx_config:get([statsd], #{})); false -> ok end. diff --git a/apps/emqx_statsd/src/emqx_statsd_schema.erl b/apps/emqx_statsd/src/emqx_statsd_schema.erl index bbc7eedc0..3af8a112c 100644 --- a/apps/emqx_statsd/src/emqx_statsd_schema.erl +++ b/apps/emqx_statsd/src/emqx_statsd_schema.erl @@ -11,9 +11,9 @@ -typerefl_from_string({ip_port/0, emqx_statsd_schema, to_ip_port}). -structs() -> ["emqx_statsd"]. +structs() -> ["statsd"]. -fields("emqx_statsd") -> +fields("statsd") -> [ {enable, emqx_schema:t(boolean(), undefined, false)} , {server, fun server/1} , {sample_time_interval, fun duration_ms/1} diff --git a/extension_schemas.config b/extension_schemas.config index cfac81b30..e25701f78 100644 --- a/extension_schemas.config +++ b/extension_schemas.config @@ -5,7 +5,6 @@ %% [ {"emqx_data_bridge", emqx_data_bridge_schema} , {"emqx_retainer", emqx_retainer_schema} -, {"emqx_statsd", emqx_statsd_schema} , {"emqx_authn", emqx_authn_schema} , {"emqx_authz", emqx_authz_schema} , {"emqx_bridge_mqtt", emqx_bridge_mqtt_schema} @@ -14,4 +13,5 @@ , {"emqx_dashboard", emqx_dashboard_schema} , {"emqx_gateway", emqx_gateway_schema} , {"emqx_prometheus", emqx_prometheus_schema} +, {"statsd", emqx_statsd_schema} ]. diff --git a/rebar.config.erl b/rebar.config.erl index a73f384b3..f0c246409 100644 --- a/rebar.config.erl +++ b/rebar.config.erl @@ -152,6 +152,7 @@ prod_overrides() -> [{add, [ {erl_opts, [deterministic]}]}]. profiles() -> + CommonCompileOpts = lists:keydelete('EMQX_EXT_SCHEMAS', 2, common_compile_opts()), Vsn = get_vsn(), [ {'emqx', [ {erl_opts, prod_compile_opts()} , {relx, relx(Vsn, cloud, bin)} @@ -169,10 +170,10 @@ profiles() -> , {relx, relx(Vsn, edge, pkg)} , {overrides, prod_overrides()} ]} - , {check, [ {erl_opts, common_compile_opts()} + , {check, [ {erl_opts, CommonCompileOpts} ]} , {test, [ {deps, test_deps()} - , {erl_opts, common_compile_opts() ++ erl_opts_i()} + , {erl_opts, CommonCompileOpts ++ erl_opts_i() } , {extra_src_dirs, [{"test", [{recursive,true}]}]} ]} ] ++ ee_profiles(Vsn).