mirror of
https://github.com/fluxerapp/fluxer
synced 2026-10-17 21:15:32 +09:00
perf(ready): send timing diagnostics only to staff sessions (#2190)
This commit is contained in:
1 parent
e7f68c2e20
commit
a22db125a9
9 files changed
+196
-15
No files matched your search
@@ -154,7 +154,7 @@ finalize_resume(Pid, Seq, MissedEvents, GwTimings0, State) ->
|
||||
ReplayStartedAt,
|
||||
GwTimings0
|
||||
),
|
||||
ResumedData = put_resumed_gateway_timings(GwTimings),
|
||||
ResumedData = put_resumed_gateway_timings(session_is_staff(Pid), GwTimings),
|
||||
SocketPid ! {dispatch, resumed, ResumedData, Seq},
|
||||
erlang:garbage_collect(self(), [{type, major}]),
|
||||
{ok, State#{
|
||||
@@ -209,9 +209,20 @@ remote_trace_meta(Operation, NodeName) ->
|
||||
_ -> #{}
|
||||
end.
|
||||
|
||||
-spec put_resumed_gateway_timings(gateway_timings:recorder()) -> map().
|
||||
put_resumed_gateway_timings(GwTimings) ->
|
||||
#{<<"_timings_gw">> => gateway_timings_payload:finalize(GwTimings)}.
|
||||
-spec session_is_staff(pid()) -> boolean().
|
||||
session_is_staff(Pid) ->
|
||||
try gen_server:call(Pid, {is_staff}, 5000) of
|
||||
IsStaff when is_boolean(IsStaff) -> IsStaff;
|
||||
_Other -> false
|
||||
catch
|
||||
exit:_Reason -> false
|
||||
end.
|
||||
|
||||
-spec put_resumed_gateway_timings(boolean(), gateway_timings:recorder()) -> map().
|
||||
put_resumed_gateway_timings(true, GwTimings) ->
|
||||
#{<<"_timings_gw">> => gateway_timings_payload:finalize(GwTimings)};
|
||||
put_resumed_gateway_timings(false, _GwTimings) ->
|
||||
#{}.
|
||||
|
||||
-spec replay_missed_events([term()], pid()) -> ok.
|
||||
replay_missed_events([], _SocketPid) ->
|
||||
|
||||
@@ -96,6 +96,8 @@ init(SessionData) ->
|
||||
{reply, term(), session_state()} | {stop, normal, term(), session_state()}.
|
||||
handle_call({token_verify, Token}, _From, State) when is_binary(Token) ->
|
||||
session_lifecycle:handle_token_verify(Token, State);
|
||||
handle_call({is_staff}, _From, State) ->
|
||||
session_lifecycle:handle_is_staff(State);
|
||||
handle_call({heartbeat_ack, Seq}, _From, State) when is_integer(Seq), Seq >= 0 ->
|
||||
session_lifecycle:handle_heartbeat_ack(Seq, State);
|
||||
handle_call({resume, Seq, SocketPid}, _From, State) when
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
serialize_state/1,
|
||||
serialize_transfer_state/1,
|
||||
handle_token_verify/2,
|
||||
handle_is_staff/1,
|
||||
handle_heartbeat_ack/2,
|
||||
handle_resume/3,
|
||||
handle_resume_offline_timeout/2,
|
||||
@@ -268,6 +269,12 @@ token_hash_matches(HashedInput, TokenHash) when
|
||||
token_hash_matches(_HashedInput, _TokenHash) ->
|
||||
false.
|
||||
|
||||
-spec handle_is_staff(session_state()) -> {reply, boolean(), session_state()}.
|
||||
handle_is_staff(#{is_staff := true} = State) ->
|
||||
{reply, true, State};
|
||||
handle_is_staff(State) ->
|
||||
{reply, false, State}.
|
||||
|
||||
-spec handle_heartbeat_ack(seq(), session_state()) ->
|
||||
{reply, boolean(), session_state()}.
|
||||
handle_heartbeat_ack(Seq, #{ack_seq := AckSeq} = State) when Seq < AckSeq ->
|
||||
|
||||
@@ -61,9 +61,9 @@ dispatch_ready_to_socket(State) ->
|
||||
#{children => [PresencesSpan, UsersSpan, BuildSpan]},
|
||||
GwTimings0
|
||||
),
|
||||
FinalReadyData = FinalReadyData0#{
|
||||
<<"_timings_gw">> => gateway_timings_payload:finalize(GwTimings)
|
||||
},
|
||||
FinalReadyData = apply_timings_visibility(
|
||||
is_staff_session(State), GwTimings, FinalReadyData0
|
||||
),
|
||||
StateWithTimings = gateway_timings:put_state(GwTimings, State),
|
||||
StateAfterReady = dispatch_event(ready, FinalReadyData, StateWithTimings),
|
||||
StateAfterGuilds = dispatch_bot_guild_creates(
|
||||
@@ -79,6 +79,18 @@ dispatch_ready_to_socket(State) ->
|
||||
erlang:garbage_collect(),
|
||||
{noreply, FinalState}.
|
||||
|
||||
-spec is_staff_session(session_state()) -> boolean().
|
||||
is_staff_session(#{is_staff := true}) ->
|
||||
true;
|
||||
is_staff_session(_State) ->
|
||||
false.
|
||||
|
||||
-spec apply_timings_visibility(boolean(), gateway_timings:recorder(), map()) -> map().
|
||||
apply_timings_visibility(true, GwTimings, ReadyData) ->
|
||||
ReadyData#{<<"_timings_gw">> => gateway_timings_payload:finalize(GwTimings)};
|
||||
apply_timings_visibility(false, _GwTimings, ReadyData) ->
|
||||
maps:without([<<"_timings">>], ReadyData).
|
||||
|
||||
-spec build_final_ready_data(
|
||||
session_state(),
|
||||
[map()],
|
||||
|
||||
Reference in new issue
Block a user