Merge pull request #11544 from paulozulato/fix-counter-unhealthy

fix: increment matched counter when bridge is unhealthy
This commit is contained in:
Paulo Zulato 2023-08-30 17:08:14 -03:00 committed by GitHub
commit 876fde34fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 2 deletions

View File

@ -281,9 +281,11 @@ query(ResId, Request, Opts) ->
{ok, _Group, #{query_mode := QM, error := Error}} ->
case {QM, Error} of
{_, unhealthy_target} ->
emqx_resource_metrics:matched_inc(ResId),
emqx_resource_metrics:dropped_resource_stopped_inc(ResId),
?RESOURCE_ERROR(unhealthy_target, "unhealthy target");
{_, {unhealthy_target, _Message}} ->
emqx_resource_metrics:matched_inc(ResId),
emqx_resource_metrics:dropped_resource_stopped_inc(ResId),
?RESOURCE_ERROR(unhealthy_target, "unhealthy target");
{simple_async, _} ->

View File

@ -919,8 +919,17 @@ t_unhealthy_target(_) ->
emqx_resource_manager:lookup(?ID)
),
%% messages are dropped when bridge is unhealthy
emqx_resource:query(?ID, message),
?assertEqual(1, emqx_resource_metrics:dropped_resource_stopped_get(?ID)).
lists:foreach(
fun(_) ->
?assertMatch(
{error, {resource_error, #{reason := unhealthy_target}}},
emqx_resource:query(?ID, message)
)
end,
lists:seq(1, 3)
),
?assertEqual(3, emqx_resource_metrics:matched_get(?ID)),
?assertEqual(3, emqx_resource_metrics:dropped_resource_stopped_get(?ID)).
t_stop_start(_) ->
?check_trace(