Documentation ¶
Overview ¶
Package cache is a tree-based cache of timestamped state provided from one or more gNMI targets. It accepts updates from the target(s) to refresh internal values that are made available to clients via subscriptions.
Index ¶
- Variables
- func T(n int64) time.Time
- type Cache
- func (c *Cache) Add(target string) *Target
- func (c *Cache) Connect(name string)
- func (c *Cache) ConnectError(name string, err error)
- func (c *Cache) GetTarget(target string) *Target
- func (c *Cache) GnmiUpdate(n *pb.Notification) error
- func (c *Cache) HasTarget(target string) bool
- func (c *Cache) LatencyWindows() []time.Duration
- func (c *Cache) Metadata() map[string]*metadata.Metadata
- func (c *Cache) Query(target string, query []string, fn ctree.VisitFunc) error
- func (c *Cache) Remove(target string)
- func (c *Cache) Reset(target string)
- func (c *Cache) SetClient(client func(*ctree.Leaf))
- func (c *Cache) Sync(name string)
- func (c *Cache) UpdateMetadata()
- func (c *Cache) UpdateSize()
- type Option
- func DisableEventDrivenEmulation() Option
- func WithAvgLatencyPrecision(avgLatencyPrecision time.Duration) Option
- func WithExcludedMeta(excluded []string) Option
- func WithFutureThreshold(futureThreshold time.Duration) Option
- func WithLatencyWindows(ws []string, metaUpdatePeriod time.Duration) (Option, error)
- func WithServerName(serverName string) Option
- type Target
Constants ¶
This section is empty.
Variables ¶
var ( // Now is a function that can be overridden in tests to alter the timestamps // applied to deletes and metadata updates. Now = time.Now // ErrStale is the error returned if an update is stale. ErrStale = errors.New("update is stale") // ErrFuture is the error returned if an update is too far in the future. ErrFuture = errors.New("update is too far in the future") )
Functions ¶
Types ¶
type Cache ¶
type Cache struct {
// contains filtered or unexported fields
}
Cache is a structure holding state information for multiple targets.
func New ¶
New creates a new instance of Cache that receives target updates from the translator and provides an interface to service client queries.
func (*Cache) Connect ¶
Connect creates an internal gnmi.Notification for metadata/connected path to set the state to true for the specified target.
func (*Cache) ConnectError ¶
ConnectError updates the target's metadata with the provided error.
func (*Cache) GetTarget ¶
GetTarget returns the Target from the cache corresponding to the target name.
func (*Cache) GnmiUpdate ¶
func (c *Cache) GnmiUpdate(n *pb.Notification) error
GnmiUpdate sends a pb.Notification into the cache. If the notification has multiple Updates/Deletes, each individual Update/Delete is sent to cache as a separate gnmi.Notification.
func (*Cache) HasTarget ¶
HasTarget reports whether the specified target exists in the cache or a glob (*) is passed which will match any target (even if no targets yet exist).
func (*Cache) LatencyWindows ¶
LatencyWindows returns the latency windows supported by the cache.
func (*Cache) Query ¶
Query calls the specified callback for all results matching the query. All values passed to fn are client.Notification.
func (*Cache) Reset ¶
Reset clears the cache for a target once a connection is resumed after having been lost.
func (*Cache) SetClient ¶
SetClient registers a callback function to receive calls for each update accepted by the cache. This call should be made prior to sending any updates into the cache, just after initialization.
func (*Cache) Sync ¶
Sync creates an internal gnmi.Notification with metadata/sync path to set the state to true for the specified target.
func (*Cache) UpdateMetadata ¶
func (c *Cache) UpdateMetadata()
UpdateMetadata copies the current metadata for each target cache to the metadata path within each target cache.
func (*Cache) UpdateSize ¶
func (c *Cache) UpdateSize()
UpdateSize computes the size of each target cache and updates the size metadata reported within the each target cache.
type Option ¶
type Option func(*options)
Option defines the function prototype to set options for creating a Cache.
func DisableEventDrivenEmulation ¶ added in v0.12.0
func DisableEventDrivenEmulation() Option
DisableEventDrivenEmulation returns an Option to disable event-driven emulation. Note that it only disables event-driven emulation. If the input data to Cache is already event-driven, this won't be able to disable the event-driven nature of the original data.
func WithAvgLatencyPrecision ¶
WithAvgLatencyPrecision returns an Option to set the precision of average latency stats calculated in Cache.
func WithExcludedMeta ¶ added in v0.11.0
WithExcludedMeta returns an Option to exclude a set of metadata from generating updates in the Cache. These metadatas are still maintained internally and available for other uses.
func WithFutureThreshold ¶ added in v0.11.0
WithFutureThreshold returns an Option to set the threshold for how far the timestamp of an update is in the future that still allows the update to be accepted in Cache.
func WithLatencyWindows ¶
WithLatencyWindows returns an Option to set latency windows for which latency stats are calculated and exported for each target in Cache. metaUpdatePeriod is the period for updating target metadata. The latency windows need to be multiples of this period.
func WithServerName ¶ added in v0.10.0
WithServerName returns an Option to set a name that can identify the Cache server.
type Target ¶
type Target struct {
// contains filtered or unexported fields
}
A Target hosts an indexed cache of state for a single target.
func (*Target) Connect ¶
func (t *Target) Connect()
Connect creates an internal gnmi.Notification for metadata/connected path to set the state to true for the specified target, and clear connectErr.
func (*Target) GnmiUpdate ¶
func (t *Target) GnmiUpdate(n *pb.Notification) error
GnmiUpdate sends a pb.Notification into the target cache. If the notification has multiple Updates/Deletes, each individual Update/Delete is sent to cache as a separate gnmi.Notification.