promutil

package
v1.117.1-cluster Latest Latest
Warning

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

Go to latest
Published: May 15, 2025 License: Apache-2.0 Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PutLabels

func PutLabels(x *Labels)

PutLabels returns x, which has been obtained via GetLabels(), to the pool.

The x mustn't be used after returning to the pool.

Types

type Duration

type Duration struct {
	D time.Duration
}

Duration is duration, which must be used in Prometheus-compatible yaml configs.

func NewDuration

func NewDuration(d time.Duration) *Duration

NewDuration returns Duration for given d.

func (*Duration) Duration

func (pd *Duration) Duration() time.Duration

Duration returns duration for pd.

func (Duration) MarshalYAML

func (pd Duration) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler interface.

func (*Duration) UnmarshalYAML

func (pd *Duration) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler interface.

type Labels

type Labels struct {
	Labels []prompbmarshal.Label
}

Labels contains Prometheus labels.

func GetLabels

func GetLabels() *Labels

GetLabels returns and empty Labels instance from the pool.

The returned Labels instance must be returned to pool via PutLabels() when no longer needed.

func MustNewLabelsFromString

func MustNewLabelsFromString(metricWithLabels string) *Labels

MustNewLabelsFromString creates labels from s, which can have the form `metric{labels}`.

This function must be used only in tests. Use NewLabelsFromString in production code.

func NewLabels

func NewLabels(capacity int) *Labels

NewLabels returns Labels with the given capacity.

func NewLabelsFromMap

func NewLabelsFromMap(m map[string]string) *Labels

NewLabelsFromMap returns Labels generated from m.

func NewLabelsFromString

func NewLabelsFromString(metricWithLabels string) (*Labels, error)

NewLabelsFromString creates labels from s, which can have the form `metric{labels}`.

This function must be used only in non performance-critical code, since it allocates too much

func (*Labels) Add

func (x *Labels) Add(name, value string)

Add adds name=value label to x.

func (*Labels) AddFrom

func (x *Labels) AddFrom(src *Labels)

AddFrom adds src labels to x.

func (*Labels) Clone

func (x *Labels) Clone() *Labels

Clone returns a clone of x.

func (*Labels) Get

func (x *Labels) Get(name string) string

Get returns value for label with the given name.

func (*Labels) GetLabels

func (x *Labels) GetLabels() []prompbmarshal.Label

GetLabels returns the list of labels from x.

func (*Labels) InitFromMap

func (x *Labels) InitFromMap(m map[string]string)

InitFromMap initializes x from m.

func (*Labels) InternStrings

func (x *Labels) InternStrings()

InternStrings interns all the strings used in x labels.

func (*Labels) Len

func (x *Labels) Len() int

Len returns the number of labels in x.

func (*Labels) Less

func (x *Labels) Less(i, j int) bool

Less compares label names at i and j index.

func (*Labels) MarshalJSON

func (x *Labels) MarshalJSON() ([]byte, error)

MarshalJSON returns JSON representation for x.

func (*Labels) MarshalYAML

func (x *Labels) MarshalYAML() (any, error)

MarshalYAML implements yaml.Marshaler interface.

func (*Labels) RemoveDuplicates

func (x *Labels) RemoveDuplicates()

RemoveDuplicates removes labels with duplicate names.

func (*Labels) RemoveLabelsWithDoubleUnderscorePrefix

func (x *Labels) RemoveLabelsWithDoubleUnderscorePrefix()

RemoveLabelsWithDoubleUnderscorePrefix removes labels with "__" prefix from x.

func (*Labels) RemoveMetaLabels

func (x *Labels) RemoveMetaLabels()

RemoveMetaLabels removes all the `__meta_` labels from x.

See https://www.robustperception.io/life-of-a-label for details.

func (*Labels) Reset

func (x *Labels) Reset()

Reset resets x.

func (*Labels) Set

func (x *Labels) Set(name, value string)

Set label value for label with given name If the label with the given name doesn't exist, it adds as the new label

func (*Labels) Sort

func (x *Labels) Sort()

Sort sorts x labels in alphabetical order of their names.

func (*Labels) SortStable

func (x *Labels) SortStable()

SortStable sorts x labels in alphabetical order of their name using stable sort.

func (*Labels) String

func (x *Labels) String() string

String returns string representation of x.

func (*Labels) Swap

func (x *Labels) Swap(i, j int)

Swap swaps labels at i and j index.

func (*Labels) ToMap

func (x *Labels) ToMap() map[string]string

ToMap returns a map for the given labels x.

func (*Labels) UnmarshalJSON

func (x *Labels) UnmarshalJSON(data []byte) error

UnmarshalJSON unmarshals JSON from data.

func (*Labels) UnmarshalYAML

func (x *Labels) UnmarshalYAML(unmarshal func(any) error) error

UnmarshalYAML implements yaml.Unmarshaler interface.

type LabelsCompressor

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

LabelsCompressor compresses []prompbmarshal.Label into short binary strings

func (*LabelsCompressor) Compress

func (lc *LabelsCompressor) Compress(dst []byte, labels []prompbmarshal.Label) []byte

Compress compresses labels, appends the compressed labels to dst and returns the result.

It is safe calling Compress from concurrent goroutines.

func (*LabelsCompressor) Decompress

func (lc *LabelsCompressor) Decompress(dst []prompbmarshal.Label, src []byte) []prompbmarshal.Label

Decompress decompresses src into []prompbmarshal.Label, appends it to dst and returns the result.

It is safe calling Decompress from concurrent goroutines.

func (*LabelsCompressor) ItemsCount

func (lc *LabelsCompressor) ItemsCount() uint64

ItemsCount returns the number of items in lc

func (*LabelsCompressor) SizeBytes

func (lc *LabelsCompressor) SizeBytes() uint64

SizeBytes returns the size of lc data in bytes

Jump to

Keyboard shortcuts

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