summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJay Doane <jaydoane@apache.org>2021-04-19 15:31:47 -0700
committerJay Doane <jaydoane@apache.org>2021-04-20 00:12:57 -0700
commit532052e6c4c5d1c9bc0e43dcca2ba784acedf36d (patch)
tree599ca26c94f670a6fad55286f0254d0a8062952f
parent62e22e34bed9dceeba5cd0a7d5a593939c93220f (diff)
downloadcouchdb-532052e6c4c5d1c9bc0e43dcca2ba784acedf36d.tar.gz
Support default IOQ in weatherreport
weatherreport previously relied on Cloudant's IOQ implementation. This adds support for the default IOQ so that it works with either.
-rw-r--r--src/ioq/src/ioq.erl10
-rw-r--r--src/weatherreport/src/weatherreport_check_ioq.erl19
2 files changed, 28 insertions, 1 deletions
diff --git a/src/ioq/src/ioq.erl b/src/ioq/src/ioq.erl
index 99b3ce385..3da640e47 100644
--- a/src/ioq/src/ioq.erl
+++ b/src/ioq/src/ioq.erl
@@ -15,6 +15,7 @@
-behaviour(config_listener).
-export([start_link/0, call/3]).
+-export([get_queue_lengths/0]).
-export([init/1, handle_call/3, handle_cast/2, handle_info/2, code_change/3, terminate/2]).
% config_listener api
@@ -50,6 +51,9 @@ call(Fd, Msg, Metadata) ->
queued_call(Fd, Msg, Priority)
end.
+get_queue_lengths() ->
+ gen_server:call(?MODULE, get_queue_lengths).
+
bypass(Priority) ->
config:get("ioq.bypass", atom_to_list(Priority)) =:= "true".
@@ -91,6 +95,12 @@ read_config(State) ->
Concurrency = list_to_integer(config:get("ioq", "concurrency", "10")),
State#state{concurrency=Concurrency, ratio=Ratio}.
+handle_call(get_queue_lengths, _From, State) ->
+ Response = #{
+ interactive => queue:len(State#state.interactive),
+ background => queue:len(State#state.background)
+ },
+ {reply, Response, State, 0};
handle_call(#request{}=Request, From, State) ->
{noreply, enqueue_request(Request#request{from=From}, State), 0}.
diff --git a/src/weatherreport/src/weatherreport_check_ioq.erl b/src/weatherreport/src/weatherreport_check_ioq.erl
index de0d8b155..2c25964ef 100644
--- a/src/weatherreport/src/weatherreport_check_ioq.erl
+++ b/src/weatherreport/src/weatherreport_check_ioq.erl
@@ -62,7 +62,24 @@ sum_queues([{_Name, Value} | Rest], Acc) ->
sum_queues(Rest, Acc + Value).
-spec check(list()) -> [{atom(), term()}].
-check(_Opts) ->
+check(Opts) ->
+ case erlang:function_exported(ioq, get_queue_lengths, 0) of
+ true ->
+ case ioq:get_queue_lengths() of
+ Queues when is_map(Queues) ->
+ Total = maps:fold(fun(_Key, Val, Acc) ->
+ Val + Acc
+ end, 0, Queues),
+ [{total_to_level(Total), {ioq_requests, Total, Queues}}];
+ Error ->
+ [{warning, {ioq_requests_unknown, Error}}]
+ end;
+ false ->
+ check_legacy(Opts)
+ end.
+
+-spec check_legacy(list()) -> [{atom(), term()}].
+check_legacy(_Opts) ->
case ioq:get_disk_queues() of
Queues when is_list(Queues) ->
Total = sum_queues(Queues, 0),