RPC: prevalidator worker introspection
This commit is contained in:
parent
98ec3393b6
commit
4e04e233a0
@ -525,6 +525,52 @@ module Protocols = struct
|
||||
|
||||
end
|
||||
|
||||
module Workers = struct
|
||||
|
||||
module Prevalidators = struct
|
||||
|
||||
let (net_id_arg : Net_id.t RPC_arg.t) =
|
||||
RPC_arg.make
|
||||
~name:"net_id"
|
||||
~descr:"The network identifier of whom the prevalidator 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 Prevalidator 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" / "prevalidators")
|
||||
|
||||
let state =
|
||||
let open Data_encoding in
|
||||
RPC_service.post_service
|
||||
~description:"Introspect the state of a prevalidator worker."
|
||||
~query: RPC_query.empty
|
||||
~error: Data_encoding.empty
|
||||
~input: empty
|
||||
~output:
|
||||
(Worker_types.full_status_encoding
|
||||
Prevalidator_worker_state.Request.encoding
|
||||
(Prevalidator_worker_state.Event.encoding Error.encoding)
|
||||
Error.encoding)
|
||||
RPC_path.(root / "workers" / "prevalidators" /: net_id_arg )
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
||||
module Network = struct
|
||||
|
||||
open P2p_types
|
||||
|
@ -170,6 +170,26 @@ module Protocols : sig
|
||||
|
||||
end
|
||||
|
||||
module Workers : sig
|
||||
|
||||
module Prevalidators : sig
|
||||
|
||||
open Prevalidator_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
|
||||
|
||||
val stat :
|
||||
|
@ -452,6 +452,25 @@ let build_rpc_directory node =
|
||||
(fun block s () () ->
|
||||
Node.RPC.complete node ~block s >>= RPC_answer.return) in
|
||||
|
||||
(* Workers : Prevalidators *)
|
||||
|
||||
let dir =
|
||||
RPC_directory.register0 dir Services.Workers.Prevalidators.list
|
||||
(fun () () ->
|
||||
RPC_answer.return
|
||||
(List.map
|
||||
(fun (id, w) -> (id, Prevalidator.status w))
|
||||
(Prevalidator.running_workers ()))) in
|
||||
let dir =
|
||||
RPC_directory.register1 dir Services.Workers.Prevalidators.state
|
||||
(fun net_id () () ->
|
||||
let w = List.assoc net_id (Prevalidator.running_workers ()) in
|
||||
RPC_answer.return
|
||||
{ Worker_types.status = Prevalidator.status w ;
|
||||
pending_requests = Prevalidator.pending_requests w ;
|
||||
backlog = Prevalidator.last_events w ;
|
||||
current_request = Prevalidator.current_request w }) in
|
||||
|
||||
(* Network : Global *)
|
||||
|
||||
let dir =
|
||||
|
Loading…
Reference in New Issue
Block a user