Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config[T any] struct { // Name identifies this scraper in logs and span attributes // (e.g. "ovs", "northd"). Required. Name string // Interval is the TTL between refreshes. Defaults to 15s. Interval time.Duration // Refresh produces the next snapshot. Required. Refresh RefreshFunc[T] // Logger receives one debug line per successful tick and one warn line // per failure. Required. Logger *slog.Logger // Tracer wraps each refresh in an `ovsx.scrape.unixctl` span. // Optional; when nil, no spans are emitted. Tracer trace.Tracer }
Config configures a Scraper.
type Outcome ¶
Outcome is the result of a single TTL refresh. It is replaced atomically on every tick
type RefreshFunc ¶
RefreshFunc produces a fresh snapshot on every tick. It is invoked with the Scraper's context (cancellation propagates) and should respect any deadline. On error the previous snapshot is preserved.
type Scraper ¶
type Scraper[T any] struct { // contains filtered or unexported fields }
Scraper runs Refresh on a ticker and stores the most recent successful result in an atomic pointer for lock-free reads.
func New ¶
New validates cfg and returns an idle Scraper. Call Run to start the ticker, or Refresh to drive one tick manually.
func (*Scraper[T]) Outcome ¶
Outcome returns the result of the most recent tick (success or failure). Returns zero value before the first tick.
func (*Scraper[T]) Refresh ¶
Refresh runs a single refresh synchronously. Exposed so tests and readyz probes can drive a tick without waiting for the ticker.
func (*Scraper[T]) Run ¶
Run drives Refresh on Config.Interval until ctx is cancelled. The first refresh runs immediately so collectors don't see a nil snapshot for a full interval after startup.
func (*Scraper[T]) Snapshot ¶
func (s *Scraper[T]) Snapshot() *T
Snapshot returns the most recent successful refresh. Returns nil before the first successful tick — callers must handle that case.
func (*Scraper[T]) Stale ¶
Stale returns nil when the last scrape succeeded and is no older than maxAge, otherwise a descriptive error. Plugs into the probes.Checker interface via a CheckerFunc wrapper so the probes package stays free of an import on internal/scrape. The caller owns the policy (what age counts as stale).