validation

package
v0.77.0 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2026 License: Apache-2.0 Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const SupportedSelectorSubset = `a stream selector ` +
	`(e.g. {scrape_job="audit-logs"}), optional line filters (|=, !=, |~, !~), ` +
	`an optional "| json", and optional label filters (e.g. | verb="delete")`

SupportedSelectorSubset describes, for humans, what ValidateSelector accepts.

Variables

View Source
var (
	ErrCodeTimeRange      = errors.New("LOGQL001")
	ErrCodeSyntax         = errors.New("LOGQL002")
	ErrCodeNotLogLines    = errors.New("LOGQL003")
	ErrCodeAggregation    = errors.New("LOGQL004")
	ErrCodeNotLogSelector = errors.New("LOGQL005")
	ErrCodePipelineBuild  = errors.New("LOGQL006")
	ErrCodeParser         = errors.New("LOGQL007")
	ErrCodeLabelFilter    = errors.New("LOGQL008")
	ErrCodeStage          = errors.New("LOGQL009")
	ErrCodeLineFilterOr   = errors.New("LOGQL010")
	ErrCodeLineFilterOp   = errors.New("LOGQL011")
	ErrCodeReservedLabel  = errors.New("LOGQL012")
)

The code every rejection carries; docs/logexport-selectors.md explains each one.

Codes are stable: append new ones, never renumber and never reuse.

Functions

func ParseSelector added in v0.76.0

func ParseSelector(selector string) (syntax.LogSelectorExpr, error)

ParseSelector validates a selector and returns the parsed expression, so that config rendering is driven from the same parse admission accepts and the two cannot drift.

func StringMatcher added in v0.76.0

func StringMatcher(f log.LabelFilterer) (*labels.Matcher, bool)

StringMatcher reports the matcher behind a label filter, for the filterers that are a single string comparison.

Note that `| verb="delete"` is not a StringLabelFilter: log.NewStringLabelFilter returns a LineFilterLabelFilter in the common case, a NoopLabelFilter when the matcher reduces to a match-all, and a StringLabelFilter only on its fallback path. All three carry a matcher; binary (and/or), numeric, duration, bytes and IP filters do not, and have no stream-selector spelling once negated.

func ValidateSelector added in v0.75.0

func ValidateSelector(selector string) error

ValidateSelector reports whether a LogExport selector is a LogQL expression the export pipeline can honour.

The CRD already validates: minLength, maxLength. This adds: the expression is syntactically valid LogQL, and is restricted to the subset the exporter renders.

The accepted subset is deliberately narrower than "any log selector", because it is bounded by what the config rendering can translate into Alloy stages:

  • stream selector + line filters -> stage.match { selector = ... }, verbatim
  • "| json" + label filters -> stage.json plus a drop of the negated filter

The pipeline selects by dropping the *negated* selector, so an expression accepted here but translated imperfectly over-exports rather than under-exports — customer logs leaving the installation, not missing data. Anything accepted here therefore has to be renderable; widen this only together with the renderer.

Rendering must be driven from the parsed expression (syntax.Expr.String()), never from the raw field value: the parser tolerates trailing "# comment" and non-canonical whitespace, so a negated term appended to the raw string can be commented out.

Types

type TenantValidator

type TenantValidator struct {
	// List of forbidden tenant ID values that pass the CRD pattern but are not allowed by Mimir
	ForbiddenValues []string
}

TenantValidator provides common validation logic for tenant IDs across API versions.

func NewTenantValidator

func NewTenantValidator() *TenantValidator

NewTenantValidator creates a new TenantValidator with default forbidden values.

func (*TenantValidator) ValidateTenantName

func (v *TenantValidator) ValidateTenantName(tenantName string) error

ValidateTenantName validates a single tenant name for common business rules. This validates: forbidden values and basic naming rules. Duplicate checking is handled separately as it requires context of all tenants.

func (*TenantValidator) ValidateTenantNames

func (v *TenantValidator) ValidateTenantNames(tenantNames []string) error

ValidateTenantNames validates a list of tenant names for all common rules. This combines forbidden value checking and duplicate detection.

func (*TenantValidator) ValidateUniqueNames

func (v *TenantValidator) ValidateUniqueNames(tenantNames []string) error

ValidateUniqueNames validates that all tenant names in the slice are unique.

Jump to

Keyboard shortcuts

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