mirror of
https://github.com/valitydev/bouncer.git
synced 2024-11-06 02:15:18 +00:00
ED-114: Dont group metrics by connection groups (#27)
This commit is contained in:
parent
e15446c301
commit
e135a9e75d
@ -36,14 +36,12 @@ handle_event(Event, State) ->
|
|||||||
%%
|
%%
|
||||||
|
|
||||||
-define(METRIC_KEY(Tag, Content), [gunner, Tag, Content]).
|
-define(METRIC_KEY(Tag, Content), [gunner, Tag, Content]).
|
||||||
-define(METRIC_KEY(Tag, Content, GroupID), [gunner, Tag, Content, group, encode_group(GroupID)]).
|
|
||||||
|
|
||||||
-define(METRIC_DURATION(Key), ?METRIC_KEY(duration, Key)).
|
-define(METRIC_DURATION(Key), ?METRIC_KEY(duration, Key)).
|
||||||
-define(METRIC_ACQUIRE(Evt, GroupID), ?METRIC_KEY(acquire, Evt, GroupID)).
|
-define(METRIC_ACQUIRE(Evt), ?METRIC_KEY(acquire, Evt)).
|
||||||
-define(METRIC_FREE(Evt, GroupID), ?METRIC_KEY(free, Evt, GroupID)).
|
-define(METRIC_FREE(Evt), ?METRIC_KEY(free, Evt)).
|
||||||
-define(METRIC_CONNECTION_COUNT(Category), ?METRIC_KEY(connections, Category)).
|
-define(METRIC_CONNECTION_COUNT(Category), ?METRIC_KEY(connections, Category)).
|
||||||
-define(METRIC_CONNECTION_COUNT(Category, GroupID), ?METRIC_KEY(connections, Category, GroupID)).
|
-define(METRIC_CONNECTION(Evt), ?METRIC_KEY(connection, Evt)).
|
||||||
-define(METRIC_CONNECTION(Evt, GroupID), ?METRIC_KEY(connection, Evt, GroupID)).
|
|
||||||
|
|
||||||
-define(TIMER_KEY(Tag, Content), {Tag, Content}).
|
-define(TIMER_KEY(Tag, Content), {Tag, Content}).
|
||||||
-define(TIMER_CLEANUP, cleanup).
|
-define(TIMER_CLEANUP, cleanup).
|
||||||
@ -113,20 +111,20 @@ create_metric(#gunner_pool_init_event{pool_opts = PoolOpts}) ->
|
|||||||
create_metric(#gunner_pool_terminate_event{}) ->
|
create_metric(#gunner_pool_terminate_event{}) ->
|
||||||
ok;
|
ok;
|
||||||
%%
|
%%
|
||||||
create_metric(#gunner_acquire_started_event{group_id = GroupID}) ->
|
create_metric(#gunner_acquire_started_event{}) ->
|
||||||
counter_inc(?METRIC_ACQUIRE(started, GroupID));
|
counter_inc(?METRIC_ACQUIRE(started));
|
||||||
create_metric(#gunner_acquire_finished_event{group_id = GroupID, result = Result}) ->
|
create_metric(#gunner_acquire_finished_event{result = Result}) ->
|
||||||
counter_inc(?METRIC_ACQUIRE([finished, encode_result(Result)], GroupID));
|
counter_inc(?METRIC_ACQUIRE([finished, encode_result(Result)]));
|
||||||
%%
|
%%
|
||||||
create_metric(#gunner_connection_locked_event{group_id = GroupID}) ->
|
create_metric(#gunner_connection_locked_event{}) ->
|
||||||
counter_inc(?METRIC_CONNECTION_COUNT(locked, GroupID));
|
counter_inc(?METRIC_CONNECTION_COUNT(locked));
|
||||||
create_metric(#gunner_connection_unlocked_event{group_id = GroupID}) ->
|
create_metric(#gunner_connection_unlocked_event{}) ->
|
||||||
counter_dec(?METRIC_CONNECTION_COUNT(locked, GroupID));
|
counter_dec(?METRIC_CONNECTION_COUNT(locked));
|
||||||
%%
|
%%
|
||||||
create_metric(#gunner_free_started_event{group_id = GroupID}) ->
|
create_metric(#gunner_free_started_event{}) ->
|
||||||
counter_inc(?METRIC_FREE(started, GroupID));
|
counter_inc(?METRIC_FREE(started));
|
||||||
create_metric(#gunner_free_finished_event{group_id = GroupID}) ->
|
create_metric(#gunner_free_finished_event{}) ->
|
||||||
counter_inc(?METRIC_FREE(finished, GroupID));
|
counter_inc(?METRIC_FREE(finished));
|
||||||
create_metric(#gunner_free_error_event{}) ->
|
create_metric(#gunner_free_error_event{}) ->
|
||||||
counter_inc([gunner, free, error]);
|
counter_inc([gunner, free, error]);
|
||||||
%%
|
%%
|
||||||
@ -138,30 +136,27 @@ create_metric(#gunner_cleanup_finished_event{active_connections = Active}) ->
|
|||||||
create_metric(#gunner_client_down_event{}) ->
|
create_metric(#gunner_client_down_event{}) ->
|
||||||
counter_inc([gunner, client, down]);
|
counter_inc([gunner, client, down]);
|
||||||
%%
|
%%
|
||||||
create_metric(#gunner_connection_init_started_event{group_id = GroupID}) ->
|
create_metric(#gunner_connection_init_started_event{}) ->
|
||||||
counter_inc(?METRIC_CONNECTION([init, started], GroupID));
|
counter_inc(?METRIC_CONNECTION([init, started]));
|
||||||
%%
|
%%
|
||||||
create_metric(#gunner_connection_init_finished_event{group_id = GroupID, result = ok}) ->
|
create_metric(#gunner_connection_init_finished_event{result = ok}) ->
|
||||||
ok = counter_inc(?METRIC_CONNECTION([init, finished, ok], GroupID)),
|
ok = counter_inc(?METRIC_CONNECTION([init, finished, ok])),
|
||||||
counter_inc(?METRIC_CONNECTION_COUNT(total, GroupID));
|
counter_inc(?METRIC_CONNECTION_COUNT(total));
|
||||||
create_metric(#gunner_connection_init_finished_event{group_id = GroupID, result = _}) ->
|
create_metric(#gunner_connection_init_finished_event{result = _}) ->
|
||||||
counter_inc(?METRIC_CONNECTION([init, finished, error], GroupID));
|
counter_inc(?METRIC_CONNECTION([init, finished, error]));
|
||||||
%%
|
%%
|
||||||
create_metric(#gunner_connection_down_event{group_id = GroupID}) ->
|
create_metric(#gunner_connection_down_event{reason = Reason}) ->
|
||||||
ok = counter_inc(?METRIC_CONNECTION(down, GroupID)),
|
ok = counter_inc(?METRIC_CONNECTION([down, encode_down_reason(Reason)])),
|
||||||
counter_dec(?METRIC_CONNECTION_COUNT(total, GroupID)).
|
counter_dec(?METRIC_CONNECTION_COUNT(total)).
|
||||||
|
|
||||||
%%
|
%%
|
||||||
%% Internal
|
%% Internal
|
||||||
%%
|
%%
|
||||||
|
|
||||||
encode_group({IP, Port}) when is_tuple(IP) ->
|
encode_down_reason(normal) ->
|
||||||
encode_group({inet:ntoa(IP), Port});
|
normal;
|
||||||
encode_group({Host, Port}) when is_list(Host) ->
|
encode_down_reason({abnormal, _}) ->
|
||||||
encode_group(list_to_binary(Host), integer_to_binary(Port)).
|
abnormal.
|
||||||
|
|
||||||
encode_group(Host, Port) ->
|
|
||||||
<<Host/binary, ":", Port/binary>>.
|
|
||||||
|
|
||||||
encode_result(ok) ->
|
encode_result(ok) ->
|
||||||
ok;
|
ok;
|
||||||
|
@ -77,9 +77,7 @@ basic_metrics_test(C) ->
|
|||||||
ct_hay_publisher:get_metric([
|
ct_hay_publisher:get_metric([
|
||||||
gunner,
|
gunner,
|
||||||
acquire,
|
acquire,
|
||||||
started,
|
started
|
||||||
group,
|
|
||||||
encode_group(?OPA_ENDPOINT)
|
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
@ -88,9 +86,7 @@ basic_metrics_test(C) ->
|
|||||||
gunner,
|
gunner,
|
||||||
connection,
|
connection,
|
||||||
init,
|
init,
|
||||||
started,
|
started
|
||||||
group,
|
|
||||||
encode_group(?OPA_ENDPOINT)
|
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
@ -100,9 +96,7 @@ basic_metrics_test(C) ->
|
|||||||
connection,
|
connection,
|
||||||
init,
|
init,
|
||||||
finished,
|
finished,
|
||||||
ok,
|
ok
|
||||||
group,
|
|
||||||
encode_group(?OPA_ENDPOINT)
|
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
@ -111,9 +105,7 @@ basic_metrics_test(C) ->
|
|||||||
gunner,
|
gunner,
|
||||||
acquire,
|
acquire,
|
||||||
finished,
|
finished,
|
||||||
ok,
|
ok
|
||||||
group,
|
|
||||||
encode_group(?OPA_ENDPOINT)
|
|
||||||
])
|
])
|
||||||
),
|
),
|
||||||
?assertEqual(
|
?assertEqual(
|
||||||
@ -121,9 +113,7 @@ basic_metrics_test(C) ->
|
|||||||
ct_hay_publisher:get_metric([
|
ct_hay_publisher:get_metric([
|
||||||
gunner,
|
gunner,
|
||||||
connections,
|
connections,
|
||||||
total,
|
total
|
||||||
group,
|
|
||||||
encode_group(?OPA_ENDPOINT)
|
|
||||||
])
|
])
|
||||||
).
|
).
|
||||||
|
|
||||||
@ -203,13 +193,3 @@ stop_bouncer(C) ->
|
|||||||
C,
|
C,
|
||||||
fun(Apps) -> genlib_app:stop_unload_applications(Apps) end
|
fun(Apps) -> genlib_app:stop_unload_applications(Apps) end
|
||||||
).
|
).
|
||||||
|
|
||||||
%%
|
|
||||||
|
|
||||||
encode_group({IP, Port}) when is_tuple(IP) ->
|
|
||||||
encode_group({inet:ntoa(IP), Port});
|
|
||||||
encode_group({Host, Port}) when is_list(Host) ->
|
|
||||||
encode_group(list_to_binary(Host), integer_to_binary(Port)).
|
|
||||||
|
|
||||||
encode_group(Host, Port) ->
|
|
||||||
<<Host/binary, ":", Port/binary>>.
|
|
||||||
|
Loading…
Reference in New Issue
Block a user