mutable

package
v0.0.0-...-be370ba Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: Apache-2.0 Imports: 21 Imported by: 0

Documentation

Overview

Package mutable handles mutable labels.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MergeRegex

func MergeRegex(input []string) (string, error)

MergeRegex returns a regular expression matching any of the input strings.

func NewIndexWrapper

func NewIndexWrapper(
	index types.Index,
	labelProcessor *LabelProcessor,
	logger zerolog.Logger,
) types.Index

NewIndexWrapper returns an index wrapper that handles mutable labels.

func NewProviderAndProcessor

func NewProviderAndProcessor(
	ctx context.Context,
	reg prometheus.Registerer,
	cluster types.Cluster,
	store Store,
	tenantLabelName string,
	logger zerolog.Logger,
) (*Provider, *LabelProcessor)

NewProviderAndProcessor builds the backend-agnostic mutable label stack on top of a backend Store: the caching Provider (used for reads and writes) and the LabelProcessor (used to translate mutable labels in queries). Both backends call this so the wiring lives in one place.

func NewQueryable

func NewQueryable(
	inner types.QueryableWithOptions,
	labelProcessor *LabelProcessor,
	logger zerolog.Logger,
) types.QueryableWithOptions

NewQueryable returns a queryable that handles mutable labels on the read path.

Types

type Label

type Label struct {
	Tenant string `json:"tenant"`
	Name   string `json:"name"`
	Value  string `json:"value"`
}

Label represents a mutable label with its value.

type LabelKey

type LabelKey struct {
	Tenant string `json:"tenant"`
	Name   string `json:"name"`
}

LabelKey is a label name and its tenant.

type LabelProcessor

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

LabelProcessor can replace mutable labels by non mutable labels.

func NewLabelProcessor

func NewLabelProcessor(provider LabelProvider, tenantLabelName string) *LabelProcessor

func (*LabelProcessor) AddMutableLabels

func (lp *LabelProcessor) AddMutableLabels(ctx context.Context, lbls labels.Labels) (labels.Labels, error)

AddMutableLabels searches for non mutable labels and add their corresponding mutable labels if they exist. For example if we have a mutable label group "mygroup" which contains 'server1', and the label instance="server1" as input, the label group="mygroup" will be added. It also removes any mutable labels present in the input.

func (*LabelProcessor) IsMutableLabel

func (lp *LabelProcessor) IsMutableLabel(ctx context.Context, tenant, name string) (bool, error)

IsMutableLabel returns whether the label name is mutable.

func (*LabelProcessor) MutableLabelNames

func (lp *LabelProcessor) MutableLabelNames(ctx context.Context, tenant string) ([]string, error)

MutableLabelNames returns all the mutable label names possible for a tenant.

func (*LabelProcessor) ReplaceMutableLabels

func (lp *LabelProcessor) ReplaceMutableLabels(
	ctx context.Context,
	matchers []*labels.Matcher,
) ([]*labels.Matcher, error)

ReplaceMutableLabels searches for mutable labels and replace them by non mutable labels. For example if we have a mutable label group "mygroup" which contains 'server1' and 'server2', the label matcher group="mygroup" becomes instance="server1|server2".

type LabelProvider

type LabelProvider interface {
	GetMutable(ctx context.Context, tenant, name, value string) (labels.Labels, error)
	GetNonMutable(ctx context.Context, tenant, name, value string) (NonMutableLabels, error)
	AllValues(ctx context.Context, tenant, name string) ([]string, error)
	MutableLabelNames(ctx context.Context, tenant string) ([]string, error)
}

LabelProvider allows to get non mutable labels from a mutable label.

type LabelWithName

type LabelWithName struct {
	Tenant         string `json:"tenant"`
	Name           string `json:"name"`
	AssociatedName string `json:"associated_name"`
}

LabelWithName represents a mutable label name with its associated non mutable label name.

type LabelWithValues

type LabelWithValues struct {
	Tenant           string   `json:"tenant"`
	Name             string   `json:"name"`
	Value            string   `json:"value"`
	AssociatedValues []string `json:"associated_values"`
}

LabelWithValues represents a mutable label with its associated non mutable labels value.

type NonMutableLabels

type NonMutableLabels struct {
	Name   string
	Values []string
}

NonMutableLabels represents a list of labels with a single name.

type Provider

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

Provider allows to get mutable labels.

func NewProvider

func NewProvider(
	ctx context.Context,
	reg prometheus.Registerer,
	cluster types.Cluster,
	store Store,
	logger zerolog.Logger,
) *Provider

NewProvider returns a new mutable label provider.

func (*Provider) AllValues

func (cp *Provider) AllValues(ctx context.Context, tenant, name string) ([]string, error)

AllValues returns all possible mutable label values for a tenant and a label name.

func (*Provider) DeleteLabelNames

func (cp *Provider) DeleteLabelNames(ctx context.Context, labelKeys []LabelKey) error

DeleteLabelNames deletes mutable label names in the store.

func (*Provider) DeleteLabelValues

func (cp *Provider) DeleteLabelValues(ctx context.Context, lbls []Label) error

DeleteLabelValues deletes label values in the store.

func (*Provider) Dump

func (cp *Provider) Dump(ctx context.Context, w io.Writer) error

Dump writes a CSV with all mutable labels known.

func (*Provider) GetMutable

func (cp *Provider) GetMutable(ctx context.Context, tenant, name, value string) (labels.Labels, error)

GetMutable returns the mutable labels corresponding to a non mutable label name and value.

func (*Provider) GetNonMutable

func (cp *Provider) GetNonMutable(ctx context.Context, tenant, name, value string) (NonMutableLabels, error)

GetNonMutable returns the non mutable labels corresponding to a mutable label name and value.

func (*Provider) Import

func (cp *Provider) Import(ctx context.Context, r io.Reader, w io.Writer, dryRun bool) error

Import read a CSV with all mutable labels to known. Existing labels are dropped then import is done. In output, show some information about import.

func (*Provider) MutableLabelNames

func (cp *Provider) MutableLabelNames(ctx context.Context, tenant string) ([]string, error)

MutableLabelNames returns all the mutable label names possible for a tenant.

func (*Provider) WriteLabelNames

func (cp *Provider) WriteLabelNames(ctx context.Context, lbls []LabelWithName) error

WriteLabelNames writes the label names to the store.

func (*Provider) WriteLabelValues

func (cp *Provider) WriteLabelValues(ctx context.Context, lbls []LabelWithValues) error

WriteLabelValues writes the label values to the store.

type Store

type Store interface {
	AssociatedNames(ctx context.Context, tenant string) (map[string]string, error)
	AssociatedValues(ctx context.Context, tenant, name string) (map[string][]string, error)
	DeleteAssociatedName(ctx context.Context, tenant, name string) error
	DeleteAssociatedValues(ctx context.Context, label Label) error
	SetAssociatedName(ctx context.Context, label LabelWithName) error
	SetAssociatedValues(ctx context.Context, label LabelWithValues) error
	AllMutableLabels(ctx context.Context) ([]LabelWithName, error)
}

Store is the backend-agnostic persistence interface for mutable labels. It is implemented by the Cassandra backend (cassandra/mutable) and the ClickHouse backend (clickhouse/mutable).

Jump to

Keyboard shortcuts

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