label

package
v0.10.0 Latest Latest
Warning

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

Go to latest
Published: Jul 30, 2020 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Distinct

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

Distinct wraps a variable-size array of `kv.KeyValue`, constructed with keys in sorted order. This can be used as a map key or for equality checking between Sets.

func (Distinct) Valid

func (d Distinct) Valid() bool

Valid returns true if this value refers to a valid `*Set`.

type Encoder

type Encoder interface {
	// Encode returns the serialized encoding of the label
	// set using its Iterator.  This result may be cached
	// by a label.Set.
	Encode(Iterator) string

	// ID returns a value that is unique for each class of
	// label encoder.  Label encoders allocate these using
	// `NewEncoderID`.
	ID() EncoderID
}

Encoder is a mechanism for serializing a label set into a specific string representation that supports caching, to avoid repeated serialization. An example could be an exporter encoding the label set into a wire representation.

func DefaultEncoder

func DefaultEncoder() Encoder

DefaultEncoder returns a label encoder that encodes labels in such a way that each escaped label's key is followed by an equal sign and then by an escaped label's value. All key-value pairs are separated by a comma.

Escaping is done by prepending a backslash before either a backslash, equal sign or a comma.

type EncoderID

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

EncoderID is used to identify distinct Encoder implementations, for caching encoded results.

func NewEncoderID

func NewEncoderID() EncoderID

NewEncoderID returns a unique label encoder ID. It should be called once per each type of label encoder. Preferably in init() or in var definition.

func (EncoderID) Valid

func (id EncoderID) Valid() bool

Valid returns true if this encoder ID was allocated by `NewEncoderID`. Invalid encoder IDs will not be cached.

type Iterator

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

Iterator allows iterating over the set of labels in order, sorted by key.

func (*Iterator) Attribute

func (i *Iterator) Attribute() kv.KeyValue

Attribute is a synonym for Label().

func (*Iterator) IndexedLabel

func (i *Iterator) IndexedLabel() (int, kv.KeyValue)

IndexedLabel returns current index and label. Must be called only after Next returns true.

func (*Iterator) Label

func (i *Iterator) Label() kv.KeyValue

Label returns current kv.KeyValue. Must be called only after Next returns true.

func (*Iterator) Len

func (i *Iterator) Len() int

Len returns a number of labels in the iterator's `*Set`.

func (*Iterator) Next

func (i *Iterator) Next() bool

Next moves the iterator to the next position. Returns false if there are no more labels.

func (*Iterator) ToSlice

func (i *Iterator) ToSlice() []kv.KeyValue

ToSlice is a convenience function that creates a slice of labels from the passed iterator. The iterator is set up to start from the beginning before creating the slice.

type MergeItererator added in v0.6.0

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

MergeIterator supports iterating over two sets of labels while eliminating duplicate values from the combined set. The first iterator value takes precedence.

func NewMergeIterator added in v0.6.0

func NewMergeIterator(s1, s2 *Set) MergeItererator

NewMergeIterator returns a MergeIterator for merging two label sets Duplicates are resolved by taking the value from the first set.

func (*MergeItererator) Label added in v0.6.0

func (m *MergeItererator) Label() kv.KeyValue

Label returns the current value after Next() returns true.

func (*MergeItererator) Next added in v0.6.0

func (m *MergeItererator) Next() bool

Next returns true if there is another label available.

type Set

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

Set is the representation for a distinct label set. It manages an immutable set of labels, with an internal cache for storing label encodings.

This type supports the `Equivalent` method of comparison using values of type `Distinct`.

This type is used to implement: 1. Metric labels 2. Resource sets 3. Correlation map (TODO)

func EmptySet

func EmptySet() *Set

func NewSet

func NewSet(kvs ...kv.KeyValue) Set

NewSet returns a new `*Set`. See the documentation for `NewSetWithSortable` for more details.

Except for empty sets, this method adds an additional allocation compared with a call to `NewSetWithSortable`.

func NewSetWithSortable

func NewSetWithSortable(kvs []kv.KeyValue, tmp *Sortable) Set

NewSetWithSortable returns a new `*Set`.

Duplicate keys are eliminated by taking the last value. This re-orders the input slice so that unique last-values are contiguous at the end of the slice.

This ensures the following:

- Last-value-wins semantics - Caller sees the reordering, but doesn't lose values - Repeated call preserve last-value wins.

Note that methods are defined `*Set`, although no allocation for `Set` is required. Callers can avoid memory allocations by:

  • allocating a `Sortable` for use as a temporary in this method
  • allocating a `Set` for storing the return value of this constructor.

The result maintains a cache of encoded labels, by label.EncoderID. This value should not be copied after its first use.

func (*Set) Encoded

func (l *Set) Encoded(encoder Encoder) string

Encoded returns the encoded form of this set, according to `encoder`. The result will be cached in this `*Set`.

func (*Set) Equals

func (l *Set) Equals(o *Set) bool

Equals returns true if the argument set is equivalent to this set.

func (*Set) Equivalent

func (l *Set) Equivalent() Distinct

Equivalent returns a value that may be used as a map key. The Distinct type guarantees that the result will equal the equivalent Distinct value of any label set with the same elements as this, where sets are made unique by choosing the last value in the input for any given key.

func (*Set) Get

func (l *Set) Get(idx int) (kv.KeyValue, bool)

Get returns the KeyValue at ordered position `idx` in this set.

func (*Set) HasValue

func (l *Set) HasValue(k kv.Key) bool

HasValue tests whether a key is defined in this set.

func (*Set) Iter

func (l *Set) Iter() Iterator

Iter returns an iterator for visiting the labels in this set.

func (*Set) Len

func (l *Set) Len() int

Len returns the number of labels in this set.

func (*Set) MarshalJSON

func (l *Set) MarshalJSON() ([]byte, error)

MarshalJSON returns the JSON encoding of the `*Set`.

func (*Set) ToSlice

func (l *Set) ToSlice() []kv.KeyValue

ToSlice returns the set of labels belonging to this set, sorted, where keys appear no more than once.

func (*Set) Value

func (l *Set) Value(k kv.Key) (kv.Value, bool)

Value returns the value of a specified key in this set.

type Sortable

type Sortable []kv.KeyValue

Sortable implements `sort.Interface`, used for sorting `kv.KeyValue`. This is an exported type to support a memory optimization. A pointer to one of these is needed for the call to `sort.Stable()`, which the caller may provide in order to avoid an allocation. See `NewSetWithSortable()`.

func (*Sortable) Len

func (l *Sortable) Len() int

Len implements `sort.Interface`.

func (*Sortable) Less

func (l *Sortable) Less(i, j int) bool

Less implements `sort.Interface`.

func (*Sortable) Swap

func (l *Sortable) Swap(i, j int)

Swap implements `sort.Interface`.

Jump to

Keyboard shortcuts

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