validation

package
v0.0.0-weekly-f4-test-... Latest Latest
Warning

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

Go to latest
Published: Mar 9, 2023 License: AGPL-3.0 Imports: 17 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ReasonLabel string = "reason"
	Unknown     Reason = "unknown"
	// InvalidLabels is a reason for discarding profiles which have labels that are invalid.
	InvalidLabels Reason = "invalid_labels"
	// MissingLabels is a reason for discarding profiles which have no labels.
	MissingLabels Reason = "missing_labels"
	// RateLimited is one of the values for the reason to discard samples.
	RateLimited Reason = "rate_limited"
	// OutOfOrder is a reason for discarding profiles when Phlare doesn't accept out
	// of order profiles.
	OutOfOrder Reason = "out_of_order"
	// MaxLabelNamesPerSeries is a reason for discarding a request which has too many label names
	MaxLabelNamesPerSeries Reason = "max_label_names_per_series"
	// LabelNameTooLong is a reason for discarding a request which has a label name too long
	LabelNameTooLong Reason = "label_name_too_long"
	// LabelValueTooLong is a reason for discarding a request which has a label value too long
	LabelValueTooLong Reason = "label_value_too_long"
	// DuplicateLabelNames is a reason for discarding a request which has duplicate label names
	DuplicateLabelNames Reason = "duplicate_label_names"
	// SeriesLimit is a reason for discarding lines when we can't create a new stream
	// because the limit of active streams has been reached.
	SeriesLimit Reason = "series_limit"

	SeriesLimitErrorMsg            = "" /* 188-byte string literal not displayed */
	MissingLabelsErrorMsg          = "error at least one label pair is required per profile"
	InvalidLabelsErrorMsg          = "invalid labels '%s' with error: %s"
	MaxLabelNamesPerSeriesErrorMsg = "profile series '%s' has %d label names; limit %d"
	LabelNameTooLongErrorMsg       = "profile with labels '%s' has label name too long: '%s'"
	LabelValueTooLongErrorMsg      = "profile with labels '%s' has label value too long: '%s'"
	DuplicateLabelNamesErrorMsg    = "profile with labels '%s' has duplicate label name: '%s'"
)

Variables

View Source
var (
	// DiscardedBytes is a metric of the total discarded bytes, by reason.
	DiscardedBytes = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "phlare",
			Name:      "discarded_bytes_total",
			Help:      "The total number of bytes that were discarded.",
		},
		[]string{ReasonLabel, "tenant"},
	)

	// DiscardedProfiles is a metric of the number of discarded profiles, by reason.
	DiscardedProfiles = promauto.NewCounterVec(
		prometheus.CounterOpts{
			Namespace: "phlare",
			Name:      "discarded_samples_total",
			Help:      "The total number of samples that were discarded.",
		},
		[]string{ReasonLabel, "tenant"},
	)
)

Functions

func SetDefaultLimitsForYAMLUnmarshalling

func SetDefaultLimitsForYAMLUnmarshalling(defaults Limits)

SetDefaultLimitsForYAMLUnmarshalling sets global default limits, used when loading Limits from YAML files. This is used to ensure per-tenant limits are defaulted to those values.

func TenantLimitsHandler

func TenantLimitsHandler(defaultLimits Limits, tenantLimits TenantLimits) http.HandlerFunc

TenantLimitsHandler handles user limits.

func ValidateLabels

func ValidateLabels(limits LabelValidationLimits, userID string, ls []*typesv1.LabelPair) error

ValidateLabels validates the labels of a profile.

Types

type Error

type Error struct {
	Reason Reason
	// contains filtered or unexported fields
}

func NewErrorf

func NewErrorf(reason Reason, msg string, args ...interface{}) *Error

func (*Error) Error

func (e *Error) Error() string

type LabelValidationLimits

type LabelValidationLimits interface {
	MaxLabelNameLength(userID string) int
	MaxLabelValueLength(userID string) int
	MaxLabelNamesPerSeries(userID string) int
}

type LimitError

type LimitError string

LimitError are errors that do not comply with the limits specified.

func (LimitError) Error

func (e LimitError) Error() string

type Limits

type Limits struct {
	// Distributor enforced limits.
	IngestionRateMB        float64 `yaml:"ingestion_rate_mb" json:"ingestion_rate_mb"`
	IngestionBurstSizeMB   float64 `yaml:"ingestion_burst_size_mb" json:"ingestion_burst_size_mb"`
	MaxLabelNameLength     int     `yaml:"max_label_name_length" json:"max_label_name_length"`
	MaxLabelValueLength    int     `yaml:"max_label_value_length" json:"max_label_value_length"`
	MaxLabelNamesPerSeries int     `yaml:"max_label_names_per_series" json:"max_label_names_per_series"`

	// Ingester enforced limits.
	MaxLocalSeriesPerTenant  int `yaml:"max_local_series_per_tenant" json:"max_local_series_per_tenant"`
	MaxGlobalSeriesPerTenant int `yaml:"max_global_series_per_tenant" json:"max_global_series_per_tenant"`

	// Querier enforced limits.
	MaxQueryLookback    model.Duration `yaml:"max_query_lookback" json:"max_query_lookback"`
	MaxQueryLength      model.Duration `yaml:"max_query_length" json:"max_query_length"`
	MaxQueryParallelism int            `yaml:"max_query_parallelism" json:"max_query_parallelism"`
}

Limits describe all the limits for tenants; can be used to describe global default limits via flags, or per-tenant limits via yaml config. NOTE: we use custom `model.Duration` instead of standard `time.Duration` because, to support tenant-friendly duration format (e.g: "1h30m45s") in JSON value.

func MockDefaultLimits

func MockDefaultLimits() *Limits

func (*Limits) RegisterFlags

func (l *Limits) RegisterFlags(f *flag.FlagSet)

RegisterFlags adds the flags required to config this to the given FlagSet

func (*Limits) UnmarshalYAML

func (l *Limits) UnmarshalYAML(unmarshal func(interface{}) error) error

UnmarshalYAML implements the yaml.Unmarshaler interface.

func (*Limits) Validate

func (l *Limits) Validate() error

Validate validates that this limits config is valid.

type Overrides

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

Overrides periodically fetch a set of per-tenant overrides, and provides convenience functions for fetching the correct value.

func MockDefaultOverrides

func MockDefaultOverrides() *Overrides

func MockOverrides

func MockOverrides(customize func(defaults *Limits, tenantLimits map[string]*Limits)) *Overrides

func NewOverrides

func NewOverrides(defaults Limits, tenantLimits TenantLimits) (*Overrides, error)

NewOverrides makes a new Overrides.

func (*Overrides) AllByTenantID

func (o *Overrides) AllByTenantID() map[string]*Limits

func (*Overrides) DefaultLimits

func (o *Overrides) DefaultLimits() *Limits

func (*Overrides) IngestionBurstSizeBytes

func (o *Overrides) IngestionBurstSizeBytes(tenantID string) int

IngestionBurstSizeBytes returns the burst size for ingestion rate.

func (*Overrides) IngestionRateBytes

func (o *Overrides) IngestionRateBytes(tenantID string) float64

IngestionRateBytes returns the limit on ingester rate (MBs per second).

func (*Overrides) MaxGlobalSeriesPerTenant

func (o *Overrides) MaxGlobalSeriesPerTenant(tenantID string) int

MaxGlobalSeriesPerTenant returns the maximum number of series a tenant is allowed to store across the cluster.

func (*Overrides) MaxLabelNameLength

func (o *Overrides) MaxLabelNameLength(tenantID string) int

MaxLabelNameLength returns maximum length a label name can be.

func (*Overrides) MaxLabelNamesPerSeries

func (o *Overrides) MaxLabelNamesPerSeries(tenantID string) int

MaxLabelNamesPerSeries returns maximum number of label/value pairs timeseries.

func (*Overrides) MaxLabelValueLength

func (o *Overrides) MaxLabelValueLength(tenantID string) int

MaxLabelValueLength returns maximum length a label value can be. This also is the maximum length of a metric name.

func (*Overrides) MaxLocalSeriesPerTenant

func (o *Overrides) MaxLocalSeriesPerTenant(tenantID string) int

MaxLocalSeriesPerTenant returns the maximum number of series a tenant is allowed to store in a single ingester.

func (*Overrides) MaxQueriersPerTenant

func (o *Overrides) MaxQueriersPerTenant(tenant string) int

MaxQueriersPerTenant returns the limit to the number of queriers that can be used Shuffle sharding will be used to distribute queries across queriers. 0 means no limit. Currently disabled.

func (*Overrides) MaxQueryLength

func (o *Overrides) MaxQueryLength(tenantID string) time.Duration

MaxQueryLength returns the limit of the length (in time) of a query.

func (*Overrides) MaxQueryLookback

func (o *Overrides) MaxQueryLookback(tenantID string) time.Duration

MaxQueryLookback returns the max lookback period of queries.

func (*Overrides) MaxQueryParallelism

func (o *Overrides) MaxQueryParallelism(tenantID string) int

MaxQueryParallelism returns the limit to the number of sub-queries the frontend will process in parallel.

type OverwriteMarshalingStringMap

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

OverwriteMarshalingStringMap will overwrite the src map when unmarshaling as opposed to merging.

func NewOverwriteMarshalingStringMap

func NewOverwriteMarshalingStringMap(m map[string]string) OverwriteMarshalingStringMap

func (*OverwriteMarshalingStringMap) Map

func (OverwriteMarshalingStringMap) MarshalJSON

func (sm OverwriteMarshalingStringMap) MarshalJSON() ([]byte, error)

MarshalJSON explicitly uses the the type receiver and not pointer receiver or it won't be called

func (OverwriteMarshalingStringMap) MarshalYAML

func (sm OverwriteMarshalingStringMap) MarshalYAML() (interface{}, error)

MarshalYAML explicitly uses the the type receiver and not pointer receiver or it won't be called

func (*OverwriteMarshalingStringMap) UnmarshalJSON

func (sm *OverwriteMarshalingStringMap) UnmarshalJSON(val []byte) error

func (*OverwriteMarshalingStringMap) UnmarshalYAML

func (sm *OverwriteMarshalingStringMap) UnmarshalYAML(unmarshal func(interface{}) error) error

type Reason

type Reason string

func ReasonOf

func ReasonOf(err error) Reason

type TenantLimits

type TenantLimits interface {
	// TenantLimits is a function that returns limits for given tenant, or
	// nil, if there are no tenant-specific limits.
	TenantLimits(tenantID string) *Limits
	// AllByTenantID gets a mapping of all tenant IDs and limits for that tenant
	AllByTenantID() map[string]*Limits
}

func NewMockTenantLimits

func NewMockTenantLimits(limits map[string]*Limits) TenantLimits

NewMockTenantLimits creates a new mockTenantLimits that returns per-tenant limits based on the given map

type TenantLimitsResponse

type TenantLimitsResponse struct {
	// Write path limits
	IngestionRate            float64 `json:"ingestion_rate"`
	IngestionBurstSize       int     `json:"ingestion_burst_size"`
	MaxGlobalSeriesPerTenant int     `json:"max_global_series_per_user"`
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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