Validate the limits config and returns an error if the validation doesn't pass
(nameValidationScheme model.ValidationScheme, shardByAllLabels bool, activeSeriesMetricsEnabled bool)
| 372 | // Validate the limits config and returns an error if the validation |
| 373 | // doesn't pass |
| 374 | func (l *Limits) Validate(nameValidationScheme model.ValidationScheme, shardByAllLabels bool, activeSeriesMetricsEnabled bool) error { |
| 375 | // The ingester.max-global-series-per-user metric is not supported |
| 376 | // if shard-by-all-labels is disabled |
| 377 | if l.MaxGlobalSeriesPerUser > 0 && !shardByAllLabels { |
| 378 | return errMaxGlobalSeriesPerUserValidation |
| 379 | } |
| 380 | |
| 381 | // The ingester.max-global-native-histograms-series-per-user metric is not supported |
| 382 | // if shard-by-all-labels is disabled |
| 383 | // or if active-series-metrics-enabled is disabled |
| 384 | if l.MaxGlobalNativeHistogramSeriesPerUser > 0 && (!shardByAllLabels || !activeSeriesMetricsEnabled) { |
| 385 | return errMaxGlobalNativeHistogramSeriesPerUserValidation |
| 386 | } |
| 387 | |
| 388 | if l.MaxLocalNativeHistogramSeriesPerUser > 0 && !activeSeriesMetricsEnabled { |
| 389 | return errMaxLocalNativeHistogramSeriesPerUserValidation |
| 390 | } |
| 391 | |
| 392 | if err := l.RulerExternalLabels.Validate(func(l labels.Label) error { |
| 393 | if !nameValidationScheme.IsValidLabelName(l.Name) { |
| 394 | return fmt.Errorf("%w: %q", errInvalidLabelName, l.Name) |
| 395 | } |
| 396 | if !model.LabelValue(l.Value).IsValid() { |
| 397 | return fmt.Errorf("%w: %q", errInvalidLabelValue, l.Value) |
| 398 | } |
| 399 | return nil |
| 400 | }); err != nil { |
| 401 | return err |
| 402 | } |
| 403 | |
| 404 | for i, rc := range l.MetricRelabelConfigs { |
| 405 | if rc == nil { |
| 406 | level.Error(util_log.Logger).Log("msg", "invalid metric_relabel_configs", "index", i, "err", "nil config") |
| 407 | return errInvalidMetricRelabelConfigs |
| 408 | } |
| 409 | if err := rc.Validate(nameValidationScheme); err != nil { |
| 410 | level.Error(util_log.Logger).Log("msg", "invalid metric_relabel_configs", "index", i, "err", err) |
| 411 | return errInvalidMetricRelabelConfigs |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | return nil |
| 416 | } |
| 417 | |
| 418 | // UnmarshalYAML implements the yaml.Unmarshaler interface. |
| 419 | func (l *Limits) UnmarshalYAML(unmarshal func(any) error) error { |