Skip to content

Commit 63bc85d

Browse files
Madan Jampanifacebook-github-bot
Madan Jampani
authored andcommitted
additional transport metrics
Summary: Adds latency metrics and counts broken down by completion status. Differential Revision: D61232187 fbshipit-source-id: f7db5787a65e1ebd6f6f28d57771b4edd35f638e
1 parent 17f5896 commit 63bc85d

4 files changed

+20
-5
lines changed

include/wa_raft.hrl

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
-define(RAFT_COUNT(Metric), ?RAFT_METRICS_MODULE:count(Metric)).
7373
-define(RAFT_COUNTV(Metric, Value), ?RAFT_METRICS_MODULE:countv(Metric, Value)).
7474
-define(RAFT_GATHER(Metric, Value), ?RAFT_METRICS_MODULE:gather(Metric, Value)).
75+
-define(RAFT_GATHER_LATENCY(Metric, Value), ?RAFT_METRICS_MODULE:gather_latency(Metric, Value)).
7576

7677
%%-------------------------------------------------------------------
7778
%% Global Configuration

src/wa_raft_metrics.erl

+8-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@
1818
-export([
1919
count/1,
2020
countv/2,
21-
gather/2
21+
gather/2,
22+
gather_latency/2
2223
]).
2324

2425
%% Public Types
@@ -39,6 +40,8 @@
3940
-callback countv(metric(), value()) -> ok.
4041
%% Report the measured value of an occurence of some metric.
4142
-callback gather(metric(), value()) -> ok.
43+
%% Report the measured latency of an occurence of some metric.
44+
-callback gather_latency(metric(), value()) -> ok.
4245

4346
%%-------------------------------------------------------------------
4447
%% Public Types
@@ -72,3 +75,7 @@ countv(_Metric, _Value) ->
7275
-spec gather(metric(), value()) -> ok.
7376
gather(_Metric, _Value) ->
7477
ok.
78+
79+
-spec gather_latency(metric(), value()) -> ok.
80+
gather_latency(_Metric, _Value) ->
81+
ok.

src/wa_raft_transport.erl

+10-3
Original file line numberDiff line numberDiff line change
@@ -529,10 +529,16 @@ handle_call(Request, _From, #state{} = State) ->
529529
-spec handle_cast(Request, State :: #state{}) -> {noreply, NewState :: #state{}}
530530
when Request :: {complete, ID :: transport_id(), FileID :: file_id(), Status :: term(), Pid :: pid()}.
531531
handle_cast({complete, ID, FileID, Status, Pid}, #state{counters = Counters} = State) ->
532-
?RAFT_COUNT('raft.transport.file.complete'),
533532
NowMillis = erlang:system_time(millisecond),
533+
?RAFT_COUNT({'raft.transport.file.send', Status}),
534534
Result0 = update_file_info(ID, FileID,
535535
fun (Info) ->
536+
case Info of
537+
#{start_ts := StartMillis} ->
538+
?RAFT_GATHER_LATENCY({'raft.transport.file.send', Status, latency_ms}, NowMillis - StartMillis);
539+
_ ->
540+
ok
541+
end,
536542
case Status of
537543
ok -> Info#{status => completed, end_ts => NowMillis};
538544
_ -> Info#{status => failed, end_ts => NowMillis, error => Status}
@@ -824,8 +830,9 @@ maybe_notify_complete(ID, _Info, #state{}) ->
824830
[ID], #{domain => [whatsapp, wa_raft]}).
825831

826832
-spec maybe_notify(transport_id(), transport_info()) -> transport_info().
827-
maybe_notify(ID, #{status := Status, notify := Notify} = Info) when Status =/= requested andalso Status =/= running ->
828-
?RAFT_COUNT('raft.transport.complete'),
833+
maybe_notify(ID, #{status := Status, notify := Notify, start_ts := Start, end_ts := End} = Info) when Status =/= requested andalso Status =/= running ->
834+
?RAFT_COUNT({'raft.transport', Status}),
835+
?RAFT_GATHER_LATENCY({'raft.transport', Status, latency_ms}, End - Start),
829836
gen_server:reply(Notify, {ok, ID}),
830837
maps:remove(notify, Info);
831838
maybe_notify(_ID, Info) ->

src/wa_raft_transport_worker.erl

+1-1
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ handle_call(Request, From, #state{number = Number} = State) ->
8888
-spec handle_cast(Request, State :: state()) -> {noreply, NewState :: state(), Timeout :: timeout()}
8989
when Request :: {send, wa_raft_transport:transport_id(), wa_raft_transport:file_id()}.
9090
handle_cast({send, ID, FileID}, #state{table = Table} = State) ->
91-
?RAFT_COUNT('raft.transport.send'),
91+
?RAFT_COUNT('raft.transport.file.send'),
9292
wa_raft_transport:update_file_info(ID, FileID,
9393
fun (Info) -> Info#{status => sending, start_ts => erlang:system_time(millisecond)} end),
9494
true = ets:insert_new(Table, {make_ref(), ID, FileID}),

0 commit comments

Comments
 (0)