status

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 16, 2026 License: AGPL-3.0 Imports: 8 Imported by: 0

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

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

func (e *Engine) CreateComponent(ctx context.Context, c core.Component) error

CreateComponent persists a new component.

func (*Engine) DeleteComponent

func (e *Engine) DeleteComponent(ctx context.Context, key string) error

DeleteComponent removes a component by key.

func (*Engine) GetComponent

func (e *Engine) GetComponent(ctx context.Context, key string) (core.Component, error)

GetComponent returns a component by key, or core.ErrNotFound.

func (*Engine) ListComponents

func (e *Engine) ListComponents(ctx context.Context) ([]core.Component, error)

ListComponents returns all components.

func (*Engine) Register

func (e *Engine) Register(p Provider)

Register adds (or replaces) a provider, keyed by its Name.

func (*Engine) Run

func (e *Engine) Run(ctx context.Context, comp core.Component) core.Check

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

func (e *Engine) RunAll(ctx context.Context) ([]core.Check, error)

RunAll checks every component and returns the resulting checks. Components are probed concurrently; an error is returned only if listing fails.

func (*Engine) SetEmitter

func (e *Engine) SetEmitter(fn func(core.Event))

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

func (e *Engine) Snapshot(ctx context.Context) (core.Health, error)

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.

func (*Engine) UpdateComponent

func (e *Engine) UpdateComponent(ctx context.Context, c core.Component) error

UpdateComponent persists changes to an existing component.

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

func (*HTTPProvider) Check

func (p *HTTPProvider) Check(ctx context.Context, comp core.Component) core.Check

Check probes comp's "url" and maps the result to a core.Check.

func (*HTTPProvider) Name

func (p *HTTPProvider) Name() string

Name identifies the provider.

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.

Jump to

Keyboard shortcuts

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