RPC: peer validator worker introspection

This commit is contained in:
Benjamin Canou 2018-01-22 18:06:18 +01:00 committed by Grégoire Henry
parent ecbf1805e1
commit e5405c2f72
3 changed files with 90 additions and 0 deletions

View File

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

View File

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

View File

@ -483,6 +483,28 @@ let build_rpc_directory node =
backlog = Block_validator.last_events w ;
current_request = Block_validator.current_request w }) in
(* Workers : Peer validators *)
let dir =
RPC_directory.register1 dir Services.Workers.Peer_validators.list
(fun net_id () () ->
RPC_answer.return
(List.filter_map
(fun ((id, peer_id), w) ->
if Net_id.equal id net_id then
Some (peer_id, Peer_validator.status w)
else None)
(Peer_validator.running_workers ()))) in
let dir =
RPC_directory.register2 dir Services.Workers.Peer_validators.state
(fun net_id peer_id () () ->
let w = List.assoc (net_id, peer_id) (Peer_validator.running_workers ()) in
RPC_answer.return
{ Worker_types.status = Peer_validator.status w ;
pending_requests = [] ;
backlog = Peer_validator.last_events w ;
current_request = Peer_validator.current_request w }) in
(* Network : Global *)
let dir =