metadata

package
v0.9.1 Latest Latest
Warning

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

Go to latest
Published: Jan 27, 2023 License: Apache-2.0 Imports: 5 Imported by: 9

Documentation

Overview

Package metadata describes metadata paths stored in the cache per target.

Index

Constants

View Source
const (
	// Root node where metadata is cached.
	Root = "meta"

	// Sync is a boolean that reports whether all target state is cached.
	Sync = "sync"
	// Connected is a boolean that reports whether updates are being received.
	Connected = "connected"
	// ConnectedAddr is a string denoting the last-hop IP address of a connected
	// target.
	ConnectedAddr = "connectedAddress"
	// AddCount is the total number of leaves that have been added.
	AddCount = "targetLeavesAdded"
	// DelCount is the total number of leaves that have been deleted.
	DelCount = "targetLeavesDeleted"
	// EmptyCount is the total number of notifications delivered that contain no
	// updates or deletes.
	EmptyCount = "targetLeavesEmpty"
	// LeafCount is the current total leaves stored in the cache.
	LeafCount = "targetLeaves"
	// UpdateCount is the total number of leaf updates received.
	UpdateCount = "targetLeavesUpdated"
	// StaleCount is the total number of leaf updates that had timestamp older
	// than that cached.
	StaleCount = "targetLeavesStale"
	// SuppressedCount is the total number of leaf updates that were suppressed
	// because the update had the same value as already cached.
	SuppressedCount = "targetLeavesSuppressed"
	// Size is the total number of bytes used to store all values.  This count
	// excludes all indexing overhead.
	Size = "targetSize"
	// LatestTimestamp is the latest timestamp for any update received for the
	// target.
	LatestTimestamp = "latestTimestamp"
	// ConnectError is the error related to connection failure.
	ConnectError = "connectError"
)

Variables

View Source
var (
	// TargetBoolValues is the list of all bool metadata fields.
	TargetBoolValues = map[string]bool{
		Sync:      true,
		Connected: true,
	}

	// TargetIntValues is the list of all int64 metadata fields.
	TargetIntValues = map[string]*IntValue{
		AddCount:        {[]string{Root, AddCount}, true},
		DelCount:        {[]string{Root, DelCount}, true},
		EmptyCount:      {[]string{Root, EmptyCount}, true},
		LeafCount:       {[]string{Root, LeafCount}, true},
		UpdateCount:     {[]string{Root, UpdateCount}, true},
		StaleCount:      {[]string{Root, StaleCount}, true},
		SuppressedCount: {[]string{Root, SuppressedCount}, true},
		Size:            {[]string{Root, Size}, true},
		LatestTimestamp: {[]string{Root, LatestTimestamp}, true},
	}

	// TargetStrValues is the list of all string metadata fields.
	TargetStrValues = map[string]*StrValue{
		ConnectedAddr: {Valid: true, InitEmptyStr: true},
		ConnectError:  {Valid: true, InitEmptyStr: false},
	}
)
View Source
var ErrInvalidValue = errors.New("invalid metadata value")

ErrInvalidValue is returned when a metadata operation is attempted on a value that does not exist.

View Source
var ErrUnsetValue = errors.New("unset value")

ErrUnsetValue is returned when a metadata Get is attempted on a value that has not been Set (or Added).

Functions

func LatencyPath

func LatencyPath(w time.Duration, typ latency.StatType) []string

LatencyPath returns the metadata path for the latency statistics of window w and type typ.

func Path

func Path(value string) []string

Path is a convenience function that will return the full metadata path for any valid metadata value. Only metadata values registered above in TargetBoolValues, TargetIntValues, and TargetStrValues will return a path. An invalid metadata value will return nil.

func RegisterIntValue

func RegisterIntValue(name string, val *IntValue)

RegisterIntValue registers an int64 type metadata whose path and options are in val.

func RegisterLatencyMetadata

func RegisterLatencyMetadata(windowSizes []time.Duration)

RegisterLatencyMetadata registers latency stats metadata for time windows specified in windowSizes. RegisterLatencyMetadata is not thread-safe and should be called before any metadata.Metadata is instantiated.

func UnregisterIntValue

func UnregisterIntValue(name string)

UnregisterIntValue unregisters an int64 type metadata name.

Types

type IntValue

type IntValue struct {
	Path     []string // Path of the int64 metadata
	InitZero bool     // Whether to initiate to 0 (for counters starting from 0).
}

IntValue contains the path and other options for an int64 metadata.

type Metadata

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

Metadata is the container for all target specific metadata.

func New

func New() *Metadata

New returns an initialized Metadata structure. Integer values are initialized to 0. Boolean values are initialized to false. String values are initialized to empty string.

func (*Metadata) AddInt

func (m *Metadata) AddInt(value string, i int64) error

AddInt atomically increments the metadata value specified by i.

func (*Metadata) Clear

func (m *Metadata) Clear()

Clear sets all metadata values to zero values, except that ConnectError is set to EmptyError.

func (*Metadata) GetBool

func (m *Metadata) GetBool(value string) (bool, error)

GetBool atomically retrieves the metadata value specified.

func (*Metadata) GetInt

func (m *Metadata) GetInt(value string) (int64, error)

GetInt atomically retrieves the metadata value specified.

func (*Metadata) GetStr

func (m *Metadata) GetStr(value string) (string, error)

GetStr atomically retrieves the metadata value specified.

func (*Metadata) ResetEntry

func (m *Metadata) ResetEntry(entry string) error

ResetEntry resets metadata entry to zero value. It will be deleted if it is Int with InitZero as false, or Str with InitEmptyStr as false.

func (*Metadata) SetBool

func (m *Metadata) SetBool(value string, v bool) error

SetBool atomically sets the metadata value specified to v.

func (*Metadata) SetInt

func (m *Metadata) SetInt(value string, v int64) error

SetInt atomically sets the metadata value specified to v.

func (*Metadata) SetStr

func (m *Metadata) SetStr(value, v string) error

SetStr atomically sets the metadata value specified to v.

type StrValue

type StrValue struct {
	Valid        bool
	InitEmptyStr bool // Whether to initiate to "".
}

StrValue contains the valid and the option to reset to emptry string.

Jump to

Keyboard shortcuts

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