Documentation
¶
Overview ¶
Package client is a typed wrapper over grpcproc's Inspector, shared by grpcprocctl and its MCP server: flat, readable views of nodes, processes and events, target parsing, and a walk over every node of a cluster.
Index ¶
- func Leading(views []ElectorView) string
- func ParseKinds(names []string) ([]string, error)
- func ParseLevel(s string) (slog.Level, error)
- func SortProcesses(ps []ProcessView, by string) error
- type Client
- func (c *Client) Cluster(ctx context.Context) ([]NodeView, error)
- func (c *Client) Cordon(ctx context.Context, cluster, node string, off bool) (string, error)
- func (c *Client) Cron(ctx context.Context, node, target string) (CronView, error)
- func (c *Client) CronJob(ctx context.Context, node, target, op, job string) error
- func (c *Client) Crons(ctx context.Context, node string) ([]CronView, error)
- func (c *Client) Election(ctx context.Context, cluster string) ([]ElectorView, error)
- func (c *Client) Exit(ctx context.Context, node, target, reason string) error
- func (c *Client) MoveLeader(ctx context.Context, cluster, to string) (string, error)
- func (c *Client) Node(ctx context.Context, node string) (NodeView, error)
- func (c *Client) Process(ctx context.Context, node, target string, ask bool, wait time.Duration) (ProcessView, error)
- func (c *Client) Processes(ctx context.Context, node string, f Filter) ([]ProcessView, error)
- func (c *Client) SetLogLevel(ctx context.Context, node, target string, level slog.Level) error
- func (c *Client) Watch(ctx context.Context, node string, fn func(EventView) bool) error
- type CronJobView
- type CronView
- type ElectorView
- type EventView
- type Filter
- type LinkView
- type NodeView
- type ProcessView
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Leading ¶ added in v0.1.0
func Leading(views []ElectorView) string
Leading is the node views say leads: the leader of the highest term, or empty while none does.
func ParseKinds ¶ added in v0.0.4
ParseKinds checks names of event kinds (spawn, exit, link-up, link-down, dead-letter), trimming spaces, and returns them.
func ParseLevel ¶
ParseLevel reads a log level: debug, info, warn, error (each with an optional offset, as in debug-4), or a number. It must fit the Inspector's int32.
func SortProcesses ¶
func SortProcesses(ps []ProcessView, by string) error
SortProcesses orders ps by pid (as listed), or by mailbox, received or sent, largest first.
Types ¶
type Client ¶
type Client struct {
// contains filtered or unexported fields
}
Client talks to one Inspector; requests about other nodes are forwarded by it.
func New ¶
func New(cc grpc.ClientConnInterface) *Client
New wraps a connection to a node serving grpcproc.inspect.v1.Inspector.
func (*Client) Cluster ¶
Cluster describes every node reachable from this one by following links, in the order found. A node that cannot be reached is reported with Error, and so is a peer a node only fails to dial (a down link), which this Inspector may reach all the same. Those peers are asked last, and together: they are the likeliest to hang until ctx ends, and one that does must not use up the time the others need.
func (*Client) Cordon ¶ added in v0.1.0
Cordon keeps node from leading cluster, or, with off, lets it lead again. It returns the node that led, once a majority holds the change; if node was that leader, it is handing over.
func (*Client) CronJob ¶ added in v0.1.0
CronJob changes the job called job of a cron process, found as Process finds one: enable, disable or remove it. The process answers once it has.
func (*Client) Crons ¶ added in v0.1.0
Crons describes the cron processes of node, or of every node reachable from this one when node is empty, in the order Cluster finds the nodes and by PID on each. A node that cannot be asked is left out; so is one with no cron process.
func (*Client) Election ¶ added in v0.1.0
Election describes the election called cluster on every node reachable from this one that takes part in it, in the order Cluster finds them. A node that runs no elector for it is left out; one that cannot be asked is listed with its Error.
func (*Client) MoveLeader ¶ added in v0.1.0
MoveLeader asks the leader of cluster to hand over: to the node to, or, with to empty, to the follower with the latest state. It returns the node that led, once that node has told its successor to campaign.
func (*Client) Process ¶
func (c *Client) Process(ctx context.Context, node, target string, ask bool, wait time.Duration) (ProcessView, error)
Process describes one process; with ask, also what it publishes about itself, waiting up to wait for a busy process to answer.
func (*Client) SetLogLevel ¶
SetLogLevel sets a process's log threshold.
type CronJobView ¶ added in v0.1.0
type CronJobView struct {
Name string `json:"name"`
Spec string `json:"spec" jsonschema:"when it runs, in crontab syntax"`
Location string `json:"location" jsonschema:"the time zone its spec is read in"`
Next string `json:"next,omitempty" jsonschema:"when it runs next, in its zone"`
Last string `json:"last,omitempty" jsonschema:"the minute its last run was due, in its zone"`
Running int `json:"running,omitzero" jsonschema:"its runs going now"`
Disabled bool `json:"disabled,omitzero" jsonschema:"kept, but not run, until enabled"`
Failure string `json:"failure,omitempty" jsonschema:"why its last failed run failed: the error it returned, a panic, timeout or replaced"`
}
CronJobView is one job of a cron process, as the process publishes it.
type CronView ¶ added in v0.1.0
type CronView struct {
Node string `json:"node"`
// Process is the cron process's registered name, or its pid.
Process string `json:"process"`
PID string `json:"pid"`
Jobs []CronJobView `json:"jobs"`
Error string `json:"error,omitempty" jsonschema:"why its jobs could not be read: it is busy, or gone"`
}
CronView is a grpcproc/cron process and its jobs.
type ElectorView ¶ added in v0.1.0
type ElectorView struct {
Node string `json:"node"`
Role string `json:"role,omitempty" jsonschema:"leader, candidate, follower, or unclustered (its view is too small to elect)"`
Term uint64 `json:"term,omitzero"`
Leader string `json:"leader,omitempty" jsonschema:"the node it follows; empty while it knows none"`
VotedFor string `json:"voted_for,omitempty"`
View []string `json:"view,omitempty" jsonschema:"the nodes whose majority elects"`
Quorum int `json:"quorum,omitzero"`
State string `` /* 136-byte string literal not displayed */
Cordoned []string `json:"cordoned,omitempty" jsonschema:"nodes that may not lead"`
Unreachable []string `json:"unreachable,omitempty" jsonschema:"nodes of its view it has not heard from since it lost them"`
Singleton string `json:"singleton,omitempty" jsonschema:"the singleton: its pid on the leader, or none, starting, stopping"`
Backoff string `json:"backoff,omitempty" jsonschema:"how long it holds off campaigning: after its singleton failed, or after it handed over"`
Error string `json:"error,omitempty" jsonschema:"why the node could not be asked"`
}
ElectorView is one node's part in a grpcproc/leader election, as its elector says: comparing the nodes is how a split view shows.
type EventView ¶
type EventView struct {
Time string `json:"time"`
Kind string `json:"kind" jsonschema:"spawn, exit, link-up, link-down or dead-letter"`
Missed uint64 `json:"missed,omitzero" jsonschema:"events lost before this one"`
Process *ProcessView `json:"process,omitempty"`
Reason string `json:"reason,omitempty"`
Peer string `json:"peer,omitempty"`
Error string `json:"error,omitempty"`
From string `json:"from,omitempty"`
To string `json:"to,omitempty"`
Type string `json:"type,omitempty" jsonschema:"message type of a dead letter"`
}
EventView is something that happened on a node.
type Filter ¶
type Filter struct {
Name string // substring of a registered name
Label string
State string // idle, running, waiting-reply, exiting
MinMailbox int
}
Filter narrows Processes; zero fields match everything.
type LinkView ¶
type LinkView struct {
Peer string `json:"peer"`
Incarnation uint64 `json:"incarnation" jsonschema:"the peer's incarnation; 0 until a dial to it succeeds"`
Direction string `json:"direction" jsonschema:"out: this node sends on it; in: the peer does"`
State string `json:"state"`
Age string `json:"age,omitempty"`
Reconnects uint64 `json:"reconnects"`
Messages uint64 `json:"messages"`
Bytes uint64 `json:"bytes"`
Queued int `` /* 156-byte string literal not displayed */
RetryIn string `` /* 200-byte string literal not displayed */
LastError string `json:"last_error,omitempty"`
}
LinkView is one direction of traffic with a peer.
type NodeView ¶
type NodeView struct {
Name string `json:"name" jsonschema:"node name"`
Incarnation uint64 `json:"incarnation,omitzero" jsonschema:"changes every time the node starts"`
Advertise string `json:"advertise,omitempty" jsonschema:"address peers dial"`
Uptime string `json:"uptime,omitempty"`
Processes int `json:"processes"`
Spawned uint64 `json:"spawned"`
Exited uint64 `json:"exited"`
DeadLetters uint64 `json:"dead_letters" jsonschema:"messages that could not be delivered"`
Links []LinkView `json:"links,omitempty"`
Error string `json:"error,omitempty" jsonschema:"why the node could not be inspected"`
}
NodeView is a node as grpcprocctl shows it and its MCP tools return it.
type ProcessView ¶
type ProcessView struct {
PID string `json:"pid"`
Name string `json:"name,omitempty" jsonschema:"the name it is registered under, if any"`
Label string `json:"label" jsonschema:"what metrics aggregate by; the message type by default"`
Type string `json:"type" jsonschema:"Go type of the messages it accepts"`
Parent string `json:"parent,omitempty" jsonschema:"the process that started it, such as its supervisor"`
State string `json:"state" jsonschema:"idle (waiting in Receive), running, waiting-reply (in a Call), exiting"`
Uptime string `json:"uptime"`
Mailbox int `json:"mailbox" jsonschema:"messages waiting"`
MailboxPeak int `json:"mailbox_peak"`
OldestWait string `json:"oldest_wait,omitempty" jsonschema:"how long the oldest waiting message has waited"`
Received uint64 `json:"received"`
Sent uint64 `json:"sent"`
CallsInFlight uint32 `json:"calls_in_flight,omitzero"`
LastMessage string `json:"last_message,omitempty" jsonschema:"type of the last message it took"`
Monitors int `json:"monitors,omitzero" jsonschema:"processes it watches"`
Links int `` /* 126-byte string literal not displayed */
TrapExit bool `json:"trap_exit,omitzero" jsonschema:"whether the exits of processes it is linked to reach it as messages"`
Watchers int `json:"watchers,omitzero" jsonschema:"processes monitoring or linked to it"`
LogLevel string `json:"log_level"`
Inspect map[string]string `json:"inspect,omitempty" jsonschema:"what the process says about itself"`
InspectError string `json:"inspect_error,omitempty" jsonschema:"why inspect is empty: busy, or gone"`
}
ProcessView is a process as grpcprocctl shows it and its MCP tools return it.