Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@ jobs:
- name: Setup Erlang
uses: erlef/setup-beam@v1
with:
otp-version: "26"
otp-version: "27"
rebar3-version: "3"

- name: Check format
run: make fmt-check

- name: Start Dependencies
run: make up

Expand All @@ -49,7 +52,7 @@ jobs:
- name: Setup Erlang
uses: erlef/setup-beam@v1
with:
otp-version: "26"
otp-version: "27"
rebar3-version: "3"

- name: Build Release
Expand Down
26 changes: 7 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
## to build emqtt without QUIC
export BUILD_WITHOUT_QUIC = 1
export PROFILE = emqx
## shallow clone for speed
export REBAR_GIT_CLONE_OPTIONS += --depth=1

## Feature Used in rebar plugin emqx_plugrel
## The Feature have not enabled by default on OTP25
Expand Down Expand Up @@ -39,10 +37,6 @@ ct: $(REBAR) rel copy-plugin
eunit: $(REBAR)
$(REBAR) as test eunit

.PHONY: xref
xref: $(REBAR)
$(REBAR) xref

.PHONY: cover
cover: $(REBAR)
$(REBAR) cover
Expand All @@ -54,7 +48,7 @@ clean:
.PHONY: distclean
distclean: clean
@rm -rf _build
@rm -f data/app.*.config data/vm.*.args rebar.lock
@rm -f rebar.lock

.PHONY: rel
rel: $(REBAR)
Expand All @@ -69,17 +63,11 @@ copy-plugin:

.PHONY: fmt
fmt: $(REBAR)
@find . \( -name '*.app.src' -o \
-name '*.erl' -o \
-name '*.hrl' -o \
-name 'rebar.config' -o \
-name '*.eterm' -o \
-name '*.escript' \) \
-not -path '*/_build/*' \
-not -path '*/deps/*' \
-not -path '*/_checkouts/*' \
-type f \
| xargs | $(REBAR) fmt --verbose -w
$(REBAR) fmt --verbose -w

.PHONY: fmt-check
fmt-check: $(REBAR)
$(REBAR) fmt --verbose --check

.PHONY: up
up:
Expand Down
4 changes: 1 addition & 3 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
services:
emqx:
image: emqx/emqx-enterprise:5.8.5
# TODO: uncomment when 5.9.0 image is released
# image: docker.io/emqx/emqx-enterprise:5.9.0
image: emqx/emqx-enterprise:5.9.0
container_name: emqx
environment:
EMQX_LOG__CONSOLE__LEVEL: debug
Expand Down
43 changes: 10 additions & 33 deletions rebar.config
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
%% -*- mode: erlang -*-
{deps, [
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.44.0"}}},
{typerefl, {git, "https://github.com/ieQu1/typerefl", {tag, "0.9.1"}}},
{emqx, {git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx"}},
{emqx_ctl, {git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx_ctl"}},
{emqx_utils,
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx_utils"}},
{emqx_durable_storage,
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"},
"apps/emqx_durable_storage"}},
{emqx_ds_backends,
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"}, "apps/emqx_ds_backends"}},
{emqx_ds_builtin_local,
{git_subdir, "https://github.com/emqx/emqx.git", {tag, "v5.8.4"},
"apps/emqx_ds_builtin_local"}}
{emqx_plugin_helper,
{git, "https://github.com/emqx/emqx-plugin-helper.git", {branch, "v5.9.0"}}}
]}.

{plugins, [
{typerefl, {git, "https://github.com/ieQu1/typerefl", {tag, "0.9.1"}}},
{hocon, {git, "https://github.com/emqx/hocon.git", {tag, "0.44.0"}}},
{emqx_plugrel, {git, "https://github.com/emqx/emqx_plugrel.git", {tag, "0.5.0"}}},
{erlfmt, "1.3.0"}
{emqx_plugin_helper,
{git, "https://github.com/emqx/emqx-plugin-helper.git", {branch, "v5.9.0"}}},
{erlfmt, "1.6.0"}
]}.

{profiles, [
Expand All @@ -39,11 +26,10 @@
{relx, [
{release,
%% Do not update version manually, use make bump-version-patch/minor/major instead
{emqx_offline_message_plugin, "1.0.1"},
[
emqx_offline_message_plugin
]
},
{emqx_offline_message_plugin, "1.0.1"}, [
emqx_offline_message_plugin,
emqx_plugin_helper
]},
{dev_mode, false},
{include_erts, false},
{include_src, false}
Expand All @@ -59,15 +45,6 @@
]},
{repo, "https://github.com/savonarola/emqx-offline-message-plugin"},
{functionality, ["Offline message persistence"]},
{compatibility, [{emqx, "~> 5.8"}]},
{compatibility, [{emqx, "~> 5.9"}]},
{description, "Offline message persistence plugin for EMQX."}
]}.

{xref_checks, [
undefined_function_calls,
undefined_functions,
locals_not_used,
deprecated_function_calls,
warnings_as_errors,
deprecated_functions
]}.
3 changes: 3 additions & 0 deletions scripts/ensure-rebar3.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ case ${OTP_VSN} in
26*)
VERSION="3.20.0-emqx-1"
;;
27*)
VERSION="3.24.0-emqx-1"
;;
*)
echo "Unsupported Erlang/OTP version $OTP_VSN"
exit 1
Expand Down
2 changes: 1 addition & 1 deletion src/emqx_offline_message_plugin_app.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-module(emqx_offline_message_plugin_app).

-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_plugin_helper/include/logger.hrl").

-behaviour(application).

Expand Down
17 changes: 6 additions & 11 deletions src/emqx_omp.erl
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
-module(emqx_omp).

-include("emqx_omp.hrl").
-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_plugin_helper/include/emqx.hrl").
-include_lib("emqx_plugin_helper/include/logger.hrl").

-behaviour(gen_server).

Expand Down Expand Up @@ -73,7 +73,9 @@ child_spec() ->

on_config_changed(OldConf, NewConf) ->
try
gen_server:call(?SERVER, #on_config_changed{old_conf = OldConf, new_conf = NewConf}, ?TIMEOUT)
gen_server:call(
?SERVER, #on_config_changed{old_conf = OldConf, new_conf = NewConf}, ?TIMEOUT
)
catch
exit:{noproc, _} ->
ok
Expand Down Expand Up @@ -162,14 +164,7 @@ status_to_error_list(ok) -> [];
status_to_error_list({error, Error}) -> [Error].

current_config() ->
case emqx_plugins:get_config(?PLUGIN_NAME_VSN) of
%% Pre 5.9.0
{ok, Config} when is_map(Config) ->
Config;
%% 5.9.0 and later
Config when is_map(Config) ->
Config
end.
emqx_plugin_helper:get_config(?PLUGIN_NAME_VSN).

init_metrics() ->
?SLOG(info, #{msg => "omp_init_metrics"}),
Expand Down
48 changes: 27 additions & 21 deletions src/emqx_omp_mysql.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

-module(emqx_omp_mysql).

-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/emqx_hooks.hrl").
-include_lib("emqx_plugin_helper/include/emqx.hrl").
-include_lib("emqx_plugin_helper/include/logger.hrl").
-include_lib("emqx_plugin_helper/include/emqx_hooks.hrl").

-include("emqx_omp.hrl").

Expand All @@ -29,7 +29,8 @@
-define(TIMEOUT, 1000).

-define(INIT_SQL, [
<<"CREATE TABLE IF NOT EXISTS `mqtt_msg` ("
<<
"CREATE TABLE IF NOT EXISTS `mqtt_msg` ("
"`id` bigint unsigned NOT NULL AUTO_INCREMENT,"
"`msgid` varchar(64) DEFAULT NULL,"
"`topic` varchar(180) NOT NULL,"
Expand All @@ -40,15 +41,18 @@
"`arrived` datetime NOT NULL,"
"PRIMARY KEY (`id`),"
"INDEX topic_index(`topic`)"
")"
"ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;">>,
")"
"ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;"
>>,

<<"CREATE TABLE IF NOT EXISTS `mqtt_sub` ("
<<
"CREATE TABLE IF NOT EXISTS `mqtt_sub` ("
"`clientid` varchar(64) NOT NULL,"
"`topic` varchar(180) NOT NULL,"
"`qos` tinyint(1) NOT NULL DEFAULT '0',"
"PRIMARY KEY (`clientid`, `topic`)"
") ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;">>
") ENGINE=InnoDB DEFAULT CHARSET=utf8MB4;"
>>
]).

-type statement() :: emqx_template_sql:statement().
Expand Down Expand Up @@ -100,7 +104,6 @@ start(ConfigRaw) ->
{MysqlConfig, ResourceOpts} = make_mysql_resource_config(ConfigRaw),
ok = start_resource(MysqlConfig, ResourceOpts),


Statements = parse_statements(
[delete_message_sql, select_message_sql, insert_subscription_sql, select_subscriptions_sql],
ConfigRaw
Expand Down Expand Up @@ -410,18 +413,21 @@ init_default_schema(ConfigRaw) ->
MysqlConfig,
ResourceOpts
),
ok = lists:foreach(fun(Sql) ->
case emqx_resource:simple_sync_query(?RESOURCE_ID_INIT, {sql, Sql, [], ?TIMEOUT}) of
{error, Reason} ->
?SLOG(error, #{
msg => "omp_mysql_init_default_schema_error",
sql => Sql,
reason => Reason
});
_ ->
ok
end
end, ?INIT_SQL),
ok = lists:foreach(
fun(Sql) ->
case emqx_resource:simple_sync_query(?RESOURCE_ID_INIT, {sql, Sql, [], ?TIMEOUT}) of
{error, Reason} ->
?SLOG(error, #{
msg => "omp_mysql_init_default_schema_error",
sql => Sql,
reason => Reason
});
_ ->
ok
end
end,
?INIT_SQL
),
ok = emqx_resource:remove_local(?RESOURCE_ID_INIT).

sync_query(Sql, Params) ->
Expand Down
8 changes: 4 additions & 4 deletions src/emqx_omp_redis.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@

-module(emqx_omp_redis).

-include_lib("emqx/include/emqx.hrl").
-include_lib("emqx/include/logger.hrl").
-include_lib("emqx/include/emqx_hooks.hrl").
-include_lib("emqx_plugin_helper/include/emqx.hrl").
-include_lib("emqx_plugin_helper/include/logger.hrl").
-include_lib("emqx_plugin_helper/include/emqx_hooks.hrl").

-include("emqx_omp.hrl").

Expand Down Expand Up @@ -433,7 +433,7 @@ stop_resource() ->
msg => omp_redis_resource_stop,
resource_id => ?RESOURCE_ID
}),
emqx_resource:remove_local(?RESOURCE_ID).
ok = emqx_resource:remove_local(?RESOURCE_ID).

sync_cmd(Cmd) ->
emqx_resource:simple_sync_query(?RESOURCE_ID, {cmd, Cmd}).
Expand Down
14 changes: 10 additions & 4 deletions src/emqx_omp_utils.erl
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

-module(emqx_omp_utils).

-include_lib("emqx/include/logger.hrl").
-include_lib("emqx_plugin_helper/include/logger.hrl").

-export([
fix_ssl_config/1,
Expand Down Expand Up @@ -97,7 +97,13 @@ resource_health_status(Name, ResourceId) ->
{ok, connected} ->
ok;
{ok, OtherStatus} ->
{error, iolist_to_binary(io_lib:format("Resource ~s is not connected, status: ~p", [Name, OtherStatus]))};
{error,
iolist_to_binary(
io_lib:format("Resource ~s is not connected, status: ~p", [Name, OtherStatus])
)};
{error, Reason} ->
{error, iolist_to_binary(io_lib:format("Resource ~s health check failed: ~p", [Name, Reason]))}
end.
{error,
iolist_to_binary(
io_lib:format("Resource ~s health check failed: ~p", [Name, Reason])
)}
end.
6 changes: 2 additions & 4 deletions test/emqx_omp_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ groups() ->
[mysql_tcp, mysql_ssl, redis_tcp, redis_ssl],
[sync, async],
[buffered, unbuffered],
%% TODO: restore t_health_check when 5.9.0 image is released
%% and used in the Docker Compose file
emqx_omp_test_helpers:all(?MODULE) -- [t_health_check]
emqx_omp_test_helpers:all(?MODULE)
]).

init_per_suite(Config) ->
Expand Down Expand Up @@ -350,7 +348,7 @@ set_server(redis_ssl, Config) ->
emqx_utils_maps:deep_put([redis, servers], Config, <<"redis-ssl:6380">>).

unique_id() ->
<<(emqx_guid:to_hexstr(emqx_guid:gen()))/binary>>.
binary:encode_hex(crypto:strong_rand_bytes(16)).

unique_topic() ->
<<"t/", (unique_id())/binary>>.
Expand Down
2 changes: 1 addition & 1 deletion test/emqx_omp_test_api_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -227,4 +227,4 @@ delete_all_actions() ->
%%--------------------------------------------------------------------

asset_path() ->
filename:join([code:lib_dir(emqx_offline_message_plugin, test), "assets"]).
filename:join([code:lib_dir(emqx_offline_message_plugin), "test", "assets"]).
4 changes: 3 additions & 1 deletion test/emqx_omp_test_helpers.erl
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ stop() ->
ok.

allow_plugin_install() ->
Command = "docker compose exec emqx /opt/emqx/bin/emqx ctl plugins allow " ++ binary_to_list(?PLUGIN_NAME_VSN),
Command =
"docker compose exec emqx /opt/emqx/bin/emqx ctl plugins allow " ++
binary_to_list(?PLUGIN_NAME_VSN),
ct:print("Command: ~s~n", [Command]),
os:cmd(Command),
timer:sleep(1000),
Expand Down