Documentation
¶
Overview ¶
Package actuator mounts a Spring-Actuator-equivalent debug/introspection surface (modules, startup, routes, health, info, config, pprof, expvar, goroutine dump, DI graph, live log-level control) on its own loopback fiber listener. All dependencies are optional so it degrades gracefully: an absent source makes its endpoint return 501/empty rather than fail boot.
Index ¶
- Constants
- type Config
- type ConfigResponse
- type DIResponse
- type EndpointToggles
- type InfoResponse
- type InstanceRoutes
- type LoggersRequest
- type LoggersResponse
- type Module
- func (m *Module) Addr() net.Addr
- func (m *Module) ConfigPath() string
- func (m *Module) Dependencies() ([]reflect.Type, []reflect.Type)
- func (m *Module) Init(ctx context.Context) error
- func (m *Module) LoadConfig(k *koanf.Koanf) error
- func (m *Module) Shutdown(ctx context.Context) error
- func (m *Module) Start(ctx context.Context) error
- type ModuleVersion
- type ModuleView
- type ModulesResponse
- type Option
- type Redactor
- type RouteView
- type RoutesResponse
- type StartupEntry
- type StartupResponse
Constants ¶
const ( ShowNever = "never" ShowAlways = "always" ShowWhenAuthorized = "when_authorized" )
ShowValues enum values for the show_values config key.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct {
// Name is the instance name.
Name string `koanf:"-"`
// Enabled gates the whole module; when false Init/Start are no-ops. Default false.
Enabled bool `koanf:"enabled"`
// Host to bind the private actuator listener. Default 127.0.0.1.
Host string `koanf:"host"`
// Port to bind. Default 6060.
Port uint16 `koanf:"port"`
// BasePath prefixes every endpoint. Default /debug.
BasePath string `koanf:"base_path"`
// ShowValues controls config-value masking: never|always|when_authorized.
// Default never (matched leaves render as ******).
ShowValues string `enum:"never,always,when_authorized" koanf:"show_values"`
// RedactPatterns extends (does not replace) the default key-redaction set.
RedactPatterns []string `koanf:"redact_patterns"`
// Endpoints toggles optional endpoint groups. All default true.
Endpoints EndpointToggles `koanf:"endpoints"`
// AllowInsecure downgrades the fail-closed security refusals (non-loopback
// without auth; sensitive endpoints without auth) to a warn. Default false.
AllowInsecure bool `koanf:"allow_insecure"`
// Mount, when set, mounts endpoints under the caller's router instead of a
// private listener (escape hatch, code-only).
Mount fiber.Router `code_only:"WithMount" koanf:"-"`
// Auth is caller-supplied middleware gating sensitive (and optionally all)
// endpoints (code-only). The real JWT verifier is a later phase.
Auth fiber.Handler `code_only:"WithAuth" koanf:"-"`
}
Config represents configuration for the actuator Module. Defaults are security-conservative: disabled, loopback-bound, values masked.
func NewDefaultConfig ¶
func NewDefaultConfig() Config
NewDefaultConfig returns default configuration.
func (*Config) LoadFromKoanf ¶
LoadFromKoanf loads configuration from koanf at the given path.
func (*Config) RequiresAuth ¶
RequiresAuth reports whether the endpoint (BasePath-relative, e.g. "/goroutine") requires auth on any bind. True for goroutine/pprof/vars/loggers.
func (*Config) SecretRedactor ¶
SecretRedactor compiles the default key patterns plus RedactPatterns into a ready Redactor honoring ShowValues.
type ConfigResponse ¶
type ConfigResponse struct {
Values map[string]any `json:"values"`
Provenance map[string]string `json:"provenance,omitempty"`
}
ConfigResponse is the /config JSON contract.
type DIResponse ¶
DIResponse is the /di JSON contract.
type EndpointToggles ¶
type EndpointToggles struct {
Pprof bool `koanf:"pprof"`
Expvar bool `koanf:"expvar"`
UI bool `koanf:"ui"`
Loggers bool `koanf:"loggers"`
}
EndpointToggles gates the optional endpoint groups. UI is kept as a config flag but has no handler this phase (dashboard deferred).
type InfoResponse ¶
type InfoResponse struct {
GoVersion string `json:"go_version"`
Path string `json:"path"`
Main ModuleVersion `json:"main"`
Settings map[string]string `json:"settings"`
Deps []ModuleVersion `json:"deps"`
}
InfoResponse is the /info JSON contract.
type InstanceRoutes ¶
InstanceRoutes is one fiber instance's routes.
type LoggersRequest ¶
type LoggersRequest struct {
Level string `json:"level"`
}
LoggersRequest is the POST /loggers JSON body.
type LoggersResponse ¶
type LoggersResponse struct {
Level string `json:"level"`
}
LoggersResponse reports the effective default level after a change.
type Module ¶
Module is the actuator [SyncModule].
func (*Module) ConfigPath ¶
ConfigPath returns modules.debug.actuator.<name>.
func (*Module) Dependencies ¶
Dependencies declares no required deps; all optional so the module degrades to 501/empty when a source is absent.
func (*Module) Init ¶
Init resolves optional sources from DI, builds the private *fiber.App (or the WithMount target), registers all endpoint handlers under BasePath, and applies the fail-closed security model. No-op when Enabled is false.
func (*Module) LoadConfig ¶
LoadConfig loads configuration from koanf.
type ModuleVersion ¶
ModuleVersion is a build-info module path/version pair.
type ModuleView ¶
type ModuleView struct {
Name string `json:"name"`
Type string `json:"type"`
InitOrder int `json:"init_order"`
Provides []string `json:"provides"`
Requires []string `json:"requires"`
Optional []string `json:"optional"`
Lifecycle string `json:"lifecycle"`
State string `json:"state"`
InitDuration string `json:"init_duration"`
}
ModuleView is one module's rendered metadata.
type ModulesResponse ¶
type ModulesResponse struct {
Modules []ModuleView `json:"modules"`
}
ModulesResponse is the /modules JSON contract.
type Option ¶
type Option func(m *Config)
Option manipulates Config.
func WithEnabled ¶
WithEnabled toggles the module in code (config normally drives this).
type Redactor ¶
type Redactor struct {
// contains filtered or unexported fields
}
Redactor walks koanf-produced structures redacting secrets. Constructed via Config.SecretRedactor/NewRedactor. Stateless after construction; safe for concurrent reads. Redaction is best-effort: value-level scrubbing is regex-based and cannot guarantee every embedded secret is caught — the wholesale redaction of passthrough (,remain) subtrees is the backstop.
func NewRedactor ¶
NewRedactor compiles the default key patterns plus any additive patterns into a Redactor honoring showValues (never|always|when_authorized).
func (*Redactor) Redact ¶
Redact returns a redacted deep copy of a koanf structure. Recurses nested map[string]any AND []any elements, wholesale-redacts subtrees under matched or passthrough keys, and scrubs value-level URI/DSN secrets in every string. When show_values disables masking, returns an unmodified deep copy.
type RouteView ¶
type RouteView struct {
Method string `json:"method"`
Path string `json:"path"`
Name string `json:"name,omitempty"`
}
RouteView is one registered route.
type RoutesResponse ¶
type RoutesResponse struct {
Instances []InstanceRoutes `json:"instances"`
}
RoutesResponse is the /routes JSON contract.
type StartupEntry ¶
type StartupEntry struct {
Name string `json:"name"`
InitOrder int `json:"init_order"`
InitDuration string `json:"init_duration"`
}
StartupEntry is one module's init timing.
type StartupResponse ¶
type StartupResponse struct {
Total string `json:"total_init_duration"`
Entries []StartupEntry `json:"entries"`
}
StartupResponse is the /startup JSON contract (init waterfall).