chewbranca commented on code in PR #5602:
URL: https://github.com/apache/couchdb/pull/5602#discussion_r2221247786


##########
src/couch_stats/src/csrt_util.erl:
##########
@@ -0,0 +1,386 @@
+% 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_util).
+
+-export([
+    is_enabled/0,
+    is_enabled_init_p/0,
+    is_enabled_reporting/0,
+    is_enabled_rpc_reporting/0,
+    get_pid_ref/0,
+    get_pid_ref/1,
+    set_pid_ref/1,
+    should_track_init_p/2,
+    tnow/0,
+    tutc/0,
+    tutc/1
+]).
+
+%% Delta API
+-export([
+    add_delta/2,
+    extract_delta/1,
+    get_delta/1,
+    get_delta_a/0,
+    get_updated_at/0,
+    maybe_add_delta/1,
+    maybe_add_delta/2,
+    make_delta/1,
+    make_dt/2,
+    make_dt/3,
+    rctx_delta/2,
+    put_delta_a/1,
+    put_updated_at/1
+]).
+
+%% Extra niceties and testing facilities
+-export([
+    set_fabric_init_p/2,
+    set_fabric_init_p/3
+]).
+
+-include_lib("csrt.hrl").
+
+-ifdef(TEST).
+-spec is_enabled() -> boolean().
+is_enabled() ->
+    %% randomly enable CSRT during testing to handle unexpected failures
+    case config:get_boolean(?CSRT, "randomize_testing", true) of
+        true ->
+            rand:uniform(100) > 80;
+        false ->
+            config:get_boolean(?CSRT, "enable", true)
+    end.
+-else.
+-spec is_enabled() -> boolean().
+is_enabled() ->
+    %% TODO: toggle back to false before merging
+    config:get_boolean(?CSRT, "enable", true).
+-endif.
+
+-spec is_enabled_init_p() -> boolean().
+is_enabled_init_p() ->
+    %% TODO: toggle back to false before merging
+    config:get_boolean(?CSRT, "enable_init_p", true).
+
+-spec should_track_init_p(Mod :: atom(), Func :: atom()) -> boolean().
+should_track_init_p(fabric_rpc, Func) ->
+    is_enabled_init_p() andalso config:get_boolean(?CSRT_INIT_P, 
fabric_conf_key(Func), false);
+should_track_init_p(_Mod, _Func) ->
+    false.
+
+%% Toggle to disable all reporting
+-spec is_enabled_reporting() -> boolean().
+is_enabled_reporting() ->
+    %% TODO: toggle back to false before merging
+    config:get_boolean(?CSRT, "enable_reporting", true).
+
+%% Toggle to disable all reporting from #rpc_worker{} types, eg only log
+%% #coordinator{} types. This is a bit of a kludge that would be better served
+%% by a dynamic match spec generator, but this provides a know for disabling
+%% any rpc worker logs, even if they hit the normal logging Threshold's.
+-spec is_enabled_rpc_reporting() -> boolean().
+is_enabled_rpc_reporting() ->
+    config:get_boolean(?CSRT, "enable_rpc_reporting", false).
+
+%% Monotnonic time now in native format using time forward only event tracking
+-spec tnow() -> integer().
+tnow() ->
+    erlang:monotonic_time().
+
+%% Get current system time in UTC RFC 3339 format
+-spec tutc() -> calendar:rfc3339_string().
+tutc() ->
+    tutc(tnow()).
+
+%% Convert a integer system time in milliseconds into UTC RFC 3339 format

Review Comment:
   Aha, good catch and suggestion! I've fixed that and updated the comment to 
drop mention of milliseconds. That was from when the deltas were in 
milliseconds rather than native format, I switched that over a while back.



-- 
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]

Reply via email to