Documentation
¶
Overview ¶
Package invoke is the process-wide invocation framework: services opt into the Invokable capability, and every instance exposes the shared default invocations (config, logs). The control channel is its gRPC surface.
Index ¶
- Constants
- func HasInvocations() bool
- func InvokeStream(ctx context.Context, target, name string, args map[string]any, emit StreamEmit) error
- func IsDrained(id string) bool
- func IsStreaming(target, name string) bool
- func Metadata(target string) map[string]string
- func Redact(cfg map[string]any) map[string]any
- func RegisterInstance(id, service string, config map[string]any, inv Invokable, ...)
- func SetDrained(id string, out bool)
- type ArgSpec
- type Builder
- type Drainable
- type Handler
- type InvocationKind
- type InvocationScope
- type InvocationSpec
- type Invokable
- type Result
- type Set
- type StreamEmit
- type StreamHandler
- type StreamInvokable
Constants ¶
const ActivityInvocation = "activity"
ActivityInvocation is a built-in invocation every service instance exposes: it reports how many requests the instance's service is currently serving, how many it has served, and how long it has been idle — so an operator can tell when a (drained) instance has quiesced and is safe to restart.
const ConfigInvocation = "config"
ConfigInvocation is the built-in invocation every service instance exposes: it returns the instance's effective, redacted configuration.
const LogLevelInvocation = "loglevel"
LogLevelInvocation is a built-in invocation every service instance exposes: it reports, and optionally sets, the process's effective log level at runtime. The change is in-memory and process-wide; a restart reverts to the configured log level.
const LogsInvocation = "logs"
LogsInvocation is a built-in invocation every service instance exposes: the process's recent log lines, filtered to the instance's service. Invoke returns a snapshot, InvokeStream follows.
const MetaInvocations = "invocations"
MetaInvocations is the registry metadata key holding a node's invocation names (comma-separated), so catalogs can be answered without dialing.
MetaSharedInvocations is the registry metadata key holding the names of a node's ScopeShared invocations (comma-separated), so the caller can send each of them to one instance only.
const RedactedValue = "<redacted>"
RedactedValue is the placeholder substituted for a secret.
const RotationInvocation = "rotation"
RotationInvocation is a built-in invocation that takes an instance out of rotation (state=drain) or returns it (state=ready) at runtime. The change is in-memory and per node: a restart reverts it. The runtime's heartbeat advertises the resulting registry state, and the service selector excludes draining nodes, so a drained instance receives no new traffic while staying alive and control-reachable.
const StackInvocation = "stack"
StackInvocation is a built-in invocation every service instance exposes: a dump of the process's goroutine stacks with basic runtime stats — the first tool to reach for when a process hangs.
const VersionInvocation = "version"
VersionInvocation is a built-in invocation every service instance exposes: the binary's build information and the process uptime, so a mixed fleet's version drift is visible with one fan-out.
Variables ¶
This section is empty.
Functions ¶
func HasInvocations ¶
func HasInvocations() bool
HasInvocations reports whether this process exposes anything invokable; the runtime gates the control channel on it.
func InvokeStream ¶
func InvokeStream(ctx context.Context, target, name string, args map[string]any, emit StreamEmit) error
InvokeStream is the streaming counterpart of Invoke: built-in defaults are handled by the framework, anything else needs the target's StreamInvokable.
func IsStreaming ¶
IsStreaming reports whether the named invocation on a target is streaming.
func Metadata ¶ added in v3.14.0
Metadata returns the registry metadata that advertises a target's invocations, so callers can list and route them without a dial.
func Redact ¶
Redact returns a deep copy of cfg with secret-looking values masked: keys matched by name, string values also checked for inline DSN credentials. The input is never modified.
func RegisterInstance ¶
func RegisterInstance(id, service string, config map[string]any, inv Invokable, counter *activity.Counter)
RegisterInstance records a service instance under its node id, with its config (redacted here), optional Invokable, and optional request counter.
func SetDrained ¶
SetDrained marks (out) or clears a node id as drained.
Types ¶
type Builder ¶
type Builder struct {
// contains filtered or unexported fields
}
Builder configures one invocation: chain Mutating/Dangerous and finish with Handle.
func (*Builder) HandleStream ¶
func (b *Builder) HandleStream(h StreamHandler)
HandleStream sets the streaming implementation, made with TypedStream, and marks the invocation streaming. An invocation may have both a Handle and a HandleStream.
type Drainable ¶ added in v3.14.0
type Drainable interface {
SetDraining(draining bool)
}
Drainable is an optional interface of an Invokable whose service does background work of its own. The rotation invocation calls SetDraining, so a drained instance also stops picking up new work, not just new traffic.
type Handler ¶
type Handler struct {
// contains filtered or unexported fields
}
Handler is a unary invocation implementation, made with Typed.
func Typed ¶ added in v3.14.0
Typed makes a Handler from fn, which takes its arguments as the struct A. Each argument is a field with an `arg:"name"` tag (`arg:"name,required"` if it is required) and a `help` tag. The field type is a string, bool, integer or float kind, time.Duration, time.Time, or an encoding.TextUnmarshaler; a slice of one of these takes comma-separated values, and a pointer to one is nil when the argument is absent. A time is RFC3339, or a duration that means that long ago. Use struct{} for no arguments.
type InvocationKind ¶
type InvocationKind string
InvocationKind classifies an invocation for audit and CLI-level gating.
const ( // KindReadonly returns a redacted, serializable snapshot and changes nothing. KindReadonly InvocationKind = "readonly" // KindMutating changes state in a bounded, expected way. KindMutating InvocationKind = "mutating" // KindDangerous changes state in a way that warrants extra confirmation. KindDangerous InvocationKind = "dangerous" )
type InvocationScope ¶ added in v3.14.0
type InvocationScope string
InvocationScope tells which instances of a service run an invocation.
const ( // ScopeInstance runs on every matched instance, because each one acts on // its own state. It is the zero value. ScopeInstance InvocationScope = "" // act on the same shared state (for example a database). ScopeShared InvocationScope = "shared" )
type InvocationSpec ¶
type InvocationSpec struct {
Name string
Description string
Args []ArgSpec
Kind InvocationKind
Scope InvocationScope
// Streaming marks an invocation that emits a stream of results (via
// InvokeStream) rather than a single one (Invoke).
Streaming bool
// StreamOnly marks a streaming invocation that has no single-result form,
// so Invoke cannot run it.
StreamOnly bool
}
InvocationSpec describes one invocation: its name, arguments and kind.
func Invocations ¶
func Invocations(target string) ([]InvocationSpec, bool)
Invocations returns the invocations a target exposes on this node: the shared defaults plus the target's own. ok is false for an unknown target.
type Invokable ¶
type Invokable interface {
// Invocations is the list of invokables exposed by the service, to help the CLI
// autocompletion. Actual Invoke() calls may be done with arbitrary `name` values.
Invocations() []InvocationSpec
// Invoke runs the named invocation with the given arguments. It is expected
// to be a router across all names returned by Invocations().
Invoke(ctx context.Context, name string, args map[string]any) (Result, error)
}
Invokable is the capability a service implements to expose operations to the Admin API. It is opt-in; a read is simply an invocation with KindReadonly.
type Set ¶
type Set struct {
// contains filtered or unexported fields
}
Set is a service's collection of named invocations. It implements Invokable: a service embeds a *Set and declares its methods instead of hand-writing the catalog, routing and required-arg checks. Build it once at construction; it is read-only afterward.
func (*Set) Invocations ¶
func (s *Set) Invocations() []InvocationSpec
Invocations implements Invokable: the catalog, in registration order.
func (*Set) InvokeStream ¶
func (s *Set) InvokeStream(ctx context.Context, name string, args map[string]any, emit StreamEmit) error
InvokeStream implements StreamInvokable.
type StreamEmit ¶
StreamEmit delivers one result of a streaming invocation; it returns an error when the consumer is gone.
type StreamHandler ¶ added in v3.14.0
type StreamHandler struct {
// contains filtered or unexported fields
}
StreamHandler is a streaming invocation implementation, made with TypedStream.
func TypedStream ¶ added in v3.14.0
func TypedStream[A any](fn func(ctx context.Context, args A, emit StreamEmit) error) StreamHandler
TypedStream is the streaming counterpart of Typed.
type StreamInvokable ¶
type StreamInvokable interface {
// InvokeStream runs the named streaming invocation, emitting each result
// until it completes, ctx is done, or emit reports the consumer gone.
InvokeStream(ctx context.Context, name string, args map[string]any, emit StreamEmit) error
}
StreamInvokable is the optional streaming counterpart of Invokable.