fix: format code
This commit is contained in:
parent
c777759707
commit
ea6b3c7b51
|
@ -307,17 +307,19 @@ calculate_rate(CurrVal, #rate{max = MaxRate0, last_v = LastVal,
|
||||||
|
|
||||||
%% calculate the max rate since the emqx startup
|
%% calculate the max rate since the emqx startup
|
||||||
MaxRate =
|
MaxRate =
|
||||||
if MaxRate0 >= CurrRate -> MaxRate0;
|
case MaxRate0 >= CurrRate of
|
||||||
true -> CurrRate
|
true -> MaxRate0;
|
||||||
|
false -> CurrRate
|
||||||
end,
|
end,
|
||||||
|
|
||||||
%% calculate the average rate in last 5 mins
|
%% calculate the average rate in last 5 mins
|
||||||
{Last5MinSamples, Acc5Min, Last5Min} =
|
{Last5MinSamples, Acc5Min, Last5Min} =
|
||||||
if Tick =< ?SAMPCOUNT_5M ->
|
case Tick =< ?SAMPCOUNT_5M of
|
||||||
|
true ->
|
||||||
Acc = AccRate5Min0 + CurrRate,
|
Acc = AccRate5Min0 + CurrRate,
|
||||||
{lists:reverse([CurrRate | lists:reverse(Last5MinSamples0)]),
|
{lists:reverse([CurrRate | lists:reverse(Last5MinSamples0)]),
|
||||||
Acc, Acc / Tick};
|
Acc, Acc / Tick};
|
||||||
true ->
|
false ->
|
||||||
[FirstRate | Rates] = Last5MinSamples0,
|
[FirstRate | Rates] = Last5MinSamples0,
|
||||||
Acc = AccRate5Min0 + CurrRate - FirstRate,
|
Acc = AccRate5Min0 + CurrRate - FirstRate,
|
||||||
{lists:reverse([CurrRate | lists:reverse(Rates)]),
|
{lists:reverse([CurrRate | lists:reverse(Rates)]),
|
||||||
|
|
|
@ -99,7 +99,7 @@ rule_info_schema() ->
|
||||||
|
|
||||||
schema("/rules") ->
|
schema("/rules") ->
|
||||||
#{
|
#{
|
||||||
operationId => '/rules',
|
'operationId' => '/rules',
|
||||||
get => #{
|
get => #{
|
||||||
tags => [<<"rules">>],
|
tags => [<<"rules">>],
|
||||||
description => <<"List all rules">>,
|
description => <<"List all rules">>,
|
||||||
|
@ -111,7 +111,7 @@ schema("/rules") ->
|
||||||
tags => [<<"rules">>],
|
tags => [<<"rules">>],
|
||||||
description => <<"Create a new rule using given Id">>,
|
description => <<"Create a new rule using given Id">>,
|
||||||
summary => <<"Create a Rule">>,
|
summary => <<"Create a Rule">>,
|
||||||
requestBody => rule_creation_schema(),
|
'requestBody' => rule_creation_schema(),
|
||||||
responses => #{
|
responses => #{
|
||||||
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
||||||
201 => rule_info_schema()
|
201 => rule_info_schema()
|
||||||
|
@ -120,7 +120,7 @@ schema("/rules") ->
|
||||||
|
|
||||||
schema("/rule_events") ->
|
schema("/rule_events") ->
|
||||||
#{
|
#{
|
||||||
operationId => '/rule_events',
|
'operationId' => '/rule_events',
|
||||||
get => #{
|
get => #{
|
||||||
tags => [<<"rules">>],
|
tags => [<<"rules">>],
|
||||||
description => <<"List all events can be used in rules">>,
|
description => <<"List all events can be used in rules">>,
|
||||||
|
@ -133,7 +133,7 @@ schema("/rule_events") ->
|
||||||
|
|
||||||
schema("/rules/:id") ->
|
schema("/rules/:id") ->
|
||||||
#{
|
#{
|
||||||
operationId => '/rules/:id',
|
'operationId' => '/rules/:id',
|
||||||
get => #{
|
get => #{
|
||||||
tags => [<<"rules">>],
|
tags => [<<"rules">>],
|
||||||
description => <<"Get a rule by given Id">>,
|
description => <<"Get a rule by given Id">>,
|
||||||
|
@ -149,7 +149,7 @@ schema("/rules/:id") ->
|
||||||
description => <<"Update a rule by given Id to all nodes in the cluster">>,
|
description => <<"Update a rule by given Id to all nodes in the cluster">>,
|
||||||
summary => <<"Update a Rule">>,
|
summary => <<"Update a Rule">>,
|
||||||
parameters => param_path_id(),
|
parameters => param_path_id(),
|
||||||
requestBody => rule_creation_schema(),
|
'requestBody' => rule_creation_schema(),
|
||||||
responses => #{
|
responses => #{
|
||||||
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
||||||
200 => rule_info_schema()
|
200 => rule_info_schema()
|
||||||
|
@ -168,7 +168,7 @@ schema("/rules/:id") ->
|
||||||
|
|
||||||
schema("/rules/:id/reset_metrics") ->
|
schema("/rules/:id/reset_metrics") ->
|
||||||
#{
|
#{
|
||||||
operationId => '/rules/:id/reset_metrics',
|
'operationId' => '/rules/:id/reset_metrics',
|
||||||
put => #{
|
put => #{
|
||||||
tags => [<<"rules">>],
|
tags => [<<"rules">>],
|
||||||
description => <<"Reset a rule metrics">>,
|
description => <<"Reset a rule metrics">>,
|
||||||
|
@ -183,12 +183,12 @@ schema("/rules/:id/reset_metrics") ->
|
||||||
|
|
||||||
schema("/rule_test") ->
|
schema("/rule_test") ->
|
||||||
#{
|
#{
|
||||||
operationId => '/rule_test',
|
'operationId' => '/rule_test',
|
||||||
post => #{
|
post => #{
|
||||||
tags => [<<"rules">>],
|
tags => [<<"rules">>],
|
||||||
description => <<"Test a rule">>,
|
description => <<"Test a rule">>,
|
||||||
summary => <<"Test a Rule">>,
|
summary => <<"Test a Rule">>,
|
||||||
requestBody => rule_test_schema(),
|
'requestBody' => rule_test_schema(),
|
||||||
responses => #{
|
responses => #{
|
||||||
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
400 => error_schema('BAD_REQUEST', "Invalid Parameters"),
|
||||||
412 => error_schema('NOT_MATCH', "SQL Not Match"),
|
412 => error_schema('NOT_MATCH', "SQL Not Match"),
|
||||||
|
|
|
@ -48,9 +48,9 @@
|
||||||
-spec(apply_rules(list(rule()), input()) -> ok).
|
-spec(apply_rules(list(rule()), input()) -> ok).
|
||||||
apply_rules([], _Input) ->
|
apply_rules([], _Input) ->
|
||||||
ok;
|
ok;
|
||||||
apply_rules([#{enable := false}|More], Input) ->
|
apply_rules([#{enable := false} | More], Input) ->
|
||||||
apply_rules(More, Input);
|
apply_rules(More, Input);
|
||||||
apply_rules([Rule|More], Input) ->
|
apply_rules([Rule | More], Input) ->
|
||||||
apply_rule_discard_result(Rule, Input),
|
apply_rule_discard_result(Rule, Input),
|
||||||
apply_rules(More, Input).
|
apply_rules(More, Input).
|
||||||
|
|
||||||
|
@ -150,14 +150,14 @@ select_and_transform(Fields, Input) ->
|
||||||
|
|
||||||
select_and_transform([], _Input, Output) ->
|
select_and_transform([], _Input, Output) ->
|
||||||
Output;
|
Output;
|
||||||
select_and_transform(['*'|More], Input, Output) ->
|
select_and_transform(['*' | More], Input, Output) ->
|
||||||
select_and_transform(More, Input, maps:merge(Output, Input));
|
select_and_transform(More, Input, maps:merge(Output, Input));
|
||||||
select_and_transform([{as, Field, Alias}|More], Input, Output) ->
|
select_and_transform([{as, Field, Alias} | More], Input, Output) ->
|
||||||
Val = eval(Field, Input),
|
Val = eval(Field, Input),
|
||||||
select_and_transform(More,
|
select_and_transform(More,
|
||||||
nested_put(Alias, Val, Input),
|
nested_put(Alias, Val, Input),
|
||||||
nested_put(Alias, Val, Output));
|
nested_put(Alias, Val, Output));
|
||||||
select_and_transform([Field|More], Input, Output) ->
|
select_and_transform([Field | More], Input, Output) ->
|
||||||
Val = eval(Field, Input),
|
Val = eval(Field, Input),
|
||||||
Key = alias(Field),
|
Key = alias(Field),
|
||||||
select_and_transform(More,
|
select_and_transform(More,
|
||||||
|
@ -172,7 +172,7 @@ select_and_collect(Fields, Input) ->
|
||||||
select_and_collect([{as, Field, {_, A} = Alias}], Input, {Output, _}) ->
|
select_and_collect([{as, Field, {_, A} = Alias}], Input, {Output, _}) ->
|
||||||
Val = eval(Field, Input),
|
Val = eval(Field, Input),
|
||||||
{nested_put(Alias, Val, Output), {A, ensure_list(Val)}};
|
{nested_put(Alias, Val, Output), {A, ensure_list(Val)}};
|
||||||
select_and_collect([{as, Field, Alias}|More], Input, {Output, LastKV}) ->
|
select_and_collect([{as, Field, Alias} | More], Input, {Output, LastKV}) ->
|
||||||
Val = eval(Field, Input),
|
Val = eval(Field, Input),
|
||||||
select_and_collect(More,
|
select_and_collect(More,
|
||||||
nested_put(Alias, Val, Input),
|
nested_put(Alias, Val, Input),
|
||||||
|
@ -181,7 +181,7 @@ select_and_collect([Field], Input, {Output, _}) ->
|
||||||
Val = eval(Field, Input),
|
Val = eval(Field, Input),
|
||||||
Key = alias(Field),
|
Key = alias(Field),
|
||||||
{nested_put(Key, Val, Output), {'item', ensure_list(Val)}};
|
{nested_put(Key, Val, Output), {'item', ensure_list(Val)}};
|
||||||
select_and_collect([Field|More], Input, {Output, LastKV}) ->
|
select_and_collect([Field | More], Input, {Output, LastKV}) ->
|
||||||
Val = eval(Field, Input),
|
Val = eval(Field, Input),
|
||||||
Key = alias(Field),
|
Key = alias(Field),
|
||||||
select_and_collect(More,
|
select_and_collect(More,
|
||||||
|
|
Loading…
Reference in New Issue