providerhealth

package
v1.5.6 Latest Latest
Warning

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

Go to latest
Published: Jun 17, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package providerhealth caches per-provider HealthChecker results so dashboards can render workspace state without hammering the underlying control planes (docker socket, k8s API server, nomad agent) on every request.

The cache is in-memory, populated by a periodic poller that runs HealthChecker.HealthCheck on every registered provider. Consumers (studio handlers, the workload-health aggregator, admin views) read from the cache via Get / Snapshot — both are O(1) and lock-free in the read path.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Cache

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

Cache holds the most recent health status per provider name. Polled by Run; consumers read with Get / Snapshot.

func NewCache

func NewCache(registry *provider.Registry, cfg Config) *Cache

NewCache wires a cache against the given registry. The cache is empty until Run() ticks at least once. Consumers calling Get before the first tick get ok=false — the studio handlers treat that as "unknown" and degrade the badge gracefully.

func (*Cache) CheckNow

func (c *Cache) CheckNow(ctx context.Context)

CheckNow runs a one-shot sweep ignoring the schedule. Useful after a provider re-registers or a manual "refresh" action.

func (*Cache) Get

func (c *Cache) Get(name string) (Status, bool)

Get returns the last-known status for a provider. ok=false when the cache hasn't seen this provider yet (cold cache, or provider just registered).

func (*Cache) Run

func (c *Cache) Run(ctx context.Context)

Run blocks until ctx is cancelled. Does an upfront sweep so the cache populates promptly, then ticks at the poll interval. Spawn this in a background goroutine — never call it inline: the sweep can block on a slow provider HealthCheck (k8s when the cluster is unreachable, for instance), and we don't want startup to depend on that.

func (*Cache) Snapshot

func (c *Cache) Snapshot() []Status

Snapshot returns a copy of every cached status. Stable iteration order is not guaranteed; sort by Name in the caller if needed.

type Config

type Config struct {
	// PollInterval is how often the cache re-checks every provider.
	// Default 30s — provider-control-plane health changes slowly,
	// so this trades a small staleness window for tiny load.
	PollInterval time.Duration

	// CheckTimeout caps each individual HealthCheck call. Set
	// shorter than PollInterval so a hung provider doesn't block
	// the whole sweep. Default 5s.
	CheckTimeout time.Duration
}

Config tunes the cache.

func DefaultConfig

func DefaultConfig() Config

DefaultConfig returns sensible defaults.

type Status

type Status struct {
	Name      string        `json:"name"`
	Healthy   bool          `json:"healthy"`
	Message   string        `json:"message"`
	Latency   time.Duration `json:"latency"`
	CheckedAt time.Time     `json:"checked_at"`
}

Status is the cached health snapshot for one provider.

Jump to

Keyboard shortcuts

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