Skip to content

A free and open source instant messaging and VoIP chat app built for friends, groups, and communities.

TypeScript fluxerfluxerapp

feat(gateway): report the session start queue length

Hampusc4d5ecd734fd
diff --git a/fluxer_gateway/src/gateway/gateway_concurrency.erl b/fluxer_gateway/src/gateway/gateway_concurrency.erl
index e7ede6e20..fa205d1da 100644
--- a/fluxer_gateway/src/gateway/gateway_concurrency.erl
+++ b/fluxer_gateway/src/gateway/gateway_concurrency.erl
@@ -9,6 +9,7 @@
request_session_start/1,
cancel_session_start/1,
release_session_start/0,
+ session_queue_length/0,
try_acquire_guild_start/0,
release_guild_start/0,
session_start_count/0,
@@ -48,6 +49,10 @@ cancel_session_start(Tag) ->
release_session_start() ->
gen_server:cast(?MODULE, {release_session_start, self()}).
+-spec session_queue_length() -> non_neg_integer().
+session_queue_length() ->
+ gen_server:call(?MODULE, session_queue_length, 1000).
+
-spec try_acquire_guild_start() -> ok | {error, at_capacity}.
try_acquire_guild_start() ->
try_acquire(?GUILD_START_IDX, fun gateway_rollout_config:max_concurrent_guild_starts/0).
@@ -120,6 +125,8 @@ handle_call({acquire, Idx, Limit}, _From, #{counters := Ref} = State) when
is_integer(Idx), is_integer(Limit)
->
{reply, do_acquire(Idx, Limit, Ref), State};
+handle_call(session_queue_length, _From, State) ->
+ {reply, maps:get(session_queued, State, 0), State};
handle_call(_Request, _From, State) ->
{reply, ok, State}.
diff --git a/fluxer_gateway/src/gateway/metrics_handler.erl b/fluxer_gateway/src/gateway/metrics_handler.erl
index 956c0dc93..7452b0cab 100644
--- a/fluxer_gateway/src/gateway/metrics_handler.erl
+++ b/fluxer_gateway/src/gateway/metrics_handler.erl
@@ -51,6 +51,7 @@ render_gateway_gauges() ->
PushActive = safe_apply_int(fun push_worker_pool:active_count/0),
ConcurrentSessions = safe_apply_int(fun gateway_concurrency:session_start_count/0),
ConcurrentGuilds = safe_apply_int(fun gateway_concurrency:guild_start_count/0),
+ QueuedSessions = safe_apply_int(fun gateway_concurrency:session_queue_length/0),
[
format_integer_metrics([
{<<"fluxer_gateway_sessions_total">>, <<"gauge">>,
@@ -74,6 +75,8 @@ render_gateway_gauges() ->
<<"Active push notification workers">>, PushActive},
{<<"fluxer_gateway_concurrent_session_starts">>, <<"gauge">>,
<<"In-flight session start operations">>, ConcurrentSessions},
+ {<<"fluxer_gateway_queued_session_starts">>, <<"gauge">>,
+ <<"Session starts waiting for admission">>, QueuedSessions},
{<<"fluxer_gateway_concurrent_guild_starts">>, <<"gauge">>,
<<"In-flight guild start operations">>, ConcurrentGuilds}
])