iilyak commented on code in PR #5491: URL: https://github.com/apache/couchdb/pull/5491#discussion_r2054405976
########## src/couch_stats/src/csrt_logger.erl: ########## @@ -0,0 +1,401 @@ +% Licensed under the Apache License, Version 2.0 (the "License"); you may not +% use this file except in compliance with the License. You may obtain a copy of +% the License at +% +% http://www.apache.org/licenses/LICENSE-2.0 +% +% Unless required by applicable law or agreed to in writing, software +% distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +% WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +% License for the specific language governing permissions and limitations under +% the License. + +-module(csrt_logger). + +%% Process lifetime logging api +-export([ + get_tracker/0, + log_process_lifetime_report/1, + put_tracker/1, + stop_tracker/0, + stop_tracker/1, + track/1, + tracker/1 +]). + +%% Raw API that bypasses is_enabled checks +-export([ + do_lifetime_report/1, + do_status_report/1, + do_report/2, + maybe_report/2 +]). + +-export([ + start_link/0, + init/1, + handle_call/3, + handle_cast/2, + handle_info/2 +]). + +%% Config update subscription API +-export([ + subscribe_changes/0, + handle_config_change/5, + handle_config_terminate/3 +]). + +%% Matchers +-export([ + get_matcher/1, + get_matchers/0, + is_match/1, + is_match/2, + matcher_on_dbname/1, + matcher_on_docs_read/1, + matcher_on_docs_written/1, + matcher_on_rows_read/1, + matcher_on_worker_changes_processed/1, + matcher_on_ioq_calls/1, + matcher_on_nonce/1, + reload_matchers/0 +]). + +-include_lib("stdlib/include/ms_transform.hrl"). +-include_lib("couch_stats_resource_tracker.hrl"). + +-define(MATCHERS_KEY, {?MODULE, all_csrt_matchers}). +-define(CONF_MATCHERS_ENABLED, "csrt_logger.matchers_enabled"). +-define(CONF_MATCHERS_THRESHOLD, "csrt_logger.matchers_threshold"). +-define(CONF_MATCHERS_DBNAMES, "csrt_logger.dbnames_io"). + +-record(st, { + matchers = #{} +}). + +-spec track(Rctx :: rctx()) -> pid(). +track(#rctx{pid_ref=PidRef}) -> + case get_tracker() of + undefined -> + Pid = spawn(?MODULE, tracker, [PidRef]), + put_tracker(Pid), + Pid; + Pid when is_pid(Pid) -> + Pid + end. + +-spec tracker(PidRef :: pid_ref()) -> ok. +tracker({Pid, _Ref}=PidRef) -> Review Comment: Nitpick. It would be best to minimize the number of places where we assume a specific structure. Since leaking implementation details and relying on them makes code harder to update. How about introducing a helper in `csrt_util` or `csrt_sever`? ```erlang tracker(PidRef) -> MonRef = csrt_server:monitor_pid_ref(PidRef), ... ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
