crowdsecurity/crowdsec · error · ErrInvalidMetricsLevel
%w: %s
Error message
%w: %s
What it means
RegisterMetrics maps a user-supplied metrics level string (e.g. full, standard, none) to a set of Prometheus collectors via a switch. An unrecognized level string falls through to default and returns this error wrapped around ErrInvalidMetricsLevel, aborting metrics registration.
Source
Thrown at pkg/metrics/metrics.go:53
case MetricsLevelAggregated:
prometheus.MustRegister(GlobalParserHits, GlobalParserHitsOk, GlobalParserHitsKo,
GlobalCsInfo, GlobalParsingHistogram, GlobalPourHistogram,
BucketsUnderflow, BucketsCanceled, BucketsInstantiation, BucketsOverflow,
LapiRouteHits,
BucketsCurrentCount,
CacheMetrics, RegexpCacheMetrics, NodesWlHitsOk, NodesWlHits,
PapiOrdersReceived, PapiInvalidOrdersReceived, PapiLastPullTimestamp, PapiPollErrors)
case MetricsLevelFull:
prometheus.MustRegister(GlobalParserHits, GlobalParserHitsOk, GlobalParserHitsKo,
NodesHits, NodesHitsOk, NodesHitsKo,
GlobalCsInfo, GlobalParsingHistogram, GlobalPourHistogram,
LapiRouteHits, LapiMachineHits, LapiBouncerHits, LapiNilDecisions, LapiNonNilDecisions, LapiResponseTime,
BucketsPour, BucketsUnderflow, BucketsCanceled, BucketsInstantiation, BucketsOverflow, BucketsCurrentCount,
GlobalActiveDecisions, GlobalAlerts, GlobalMachinesLastHeartbeatTimestamp, NodesWlHitsOk, NodesWlHits,
CacheMetrics, RegexpCacheMetrics,
PapiOrdersReceived, PapiInvalidOrdersReceived, PapiLastPullTimestamp, PapiPollErrors)
default:
return fmt.Errorf("%w: %s", ErrInvalidMetricsLevel, metricsLevel)
}
return nil
}
View on GitHub (pinned to 909b515798)
Solutions
- Set prometheus.level in the config to one of the supported values: none, standard, or full.
- Check for typos, trailing whitespace, and correct casing in the config value.
- Consult the current version's documentation, as the accepted level names may have changed between releases.
Example fix
// before (config.yaml) prometheus: level: verbose // after prometheus: level: full
Defensive patterns
Strategy: validation
Validate before calling
var validLevels = map[string]bool{"none": true, "standard": true, "full": true}
level := strings.TrimSpace(cfg.Prometheus.Level)
if !validLevels[level] {
return fmt.Errorf("prometheus.level %q must be one of: none, standard, full", level)
} Try / catch
if err := metrics.RegisterMetrics(level); err != nil {
if errors.Is(err, metrics.ErrInvalidMetricsLevel) {
logger.Fatalf("unsupported prometheus level %q: use none|standard|full", level)
}
return err
} Prevention
- Only set prometheus.level from the documented set (none/standard/full).
- Trim whitespace and use lowercase in config values.
- Re-check accepted values after crowdsec upgrades.
When it happens
Trigger: registerPrometheus calls RegisterMetrics with a prometheus_level config value that matches none of the switch cases (typo, wrong case, or unsupported level).
Common situations: config.yaml has prometheus: level: verbose instead of full/standard/none; upgrading crowdsec where a level name was renamed; hand-edited config with trailing whitespace or wrong casing.
Understand the failure class
Background: Invalid enum value errors: "Unknown type", "Invalid scope", "must be one of" — when a string is not on the library's allowed list — this error's family across 23 libraries.
Related errors
- path must start with /
- on_challenge hooks are only valid in-band, not under outofba
- empty cti key
- no listen_uri or listen_socket specified
- no configuration paths provided
AI-assisted analysis of crowdsecurity/crowdsec@909b515798 (2026-09-06).
Data as JSON: /api/errors/78da8b6300dc72f5.
Report an issue: GitHub.