Documentation
¶
Index ¶
- Constants
- Variables
- func DumpToFile(dir, file string, obj any) error
- func FileNameToNodeName(name string) string
- func LoadFromFile(dir, file string, obj any) error
- func NodeNameToFileName(name string) string
- type NodeOption
- type NodeRecorder
- type Option
- type RecordedStatus
- type Recorder
- func (rr *Recorder) Cap() int
- func (rr *Recorder) Content() map[string][]RecordedStatus
- func (rr *Recorder) ContentForNode(nodeName string) ([]RecordedStatus, bool)
- func (rr *Recorder) CountNodes() int
- func (rr *Recorder) CountRecords(nodeName string) int
- func (rr *Recorder) Len() int
- func (rr *Recorder) MaxNodes() int
- func (rr *Recorder) Push(st podfingerprint.Status) error
- type Timestamper
Constants ¶
const (
DefaultMaxNodes = 1023
)
Variables ¶
Functions ¶
func DumpToFile ¶
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 LoadFromFile ¶
LoadFromFile decodes the JSON data found in `file` placed in `dir` and stores it into `obj`, which must be a pointer.
func NodeNameToFileName ¶
Types ¶
type NodeOption ¶ added in v0.2.5
type NodeOption func(*NodeRecorder)
func WithCapacity ¶ added in v0.2.5
func WithCapacity(capacity int) NodeOption
func WithTimestamper ¶ added in v0.2.6
func WithTimestamper(tsr func() time.Time) NodeOption
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, opts ...NodeOption) (*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 Option ¶ added in v0.2.6
type Option func(*Recorder)
func WithMaxNodes ¶ added in v0.2.6
func WithNodeCapacity ¶ added in v0.2.6
func WithNodeTimestamper ¶ added in v0.2.6
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 ¶
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) 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 ¶
CountNodes returns how many Nodes are known to the Recorder
func (*Recorder) CountRecords ¶
CountRecords returns how many Records are held for the give nodeName in the 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 ¶
Timestampr is the function called to get the timestamps. A good default is time.Now