promutils

package
v0.0.0-...-7d8b796 Latest Latest
Warning

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

Go to latest
Published: Oct 16, 2024 License: Apache-2.0 Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ParseDuration

func ParseDuration(s string) (time.Duration, error)

ParseDuration parses duration string in Prometheus format

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() (interface{}, error)

MarshalYAML implements yaml.Marshaler interface.

func (*Duration) UnmarshalYAML

func (pd *Duration) UnmarshalYAML(unmarshal func(interface{}) 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 tests

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 respresentation for x.

func (*Labels) MarshalYAML

func (x *Labels) MarshalYAML() (interface{}, 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 fo details.

func (*Labels) Reset

func (x *Labels) Reset()

Reset resets x.

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(interface{}) error) error

UnmarshalYAML implements yaml.Unmarshaler interface.

Jump to

Keyboard shortcuts

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