Documentation
¶
Overview ¶
Package status evaluates the health of monitored components. A Provider is a pluggable check (HTTP, TCP, a custom probe); the engine runs providers and aggregates their results into a core.Health snapshot.
Index ¶
- type Engine
- func (e *Engine) CreateComponent(ctx context.Context, c core.Component) error
- func (e *Engine) DeleteComponent(ctx context.Context, key string) error
- func (e *Engine) GetComponent(ctx context.Context, key string) (core.Component, error)
- func (e *Engine) ListComponents(ctx context.Context) ([]core.Component, error)
- func (e *Engine) Register(p Provider)
- func (e *Engine) Run(ctx context.Context, comp core.Component) core.Check
- func (e *Engine) RunAll(ctx context.Context) ([]core.Check, error)
- func (e *Engine) SetEmitter(fn func(core.Event))
- func (e *Engine) Snapshot(ctx context.Context) (core.Health, error)
- func (e *Engine) UpdateComponent(ctx context.Context, c core.Component) error
- type HTTPProvider
- type Provider
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Engine ¶
type Engine struct {
// contains filtered or unexported fields
}
Engine runs status providers against components and aggregates the results. It depends only on the narrow ComponentStore and CheckStore seams so it can be wired against any backend (or a fake in tests).
func New ¶
func New(comps store.ComponentStore, checks store.CheckStore, providers ...Provider) *Engine
New builds an Engine and registers the given providers by Name.
func (*Engine) CreateComponent ¶
CreateComponent persists a new component.
func (*Engine) DeleteComponent ¶
DeleteComponent removes a component by key.
func (*Engine) GetComponent ¶
GetComponent returns a component by key, or core.ErrNotFound.
func (*Engine) ListComponents ¶
ListComponents returns all components.
func (*Engine) Run ¶
Run checks a single component with its configured provider, records the result, and returns it. If the provider is unknown the result is a StateUnknown check; it is still recorded so the snapshot reflects reality.
func (*Engine) RunAll ¶
RunAll checks every component and returns the resulting checks. Components are probed concurrently; an error is returned only if listing fails.
func (*Engine) SetEmitter ¶
SetEmitter installs an event sink (e.g. a notify.Dispatcher's Emit). Passing nil disables emission. Safe to call once at startup before checks run.
func (*Engine) Snapshot ¶
Snapshot reads the latest check per component and aggregates them into a core.Health.
Aggregation rule: the overall State is the worst (highest) state across components, but StateUnknown is treated as least-severe so a single not-yet-checked component cannot mask a real StateDown. When there are no checks at all, the overall State is StateUnknown.
type HTTPProvider ¶
type HTTPProvider struct {
// Client issues the probe request. If nil, http.DefaultClient is used. A
// per-request timeout is applied via context regardless of Client.Timeout.
Client *http.Client
}
HTTPProvider checks a component by issuing an HTTP request and inspecting the response status.
It reads its target from core.Component.Config:
url required; the endpoint to probe method optional; request method, default "GET" expect_status optional; an exact status code that means operational timeout optional; a Go duration string (e.g. "2s"), default 5s
State mapping:
2xx, or the exact expect_status if set -> StateOperational any other HTTP response received -> StateDegraded connection error or timeout -> StateDown missing "url" -> StateUnknown
type Provider ¶
type Provider interface {
// Name identifies the provider, e.g. "http".
Name() string
// Check probes the component described by cfg and returns its state.
Check(ctx context.Context, comp core.Component) core.Check
}
Provider performs a single health check for a component. Implementations are registered by name and selected per-component via core.Component.Provider.
Directories
¶
| Path | Synopsis |
|---|---|
|
Package cloudflare provides Console status providers backed by Cloudflare's APIs.
|
Package cloudflare provides Console status providers backed by Cloudflare's APIs. |
|
Package heroku provides Console status providers backed by Heroku's Platform API.
|
Package heroku provides Console status providers backed by Heroku's Platform API. |
|
Package sentry provides Console status providers backed by Sentry's API.
|
Package sentry provides Console status providers backed by Sentry's API. |