refactor(rule_engine_metrics): refactor code_change

This commit is contained in:
EMQ-YangM 2022-01-11 03:03:18 -08:00
parent 7605fa5e64
commit de58c8e7bc
1 changed files with 53 additions and 51 deletions

View File

@ -324,58 +324,60 @@ handle_info(ticking, State = #state{rule_speeds = RuleSpeeds0}) ->
handle_info(_Info, State) -> handle_info(_Info, State) ->
{noreply, State}. {noreply, State}.
code_change({down, _Vsn}, State = #state{metric_ids = MIDs}, [Vsn]) code_change({down, _Vsn}, State = #state{metric_ids = MIDs}, [Vsn]) ->
when Vsn =:= "4.3.0"; case string:tokens(Vsn, ".") of
Vsn =:= "4.3.1"; ["4", "3", Val] ->
Vsn =:= "4.3.2"; case string:to_integer(Val) =< 7 of
Vsn =:= "4.3.3"; true ->
Vsn =:= "4.3.4"; [begin
Vsn =:= "4.3.5"; Passed = get_rules_passed(Id),
Vsn =:= "4.3.6" -> Take = get_actions_taken(Id),
[begin Success = get_actions_success(Id),
Passed = get_rules_passed(Id), Error = get_actions_error(Id),
Take = get_actions_taken(Id), Exception = get_actions_exception(Id),
Success = get_actions_success(Id), Retry = get_actions_retry(Id),
Error = get_actions_error(Id), ok = delete_counters(Id),
Exception = get_actions_exception(Id), ok = create_counters(Id, 7),
Retry = get_actions_retry(Id), inc_rules_matched(Id, Passed),
ok = delete_counters(Id), inc_actions_taken(Id, Take),
ok = create_counters(Id, 7), inc_actions_success(Id, Success),
inc_rules_matched(Id, Passed), inc_actions_error(Id, Error),
inc_actions_taken(Id, Take), inc_actions_exception(Id, Exception),
inc_actions_success(Id, Success), inc_actions_retry(Id, Retry)
inc_actions_error(Id, Error), end || Id <- sets:to_list(MIDs)],
inc_actions_exception(Id, Exception), {ok, State};
inc_actions_retry(Id, Retry) false -> {ok, State}
end || Id <- sets:to_list(MIDs)], end;
{ok, State}; _ -> {ok, State}
end;
code_change(_Vsn, State = #state{metric_ids = MIDs}, [Vsn]) code_change(_Vsn, State = #state{metric_ids = MIDs}, [Vsn]) ->
when Vsn =:= "4.3.0"; case string:tokens(Vsn, ".") of
Vsn =:= "4.3.1"; ["4", "3", Val] ->
Vsn =:= "4.3.2"; case string:to_integer(Val) =< 7 of
Vsn =:= "4.3.3"; true ->
Vsn =:= "4.3.4"; [begin
Vsn =:= "4.3.5"; Matched = get_rules_matched(Id),
Vsn =:= "4.3.6" -> Take = get_actions_taken(Id),
[begin Success = get_actions_success(Id),
Matched = get_rules_matched(Id), Error = get_actions_error(Id),
Take = get_actions_taken(Id), Exception = get_actions_exception(Id),
Success = get_actions_success(Id), Retry = get_actions_retry(Id),
Error = get_actions_error(Id), ok = delete_counters(Id),
Exception = get_actions_exception(Id), ok = create_counters(Id),
Retry = get_actions_retry(Id), inc_rules_matched(Id, Matched),
ok = delete_counters(Id), inc_rules_passed(Id, Matched),
ok = create_counters(Id), inc_actions_taken(Id, Take),
inc_rules_matched(Id, Matched), inc_actions_success(Id, Success),
inc_rules_passed(Id, Matched), inc_actions_error(Id, Error),
inc_actions_taken(Id, Take), inc_actions_exception(Id, Exception),
inc_actions_success(Id, Success), inc_actions_retry(Id, Retry)
inc_actions_error(Id, Error), end || Id <- sets:to_list(MIDs)],
inc_actions_exception(Id, Exception), {ok, State};
inc_actions_retry(Id, Retry) false -> {ok, State}
end || Id <- sets:to_list(MIDs)], end;
{ok, State}; _ -> {ok, State}
end;
code_change(_OldVsn, State, _Extra) -> code_change(_OldVsn, State, _Extra) ->
{ok, State}. {ok, State}.