labelnamevalueindex

package
v1.11.0-cni-plu...-0883212 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2024 License: Apache-2.0, Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type FullScanStrategy

type FullScanStrategy[ItemID comparable, Item Labeled] struct {
	// contains filtered or unexported fields
}

FullScanStrategy is a ScanStrategy that scans all items in a completely unoptimized way. It is returned if the selector cannot be optimized.

func (FullScanStrategy[ItemID, Item]) EstimatedItemsToScan

func (s FullScanStrategy[ItemID, Item]) EstimatedItemsToScan() int

func (FullScanStrategy[ItemID, Item]) Name

func (s FullScanStrategy[ItemID, Item]) Name() string

func (FullScanStrategy[ItemID, Item]) Scan

func (s FullScanStrategy[ItemID, Item]) Scan(f func(id ItemID) bool)

func (FullScanStrategy[ItemID, Item]) String

func (s FullScanStrategy[ItemID, Item]) String() string

type LabelNameMultiValueStrategy

type LabelNameMultiValueStrategy[ItemID comparable] struct {
	// contains filtered or unexported fields
}

LabelNameMultiValueStrategy is a ScanStrategy that scans over items that have specific, values for a certain label.

func (LabelNameMultiValueStrategy[ItemID]) EstimatedItemsToScan

func (s LabelNameMultiValueStrategy[ItemID]) EstimatedItemsToScan() int

func (LabelNameMultiValueStrategy[ItemID]) Name

func (s LabelNameMultiValueStrategy[ItemID]) Name() string

func (LabelNameMultiValueStrategy[ItemID]) Scan

func (s LabelNameMultiValueStrategy[ItemID]) Scan(f func(id ItemID) bool)

func (LabelNameMultiValueStrategy[ItemID]) String

func (s LabelNameMultiValueStrategy[ItemID]) String() string

type LabelNameSingleValueStrategy

type LabelNameSingleValueStrategy[ItemID comparable] struct {
	// contains filtered or unexported fields
}

LabelNameSingleValueStrategy is a ScanStrategy that scans over items that have a specific value for a certain label. It is the narrowest, most optimized strategy.

func (LabelNameSingleValueStrategy[ItemID]) EstimatedItemsToScan

func (s LabelNameSingleValueStrategy[ItemID]) EstimatedItemsToScan() int

func (LabelNameSingleValueStrategy[ItemID]) Name

func (s LabelNameSingleValueStrategy[ItemID]) Name() string

func (LabelNameSingleValueStrategy[ItemID]) Scan

func (s LabelNameSingleValueStrategy[ItemID]) Scan(f func(id ItemID) bool)

func (LabelNameSingleValueStrategy[ItemID]) String

func (s LabelNameSingleValueStrategy[ItemID]) String() string

type LabelNameStrategy

type LabelNameStrategy[ItemID comparable] struct {
	// contains filtered or unexported fields
}

LabelNameStrategy is a ScanStrategy that scans all object that have a particular label, no matter the value of that label. It is used for selectors such as "has(labelName)".

func (LabelNameStrategy[ItemID]) EstimatedItemsToScan

func (s LabelNameStrategy[ItemID]) EstimatedItemsToScan() int

func (LabelNameStrategy[ItemID]) Name

func (s LabelNameStrategy[ItemID]) Name() string

func (LabelNameStrategy[ItemID]) Scan

func (s LabelNameStrategy[ItemID]) Scan(f func(id ItemID) bool)

func (LabelNameStrategy[ItemID]) String

func (s LabelNameStrategy[ItemID]) String() string

type LabelNameValueIndex

type LabelNameValueIndex[ItemID comparable, Item Labeled] struct {
	// contains filtered or unexported fields
}

LabelNameValueIndex stores a set of Labeled objects by ID, and it indexes them according to their own (not inherited) labels/label values for efficient scans based on selector LabelRestrictions. The StrategyFor method returns the most efficient strategy for a particular restriction. Returning strategies allows the caller to compare different available strategies against each other without executing them.

Note: LabelNameValueIndex is not inheritance-aware, it indexes items solely on their own labels without taking parents into account. This avoids needing to reindex every item when a parent changes, allowing that to be handled more efficiently at the layer above.

func New

func New[ItemID comparable, Item Labeled](nameOfTrackedItems string) *LabelNameValueIndex[ItemID, Item]

func (*LabelNameValueIndex[ItemID, Item]) Add

func (idx *LabelNameValueIndex[ItemID, Item]) Add(id ItemID, item Item)

Add an item to the index. Note: its labels will be captured at this time, so if the objects labels are mutated, it is important to remove the item before changing its labels and then re-Add the updated item.

To avoid the above bug, panics if the same ID is added twice.

func (*LabelNameValueIndex[ItemID, Item]) FullScanStrategy

func (idx *LabelNameValueIndex[ItemID, Item]) FullScanStrategy() ScanStrategy[ItemID]

FullScanStrategy returns a scan strategy that scans all items.

func (*LabelNameValueIndex[ItemID, Item]) Get

func (idx *LabelNameValueIndex[ItemID, Item]) Get(id ItemID) (Item, bool)

Get looks up an item by its ID. (Allows this object to be the primary map datastructure for storing the items.)

func (*LabelNameValueIndex[ItemID, Item]) Len

func (idx *LabelNameValueIndex[ItemID, Item]) Len() int

func (*LabelNameValueIndex[ItemID, Item]) Remove

func (idx *LabelNameValueIndex[ItemID, Item]) Remove(id ItemID)

Remove an item from the index. Note that it is important that the labels are not mutated between Add and Remove calls.

func (*LabelNameValueIndex[ItemID, Item]) StrategyFor

func (idx *LabelNameValueIndex[ItemID, Item]) StrategyFor(labelName string, r parser.LabelRestriction) ScanStrategy[ItemID]

StrategyFor returns the best available ScanStrategy for the given label name and selector LabelRestriction (which should be the restriction for that label). If the LabelRestriction is not "useful", returns FullScanStrategy().

type Labeled

type Labeled interface {
	OwnLabels() map[string]string
}

type NoMatchStrategy

type NoMatchStrategy[ItemID any] struct {
}

NoMatchStrategy is a ScanStrategy that produces no items, it is returned when the index can prove that there are no matching items.

func (NoMatchStrategy[ItemID]) EstimatedItemsToScan

func (n NoMatchStrategy[ItemID]) EstimatedItemsToScan() int

func (NoMatchStrategy[ItemID]) Name

func (n NoMatchStrategy[ItemID]) Name() string

func (NoMatchStrategy[ItemID]) Scan

func (n NoMatchStrategy[ItemID]) Scan(func(id ItemID) bool)

func (NoMatchStrategy[ItemID]) String

func (n NoMatchStrategy[ItemID]) String() string

type ScanStrategy

type ScanStrategy[ItemID any] interface {
	// EstimatedItemsToScan returns an estimate for how many items this scan
	// strategy would produce if Scan() was called.  Some strategies return
	// an approximate value because calculating the real value would require
	// executing the scan.
	EstimatedItemsToScan() int

	// Scan executes the scan. It calls the given func once with each ID
	// produced by the scan.  Each ID is only emitted once (the strategy is
	// responsible for any deduplication).  Scanning continues while the func
	// returns true.
	Scan(func(id ItemID) bool)

	// Name of the strategy (used in prometheus metrics).
	Name() string

	fmt.Stringer
}

ScanStrategy abstracts over particular types of scans of the index, allowing them to be compared/scored without actually executing the scan until ready to do so.

Jump to

Keyboard shortcuts

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