store

package
v0.4.4 Latest Latest
Warning

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

Go to latest
Published: Apr 16, 2024 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Overview

store contains an interface for accumulating and accessing vanflow record state, as well as an in memory cache implementation that stores records in a synchronized map.

Index

Constants

View Source
const (
	IndexBySource = "source"
	IndexBySite   = "site"
)

Variables

This section is empty.

Functions

func WithIfMatch

func WithIfMatch(ctx context.Context, etag string) context.Context

WithIfMatch returns a new context loaded with an ETag for an If-Match conditional

Types

type CacheConfig

type CacheConfig struct {
	Key      KeyFunc
	Indexers map[string]CacheIndexer

	EventHandlers EventHandlerFuncs
}

type CacheIndexer

type CacheIndexer func(Entry) []string

CacheIndexer returns a list of index buckets that an entry belongs to. For example, a "IndexBySite" index might have a Link entry that belongs to the bucket for the two sites it connects.

type DispatchRegistry

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

DispatchRegistry serves as a registry where store implementations are registered by record type. Used to create a dispatcher for each event source so that updates can be dispatched to the appropriate store.

func (DispatchRegistry) NewDispatcher

func (d DispatchRegistry) NewDispatcher(source SourceRef) Dispatcher

NewDispatcher creates a new dispatcher for that source

func (*DispatchRegistry) RegisterStore

func (d *DispatchRegistry) RegisterStore(record vanflow.Record, stor Interface)

RegisterStore includes a store for the given record type in the registry. Subsequent Dispatchers will route records matching that record type to this store.

type Dispatcher

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

Dispatcher provides the means to dispatch Records from a given RecordMessage to multiple configured stores based on the record's type.

func (Dispatcher) Dispatch

func (d Dispatcher) Dispatch(msg vanflow.RecordMessage)

Dispatch each record in the message to the configured store.

type Entry

type Entry struct {
	Meta     Metadata
	TypeMeta vanflow.TypeMeta
	Record   vanflow.Record
}

Entry is the unit of storage in the store. It wraps a Record with additional context about that record that may not be a part of the record itself.

type EventHandlerFuncs

type EventHandlerFuncs struct {
	OnAdd    func(entry Entry)
	OnChange func(prev, curr Entry)
	OnDelete func(entry Entry)
}

type Interface

type Interface interface {
	RecordAccumulator

	Get(ctx context.Context, obj Entry) (Single, error)
	Add(ctx context.Context, obj Entry) error
	Update(ctx context.Context, obj Entry) error
	Delete(ctx context.Context, obj Entry) error

	List(ctx context.Context, opts *Selector) (Set, error)
	Index(ctx context.Context, idx string, obj Entry, opts *Selector) (Set, error)
	IndexValues(ctx context.Context, idx string) ([]string, error)

	Replace(context.Context, []Entry) error
}

Interface (externally store.Interface) descibes the methods for interracting with a store

func NewDefaultCachingStore

func NewDefaultCachingStore(cfg CacheConfig) Interface

type KeyFunc

type KeyFunc func(entry Entry) (string, error)

KeyFunc returns the identity of the entry so that the cache knows how to store it.

type Metadata

type Metadata struct {
	// Source of the Entry
	Source SourceRef
	// UpdatedAt last time the entry was updated
	UpdatedAt time.Time
	// Annotations that describe the entry
	Annotations map[string]string
}

Metadata about a Entry

type Ordering

type Ordering int
const (
	Ascending  Ordering = 0
	Descending Ordering = 1
)

type RecordAccumulator

type RecordAccumulator interface {
	// Accumulate new partial state from a Record
	Accumulate(source SourceRef, record vanflow.Record) error
}

type Selector

type Selector struct {
	Offset   int
	Limit    int
	Continue string

	Ordering Ordering
}

type Set

type Set struct {
	Entries []Entry

	Continue string
}

Set wraps a collection of Entries with additional store context

type Single

type Single struct {
	Entry

	Found bool
	ETag  string
}

Single wraps an Entry with additional store context

type SourceRef

type SourceRef struct {
	APIVersion string
	Type       string
	Name       string
}

SourceRef describes the source of an entry

func (SourceRef) String

func (ref SourceRef) String() string

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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