collect

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 9, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Overview

Package collect holds the values long-running collectors publish between recomputes (design §4.1 gap 2). A change requests a recompute through pkg/trigger; the engine reads a Snapshot per computation and its Print on every confirm tick (D-019).

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Aging added in v0.6.0

type Aging interface {
	StalePrint(now time.Time) uint64
}

Aging is implemented by a value's Data whose parts go stale on their own, such as one scrape per install. StalePrint names the parts stale at now.

type Snapshot

type Snapshot struct {
	// Values is a copy of the map; the values' Data is shared and read-only.
	Values map[string]Value
	// Print covers each key's fingerprint, state, reason and expiry, so an
	// expiry is a change. It is zero for an empty store.
	Print uint64
}

Snapshot is the store's values at one instant. An expired value is already Unavailable in it, without data.

func (Snapshot) Get

func (s Snapshot) Get(key string) (Value, bool)

Get returns the value under key. A value that is not OK carries its state and reason, never data.

func (Snapshot) StalePrint added in v0.6.0

func (s Snapshot) StalePrint(now time.Time) uint64

StalePrint covers which parts of s's OK Aging values are stale at now, in key order, so a part turning stale changes it; zero when none can.

type Stamped added in v0.6.0

type Stamped interface {
	StampFor(install string) (time.Time, bool)
}

Stamped is implemented by a value's Data that times each install's part. A check may stamp its result with that time; a memoized result is restamped from it.

type State

type State string

State is a value's availability.

const (
	OK          State = "ok"
	Failing     State = "failing"
	Off         State = "off"
	Unavailable State = "unavailable"
)

Value states. Collectors set OK by Publish and Failing or Off by Fail; Unavailable marks an expired value or one of a stopped collector.

type Store

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

Store holds the collected values by key, "<collector>/<key>". It is safe for concurrent use.

func New

func New(changes *trigger.Signal, now func() time.Time) *Store

New returns an empty Store that notifies changes on every change; a nil changes never notifies.

func (*Store) Fail

func (s *Store) Fail(key string, st State, reason string)

Fail marks key as Failing or Off with reason and drops its data; any other st is recorded as Failing. It notifies when the state or reason changes. A stopped collector's failure is dropped.

func (*Store) Publish

func (s *Store) Publish(key string, data any, fingerprint uint64, ttl time.Duration)

Publish stores data under key with State OK, expiring after ttl (zero means never), and takes ownership of data. It notifies only when the fingerprint changes, the previous value was not current or the expiry moves earlier (or appears), so the engine schedules it. A stopped collector's publish is dropped.

func (*Store) Snapshot

func (s *Store) Snapshot() Snapshot

Snapshot returns the values at the store's now.

func (*Store) Stop

func (s *Store) Stop(collector string)

Stop expires every value of collector and drops its later publishes. It notifies when a value changed.

type Value

type Value struct {
	// Data is owned by the store once published: the collector never mutates
	// it afterwards and readers treat it as read-only.
	Data any
	// Fingerprint identifies Data; an equal fingerprint is no change.
	Fingerprint uint64
	// At is when the value was last published or failed.
	At time.Time
	// Expires is when the value turns Unavailable; zero means never.
	Expires time.Time
	State   State
	// Reason explains a state other than OK.
	Reason string
}

Value is one published value. Data is set only while State is OK.

Jump to

Keyboard shortcuts

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