You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2025/03/11 16:17:12 UTC

(couchdb) 02/06: s/couch_stats_resource_tracker:/csrt:/

This is an automated email from the ASF dual-hosted git repository.

chewbranca pushed a commit to branch couch-stats-resource-tracker-v3
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 095ba8d4fa02ae3d303fd4a8cdd0f5a7f5550be3
Author: Russell Branca <ch...@apache.org>
AuthorDate: Thu Jan 9 17:53:47 2025 -0800

    s/couch_stats_resource_tracker:/csrt:/
---
 src/chttpd/src/chttpd.erl           | 14 +++++++-------
 src/chttpd/src/chttpd_db.erl        |  4 ++--
 src/chttpd/src/chttpd_misc.erl      | 12 ++++++------
 src/couch_stats/src/csrt_logger.erl |  6 +++---
 src/fabric/src/fabric_rpc.erl       |  6 +++---
 src/fabric/src/fabric_util.erl      |  2 +-
 src/ioq/src/ioq.erl                 |  2 +-
 src/mem3/src/mem3_rpc.erl           |  2 +-
 src/rexi/src/rexi_server.erl        |  8 ++++----
 src/rexi/src/rexi_utils.erl         |  8 ++++----
 10 files changed, 32 insertions(+), 32 deletions(-)

diff --git a/src/chttpd/src/chttpd.erl b/src/chttpd/src/chttpd.erl
index 99220a0b0..a8dec6517 100644
--- a/src/chttpd/src/chttpd.erl
+++ b/src/chttpd/src/chttpd.erl
@@ -324,8 +324,8 @@ handle_request_int(MochiReq) ->
     chttpd_util:mochiweb_client_req_set(MochiReq),
 
     %% This is probably better in before_request, but having Path is nice
-    couch_stats_resource_tracker:create_coordinator_context(HttpReq0, Path),
-    couch_stats_resource_tracker:set_context_handler_fun(?MODULE, ?FUNCTION_NAME),
+    csrt:create_coordinator_context(HttpReq0, Path),
+    csrt:set_context_handler_fun(?MODULE, ?FUNCTION_NAME),
 
     {HttpReq2, Response} =
         case before_request(HttpReq0) of
@@ -357,7 +357,7 @@ handle_request_int(MochiReq) ->
 
 before_request(HttpReq) ->
     try
-        couch_stats_resource_tracker:set_context_handler_fun(?MODULE, ?FUNCTION_NAME),
+        csrt:set_context_handler_fun(?MODULE, ?FUNCTION_NAME),
         chttpd_stats:init(),
         chttpd_plugin:before_request(HttpReq)
     catch
@@ -378,7 +378,7 @@ after_request(HttpReq, HttpResp0) ->
     chttpd_stats:report(HttpReq, HttpResp2),
     maybe_log(HttpReq, HttpResp2),
     %% NOTE: do not set_context_handler_fun to preserve the Handler
-    couch_stats_resource_tracker:destroy_context(),
+    csrt:destroy_context(),
     HttpResp2.
 
 process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
@@ -391,7 +391,7 @@ process_request(#httpd{mochi_req = MochiReq} = HttpReq) ->
     RawUri = MochiReq:get(raw_path),
 
     try
-        couch_stats_resource_tracker:set_context_handler_fun(?MODULE, ?FUNCTION_NAME),
+        csrt:set_context_handler_fun(?MODULE, ?FUNCTION_NAME),
         couch_httpd:validate_host(HttpReq),
         check_request_uri_length(RawUri),
         check_url_encoding(RawUri),
@@ -417,12 +417,12 @@ handle_req_after_auth(HandlerKey, HttpReq) ->
             HandlerKey,
             fun chttpd_db:handle_request/1
         ),
-        couch_stats_resource_tracker:set_context_handler_fun(HandlerFun),
+        csrt:set_context_handler_fun(HandlerFun),
         AuthorizedReq = chttpd_auth:authorize(
             possibly_hack(HttpReq),
             fun chttpd_auth_request:authorize_request/1
         ),
-        couch_stats_resource_tracker:set_context_username(AuthorizedReq),
+        csrt:set_context_username(AuthorizedReq),
         {AuthorizedReq, HandlerFun(AuthorizedReq)}
     catch
         ErrorType:Error:Stack ->
diff --git a/src/chttpd/src/chttpd_db.erl b/src/chttpd/src/chttpd_db.erl
index 8a816abde..4643693e1 100644
--- a/src/chttpd/src/chttpd_db.erl
+++ b/src/chttpd/src/chttpd_db.erl
@@ -83,7 +83,7 @@
 
 % Database request handlers
 handle_request(#httpd{path_parts = [DbName | RestParts], method = Method} = Req) ->
-    couch_stats_resource_tracker:set_context_dbname(DbName),
+    csrt:set_context_dbname(DbName),
     case {Method, RestParts} of
         {'PUT', []} ->
             create_db_req(Req, DbName);
@@ -104,7 +104,7 @@ handle_request(#httpd{path_parts = [DbName | RestParts], method = Method} = Req)
             do_db_req(Req, fun db_req/2);
         {_, [SecondPart | _]} ->
             Handler = chttpd_handlers:db_handler(SecondPart, fun db_req/2),
-            couch_stats_resource_tracker:set_context_handler_fun(Handler),
+            csrt:set_context_handler_fun(Handler),
             do_db_req(Req, Handler)
     end.
 
diff --git a/src/chttpd/src/chttpd_misc.erl b/src/chttpd/src/chttpd_misc.erl
index add5443f9..73b4fca2b 100644
--- a/src/chttpd/src/chttpd_misc.erl
+++ b/src/chttpd/src/chttpd_misc.erl
@@ -233,13 +233,13 @@ handle_resource_status_req(#httpd{method = 'POST'} = Req) ->
     Key = proplists:get_value(<<"key">>, Props),
     Val = proplists:get_value(<<"val">>, Props),
 
-    CountBy = fun couch_stats_resource_tracker:count_by/1,
-    GroupBy = fun couch_stats_resource_tracker:group_by/2,
-    SortedBy1 = fun couch_stats_resource_tracker:sorted_by/1,
-    SortedBy2 = fun couch_stats_resource_tracker:sorted_by/2,
+    CountBy = fun csrt:count_by/1,
+    GroupBy = fun csrt:group_by/2,
+    SortedBy1 = fun csrt:sorted_by/1,
+    SortedBy2 = fun csrt:sorted_by/2,
     ConvertEle = fun erlang:binary_to_existing_atom/1,
     ConvertList = fun(L) -> [ConvertEle(E) || E <- L] end,
-    ToJson = fun couch_stats_resource_tracker:term_to_flat_json/1,
+    ToJson = fun csrt:to_json/1,
     JsonKeys = fun(PL) -> [[ToJson(K), V] || {K, V} <- PL] end,
 
     Fun = case {Action, Key, Val} of
@@ -318,7 +318,7 @@ handle_resource_status_req(#httpd{method = 'GET'} = Req) ->
     ok = chttpd:verify_is_server_admin(Req),
     {Resp, Bad} = rpc:multicall(erlang, apply, [
         fun() ->
-            {node(), couch_stats_resource_tracker:active()}
+            {node(), csrt:active()}
         end,
         []
     ]),
diff --git a/src/couch_stats/src/csrt_logger.erl b/src/couch_stats/src/csrt_logger.erl
index c4e064bf3..e4df3d053 100644
--- a/src/couch_stats/src/csrt_logger.erl
+++ b/src/couch_stats/src/csrt_logger.erl
@@ -141,7 +141,7 @@ log_level() ->
 
 
 maybe_report(PidRef) ->
-    Rctx = couch_stats_resource_tracker:get_resource(PidRef),
+    Rctx = csrt:get_resource(PidRef),
     case is_match(Rctx) of
         true ->
             report(Rctx),
@@ -154,7 +154,7 @@ maybe_report_old(PidRef) ->
     Level = log_level(),
     case Level > ?NO_LOG of
         true ->
-            Rctx = couch_stats_resource_tracker:get_resource(PidRef),
+            Rctx = csrt:get_resource(PidRef),
             RLevel = log_level(Rctx),
             %% io:format("CSRT LOGGER TRIGGERING{~p} ~p =<? ~p~n", [Rctx#rctx.type, RLevel, Level]),
             case RLevel >= Level of
@@ -257,7 +257,7 @@ maybe_report_int(#rctx{}=Rctx, _RLevel, _Level, #st{matchers=Matchers, should_tr
 report(Rctx) ->
     couch_log:report(
         "csrt-pid-usage-lifetime",
-        couch_stats_resource_tracker:to_json(Rctx)
+        csrt:to_json(Rctx)
     ).
 
 get_server() ->
diff --git a/src/fabric/src/fabric_rpc.erl b/src/fabric/src/fabric_rpc.erl
index 53b34f41a..16bea8433 100644
--- a/src/fabric/src/fabric_rpc.erl
+++ b/src/fabric/src/fabric_rpc.erl
@@ -497,7 +497,7 @@ view_cb({row, Props}, #mrargs{extra = Options} = Acc) ->
     %% TODO: wire in csrt tracking
     %% TODO: distinguish between all_docs vs view call
     couch_stats:increment_counter([fabric_rpc, view, rows_read]),
-    %%couch_stats_resource_tracker:inc(rows_read),
+    %%csrt:inc(rows_read),
     % Adding another row
     ViewRow = fabric_view_row:from_props(Props, Options),
     ok = rexi:stream2(ViewRow),
@@ -674,13 +674,13 @@ clean_stack(S) ->
     ).
 
 set_io_priority(DbName, Options) ->
-    couch_stats_resource_tracker:set_context_dbname(DbName),
+    csrt:set_context_dbname(DbName),
     %% TODO: better approach here than using proplists?
     case proplists:get_value(user_ctx, Options) of
         undefined ->
             ok;
         #user_ctx{name = UserName} ->
-            couch_stats_resource_tracker:set_context_username(UserName)
+            csrt:set_context_username(UserName)
     end,
     case lists:keyfind(io_priority, 1, Options) of
         {io_priority, Pri} ->
diff --git a/src/fabric/src/fabric_util.erl b/src/fabric/src/fabric_util.erl
index 52032f0ec..49130228c 100644
--- a/src/fabric/src/fabric_util.erl
+++ b/src/fabric/src/fabric_util.erl
@@ -145,7 +145,7 @@ await_shard_response(Ref, Name, Rest, Opts, Factor, Timeout) ->
     receive
         Msg0 ->
             {Msg, Delta} = rexi_utils:extract_delta(Msg0),
-            couch_stats_resource_tracker:accumulate_delta(Delta),
+            csrt:accumulate_delta(Delta),
             case Msg of
                 {Ref, {ok, Db}} ->
                     {ok, Db};
diff --git a/src/ioq/src/ioq.erl b/src/ioq/src/ioq.erl
index 8a7e68941..1324c07ff 100644
--- a/src/ioq/src/ioq.erl
+++ b/src/ioq/src/ioq.erl
@@ -59,7 +59,7 @@ call_search(Fd, Msg, Metadata) ->
     call(Fd, Msg, Metadata).
 
 call(Fd, Msg, Metadata) ->
-    couch_stats_resource_tracker:ioq_called(),
+    csrt:ioq_called(),
     Priority = io_class(Msg, Metadata),
     case bypass(Priority) of
         true ->
diff --git a/src/mem3/src/mem3_rpc.erl b/src/mem3/src/mem3_rpc.erl
index 81b4fec27..05b2d3773 100644
--- a/src/mem3/src/mem3_rpc.erl
+++ b/src/mem3/src/mem3_rpc.erl
@@ -393,7 +393,7 @@ wait_message(Node, Ref, Mon, Timeout) ->
 
 process_raw_message(Msg0, Node, Ref, Mon, Timeout) ->
     {Msg, Delta} = rexi_utils:extract_delta(Msg0),
-    couch_stats_resource_tracker:accumulate_delta(Delta),
+    csrt:accumulate_delta(Delta),
     case Msg of
         {Ref, {ok, Reply}} ->
             Reply;
diff --git a/src/rexi/src/rexi_server.erl b/src/rexi/src/rexi_server.erl
index 20a9f598e..ec35c9dc2 100644
--- a/src/rexi/src/rexi_server.erl
+++ b/src/rexi/src/rexi_server.erl
@@ -139,15 +139,15 @@ init_p(From, {M, F, A}, Nonce) ->
     put('$initial_call', MFA),
     put(nonce, Nonce),
     try
-        couch_stats_resource_tracker:create_worker_context(From, MFA, Nonce),
+        csrt:create_worker_context(From, MFA, Nonce),
         couch_stats:maybe_track_rexi_init_p(MFA),
         apply(M, F, A)
     catch
         exit:normal ->
-            couch_stats_resource_tracker:destroy_context(),
+            csrt:destroy_context(),
             ok;
         Class:Reason:Stack0 ->
-            couch_stats_resource_tracker:destroy_context(),
+            csrt:destroy_context(),
             Stack = clean_stack(Stack0),
             {ClientPid, _ClientRef} = From,
             couch_log:error(
@@ -163,7 +163,7 @@ init_p(From, {M, F, A}, Nonce) ->
                 ]
             ),
             exit(#error{
-                delta = couch_stats_resource_tracker:make_delta(),
+                delta = csrt:make_delta(),
                 timestamp = os:timestamp(),
                 reason = {Class, Reason},
                 mfa = {M, F, A},
diff --git a/src/rexi/src/rexi_utils.erl b/src/rexi/src/rexi_utils.erl
index 8b9855169..ea9aec16c 100644
--- a/src/rexi/src/rexi_utils.erl
+++ b/src/rexi/src/rexi_utils.erl
@@ -70,7 +70,7 @@ process_message(RefList, Keypos, Fun, Acc0, TimeoutRef, PerMsgTO) ->
 
 process_raw_message(Payload0, RefList, Keypos, Fun, Acc0, TimeoutRef) ->
     {Payload, Delta} = extract_delta(Payload0),
-    couch_stats_resource_tracker:accumulate_delta(Delta),
+    csrt:accumulate_delta(Delta),
     case Payload of
         {timeout, TimeoutRef} ->
             {timeout, Acc0};
@@ -128,10 +128,10 @@ extract_delta({A, B, C, D, E, F, G, {delta, Delta}}) -> {{A, B, C, D, E, F, G},
 extract_delta(T) -> {T, undefined}.
 
 get_delta() ->
-    {delta, couch_stats_resource_tracker:make_delta()}.
+    {delta, csrt:make_delta()}.
 
 maybe_add_delta(T) ->
-    case couch_stats_resource_tracker:is_enabled() of
+    case csrt:is_enabled() of
         false ->
             T;
         true ->
@@ -147,7 +147,7 @@ maybe_add_delta(T, undefined) ->
 maybe_add_delta(T, Delta) when is_map(Delta) ->
     maybe_add_delta(T, {delta, Delta});
 maybe_add_delta(T, {delta, _} = Delta) ->
-    case couch_stats_resource_tracker:is_enabled() of
+    case csrt:is_enabled() of
         false ->
             T;
         true ->