record

package
v0.2.4 Latest Latest
Warning

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

Go to latest
Published: Sep 23, 2025 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrInvalidCapacity  = errors.New("invalid capacity")
	ErrInvalidNodeCount = errors.New("invalid node count")
	ErrMissingNode      = errors.New("missing node")
	ErrMismatchingNode  = errors.New("mismatching node")
	ErrTooManyNodes     = errors.New("excessive node count")
)

Functions

func DumpToFile

func DumpToFile(dir, file string, obj any) error

DumpToFile encodes in JSON and dumps the given `obj` to a file. `dir` is the base directory on which the file must be created `file` is the name of the file to create in `dir`. The old file, if present, is always updated atomically.

func FileNameToNodeName

func FileNameToNodeName(name string) string

func LoadFromFile

func LoadFromFile(dir, file string, obj any) error

LoadFromFile decodes the JSON data found in `file` placed in `dir` and stores it into `obj`, which must be a pointer.

func NodeNameToFileName

func NodeNameToFileName(name string) string

Types

type NodeRecorder

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

NodeRecorder stores all the recorded statuses for a given node name. Statuses belonging to different nodes won't be accepted.

func NewNodeRecorder

func NewNodeRecorder(nodeName string, capacity int, timestamper Timestamper) (*NodeRecorder, error)

NewNodeRecorder creates a new recorder for the given node with the given capacity. The record is a ring buffer, so only the latest <capacity> Statuses are kept at any time. The timestamper callback is used to mark times. Use `time.Now` if unsure. Returns the newly created instance; if parameters are incorrect, returns an error, on which case the returned instance should be ignored.

func (*NodeRecorder) Cap

func (nr *NodeRecorder) Cap() int

Cap returns the maximum capacity of the NodeRecorder

func (*NodeRecorder) Content

func (nr *NodeRecorder) Content() []RecordedStatus

Content() returns a shallow copy of all the recorded statuses.

func (*NodeRecorder) Len

func (nr *NodeRecorder) Len() int

Len returns how many Statuses are currently held in the NodeRecorder

func (*NodeRecorder) Push

func (nr *NodeRecorder) Push(st podfingerprint.Status) error

Push adds a new Status to the record, evicting the oldest Status if necessary. The pushed status is a full independent copy of the provided Status. If the Status added is inconsistent, returns an error detailing the reason. Statuses are evicted only in case of success.

type RecordedStatus

type RecordedStatus struct {
	podfingerprint.Status
	// RecordTime is a timestamp of when the RecordedStatus was added to the record
	RecordTime time.Time `json:"recordTime"`
}

RecordedStatus is a Status plus additional metadata

func (RecordedStatus) Equal

func (rs RecordedStatus) Equal(x RecordedStatus) bool

type Recorder

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

Recorder stores all the recorded statuses, dividing them by node name. There is a hard cap of how many nodes are managed, and how many Statuses are recorded per node.

func NewRecorder

func NewRecorder(maxNodes, nodeCapacity int, timestamper Timestamper) (*Recorder, error)

NewRecorder creates a new recorder up to the given node count, each with the given capacity. Each per-node recorder is a ring buffer, so only the latest <nodeCapacity> Statuses are kept at any time for each node. The per-node records are created lazily as needed. The timestamper callback is used to mark times. Use `time.Now` if unsure. Returns the newly created instance; if parameters are incorrect, returns an error, on which case the returned instance should be ignored.

func (*Recorder) Cap

func (rr *Recorder) Cap() int

Cap returns the maximum capacity of each NodeRecorder

func (*Recorder) Content

func (rr *Recorder) Content() map[string][]RecordedStatus

Content() returns a shallow copy of all the recorded statuses, by node name.

func (*Recorder) ContentForNode

func (rr *Recorder) ContentForNode(nodeName string) ([]RecordedStatus, bool)

ContentForNode returns a shallow copy of all the recorded status for the given nodeName. Returns the content and a boolean which tells if the node is known or not

func (*Recorder) CountNodes

func (rr *Recorder) CountNodes() int

CountNodes returns how many Nodes are known to the Recorder

func (*Recorder) CountRecords

func (rr *Recorder) CountRecords(nodeName string) int

CountRecords returns how many Records are held for the give nodeName in the Recorder

func (*Recorder) Len

func (rr *Recorder) Len() int

Len returns the total number of records across all nodes

func (*Recorder) MaxNodes

func (rr *Recorder) MaxNodes() int

Cap returns the maximum nodes allowed in this Recorder

func (*Recorder) Push

func (rr *Recorder) Push(st podfingerprint.Status) error

Push adds a new Status to the record for its node, evicting the oldest Status belonging to the same node if necessary. Per-node records are created lazily as needed, up to the configured maximum. The pushed status is a full independent copy of the provided Status. If the Status added is inconsistent, returns an error detailing the reason. Statuses are evicted only in case of success.

type Timestamper

type Timestamper func() time.Time

Timestampr is the function called to get the timestamps. A good default is time.Now

Jump to

Keyboard shortcuts

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