Documentation
Observability
What a node reports about its processes and links: snapshots, events, hooks, logging and OpenTelemetry.
Every process and every link keeps counters, a process can publish its own state, and the node reports all of it through one Go API. The Inspector serves the same data over gRPC, to the command line, the web UI and AI agents.
- Counters are always on: atomics on the process and the link, read by snapshot, with nothing to configure.
- The core imports no metrics or tracing library. The
Hooksinterface is the single tap;grpcproc/otelimplements it, in a module of its own. - The Go API is the source of truth. The Inspector and every tool built on it expose exactly what
node.Info()andnode.Processes()return.
Snapshots
node.Processes() is every local process, ordered by PID; node.Process(pid) is one; node.Info() is the node with its links; node.Peers() the peers with a live link. Each is a copy taken at the call, in a stable order, so a test can assert on it and a tool can render it. A ProcessInfo has:
| Field | Meaning |
|---|---|
PID | The process, anywhere in the cluster. |
Name | What WithName registered; empty for an unnamed process. |
Label | What WithLabel set, by default the type of the mailbox: the low-cardinality key metrics aggregate by. |
Type | The Go type of the mailbox, for display. |
Parent | The process that spawned it; zero for Node.Spawn. |
State | idle in Receive, running between two, waiting-reply in a Call, or exiting. |
StartedAt | When it was spawned. |
Mailbox | Depth, Peak, and OldestAge: how long the oldest queued message has waited. A depth that grows and an age that grows with it is a process that does not keep up. |
Received, Sent | Messages taken from the mailbox, and messages sent. |
CallsInFlight | Calls it has made and not yet been answered. |
LastMessage | The protobuf full name of the last message taken from the mailbox. |
Monitors, Links, Watchers | Monitors and links it holds on others, and how many processes monitor or are linked to it. |
Wakeups | How many times Receive returned. |
Busy, BusyFor | The time it has spent anywhere but waiting in Receive, waits in Call included, and at least how long it has been on its current message, or on the timeout that woke it, 0 while it waits. The growth of Busy between two snapshots, over the time between them, is the share of that time it was busy: near 1, it is never idle, and a growing Depth says it does not keep up. |
LogLevel, TrapExit | The threshold of its logger, and whether it traps exits. |
A LinkInfo describes one direction of traffic with a peer: Peer, whether this node opened the stream (Outbound), its State, when it was established and how many times it reconnected, how many sessions with the peer ended (Sessions, which keeps growing for a peer whose links keep breaking), envelopes and bytes carried, envelopes Queued to be written and their QueuedBytes, and for a peer whose dials fail, or whose last link ended soon after it came up, the LastError and the RetryAt before which every send to it fails at once. A NodeInfo holds the node's identity and address, when it started, how many processes it runs and has spawned and exited, its dead letters, and its links, ordered by peer name.
Inspecting a process
WithInspect gives a process a function that returns a map of what it wants to publish, and node.Inspect asks for it:
node.Spawn(run, grpcproc.WithInspect(func() map[string]string {
return map[string]string{
"state": rec.state.String(),
"pending": strconv.Itoa(rec.pendingUploads),
}
}))
state, err := node.Inspect(ctx, pid)The function runs on the process's own goroutine, inside Receive, between two messages, so it reads the process's state with no lock. A process busy in a handler answers when it next receives. One that never does cannot answer, and Inspect fails with busy for 12s: the process is stuck in one message, and LastMessage says which kind.
With a state machine the map is one line:
grpcproc.WithInspect(func() map[string]string { return map[string]string{"state": rec.state.String()} })Supervisors publish their children, each child's PID and restart count, and how many restarts they have made against their limit; the Inspector shows it as grpcprocctl inspect.
Events
node.Subscribe(ctx, buffer) is a channel of what happens on the node: a spawn, an exit with its reason, a session with a peer beginning or ending (its first link up, the peer declared down), a member Members lists or lists no more, a dead letter. Each Event has a Kind and the fields that kind fills: the Process snapshot for a spawn or an exit, the Peer and an error for a link, the Member for a member, From, To, the message Type and a reason for a dead letter.
Publishing never blocks the node. A subscriber whose buffer is full loses the event, and the next one it receives carries Missed, how many were lost in between. With no subscriber the cost is one atomic load at each point that would publish. The channel closes when ctx ends or the node stops.
These are the node's own events. An application's events, published by one process for others on any node, go through Pub/sub.
The supervisor example crashes an actor and follows what the supervisor does through the events:
// Crash it, and follow what the supervisor does through node events.
events := node.Subscribe(ctx, 16)
if err := inventory.Restock(ctx, node, &shoppb.Restock{Sku: "apple", Qty: 0}); err != nil {
log.Fatal(err)
}
for e := range events {
if e.Process.Name != "inventory" {
continue
}
if e.Kind == grpcproc.EventExit {
fmt.Println("inventory exited:", e.Reason)
}
if e.Kind == grpcproc.EventSpawn {
fmt.Println("inventory started again")
break
}
}Hooks
Config.Hooks is the synchronous tap for everything else. Every method runs on the goroutine doing the work, so an implementation must be cheap and must not call back into the node:
type Hooks interface {
OnSpawn(ProcessInfo)
OnExit(info ProcessInfo, reason string)
OnSend(s SendInfo, md Metadata) (Metadata, Done)
OnReceive(r ReceiveInfo, md Metadata) (Metadata, Done)
OnDeadLetter(from, to PID, body proto.Message, reason string)
OnLinkUp(peer NodeID)
OnLinkDown(peer NodeID, err error)
OnMemberUp(m Member) // Members lists it anew or changed: new, a newer incarnation, other metadata
OnMemberDown(m Member) // Members lists it no more
}
type Done func(err error)OnSend runs before a send or a call leaves its sender, OnReceive when a process takes a message, a Down or an Exited from its mailbox. Both return the metadata to use from then on, and a Done that closes what they started: a send once it is handed to delivery, a call once it returns, the handling of a message when the process next calls Receive or exits, with the exit reason as the error.
A process remembers the metadata of the message it is handling, as OnReceive returned it, and its own sends and calls inherit it. So a tracer that puts the handling span in the metadata sees everything the handler sends as that span's child, and trace chains form across processes and nodes without a context threaded through handlers.
Metadata is a map[string]string carried with every message, untouched: trace context, a tenant, a request id. WithMetadata(ctx, md) sets it for a node's sends and every call, and MetadataFrom(ctx) reads it back. The hooks must not modify the map they are given, which may be shared; they return a copy to change it.
OnMemberUp and OnMemberDown follow Members: each runs on the goroutine reading the Membership, once the node has applied an event that changed what Members lists, so whatever places work by the members learns of a change exactly when Members shows it. An event that changes nothing, an older incarnation reported up say, runs neither.
Embed NopHooks and override what you need. JoinHooks combines several: metadata threads through them in order, and their Dones run in reverse. With no hooks, the cost is a nil check per message.
Logging
p.Log() is a *slog.Logger with the process's PID and label attached, built on Config.Logger, by default slog.Default(). Each process has a threshold of its own: node.SetLogLevel(pid, level) changes it at runtime, the Inspector's SetLogLevel does the same over gRPC, and ProcessInfo.LogLevel reports it.
p.Log().Info("charged", "order", m.Body.Order, "amount", m.Body.Amount)
if err := node.SetLogLevel(pid, slog.LevelDebug); err != nil {
return err // ErrNoProc: no such local process
}A panic in a process is logged with its stack, and the process exits with reason panic: …. Goroutine dumps and heap profiles are net/http/pprof's job.
A process's goroutine, and every goroutine its code starts, carries the pprof labels grpcproc.label, grpcproc.pid and, for a named process, grpcproc.name; the goroutines the node starts, a link's among them, carry none. So a CPU profile splits by process, and a goroutine dump says whose each goroutine is. pprof.Do over p.Context() adds labels of your own to them.
go tool pprof -tags http://localhost:6060/debug/pprof/profile # CPU by label and by PID
go tool pprof -tagfocus=grpcproc.label=ledger http://localhost:6060/debug/pprof/profileOpenTelemetry
grpcproc/otel implements Hooks with OpenTelemetry: a span for every send, call and handled message, chained across processes and nodes, and metrics keyed by process label. It is a separate module.
go get github.com/floatdrop/grpcproc/otelh, err := grpcprocotel.New() // global meter and tracer providers and propagator; see Options
node, err := grpcproc.NewNode(grpcproc.Config{…, Hooks: grpcproc.JoinHooks(h, myHooks)})
reg, err := h.Observe(node) // gauges read from node snapshots at each collection
defer reg.Unregister()
lreg, err := h.ObserveLeader(node) // gauges of the node's grpcproc/leader elections
defer lreg.Unregister()Traces
| Where | Span |
|---|---|
Send | send <message type>, a producer span, child of the context the sender carries. |
Call | call <message type>, a client span, child of the context the sender carries. |
| A process takes a message | process <message type>, a consumer span (server for a call), child of the sender's span. |
| A process takes a Down | process grpcproc.Down, a consumer span with no parent. |
| A process that traps exits takes an Exited | process grpcproc.Exited, a consumer span with no parent. |
A handling span lasts until the process calls Receive again, or exits, with an error status if abnormally. Everything the process sends meanwhile is its child, because the process's sends inherit the metadata of the message it is handling and the hooks put the span there. For a handler's own spans, a database call say, take the handling span from the message, in the message's context, which ends when its caller stops waiting:
ctx, cancel := m.Context(p.Context())
defer cancel()
ctx, span := tracer.Start(h.Extract(ctx, m.Metadata), "load order")
defer span.End()Spans carry messaging.system=grpcproc, messaging.operation.type, messaging.destination.name, grpcproc.message.type, grpcproc.label and grpcproc.pid; failed sends and calls carry error.type.
Metrics
No metric carries a PID: the process label is the unit, and every other attribute is bounded, so a system that spawns a process per session does not make a series for each.
| Name | Type and attributes |
|---|---|
grpcproc.messages.sent | counter; grpcproc.label (the sender's), grpcproc.call, grpcproc.remote |
grpcproc.messages.received | counter; grpcproc.label |
grpcproc.mailbox.wait | histogram, seconds; grpcproc.label |
grpcproc.process.duration | histogram, seconds, from taking a message to the next Receive; grpcproc.label |
grpcproc.call.duration | histogram, seconds; grpcproc.label, grpcproc.remote, error.type on failure |
grpcproc.processes.spawned | counter; grpcproc.label |
grpcproc.processes.exited | counter; grpcproc.label, grpcproc.reason: normal, shutdown, killed, noproc, noconnection, type; max restarts from actor, timeout and replaced from cron, demoted from leader; panic or error |
grpcproc.dead_letters | counter; grpcproc.reason, grpcproc.message.type |
grpcproc.links.up, grpcproc.links.down | counter; grpcproc.peer |
grpcproc.processes | gauge, from Observe; grpcproc.label |
grpcproc.mailbox.depth | gauge, from Observe, summed; grpcproc.label |
grpcproc.mailbox.oldest | gauge, from Observe, seconds, maximum; grpcproc.label |
grpcproc.link.messages, grpcproc.link.bytes | counter, from Observe; grpcproc.peer, grpcproc.direction |
error.type is one of noproc, type, mailbox_full (the callee's mailbox was full), too_large (the message or its reply was over MaxMessageSize), busy (the link to the peer was full), noconnection, timeout, canceled, remote (the handler returned an error) or other. Errors and exit reasons says what each means.
Leader elections
ObserveLeader reads each grpcproc/leader elector on the node, the processes named leader.ElectorName(cluster) with its label, at each collection, from its inspect map, and reports one set of gauges per election, by grpcproc.leader.cluster. The electors are asked at once. One that the node's snapshot shows on one message for a second, busy in a slow Store say, or that does not answer within a second of a collection that lasts that long, is reported as stalled, with no other gauge.
| Name | What it says |
|---|---|
grpcproc.leader.electors | 1, with grpcproc.leader.role: leader, candidate, follower or unclustered |
grpcproc.leader.stalled | 1 while the elector is on one message for a second or more, or does not answer within one; 0 while it answers. |
grpcproc.leader.term | The elector's term. |
grpcproc.leader.view, grpcproc.leader.quorum | The nodes whose majority elects, and how many that majority is. |
grpcproc.leader.reachable | The nodes of the view it hears from, itself included. |
grpcproc.leader.singleton | 1 while the singleton runs on this node. |
grpcproc.leader.checkpoints.waiting | Checkpoint calls waiting for a majority to hold their state. |
Alerts per cluster, in PromQL, with the names as the Prometheus exporter writes them: dots turned to underscores, and a unit suffix where there is one:
# No leader: the leaders, with a 0 for every elector, so that none adds up to 0.
# A cluster below MinClusterSize has none by design: its electors are unclustered.
sum by (grpcproc_leader_cluster) (grpcproc_leader_electors{grpcproc_leader_role="leader"} or grpcproc_leader_electors * 0) < 1
# No node of a cluster reporting at all: one rule per cluster.
absent(grpcproc_leader_electors{grpcproc_leader_cluster="scheduler"})
# Two leaders: a leader cut off from the others has not noticed.
sum by (grpcproc_leader_cluster) (grpcproc_leader_electors{grpcproc_leader_role="leader"}) > 1
# The singleton runs nowhere, or twice.
sum by (grpcproc_leader_cluster) (grpcproc_leader_singleton) != 1
# One more node lost and this side has no majority; below it, none can be elected.
# A view of one or two never has a node to spare.
grpcproc_leader_reachable <= grpcproc_leader_quorum and grpcproc_leader_view >= 3
# Elections keep happening.
changes(max by (grpcproc_leader_cluster) (grpcproc_leader_term)[15m:]) > 3
# A majority is not taking the leader's state.
grpcproc_leader_checkpoints_waiting > 0
# An elector held up for a second or more, which sends no heartbeat or vote meanwhile.
grpcproc_leader_stalled > 0Give each a for: of a few scrape intervals, a minute say: an election, and a hand-over, whose Resign stops the old singleton before the next leader starts its own, leave no leader or no singleton for a moment, and a leader cut off from the others leads for up to two election timeouts after they elect another. A stalled elector is in none of the sums: when the leader is the one held up, the other nodes' gauges show no leader, and with no other node reporting the sums are empty, which only "stalled" alerts on. A second is fixed: with an ElectionTimeout above it, a Store slow enough to be stalled can still be within it, so give "stalled" a for: longer than the timeout.