tagset

package module
v0.52.1 Latest Latest
Warning

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

Go to latest
Published: Apr 3, 2024 License: Apache-2.0 Imports: 6 Imported by: 3

Documentation

Overview

Package tagset supports creation and manipulation of sets of tags. It does so in a safe and efficient fashion, supporting:

- consistent hashing of tagsets to recognize commonalities - flexible combination of tagsets from multiple sources - immutability to allow re-use of tagsets

The package otherwise presents a fairly abstract API that allows performance optimizations without changing semantics.

Accumulators

HashlessTagsAccumulator and HashingTagsAccumulator both allow building tagsets bit-by-bit, by appending new tags.

HashedTags

The HashedTags type represents an _immutable_ set of tags and associated hashes. It is the primary data structure used to represent a set of tags.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type CompositeTags

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

CompositeTags stores read-only views of two tag sets and provides methods to iterate them easily.

CompositeTags is designed to be used for metric tags created by the aggregator (Context, Serie, SketchSeries, ...).

func CombineCompositeTagsAndSlice

func CombineCompositeTagsAndSlice(compositeTags CompositeTags, tags []string) CompositeTags

CombineCompositeTagsAndSlice creates a new CompositeTags from an existing CompositeTags and string slice.

Returned value may reference the argument slices directly (or not). Callers should avoid modifying the slices after calling this function. Slices contained in compositeTags are not modified, but may be copied. Prefer constructing a complete value in one go with NewCompositeTags instead.

func CompositeTagsFromSlice

func CompositeTagsFromSlice(tags []string) CompositeTags

CompositeTagsFromSlice creates a new CompositeTags from a slice

func NewCompositeTags

func NewCompositeTags(tags1 []string, tags2 []string) CompositeTags

NewCompositeTags creates a new CompositeTags with the given slices.

Returned value may reference the argument slices directly (or not). Callers should avoid modifying the slices after calling this function.

func (*CompositeTags) CombineWithSlice

func (t *CompositeTags) CombineWithSlice(tags []string)

CombineWithSlice adds tags to the composite tags. Consumes the slice.

Returned value may reference the argument tags slice directly (or not). Callers should avoid modifying the slices after calling this function. Slices contained in t are not modified, but may be copied. Prefer constructing a complete value in one go with NewCompositeTags instead.

func (CompositeTags) Find

func (t CompositeTags) Find(callback func(tag string) bool) bool

Find returns whether `callback` returns true for a tag

func (CompositeTags) ForEach

func (t CompositeTags) ForEach(callback func(tag string))

ForEach applies `callback` to each tag

func (CompositeTags) ForEachErr

func (t CompositeTags) ForEachErr(callback func(tag string) error) error

ForEachErr applies `callback` to each tag while `callback“ returns nil. The first error is returned.

func (CompositeTags) Join

func (t CompositeTags) Join(separator string) string

Join performs strings.Join on tags

func (CompositeTags) Len

func (t CompositeTags) Len() int

Len returns the length of the tags

func (CompositeTags) MarshalJSON

func (t CompositeTags) MarshalJSON() ([]byte, error)

MarshalJSON serializes a Payload to JSON

func (*CompositeTags) UnmarshalJSON

func (t *CompositeTags) UnmarshalJSON(b []byte) error

UnmarshalJSON implements the json.Unmarshaler interface. UnmarshalJSON receiver need to be a pointer to modify `t`.

func (CompositeTags) UnsafeToReadOnlySliceString

func (t CompositeTags) UnsafeToReadOnlySliceString() []string

UnsafeToReadOnlySliceString creates a new slice containing all tags. The caller of this method must ensure that the slice is never mutated. Should be used only for performance reasons.

type HashGenerator

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

A HashGenerator generates hashes for tag sets, with the property that the hash is invariant over re-ordering of tags and duplicate tags.

This type holds storage for hash operations that can be re-used between operations. It is not threadsafe and the caller must ensure that an instance's Hash method is not called concurrently.

func NewHashGenerator

func NewHashGenerator() *HashGenerator

NewHashGenerator creates a new HashGenerator

func (*HashGenerator) Dedup2

Dedup2 removes duplicates from two tags accumulators. Duplicate tags are removed, so at the end tag each tag is present once in either l or r, but not both at the same time.

First, duplicates are removed from l. Then duplicates are removed from r, including any tags that are already present in l.

func (*HashGenerator) Hash

Hash calculates the cumulative XOR of all unique tags in the builder. As a side-effect, it sorts and deduplicates the hashes contained in the builder.

type HashedTags

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

HashedTags is an immutable slice of pre-hashed tags.

func NewHashedTagsFromSlice

func NewHashedTagsFromSlice(tags []string) HashedTags

NewHashedTagsFromSlice creates a new instance, re-using tags as the internal slice.

func (HashedTags) Copy

func (h HashedTags) Copy() []string

Copy returns a new slice with the copy of the tags

func (HashedTags) Get

func (h HashedTags) Get() []string

Get returns the internal slice.

NOTE: this returns a mutable reference to data in this immutable data structure. It is still used by comp/core/tagger/tagstore, but new uses should not be added.

func (HashedTags) Len

func (h HashedTags) Len() int

Len returns number of tags

func (HashedTags) Slice

func (h HashedTags) Slice(i, j int) HashedTags

Slice returns a shared sub-slice of tags from t.

type HashingTagsAccumulator

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

HashingTagsAccumulator allows to build a slice of tags, including the hashes of each tag.

This type implements TagsAccumulator.

func NewHashingTagsAccumulator

func NewHashingTagsAccumulator() *HashingTagsAccumulator

NewHashingTagsAccumulator returns a new empty HashingTagsAccumulator

func NewHashingTagsAccumulatorWithTags

func NewHashingTagsAccumulatorWithTags(tags []string) *HashingTagsAccumulator

NewHashingTagsAccumulatorWithTags return a new HashingTagsAccumulator, initialized with tags.

func (*HashingTagsAccumulator) Append

func (h *HashingTagsAccumulator) Append(tags ...string)

Append appends tags to the builder

func (*HashingTagsAccumulator) AppendHashed

func (h *HashingTagsAccumulator) AppendHashed(src HashedTags)

AppendHashed appends tags and corresponding hashes to the builder

func (HashingTagsAccumulator) Copy

func (h HashingTagsAccumulator) Copy() []string

Copy returns a new slice with the copy of the tags

func (*HashingTagsAccumulator) Dup

Dup returns a complete copy of HashingTagsAccumulator

func (*HashingTagsAccumulator) Get

func (h *HashingTagsAccumulator) Get() []string

Get returns the internal slice

func (*HashingTagsAccumulator) Hash

func (h *HashingTagsAccumulator) Hash() uint64

Hash returns combined hashes of all tags in the accumulator.

Does not account for possibility of duplicates. Must be called after a call to Dedup2 or SortUniq first.

func (*HashingTagsAccumulator) Hashes

func (h *HashingTagsAccumulator) Hashes() []uint64

Hashes returns the internal slice of tag hashes

func (HashingTagsAccumulator) Len

func (h HashingTagsAccumulator) Len() int

Len returns number of tags

func (*HashingTagsAccumulator) Less

func (h *HashingTagsAccumulator) Less(i, j int) bool

Less implements sort.Interface.Less

func (*HashingTagsAccumulator) Reset

func (h *HashingTagsAccumulator) Reset()

Reset resets the size of the builder to 0 without discaring the internal buffer

func (*HashingTagsAccumulator) SortUniq

func (h *HashingTagsAccumulator) SortUniq()

SortUniq sorts and remove duplicate in place

func (*HashingTagsAccumulator) Swap

func (h *HashingTagsAccumulator) Swap(i, j int)

Swap implements sort.Interface.Swap

func (*HashingTagsAccumulator) Truncate

func (h *HashingTagsAccumulator) Truncate(len int)

Truncate retains first n tags in the buffer without discarding the internal buffer

type HashlessTagsAccumulator

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

HashlessTagsAccumulator allows to build a slice of tags, in a context where the hashes for those tags are not useful.

This type implements TagsAccumulator.

func NewHashlessTagsAccumulator

func NewHashlessTagsAccumulator() *HashlessTagsAccumulator

NewHashlessTagsAccumulator returns a new empty HashlessTagsAccumulator.

func NewHashlessTagsAccumulatorFromSlice

func NewHashlessTagsAccumulatorFromSlice(data []string) *HashlessTagsAccumulator

NewHashlessTagsAccumulatorFromSlice return a new HashlessTagsAccumulator with the input slice for it's internal buffer.

func (*HashlessTagsAccumulator) Append

func (h *HashlessTagsAccumulator) Append(tags ...string)

Append appends tags to the builder

func (*HashlessTagsAccumulator) AppendHashed

func (h *HashlessTagsAccumulator) AppendHashed(src HashedTags)

AppendHashed appends tags and corresponding hashes to the builder

func (*HashlessTagsAccumulator) AppendHashlessAccumulator

func (h *HashlessTagsAccumulator) AppendHashlessAccumulator(src *HashlessTagsAccumulator)

AppendHashlessAccumulator appends tags from the given accumulator

func (*HashlessTagsAccumulator) Copy

func (h *HashlessTagsAccumulator) Copy() []string

Copy returns a new slice with the copy of the tags

func (*HashlessTagsAccumulator) Get

func (h *HashlessTagsAccumulator) Get() []string

Get returns the internal slice

func (*HashlessTagsAccumulator) Reset

func (h *HashlessTagsAccumulator) Reset()

Reset resets the size of the builder to 0 without discarding the internal buffer

func (*HashlessTagsAccumulator) SortUniq

func (h *HashlessTagsAccumulator) SortUniq()

SortUniq sorts and remove duplicate in place

type TagsAccumulator

type TagsAccumulator interface {
	// Append the given tags to the tag set
	Append(...string)
	// Append the tags contained in the given HashedTags instance to the tag set.
	AppendHashed(HashedTags)
}

A TagsAccumulator accumulates tags. The underlying type will provide a means of getting the resulting tag set.

Jump to

Keyboard shortcuts

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