RPC: net validator worker introspection

This commit is contained in:
Benjamin Canou 2018-01-22 18:08:41 +01:00 committed by Grégoire Henry
parent 0779221d04
commit 6f34b85504
3 changed files with 77 additions and 0 deletions

View File

@ -637,6 +637,47 @@ module Workers = struct
end
module Net_validators = struct
let (net_id_arg : Net_id.t RPC_arg.t) =
RPC_arg.make
~name:"net_id"
~descr:"The network identifier of whom the net validator is responsible."
~destruct:(fun s -> try
Ok (Net_id.of_b58check_exn s)
with Failure msg -> Error msg)
~construct:Net_id.to_b58check
()
let list =
RPC_service.post_service
~description:"Lists the net validator workers and their status."
~query: RPC_query.empty
~error: Data_encoding.empty
~input: empty
~output:
(list
(obj2
(req "net_id" Net_id.encoding)
(req "status" (Worker_types.worker_status_encoding Error.encoding))))
RPC_path.(root / "workers" / "net_validators")
let state =
let open Data_encoding in
RPC_service.post_service
~description:"Introspect the state of a net validator worker."
~query: RPC_query.empty
~error: Data_encoding.empty
~input: empty
~output:
(Worker_types.full_status_encoding
Net_validator_worker_state.Request.encoding
(Net_validator_worker_state.Event.encoding Error.encoding)
Error.encoding)
RPC_path.(root / "workers" / "net_validators" /: net_id_arg )
end
end

View File

@ -218,6 +218,23 @@ module Workers : sig
end
module Net_validators : sig
open Net_validator_worker_state
val list :
([ `POST ], unit,
unit, unit, unit,
(Net_id.t * Worker_types.worker_status) list, unit) RPC_service.t
val state :
([ `POST ], unit,
unit * Net_id.t, unit, unit,
(Request.view, Event.t) Worker_types.full_status, unit)
RPC_service.t
end
end
module Network : sig

View File

@ -505,6 +505,25 @@ let build_rpc_directory node =
backlog = Peer_validator.last_events w ;
current_request = Peer_validator.current_request w }) in
(* Workers : Net validators *)
let dir =
RPC_directory.register0 dir Services.Workers.Net_validators.list
(fun () () ->
RPC_answer.return
(List.map
(fun (id, w) -> (id, Net_validator.status w))
(Net_validator.running_workers ()))) in
let dir =
RPC_directory.register1 dir Services.Workers.Net_validators.state
(fun net_id () () ->
let w = List.assoc net_id (Net_validator.running_workers ()) in
RPC_answer.return
{ Worker_types.status = Net_validator.status w ;
pending_requests = Net_validator.pending_requests w ;
backlog = Net_validator.last_events w ;
current_request = Net_validator.current_request w }) in
(* Network : Global *)
let dir =