Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
175a76d
Add Couch Stats Resource Tracker (CSRT)
chewbranca Jun 7, 2024
d99c812
Remove no longer used conf_get fun
chewbranca Mar 25, 2025
922b3f8
Cleanup Dialyzer specs
chewbranca Mar 25, 2025
375ec28
Fix type in metric name
chewbranca Apr 8, 2025
ada453e
Update CSRT tests for ioq parallel read changes
chewbranca Apr 8, 2025
9aadac4
Add csrt_logger:register_matcher
chewbranca Apr 8, 2025
1421a50
Rework changes_processed vs rows
chewbranca Apr 8, 2025
cba2e9c
Format code
chewbranca Apr 8, 2025
020743f
CI Bump..
chewbranca Apr 9, 2025
975818e
Create delta prior to deleting the context
chewbranca Apr 9, 2025
a8dd0d6
Updates based on PR feedback
chewbranca Apr 25, 2025
f280d1b
Address more PR feedback
chewbranca May 7, 2025
ae419d6
Fix erlfmt-check
chewbranca May 7, 2025
57c19cd
Rework and fix csrt_util init_p ini lookup tests
chewbranca May 7, 2025
2bfefd4
Rework delta handling back to normal process_message semantics
chewbranca May 8, 2025
089f02d
More cleanup
chewbranca May 8, 2025
a999033
Erlfmt rexi_tests.erl
chewbranca May 8, 2025
e070513
Revert "CI Bump.."
chewbranca May 17, 2025
befdfcb
More PR cleanup
chewbranca May 17, 2025
11f9755
More cleanup
chewbranca Jun 2, 2025
6fd6a29
Cleanup #rctx{} and other reworkings
chewbranca Jun 3, 2025
fbd7455
make erlfmt-format
chewbranca Jun 3, 2025
04c588d
Cleanup csrt_query:field/2
chewbranca Jun 3, 2025
1063b8a
Clarify is_rctx_stat_field
chewbranca Jun 3, 2025
f6a7bf6
Fix csrt:inc/N typespec
chewbranca Jun 4, 2025
d973007
Batch accumulate_delta updates in single ets:update_counter call
chewbranca Jun 10, 2025
7211093
Fixup csrt_logger report tests
chewbranca Jun 10, 2025
a7f3342
Update deregister logic and testing
chewbranca Jun 11, 2025
b58e04a
make erlfmt-format
chewbranca Jun 11, 2025
c9371ee
Assert registered matchers persist a after global reload
chewbranca Jun 11, 2025
06da5f2
Cleanup is_enabled settings
chewbranca Jun 12, 2025
c41ac4f
Rework updated_at logic
chewbranca Jun 12, 2025
e4198ed
Add csrt_logger:matcher_on_long_reqs
chewbranca Jun 12, 2025
720649d
Cleanup Dialyzer findings
chewbranca Jun 12, 2025
0a6c556
make erlfmt-format
chewbranca Jun 12, 2025
7b96f89
Test csrt_util:field for all #rctx{} fields
chewbranca Jun 14, 2025
3e4736a
Use dedicated transient CSRT supervisor
chewbranca Jun 14, 2025
7de1d96
Cleanup delta handling and type specs
chewbranca Jun 14, 2025
e41e441
Fixup maybe_add_delta type restrucuring
chewbranca Jun 17, 2025
3074f77
make erlfmt-format
chewbranca Jun 17, 2025
5919cc2
Add csrt:proc_window based on recon:proc_window
chewbranca Jun 17, 2025
39c4675
Add dedicated toggle to disable #rpc_worker{} reporting
chewbranca Jun 17, 2025
c489a61
make erlfmt-format
chewbranca Jun 17, 2025
9735ca7
Remove extraneous function head
chewbranca Jun 17, 2025
6224242
Cleanup instantiation of base #rctx{} match spec
chewbranca Jun 17, 2025
97329a7
Fix csrt_logger dbname io tests
chewbranca Jun 18, 2025
5166762
make erlfmt-format
chewbranca Jun 19, 2025
45a94e5
Cleanup matchers
chewbranca Jun 19, 2025
24d5626
Rework csrt_logger:add_matcher error type
chewbranca Jun 19, 2025
6533bc7
Cleanup Dialyzer and a few other things
chewbranca Jun 19, 2025
7497f09
Simple make_dt time conversions
chewbranca Jun 19, 2025
9016bd1
Cleanup MatcherGen error handling
chewbranca Jun 19, 2025
1db2e8d
make erlfmt-format
chewbranca Jun 19, 2025
73a5893
Remove debug TODO
chewbranca Jun 19, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
make erlfmt-format
  • Loading branch information
chewbranca committed Jun 17, 2025
commit c489a61caee4e558a80f540e23e9ae7387808591
4 changes: 2 additions & 2 deletions src/couch_stats/src/csrt.erl
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ destroy_context(PidRef) ->
clear_pdict_markers() ->
ok = lists:foreach(
fun
({{csrt,_} = K , _V}) ->
({{csrt, _} = K, _V}) ->
erlang:erase(K);
(_) ->
ok
Expand Down Expand Up @@ -428,7 +428,7 @@ pid_ref_attrs(AttrName) ->
%% returning on pid_ref() rather than pid().
%% [1] https://github.com/ferd/recon/blob/c2a76855be3a226a3148c0dfc21ce000b6186ef8/src/recon.erl#L268-L300
-spec proc_window(AttrName, Num, Time) -> term() | throw(any()) when
AttrName :: rctx_field(), Num :: non_neg_integer(), Time :: pos_integer().
AttrName :: rctx_field(), Num :: non_neg_integer(), Time :: pos_integer().
proc_window(AttrName, Num, Time) ->
csrt_logger:proc_window(AttrName, Num, Time).

Expand Down
19 changes: 10 additions & 9 deletions src/couch_stats/src/csrt_logger.erl
Original file line number Diff line number Diff line change
Expand Up @@ -145,12 +145,13 @@ log_process_lifetime_report(PidRef) ->
%% Return a subset of Matchers for each Matcher that matches on Rctxs
-spec find_matches(Rctxs :: [rctx()], Matchers :: matchers()) -> matchers().
find_matches(Rctxs, Matchers) when is_list(Rctxs) andalso is_map(Matchers) ->
Rctxs1 = case csrt_util:is_enabled_rpc_reporting() of
true ->
Rctxs;
false ->
[Rctx || #rctx{type=#coordinator{}}=Rctx <- Rctxs]
end,
Rctxs1 =
case csrt_util:is_enabled_rpc_reporting() of
true ->
Rctxs;
false ->
[Rctx || #rctx{type = #coordinator{}} = Rctx <- Rctxs]
end,
maps:filter(
fun(_Name, {_MSpec, CompMSpec}) ->
(catch ets:match_spec_run(Rctxs1, CompMSpec)) =/= []
Expand Down Expand Up @@ -430,7 +431,7 @@ matcher_on_ioq_calls(Threshold) when
pid_ref_matchspec(AttrName) ->
#{size := Size, field_idx := FieldIdx} = csrt_util:rctx_record_info(),
RctxMatch0 = list_to_tuple([rctx | lists:duplicate(Size - 1, '_')]),
RctxMatch1 = setelement(maps:get(pid_ref, FieldIdx) + 1 , RctxMatch0, '$1'),
RctxMatch1 = setelement(maps:get(pid_ref, FieldIdx) + 1, RctxMatch0, '$1'),
RctxMatch = setelement(maps:get(AttrName, FieldIdx) + 1, RctxMatch1, '$2'),
MatchSpec = [{RctxMatch, [], [{{'$1', '$2'}}]}],
{MatchSpec, ets:match_spec_compile(MatchSpec)}.
Expand All @@ -448,10 +449,10 @@ pid_ref_attrs(AttrName) ->
%% pid_ref() rather than pid().
%% [1] https://github.com/ferd/recon/blob/c2a76855be3a226a3148c0dfc21ce000b6186ef8/src/recon.erl#L268-L300
-spec proc_window(AttrName, Num, Time) -> term() | throw(any()) when
AttrName :: rctx_field(), Num :: non_neg_integer(), Time :: pos_integer().
AttrName :: rctx_field(), Num :: non_neg_integer(), Time :: pos_integer().
proc_window(AttrName, Num, Time) ->
Sample = fun() -> pid_ref_attrs(AttrName) end,
{First,Last} = recon_lib:sample(Time, Sample),
{First, Last} = recon_lib:sample(Time, Sample),
recon_lib:sublist_top_n_attrs(recon_lib:sliding_window(First, Last), Num).

-spec add_matcher(Name, MSpec, Matchers) -> {ok, matchers()} | {error, badarg} when
Expand Down
7 changes: 6 additions & 1 deletion src/couch_stats/src/csrt_util.erl
Original file line number Diff line number Diff line change
Expand Up @@ -433,7 +433,12 @@ fabric_conf_key(Key) ->
%% Double underscore to separate Mod and Func
"fabric_rpc__" ++ atom_to_list(Key).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That would be a great place to optimize in the future. Maybe add a TODO. One strategy is to implement the set_fabric_conf_key and call it from set_fabric_init_p. The implementation would store the mapping of keys to "fabric_rpc__" in persistent term.

Copy link
Contributor

@iilyak iilyak Jun 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe use memoize here

fabric_conf_key(Key) ->
    case persistent_term:get({{?MODULE, fabric_conf_key}, Key}, undefined) of
        undefined ->
            %% Double underscore to separate Mod and Func
            ConfKey = "fabric_rpc__" ++ atom_to_list(Key),
            ok = persistent_term:put({{?MODULE, fabric_conf_key}, Key}, ConfKey),
            ConfKey;
        ConfKey ->
            ConfKey
    end.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I also came up with this ugly monster.

-define(MEMOIZED(Id, Key, Body),
    case persistent_term:get({{?MODULE, Id}, Key}, undefined) of
        undefined ->
            V = Body,
            ok = persistent_term:put({{?MODULE, Id}, Key}, V),
            V;
        Value ->
            Value
    end
).

fabric_conf_key_m(Key) ->
    ?MEMOIZED(?FUNCTION_NAME, Key, "fabric_rpc__" ++ atom_to_list(Key)).

This also works

-define(MEMOIZED(Key, Body),
    case persistent_term:get({{?MODULE, ?FUNCTION_NAME}, Key}, undefined) of
        undefined ->
            V = Body,
            ok = persistent_term:put({{?MODULE, ?FUNCTION_NAME}, Key}, V),
            V;
        Value ->
            Value
    end
).

fabric_conf_key_m(Key) ->
    ?MEMOIZED(Key, "fabric_rpc__" ++ atom_to_list(Key)).

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

And finally a version suitable for inclusion into couch_util to update similar places in CouchDB codebase

% src/couch/include/couch_db.hrl
-define(PREFIXED_ATOM_AS_STRING(Prefix, Key), couch_util:prefixed_atom_as_string(?MODULE, Prefix, Key)).

% src/couch/src/couch_util.erl
prefixed_atom_as_string(Scope, Prefix, Key) ->
    case persistent_term:get({{Scope, Prefix}, Key}, undefined) of
        undefined ->
            V = Prefix ++ atom_to_list(Key),
            ok = persistent_term:put({{Scope, Prefix}, Key}, V),
            V;
        Value ->
            Value
    end.

% src/couch_stats/src/csrt_util.erl
fabric_conf_key(Key) ->
    ?PREFIXED_ATOM_AS_STRING("fabric_rpc__", Key).


-spec rctx_record_info() -> #{fields => [rctx_field()], size => pos_integer(), field_idx => #{rctx_field() => pos_integer()}}.
-spec rctx_record_info() ->
#{
fields => [rctx_field()],
size => pos_integer(),
field_idx => #{rctx_field() => pos_integer()}
}.
rctx_record_info() ->
Fields = record_info(fields, rctx),
Size = record_info(size, rctx),
Expand Down