Documentation ¶
Index ¶
- type Distinct
- type Encoder
- type EncoderID
- type Iterator
- type MergeItererator
- type Set
- func (l *Set) Encoded(encoder Encoder) string
- func (l *Set) Equals(o *Set) bool
- func (l *Set) Equivalent() Distinct
- func (l *Set) Get(idx int) (kv.KeyValue, bool)
- func (l *Set) HasValue(k kv.Key) bool
- func (l *Set) Iter() Iterator
- func (l *Set) Len() int
- func (l *Set) MarshalJSON() ([]byte, error)
- func (l *Set) ToSlice() []kv.KeyValue
- func (l *Set) Value(k kv.Key) (value.Value, bool)
- type Sortable
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.
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.
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) IndexedAttribute ¶
IndexedAttribute is a synonym for IndexedLabel().
func (*Iterator) IndexedLabel ¶
IndexedLabel returns current index and label. Must be called only after Next returns true.
func (*Iterator) Label ¶
Label returns current kv.KeyValue. Must be called only after Next returns true.
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 NewSet ¶
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 ¶
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 ¶
Encoded returns the encoded form of this set, according to `encoder`. The result will be cached in this `*Set`.
func (*Set) Equivalent ¶
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) MarshalJSON ¶
MarshalJSON returns the JSON encoding of the `*Set`.
type Sortable ¶
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()`.