Merge branch 'dev/v5.0' into umbrella-for-430
This commit is contained in:
commit
5f0f91bb15
|
@ -12,32 +12,26 @@ ebin
|
|||
test/ebin/*.beam
|
||||
.exrc
|
||||
plugins/*/ebin
|
||||
log/
|
||||
*.swp
|
||||
*.so
|
||||
.erlang.mk/
|
||||
cover/
|
||||
emqx.d
|
||||
eunit.coverdata
|
||||
test/ct.cover.spec
|
||||
logs
|
||||
ct.coverdata
|
||||
.idea/
|
||||
emqx.iml
|
||||
_rel/
|
||||
data/
|
||||
_build
|
||||
.rebar3
|
||||
rebar3.crashdump
|
||||
.DS_Store
|
||||
emqx.iml
|
||||
bbmustache/
|
||||
etc/gen.emqx.conf
|
||||
compile_commands.json
|
||||
cuttlefish
|
||||
rebar.lock
|
||||
xrefr
|
||||
erlang.mk
|
||||
*.coverdata
|
||||
etc/emqx.conf.rendered
|
||||
Mnesia.*/
|
||||
*.DS_Store
|
||||
_checkouts
|
||||
rebar.config.rendered
|
||||
/rebar3
|
||||
|
|
183
Makefile
183
Makefile
|
@ -1,139 +1,62 @@
|
|||
## shallow clone for speed
|
||||
REBAR_VERSION = 3.13.2-emqx-3
|
||||
REBAR = ./rebar3
|
||||
|
||||
REBAR_GIT_CLONE_OPTIONS += --depth 1
|
||||
export REBAR_GIT_CLONE_OPTIONS
|
||||
PROFILE ?= emqx
|
||||
PROFILES := emqx emqx-edge
|
||||
PKG_PROFILES := emqx-pkg emqx-edge-pkg
|
||||
|
||||
SUITES_FILES := $(shell find test -name '*_SUITE.erl' | sort)
|
||||
export REBAR_GIT_CLONE_OPTIONS=--depth=1
|
||||
|
||||
CT_SUITES := $(foreach value,$(SUITES_FILES),$(shell val=$$(basename $(value) .erl); echo $${val%_*}))
|
||||
|
||||
CT_NODE_NAME = emqxct@127.0.0.1
|
||||
|
||||
RUN_NODE_NAME = emqxdebug@127.0.0.1
|
||||
.PHONY: default
|
||||
default: $(REBAR) $(PROFILE)
|
||||
|
||||
.PHONY: all
|
||||
all: compile
|
||||
all: $(REBAR) $(PROFILES)
|
||||
|
||||
.PHONY: tests
|
||||
tests: eunit ct
|
||||
.PHONY: ensure-rebar3
|
||||
ensure-rebar3:
|
||||
@./ensure-rebar3.sh $(REBAR_VERSION)
|
||||
|
||||
.PHONY: run
|
||||
run: run_setup unlock
|
||||
@rebar3 as test get-deps
|
||||
@rebar3 as test auto --name $(RUN_NODE_NAME) --script scripts/run_emqx.escript
|
||||
|
||||
.PHONY: run_setup
|
||||
run_setup:
|
||||
@erl -noshell -eval \
|
||||
"{ok, [[HOME]]} = init:get_argument(home), \
|
||||
FilePath = HOME ++ \"/.config/rebar3/rebar.config\", \
|
||||
case file:consult(FilePath) of \
|
||||
{ok, Term} -> \
|
||||
NewTerm = case lists:keyfind(plugins, 1, Term) of \
|
||||
false -> [{plugins, [rebar3_auto]} | Term]; \
|
||||
{plugins, OldPlugins} -> \
|
||||
NewPlugins0 = OldPlugins -- [rebar3_auto], \
|
||||
NewPlugins = [rebar3_auto | NewPlugins0], \
|
||||
lists:keyreplace(plugins, 1, Term, {plugins, NewPlugins}) \
|
||||
end, \
|
||||
ok = file:write_file(FilePath, [io_lib:format(\"~p.\n\", [I]) || I <- NewTerm]); \
|
||||
_Enoent -> \
|
||||
os:cmd(\"mkdir -p ~/.config/rebar3/ \"), \
|
||||
NewTerm=[{plugins, [rebar3_auto]}], \
|
||||
ok = file:write_file(FilePath, [io_lib:format(\"~p.\n\", [I]) || I <- NewTerm]) \
|
||||
end, \
|
||||
halt(0)."
|
||||
|
||||
.PHONY: shell
|
||||
shell:
|
||||
@rebar3 as test auto
|
||||
|
||||
compile: unlock
|
||||
@rebar3 compile
|
||||
|
||||
unlock:
|
||||
@rebar3 unlock
|
||||
|
||||
clean: distclean
|
||||
|
||||
## Cuttlefish escript is built by default when cuttlefish app (as dependency) was built
|
||||
CUTTLEFISH_SCRIPT := _build/default/lib/cuttlefish/cuttlefish
|
||||
|
||||
.PHONY: cover
|
||||
cover:
|
||||
@rebar3 cover
|
||||
|
||||
.PHONY: coveralls
|
||||
coveralls:
|
||||
@rebar3 as test coveralls send
|
||||
|
||||
.PHONY: xref
|
||||
xref:
|
||||
@rebar3 xref
|
||||
|
||||
.PHONY: dialyzer
|
||||
dialyzer:
|
||||
@rebar3 dialyzer
|
||||
|
||||
.PHONY: proper
|
||||
proper:
|
||||
@rebar3 proper -d test/props -c
|
||||
|
||||
.PHONY: deps
|
||||
deps:
|
||||
@rebar3 get-deps
|
||||
|
||||
.PHONY: eunit
|
||||
eunit:
|
||||
@rebar3 eunit -v
|
||||
|
||||
.PHONY: ct_setup
|
||||
ct_setup:
|
||||
rebar3 as test compile
|
||||
@mkdir -p data
|
||||
@if [ ! -f data/loaded_plugins ]; then touch data/loaded_plugins; fi
|
||||
@ln -s -f '../../../../etc' _build/test/lib/emqx/
|
||||
@ln -s -f '../../../../data' _build/test/lib/emqx/
|
||||
|
||||
.PHONY: ct
|
||||
ct: ct_setup
|
||||
@rebar3 ct -v --name $(CT_NODE_NAME) --suite=$(shell echo $(foreach var,$(CT_SUITES),test/$(var)_SUITE) | tr ' ' ',')
|
||||
|
||||
## Run one single CT with rebar3
|
||||
## e.g. make ct-one-suite suite=emqx_bridge
|
||||
.PHONY: $(SUITES:%=ct-%)
|
||||
$(CT_SUITES:%=ct-%): ct_setup
|
||||
@rebar3 ct -v --readable=false --name $(CT_NODE_NAME) --suite=$(@:ct-%=%)_SUITE --cover
|
||||
|
||||
.PHONY: app.config
|
||||
app.config: $(CUTTLEFISH_SCRIPT) etc/gen.emqx.conf
|
||||
$(CUTTLEFISH_SCRIPT) -l info -e etc/ -c etc/gen.emqx.conf -i priv/emqx.schema -d data/
|
||||
|
||||
$(CUTTLEFISH_SCRIPT):
|
||||
@rebar3 get-deps
|
||||
@if [ ! -f cuttlefish ]; then make -C _build/default/lib/cuttlefish; fi
|
||||
|
||||
bbmustache:
|
||||
@git clone https://github.com/soranoba/bbmustache.git && cd bbmustache && ./rebar3 compile && cd ..
|
||||
|
||||
# This hack is to generate a conf file for testing
|
||||
# relx overlay is used for release
|
||||
etc/gen.emqx.conf: bbmustache etc/emqx.conf
|
||||
@erl -noshell -pa bbmustache/_build/default/lib/bbmustache/ebin -eval \
|
||||
"{ok, Temp} = file:read_file('etc/emqx.conf'), \
|
||||
{ok, Vars0} = file:consult('vars'), \
|
||||
Vars = [{atom_to_list(N), list_to_binary(V)} || {N, V} <- Vars0], \
|
||||
Targ = bbmustache:render(Temp, Vars), \
|
||||
ok = file:write_file('etc/gen.emqx.conf', Targ), \
|
||||
halt(0)."
|
||||
|
||||
.PHONY: gen-clean
|
||||
gen-clean:
|
||||
@rm -rf bbmustache
|
||||
@rm -f etc/gen.emqx.conf etc/emqx.conf.rendered
|
||||
$(REBAR): ensure-rebar3
|
||||
|
||||
.PHONY: distclean
|
||||
distclean: gen-clean
|
||||
@rm -rf Mnesia.*
|
||||
@rm -rf _build cover deps logs log data
|
||||
@rm -f rebar.lock compile_commands.json cuttlefish erl_crash.dump
|
||||
distclean:
|
||||
@rm -rf _build
|
||||
|
||||
.PHONY: $(PROFILES)
|
||||
$(PROFILES:%=%): $(REBAR)
|
||||
ifneq ($(shell echo $(@) |grep edge),)
|
||||
export EMQX_DESC="EMQ X Edge"
|
||||
else
|
||||
export EMQX_DESC="EMQ X Broker"
|
||||
endif
|
||||
$(REBAR) as $(@) release
|
||||
|
||||
.PHONY: $(PROFILES:%=build-%)
|
||||
$(PROFILES:%=build-%): $(REBAR)
|
||||
$(REBAR) as $(@:build-%=%) compile
|
||||
|
||||
# rebar clean
|
||||
.PHONY: clean $(PROFILES:%=clean-%)
|
||||
clean: $(PROFILES:%=clean-%) clean-stamps
|
||||
$(PROFILES:%=clean-%): $(REBAR)
|
||||
$(REBAR) as $(@:clean-%=%) clean
|
||||
|
||||
.PHONY: clean-stamps
|
||||
clean-stamps:
|
||||
find -L _build -name '.stamp' -type f | xargs rm -f
|
||||
|
||||
.PHONY: deps-all
|
||||
deps-all: $(REBAR) $(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%)
|
||||
|
||||
.PHONY: $(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%)
|
||||
$(PROFILES:%=deps-%) $(PKG_PROFILES:%=deps-%): $(REBAR)
|
||||
ifneq ($(shell echo $(@) |grep edge),)
|
||||
export EMQX_DESC="EMQ X Edge"
|
||||
else
|
||||
export EMQX_DESC="EMQ X Broker"
|
||||
endif
|
||||
$(REBAR) as $(@:deps-%=%) get-deps
|
||||
|
||||
include packages.mk
|
||||
include docker.mk
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
{deps, []}.
|
|
@ -1,11 +1,10 @@
|
|||
{application, emqx,
|
||||
[{description, "EMQ X Broker"},
|
||||
{id, "emqx"},
|
||||
{vsn, "git"},
|
||||
{vsn, "5.0.0"}, % strict semver, bump manually!
|
||||
{modules, []},
|
||||
{registered, []},
|
||||
{applications, [kernel,stdlib,gproc,gen_rpc,esockd,cowboy,
|
||||
sasl,os_mon]},
|
||||
{applications, [kernel,stdlib,gproc,gen_rpc,esockd,cowboy,sasl,os_mon,emqx_libs]},
|
||||
{mod, {emqx_app,[]}},
|
||||
{env, []},
|
||||
{licenses, ["Apache-2.0"]},
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
-module(emqx).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[EMQ X]").
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(emqx_access_control).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
|
||||
-export([authenticate/1]).
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(emqx_access_rule).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
|
||||
%% APIs
|
||||
-export([ match/3
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(emqx_acl_cache).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
|
||||
-export([ list_acl_cache/0
|
||||
, get_acl_cache/2
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Alarm Handler]").
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(gen_event).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Alarm Handler]").
|
||||
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Banned]").
|
||||
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-logger_header("[Broker]").
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Broker Helper]").
|
||||
|
|
@ -17,10 +17,10 @@
|
|||
%% MQTT Channel
|
||||
-module(emqx_channel).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Channel]").
|
||||
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[CM]").
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
-module(emqx_cm_locker).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([start_link/0]).
|
||||
|
|
@ -19,9 +19,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Registry]").
|
||||
|
|
@ -17,10 +17,10 @@
|
|||
%% MQTT/TCP|TLS Connection
|
||||
-module(emqx_connection).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[MQTT]").
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("types.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Ctl]").
|
||||
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("types.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Flapping]").
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
-module(emqx_frame).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-export([ initial_parse_state/0
|
||||
, initial_parse_state/1
|
|
@ -26,7 +26,7 @@
|
|||
|
||||
-module(emqx_gc).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ init/1
|
||||
, run/2
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([start_link/0, stop/0]).
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Hooks]").
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
%% Ratelimit or Quota checker
|
||||
-module(emqx_limiter).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ init/2
|
||||
, init/4 %% XXX: Compatible with before 4.2 version
|
|
@ -17,7 +17,7 @@
|
|||
%% @doc Start/Stop MQTT listeners.
|
||||
-module(emqx_listeners).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
%% APIs
|
||||
-export([ start/0
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-compile(inline).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
%% Create
|
||||
-export([ make/2
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
-behavior(gen_server).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-logger_header("[Metrics]").
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-compile(inline).
|
||||
|
||||
-include("types.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-export([ merge_opts/2
|
||||
, maybe_apply/2
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(emqx_gen_mod).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[ACL_INTERNAL]").
|
||||
|
|
@ -19,8 +19,8 @@
|
|||
-behaviour(gen_server).
|
||||
-behaviour(emqx_gen_mod).
|
||||
|
||||
-include_lib("emqx/include/emqx.hrl").
|
||||
-include_lib("emqx/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(emqx_gen_mod).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Presence]").
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(emqx_gen_mod).
|
||||
|
||||
-include_lib("emqx.hrl").
|
||||
-include_lib("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-ifdef(TEST).
|
||||
-export([ compile/1
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(emqx_gen_mod).
|
||||
|
||||
-include_lib("emqx.hrl").
|
||||
-include_lib("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
%% emqx_gen_mod callbacks
|
||||
-export([ load/1
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(supervisor).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ start_link/0
|
||||
, start_child/1
|
|
@ -19,9 +19,9 @@
|
|||
-behaviour(gen_server).
|
||||
-behaviour(emqx_gen_mod).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-logger_header("[TOPIC_METRICS]").
|
||||
|
||||
|
@ -52,6 +52,9 @@
|
|||
, all_registered_topics/0
|
||||
]).
|
||||
|
||||
%% stats.
|
||||
-export([ rates/2 ]).
|
||||
|
||||
%% gen_server callbacks
|
||||
-export([ init/1
|
||||
, handle_call/3
|
||||
|
@ -78,13 +81,15 @@
|
|||
]).
|
||||
|
||||
-define(TICKING_INTERVAL, 1).
|
||||
-define(SPEED_AVERAGE_WINDOW_SIZE, 5).
|
||||
-define(SPEED_MEDIUM_WINDOW_SIZE, 60).
|
||||
-define(SPEED_LONG_WINDOW_SIZE, 300).
|
||||
|
||||
-record(speed, {
|
||||
last = 0 :: number(),
|
||||
tick = 1 :: number(),
|
||||
last_v = 0 :: number(),
|
||||
acc = 0 :: number(),
|
||||
samples = [] :: list()
|
||||
last_medium = 0 :: number(),
|
||||
last_long = 0 :: number()
|
||||
}).
|
||||
|
||||
-record(state, {
|
||||
|
@ -180,7 +185,15 @@ val(Topic, Metric) ->
|
|||
end.
|
||||
|
||||
rate(Topic, Metric) ->
|
||||
gen_server:call(?MODULE, {get_rate, Topic, Metric}).
|
||||
case rates(Topic, Metric) of
|
||||
#{short := Last} ->
|
||||
Last;
|
||||
{error, Reason} ->
|
||||
{error, Reason}
|
||||
end.
|
||||
|
||||
rates(Topic, Metric) ->
|
||||
gen_server:call(?MODULE, {get_rates, Topic, Metric}).
|
||||
|
||||
metrics(Topic) ->
|
||||
case ets:lookup(?TAB, Topic) of
|
||||
|
@ -253,7 +266,7 @@ handle_call({unregister, Topic}, _From, State = #state{speeds = Speeds}) ->
|
|||
{reply, ok, State#state{speeds = NSpeeds}}
|
||||
end;
|
||||
|
||||
handle_call({get_rate, Topic, Metric}, _From, State = #state{speeds = Speeds}) ->
|
||||
handle_call({get_rates, Topic, Metric}, _From, State = #state{speeds = Speeds}) ->
|
||||
case is_registered(Topic) of
|
||||
false ->
|
||||
{reply, {error, topic_not_found}, State};
|
||||
|
@ -261,8 +274,8 @@ handle_call({get_rate, Topic, Metric}, _From, State = #state{speeds = Speeds}) -
|
|||
case maps:get({Topic, Metric}, Speeds, undefined) of
|
||||
undefined ->
|
||||
{reply, {error, invalid_metric}, State};
|
||||
#speed{last = Last} ->
|
||||
{reply, Last, State}
|
||||
#speed{last = Short, last_medium = Medium, last_long = Long} ->
|
||||
{reply, #{ short => Short, medium => Medium, long => Long }, State}
|
||||
end
|
||||
end.
|
||||
|
||||
|
@ -358,25 +371,29 @@ counters_size() ->
|
|||
number_of_registered_topics() ->
|
||||
proplists:get_value(size, ets:info(?TAB)).
|
||||
|
||||
calculate_speed(CurVal, #speed{last_v = LastVal, tick = Tick, acc = Acc, samples = Samples}) ->
|
||||
calculate_speed(CurVal, #speed{last = Last,
|
||||
last_v = LastVal,
|
||||
last_medium = LastMedium,
|
||||
last_long = LastLong
|
||||
}) ->
|
||||
%% calculate the current speed based on the last value of the counter
|
||||
CurSpeed = (CurVal - LastVal) / ?TICKING_INTERVAL,
|
||||
#speed{
|
||||
last_v = CurVal,
|
||||
last = short_mma(Last, CurSpeed),
|
||||
last_medium = medium_mma(LastMedium, CurSpeed),
|
||||
last_long = long_mma(LastLong, CurSpeed)
|
||||
}.
|
||||
|
||||
%% calculate the average speed in last 5 seconds
|
||||
case Tick < 5 of
|
||||
true ->
|
||||
Acc1 = Acc + CurSpeed,
|
||||
#speed{last = Acc1 / Tick,
|
||||
last_v = CurVal,
|
||||
acc = Acc1,
|
||||
samples = Samples ++ [CurSpeed],
|
||||
tick = Tick + 1};
|
||||
false ->
|
||||
[FirstSpeed | Speeds] = Samples,
|
||||
Acc1 = Acc + CurSpeed - FirstSpeed,
|
||||
#speed{last = Acc1 / Tick,
|
||||
last_v = CurVal,
|
||||
acc = Acc1,
|
||||
samples = Speeds ++ [CurSpeed],
|
||||
tick = Tick}
|
||||
end.
|
||||
%% Modified Moving Average ref: https://en.wikipedia.org/wiki/Moving_average
|
||||
mma(WindowSize, LastSpeed, CurSpeed) ->
|
||||
(LastSpeed * (WindowSize - 1) + CurSpeed) / WindowSize.
|
||||
|
||||
short_mma(LastSpeed, CurSpeed) ->
|
||||
mma(?SPEED_AVERAGE_WINDOW_SIZE, LastSpeed, CurSpeed).
|
||||
|
||||
medium_mma(LastSpeed, CurSpeed) ->
|
||||
mma(?SPEED_MEDIUM_WINDOW_SIZE, LastSpeed, CurSpeed).
|
||||
|
||||
long_mma(LastSpeed, CurSpeed) ->
|
||||
mma(?SPEED_LONG_WINDOW_SIZE, LastSpeed, CurSpeed).
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(emqx_modules).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Modules]").
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
-module(emqx_mountpoint).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ mount/2
|
||||
, unmount/2
|
|
@ -17,8 +17,8 @@
|
|||
%% @doc MQTTv5 Capabilities
|
||||
-module(emqx_mqtt_caps).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ check_pub/2
|
||||
, check_sub/3
|
|
@ -17,7 +17,7 @@
|
|||
%% @doc MQTT5 Properties
|
||||
-module(emqx_mqtt_props).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-export([ id/1
|
||||
, name/1
|
|
@ -49,9 +49,9 @@
|
|||
|
||||
-module(emqx_mqueue).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("types.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-export([ init/1
|
||||
, info/1
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[OS_MON]").
|
||||
|
||||
|
@ -47,7 +47,7 @@
|
|||
, code_change/3
|
||||
]).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
|
||||
-define(OS_MON, ?MODULE).
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
-module(emqx_packet).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
%% Header APIs
|
||||
-export([ type/1
|
|
@ -17,7 +17,7 @@
|
|||
%% @doc The utility functions for erlang process dictionary.
|
||||
-module(emqx_pd).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ get_counters/1
|
||||
, get_counter/1
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
-module(emqx_plugins).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Plugins]").
|
||||
|
||||
|
@ -234,7 +234,7 @@ generate_configs(App) ->
|
|||
Conf = cuttlefish_conf:file(ConfFile),
|
||||
cuttlefish_generator:map(Schema, Conf);
|
||||
{false, false} ->
|
||||
error(no_avaliable_configuration)
|
||||
error({config_not_found, {ConfigFile, ConfFile, SchemaFile}})
|
||||
end.
|
||||
|
||||
apply_configs([]) ->
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Pool]").
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(supervisor).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([spec/1, spec/2]).
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(emqx_psk).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[PSK]").
|
||||
|
|
@ -17,7 +17,7 @@
|
|||
%% @doc MQTT5 reason codes
|
||||
-module(emqx_reason_codes).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
|
||||
-export([ name/1
|
||||
, name/2
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("ekka/include/ekka.hrl").
|
||||
|
||||
-logger_header("[Router]").
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Router Helper]").
|
||||
|
|
@ -43,10 +43,10 @@
|
|||
%% MQTT Session
|
||||
-module(emqx_session).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Session]").
|
||||
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Shared Sub]").
|
||||
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Stats]").
|
||||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(supervisor).
|
||||
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export([ start_link/0
|
||||
, start_child/1
|
|
@ -18,9 +18,9 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("types.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[SYS]").
|
||||
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
-behavior(gen_server).
|
||||
|
||||
-include("types.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[SYSMON]").
|
||||
|
|
@ -16,8 +16,8 @@
|
|||
|
||||
-module(emqx_tracer).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
-logger_header("[Tracer]").
|
||||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
-module(emqx_trie).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
|
||||
%% Mnesia bootstrap
|
||||
-export([mnesia/1]).
|
|
@ -16,9 +16,9 @@
|
|||
|
||||
-module(emqx_types).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-export_type([ ver/0
|
||||
, qos/0
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("logger.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
|
||||
%% APIs
|
||||
-export([start_link/1]).
|
|
@ -17,10 +17,10 @@
|
|||
%% MQTT/WS|WSS Connection
|
||||
-module(emqx_ws_connection).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[MQTT/WS]").
|
||||
|
|
@ -18,10 +18,10 @@
|
|||
|
||||
-behaviour(gen_server).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include("logger.hrl").
|
||||
-include("types.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/logger.hrl").
|
||||
-include_lib("emqx_libs/include/types.hrl").
|
||||
|
||||
-logger_header("[Zone]").
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
-include_lib("common_test/include/ct.hrl").
|
||||
|
|
@ -19,7 +19,7 @@
|
|||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
all() -> emqx_ct:all(?MODULE).
|
|
@ -19,8 +19,8 @@
|
|||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include("emqx_mqtt.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx_mqtt.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
all() -> emqx_ct:all(?MODULE).
|
|
@ -19,7 +19,7 @@
|
|||
-compile(export_all).
|
||||
-compile(nowarn_export_all).
|
||||
|
||||
-include("emqx.hrl").
|
||||
-include_lib("emqx_libs/include/emqx.hrl").
|
||||
-include_lib("eunit/include/eunit.hrl").
|
||||
|
||||
all() -> emqx_ct:all(?MODULE).
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue