This is an automated email from the ASF dual-hosted git repository. chewbranca pushed a commit to branch couch-stats-resource-tracker-v3-rebase-http-main in repository https://gitbox.apache.org/repos/asf/couchdb.git
commit 927c5729db82e2a4119dd7054c15320c0da1175e Author: Russell Branca <[email protected]> AuthorDate: Tue Jun 24 20:22:36 2025 -0700 make erlfmt-format --- src/chttpd/src/chttpd_node.erl | 10 ++++- src/couch_stats/src/csrt.erl | 79 ++++++++++++++++++++++++-------------- src/couch_stats/src/csrt_httpd.erl | 3 +- 3 files changed, 60 insertions(+), 32 deletions(-) diff --git a/src/chttpd/src/chttpd_node.erl b/src/chttpd/src/chttpd_node.erl index f08530ce1..3869b279a 100644 --- a/src/chttpd/src/chttpd_node.erl +++ b/src/chttpd/src/chttpd_node.erl @@ -178,7 +178,11 @@ handle_node_req(#httpd{method = 'POST', path_parts = [_, Node, <<"_restart">>]} send_json(Req, 200, {[{ok, true}]}); handle_node_req(#httpd{path_parts = [_, _Node, <<"_restart">>]} = Req) -> send_method_not_allowed(Req, "POST"); -handle_node_req(#httpd{method = 'GET', path_parts = [_, Node, <<"_active_resources">>, <<"_match">>, MatcherName]} = Req) -> +handle_node_req( + #httpd{ + method = 'GET', path_parts = [_, Node, <<"_active_resources">>, <<"_match">>, MatcherName] + } = Req +) -> case call_node(Node, csrt, query_matcher, [binary_to_list(MatcherName)]) of {ok, Rctxs} -> send_json(Req, 200, Rctxs); @@ -187,7 +191,9 @@ handle_node_req(#httpd{method = 'GET', path_parts = [_, Node, <<"_active_resourc {error, Reason} -> throw({bad_request, Reason}) end; -handle_node_req(#httpd{method = _, path_parts = [_, _Node, <<"_active_resources">>, <<"_match">> | _]} = Req) -> +handle_node_req( + #httpd{method = _, path_parts = [_, _Node, <<"_active_resources">>, <<"_match">> | _]} = Req +) -> send_method_not_allowed(Req, "GET"); handle_node_req(#httpd{ path_parts = [_, Node | PathParts], diff --git a/src/couch_stats/src/csrt.erl b/src/couch_stats/src/csrt.erl index 1efdf5ec3..d432ea990 100644 --- a/src/couch_stats/src/csrt.erl +++ b/src/couch_stats/src/csrt.erl @@ -125,32 +125,53 @@ rpc(FName, Args) when is_atom(FName) andalso is_list(Args) -> {Results, lists:usort(Errors), BadNodes}. split_response(Resp) -> - lists:foldl(fun(Message, {Results, Errors}) -> - case Message of - {badrpc, _} = E -> - {Results, [E | Errors]}; - Result -> - {[Result | Results], Errors} - end - end, {[], []}, Resp). - -call({active, []}) -> {node(), active()}; -call({active, [json]}) -> {node(), active(json)}; -call({active_coordinators, []}) -> {node(), active_coordinators()}; -call({active_coordinators, [json]}) -> {node(), active_coordinators(json)}; -call({active_workers, []}) -> {node(), active_workers()}; -call({active_workers, [json]}) -> {node(), active_workers(json)}; -call({count_by, [Key]}) -> {node(), count_by(Key)}; -call({find_by_nonce, [Nonce]}) -> {node(), find_by_nonce(Nonce)}; -call({find_by_pid, [Pid]}) -> {node(), find_by_pid(Pid)}; -call({find_by_pidref, [PidRef]}) -> {node(), find_by_pidref(PidRef)}; -call({find_workers_by_pidref, [PidRef]}) -> {node(), find_workers_by_pidref(PidRef)}; -call({group_by, [Key, Val]}) -> {node(), group_by(Key, Val)}; -call({group_by, [Key, Val, Agg]}) -> {node(), group_by(Key, Val, Agg)}; -call({sorted, [Map]}) -> {node(), sorted(Map)}; -call({sorted_by, [Key]}) -> {node(), sorted_by(Key)}; -call({sorted_by, [Key, Val]}) -> {node(), sorted_by(Key, Val)}; -call({sorted_by, [Key, Val, Agg]}) -> {node(), sorted_by(Key, Val, Agg)}; + lists:foldl( + fun(Message, {Results, Errors}) -> + case Message of + {badrpc, _} = E -> + {Results, [E | Errors]}; + Result -> + {[Result | Results], Errors} + end + end, + {[], []}, + Resp + ). + +call({active, []}) -> + {node(), active()}; +call({active, [json]}) -> + {node(), active(json)}; +call({active_coordinators, []}) -> + {node(), active_coordinators()}; +call({active_coordinators, [json]}) -> + {node(), active_coordinators(json)}; +call({active_workers, []}) -> + {node(), active_workers()}; +call({active_workers, [json]}) -> + {node(), active_workers(json)}; +call({count_by, [Key]}) -> + {node(), count_by(Key)}; +call({find_by_nonce, [Nonce]}) -> + {node(), find_by_nonce(Nonce)}; +call({find_by_pid, [Pid]}) -> + {node(), find_by_pid(Pid)}; +call({find_by_pidref, [PidRef]}) -> + {node(), find_by_pidref(PidRef)}; +call({find_workers_by_pidref, [PidRef]}) -> + {node(), find_workers_by_pidref(PidRef)}; +call({group_by, [Key, Val]}) -> + {node(), group_by(Key, Val)}; +call({group_by, [Key, Val, Agg]}) -> + {node(), group_by(Key, Val, Agg)}; +call({sorted, [Map]}) -> + {node(), sorted(Map)}; +call({sorted_by, [Key]}) -> + {node(), sorted_by(Key)}; +call({sorted_by, [Key, Val]}) -> + {node(), sorted_by(Key, Val)}; +call({sorted_by, [Key, Val, Agg]}) -> + {node(), sorted_by(Key, Val, Agg)}; call({FunName, Args}) -> FunNameBin = atom_to_binary(FunName), ArityBin = integer_to_binary(length(Args)), @@ -489,12 +510,14 @@ pid_ref_attrs(AttrName) -> proc_window(AttrName, Num, Time) -> csrt_logger:proc_window(AttrName, Num, Time). --spec query_matcher(MatcherName :: matcher_name()) -> {ok, query_result()} +-spec query_matcher(MatcherName :: matcher_name()) -> + {ok, query_result()} | {error, any()}. query_matcher(MatcherName) -> csrt_query:query_matcher(MatcherName). --spec query_matcher(MatcherName :: matcher_name(), Limit :: pos_integer()) -> {ok, query_result()} +-spec query_matcher(MatcherName :: matcher_name(), Limit :: pos_integer()) -> + {ok, query_result()} | {error, any()}. query_matcher(MatcherName, Limit) -> csrt_query:query_matcher(MatcherName, Limit). diff --git a/src/couch_stats/src/csrt_httpd.erl b/src/couch_stats/src/csrt_httpd.erl index a14d219fa..cf6f56437 100644 --- a/src/couch_stats/src/csrt_httpd.erl +++ b/src/couch_stats/src/csrt_httpd.erl @@ -59,7 +59,6 @@ handle_resource_status_req( handle_resource_status_req(#httpd{path_parts = [<<"_active_resources">>]} = Req) -> ok = chttpd:verify_is_server_admin(Req), send_method_not_allowed(Req, "GET,HEAD"); - handle_resource_status_req(Req) -> ok = chttpd:verify_is_server_admin(Req), send_method_not_allowed(Req, "GET,HEAD,POST"). @@ -166,4 +165,4 @@ send_error(Req, {unknown_matcher, Matcher}) -> send_error(Req, {invalid_key, FieldName}) -> chttpd:send_error(Req, {bad_request, <<"Unknown field name '", FieldName/binary, "'">>}); send_error(Req, Reason) -> - chttpd:send_error(Req, {error, Reason}). \ No newline at end of file + chttpd:send_error(Req, {error, Reason}).
