invoke

package
v3.15.2 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 12, 2026 License: Apache-2.0 Imports: 18 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

View Source
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.

View Source
const ConfigInvocation = "config"

ConfigInvocation is the built-in invocation every service instance exposes: it returns the instance's effective, redacted configuration.

View Source
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.

View Source
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.

View Source
const MetaInvocations = "invocations"

MetaInvocations is the registry metadata key holding a node's invocation names (comma-separated), so catalogs can be answered without dialing.

View Source
const MetaSharedInvocations = "shared_invocations"

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.

View Source
const RedactedValue = "<redacted>"

RedactedValue is the placeholder substituted for a secret.

View Source
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.

View Source
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.

View Source
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 IsDrained

func IsDrained(id string) bool

IsDrained reports whether a node id has been taken out of rotation.

func IsStreaming

func IsStreaming(target, name string) bool

IsStreaming reports whether the named invocation on a target is streaming.

func Metadata added in v3.14.0

func Metadata(target string) map[string]string

Metadata returns the registry metadata that advertises a target's invocations, so callers can list and route them without a dial.

func Redact

func Redact(cfg map[string]any) map[string]any

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

func SetDrained(id string, out bool)

SetDrained marks (out) or clears a node id as drained.

Types

type ArgSpec

type ArgSpec struct {
	Name        string
	Description string
	Required    bool
}

ArgSpec describes one argument an invocation accepts.

type Builder

type Builder struct {
	// contains filtered or unexported fields
}

Builder configures one invocation: chain Mutating/Dangerous and finish with Handle.

func (*Builder) Dangerous

func (b *Builder) Dangerous() *Builder

Dangerous marks the invocation as warranting a confirmation prompt.

func (*Builder) Handle

func (b *Builder) Handle(h Handler)

Handle sets the unary implementation, made with Typed.

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.

func (*Builder) Mutating

func (b *Builder) Mutating() *Builder

Mutating marks the invocation as changing state.

func (*Builder) Shared added in v3.14.0

func (b *Builder) Shared() *Builder

Shared marks the invocation as acting on state that all instances share, so one instance per service runs it.

func (*Builder) Stream

func (b *Builder) Stream() *Builder

Stream marks the invocation as producing a stream of results (implied by 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

func Typed[A any](fn func(ctx context.Context, args A) (Result, error)) Handler

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 = ""
	// ScopeShared runs on one live instance per service, because all instances
	// 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 Result

type Result map[string]any

Result is an invocation's serializable, already-redacted return value.

func Invoke

func Invoke(ctx context.Context, target, name string, args map[string]any) (Result, error)

Invoke runs a named invocation on a target: built-in defaults are handled by the framework, anything else is delegated to the target's Invokable.

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 NewSet

func NewSet() *Set

NewSet returns an empty Set.

func (*Set) Add

func (s *Set) Add(name, description string) *Builder

Add begins registering an invocation (KindReadonly by default).

func (*Set) Invocations

func (s *Set) Invocations() []InvocationSpec

Invocations implements Invokable: the catalog, in registration order.

func (*Set) Invoke

func (s *Set) Invoke(ctx context.Context, name string, args map[string]any) (Result, error)

Invoke implements Invokable.

func (*Set) InvokeStream

func (s *Set) InvokeStream(ctx context.Context, name string, args map[string]any, emit StreamEmit) error

InvokeStream implements StreamInvokable.

type StreamEmit

type StreamEmit func(Result) error

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.

Directories

Path Synopsis
Package client resolves invocation targets through the service registry and runs invocations over the control channel.
Package client resolves invocation targets through the service registry and runs invocations over the control channel.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL