validation

package
v1.3.0-rc.1.0...-65594da Latest Latest
Warning

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

Go to latest
Published: Jun 29, 2021 License: Apache-2.0 Imports: 13 Imported by: 0

Documentation

Index

Constants

View Source
const (
	LocalIngestionRateStrategy  = "local"
	GlobalIngestionRateStrategy = "global"
)

Supported values for enum limits

View Source
const (

	// ErrQueryTooLong is used in chunk store, querier and query frontend.
	ErrQueryTooLong = "the query time range exceeds the limit (query length: %s, limit: %s)"

	// RateLimited is one of the values for the reason to discard samples.
	// Declared here to avoid duplication in ingester and distributor.
	RateLimited = "rate_limited"
)

Variables

View Source
var DiscardedMetadata = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Name: "cortex_discarded_metadata_total",
		Help: "The total number of metadata that were discarded.",
	},
	[]string{discardReasonLabel, "user"},
)

DiscardedMetadata is a metric of the number of discarded metadata, by reason.

View Source
var DiscardedSamples = prometheus.NewCounterVec(
	prometheus.CounterOpts{
		Name: "cortex_discarded_samples_total",
		Help: "The total number of samples that were discarded.",
	},
	[]string{discardReasonLabel, "user"},
)

DiscardedSamples is a metric of the number of discarded samples, by reason.

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 ValidateLabels

func ValidateLabels(cfg LabelValidationConfig, userID string, ls []client.LabelAdapter, skipLabelNameValidation bool) error

ValidateLabels returns an err if the labels are invalid.

func ValidateMetadata

func ValidateMetadata(cfg MetadataValidationConfig, userID string, metadata *client.MetricMetadata) error

ValidateMetadata returns an err if a metric metadata is invalid.

func ValidateSample

func ValidateSample(cfg SampleValidationConfig, userID string, metricName string, s client.Sample) error

ValidateSample returns an err if the sample is invalid.

Types

type LabelValidationConfig

type LabelValidationConfig interface {
	EnforceMetricName(userID string) bool
	MaxLabelNamesPerSeries(userID string) int
	MaxLabelNameLength(userID string) int
	MaxLabelValueLength(userID string) int
}

LabelValidationConfig helps with getting required config to validate labels.

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.
	IngestionRate             float64             `yaml:"ingestion_rate"`
	IngestionRateStrategy     string              `yaml:"ingestion_rate_strategy"`
	IngestionBurstSize        int                 `yaml:"ingestion_burst_size"`
	AcceptHASamples           bool                `yaml:"accept_ha_samples"`
	HAClusterLabel            string              `yaml:"ha_cluster_label"`
	HAReplicaLabel            string              `yaml:"ha_replica_label"`
	DropLabels                flagext.StringSlice `yaml:"drop_labels"`
	MaxLabelNameLength        int                 `yaml:"max_label_name_length"`
	MaxLabelValueLength       int                 `yaml:"max_label_value_length"`
	MaxLabelNamesPerSeries    int                 `yaml:"max_label_names_per_series"`
	MaxMetadataLength         int                 `yaml:"max_metadata_length"`
	RejectOldSamples          bool                `yaml:"reject_old_samples"`
	RejectOldSamplesMaxAge    time.Duration       `yaml:"reject_old_samples_max_age"`
	CreationGracePeriod       time.Duration       `yaml:"creation_grace_period"`
	EnforceMetadataMetricName bool                `yaml:"enforce_metadata_metric_name"`
	EnforceMetricName         bool                `yaml:"enforce_metric_name"`
	IngestionTenantShardSize  int                 `yaml:"ingestion_tenant_shard_size"`
	MetricRelabelConfigs      []*relabel.Config   `` /* 255-byte string literal not displayed */

	// Ingester enforced limits.
	// Series
	MaxSeriesPerQuery        int `yaml:"max_series_per_query"`
	MaxSamplesPerQuery       int `yaml:"max_samples_per_query"`
	MaxLocalSeriesPerUser    int `yaml:"max_series_per_user"`
	MaxLocalSeriesPerMetric  int `yaml:"max_series_per_metric"`
	MaxGlobalSeriesPerUser   int `yaml:"max_global_series_per_user"`
	MaxGlobalSeriesPerMetric int `yaml:"max_global_series_per_metric"`
	MinChunkLength           int `yaml:"min_chunk_length"`
	// Metadata
	MaxLocalMetricsWithMetadataPerUser  int `yaml:"max_metadata_per_user"`
	MaxLocalMetadataPerMetric           int `yaml:"max_metadata_per_metric"`
	MaxGlobalMetricsWithMetadataPerUser int `yaml:"max_global_metadata_per_user"`
	MaxGlobalMetadataPerMetric          int `yaml:"max_global_metadata_per_metric"`

	// Querier enforced limits.
	MaxChunksPerQuery    int           `yaml:"max_chunks_per_query"`
	MaxQueryLength       time.Duration `yaml:"max_query_length"`
	MaxQueryParallelism  int           `yaml:"max_query_parallelism"`
	CardinalityLimit     int           `yaml:"cardinality_limit"`
	MaxCacheFreshness    time.Duration `yaml:"max_cache_freshness"`
	MaxQueriersPerTenant int           `yaml:"max_queriers_per_tenant"`

	// Ruler defaults and limits.
	RulerEvaluationDelay        time.Duration `yaml:"ruler_evaluation_delay_duration"`
	RulerTenantShardSize        int           `yaml:"ruler_tenant_shard_size"`
	RulerMaxRulesPerRuleGroup   int           `yaml:"ruler_max_rules_per_rule_group"`
	RulerMaxRuleGroupsPerTenant int           `yaml:"ruler_max_rule_groups_per_tenant"`

	// Store-gateway.
	StoreGatewayTenantShardSize int `yaml:"store_gateway_tenant_shard_size"`

	// Config for overrides, convenient if it goes here. [Deprecated in favor of RuntimeConfig flag in cortex.Config]
	PerTenantOverrideConfig string        `yaml:"per_tenant_override_config"`
	PerTenantOverridePeriod time.Duration `yaml:"per_tenant_override_period"`
}

Limits describe all the limits for users; can be used to describe global default limits via flags, or per-user limits via yaml config.

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(shardByAllLabels bool) error

Validate the limits config and returns an error if the validation doesn't pass

type MetadataValidationConfig

type MetadataValidationConfig interface {
	EnforceMetadataMetricName(userID string) bool
	MaxMetadataLength(userID string) int
}

MetadataValidationConfig helps with getting required config to validate metadata.

type Overrides

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

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

func NewOverrides

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

NewOverrides makes a new Overrides.

func (*Overrides) AcceptHASamples

func (o *Overrides) AcceptHASamples(userID string) bool

AcceptHASamples returns whether the distributor should track and accept samples from HA replicas for this user.

func (*Overrides) CardinalityLimit

func (o *Overrides) CardinalityLimit(userID string) int

CardinalityLimit returns the maximum number of timeseries allowed in a query.

func (*Overrides) CreationGracePeriod

func (o *Overrides) CreationGracePeriod(userID string) time.Duration

CreationGracePeriod is misnamed, and actually returns how far into the future we should accept samples.

func (*Overrides) DropLabels

func (o *Overrides) DropLabels(userID string) flagext.StringSlice

DropLabels returns the list of labels to be dropped when ingesting HA samples for the user.

func (*Overrides) EnforceMetadataMetricName

func (o *Overrides) EnforceMetadataMetricName(userID string) bool

EnforceMetadataMetricName whether to enforce the presence of a metric name on metadata.

func (*Overrides) EnforceMetricName

func (o *Overrides) EnforceMetricName(userID string) bool

EnforceMetricName whether to enforce the presence of a metric name.

func (*Overrides) EvaluationDelay

func (o *Overrides) EvaluationDelay(userID string) time.Duration

EvaluationDelay returns the rules evaluation delay for a given user.

func (*Overrides) HAClusterLabel

func (o *Overrides) HAClusterLabel(userID string) string

HAClusterLabel returns the cluster label to look for when deciding whether to accept a sample from a Prometheus HA replica.

func (*Overrides) HAReplicaLabel

func (o *Overrides) HAReplicaLabel(userID string) string

HAReplicaLabel returns the replica label to look for when deciding whether to accept a sample from a Prometheus HA replica.

func (*Overrides) IngestionBurstSize

func (o *Overrides) IngestionBurstSize(userID string) int

IngestionBurstSize returns the burst size for ingestion rate.

func (*Overrides) IngestionRate

func (o *Overrides) IngestionRate(userID string) float64

IngestionRate returns the limit on ingester rate (samples per second).

func (*Overrides) IngestionRateStrategy

func (o *Overrides) IngestionRateStrategy() string

IngestionRateStrategy returns whether the ingestion rate limit should be individually applied to each distributor instance (local) or evenly shared across the cluster (global).

func (*Overrides) IngestionTenantShardSize

func (o *Overrides) IngestionTenantShardSize(userID string) int

IngestionTenantShardSize returns the ingesters shard size for a given user.

func (*Overrides) MaxCacheFreshness

func (o *Overrides) MaxCacheFreshness(userID string) time.Duration

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

func (*Overrides) MaxChunksPerQuery

func (o *Overrides) MaxChunksPerQuery(userID string) int

MaxChunksPerQuery returns the maximum number of chunks allowed per query.

func (*Overrides) MaxGlobalMetadataPerMetric

func (o *Overrides) MaxGlobalMetadataPerMetric(userID string) int

MaxGlobalMetadataPerMetric returns the maximum number of metadata allowed per metric across the cluster.

func (*Overrides) MaxGlobalMetricsWithMetadataPerUser

func (o *Overrides) MaxGlobalMetricsWithMetadataPerUser(userID string) int

MaxGlobalMetricsWithMetadataPerUser returns the maximum number of metrics with metadata a user is allowed to store across the cluster.

func (*Overrides) MaxGlobalSeriesPerMetric

func (o *Overrides) MaxGlobalSeriesPerMetric(userID string) int

MaxGlobalSeriesPerMetric returns the maximum number of series allowed per metric across the cluster.

func (*Overrides) MaxGlobalSeriesPerUser

func (o *Overrides) MaxGlobalSeriesPerUser(userID string) int

MaxGlobalSeriesPerUser returns the maximum number of series a user is allowed to store across the cluster.

func (*Overrides) MaxLabelNameLength

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

MaxLabelNameLength returns maximum length a label name can be.

func (*Overrides) MaxLabelNamesPerSeries

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

MaxLabelNamesPerSeries returns maximum number of label/value pairs timeseries.

func (*Overrides) MaxLabelValueLength

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

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

func (*Overrides) MaxLocalMetadataPerMetric

func (o *Overrides) MaxLocalMetadataPerMetric(userID string) int

MaxLocalMetadataPerMetric returns the maximum number of metadata allowed per metric in a single ingester.

func (*Overrides) MaxLocalMetricsWithMetadataPerUser

func (o *Overrides) MaxLocalMetricsWithMetadataPerUser(userID string) int

MaxLocalMetricsWithMetadataPerUser returns the maximum number of metrics with metadata a user is allowed to store in a single ingester.

func (*Overrides) MaxLocalSeriesPerMetric

func (o *Overrides) MaxLocalSeriesPerMetric(userID string) int

MaxLocalSeriesPerMetric returns the maximum number of series allowed per metric in a single ingester.

func (*Overrides) MaxLocalSeriesPerUser

func (o *Overrides) MaxLocalSeriesPerUser(userID string) int

MaxLocalSeriesPerUser returns the maximum number of series a user is allowed to store in a single ingester.

func (*Overrides) MaxMetadataLength

func (o *Overrides) MaxMetadataLength(userID string) int

MaxMetadataLength returns maximum length metadata can be. Metadata refers to the Metric Name, HELP and UNIT.

func (*Overrides) MaxQueriersPerUser

func (o *Overrides) MaxQueriersPerUser(userID string) int

MaxQueriersPerUser returns the maximum number of queriers that can handle requests for this user.

func (*Overrides) MaxQueryLength

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

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

func (*Overrides) MaxQueryParallelism

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

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

func (*Overrides) MaxSamplesPerQuery

func (o *Overrides) MaxSamplesPerQuery(userID string) int

MaxSamplesPerQuery returns the maximum number of samples in a query (from the ingester).

func (*Overrides) MaxSeriesPerQuery

func (o *Overrides) MaxSeriesPerQuery(userID string) int

MaxSeriesPerQuery returns the maximum number of series a query is allowed to hit.

func (*Overrides) MetricRelabelConfigs

func (o *Overrides) MetricRelabelConfigs(userID string) []*relabel.Config

MetricRelabelConfigs returns the metric relabel configs for a given user.

func (*Overrides) MinChunkLength

func (o *Overrides) MinChunkLength(userID string) int

MinChunkLength returns the minimum size of chunk that will be saved by ingesters

func (*Overrides) RejectOldSamples

func (o *Overrides) RejectOldSamples(userID string) bool

RejectOldSamples returns true when we should reject samples older than certain age.

func (*Overrides) RejectOldSamplesMaxAge

func (o *Overrides) RejectOldSamplesMaxAge(userID string) time.Duration

RejectOldSamplesMaxAge returns the age at which samples should be rejected.

func (*Overrides) RulerMaxRuleGroupsPerTenant

func (o *Overrides) RulerMaxRuleGroupsPerTenant(userID string) int

RulerMaxRuleGroupsPerTenant returns the maximum number of rule groups for a given user.

func (*Overrides) RulerMaxRulesPerRuleGroup

func (o *Overrides) RulerMaxRulesPerRuleGroup(userID string) int

RulerMaxRulesPerRuleGroup returns the maximum number of rules per rule group for a given user.

func (*Overrides) RulerTenantShardSize

func (o *Overrides) RulerTenantShardSize(userID string) int

RulerTenantShardSize returns shard size (number of rulers) used by this tenant when using shuffle-sharding strategy.

func (*Overrides) StoreGatewayTenantShardSize

func (o *Overrides) StoreGatewayTenantShardSize(userID string) int

StoreGatewayTenantShardSize returns the store-gateway shard size for a given user.

type SampleValidationConfig

type SampleValidationConfig interface {
	RejectOldSamples(userID string) bool
	RejectOldSamplesMaxAge(userID string) time.Duration
	CreationGracePeriod(userID string) time.Duration
}

SampleValidationConfig helps with getting required config to validate sample.

type TenantLimits

type TenantLimits func(userID string) *Limits

TenantLimits is a function that returns limits for given tenant, or nil, if there are no tenant-specific limits.

Jump to

Keyboard shortcuts

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