fix(telemetry): do not crash if bridge app is not ready yet

This commit is contained in:
Thales Macedo Garitezi 2022-04-25 11:15:59 -03:00
parent 3716ee60fb
commit ada3b03f6e
No known key found for this signature in database
GPG Key ID: DD279F8152A9B6DD
1 changed files with 24 additions and 17 deletions

View File

@ -431,23 +431,30 @@ if_only_to_toggle_enable(OldConf, Conf) ->
} }
} when BridgeType :: atom(). } when BridgeType :: atom().
get_basic_usage_info() -> get_basic_usage_info() ->
lists:foldl( InitialAcc = #{num_bridges => 0, count_by_type => #{}},
fun(#{resource_data := #{config := #{enable := false}}}, Acc) -> try
Acc; lists:foldl(
(#{type := BridgeType}, Acc) -> fun(#{resource_data := #{config := #{enable := false}}}, Acc) ->
NumBridges = maps:get(num_bridges, Acc), Acc;
CountByType0 = maps:get(count_by_type, Acc), (#{type := BridgeType}, Acc) ->
CountByType = maps:update_with( NumBridges = maps:get(num_bridges, Acc),
binary_to_atom(BridgeType, utf8), CountByType0 = maps:get(count_by_type, Acc),
fun(X) -> X + 1 end, CountByType = maps:update_with(
1, binary_to_atom(BridgeType, utf8),
CountByType0), fun(X) -> X + 1 end,
Acc#{ num_bridges => NumBridges + 1 1,
, count_by_type => CountByType CountByType0),
} Acc#{ num_bridges => NumBridges + 1
end, , count_by_type => CountByType
#{num_bridges => 0, count_by_type => #{}}, }
list()). end,
InitialAcc,
list())
catch
%% for instance, when the bridge app is not ready yet.
_:_ ->
InitialAcc
end.
bin(Bin) when is_binary(Bin) -> Bin; bin(Bin) when is_binary(Bin) -> Bin;
bin(Str) when is_list(Str) -> list_to_binary(Str); bin(Str) when is_list(Str) -> list_to_binary(Str);