fix(metrics): sanitize custom field names before Prometheus & OTLP validation #1290
fix(metrics): sanitize custom field names before Prometheus & OTLP validation #1290ooye-sanket wants to merge 3 commits intofalcosecurity:masterfrom
Conversation
Replace dots with underscores in custom field names before regex validation to prevent label cardinality mismatches. **Changes:** - Line ~45-50: Sanitize customfields key using `strings.ReplaceAll(i, ".", "_")` - Store sanitized name in variable for reuse in validation and append - Update error log to show both original and sanitized field names **Why:** Custom fields with dots (e.g., `k8s.cluster.name`) were failing validation but still being counted in expected label count, causing panic: "inconsistent label cardinality: expected 8 label values but got 7" **Related:** - Part of fix for issue #3748 - Works in conjunction with handlers.go and otlp_metrics.go fixes Signed-off-by: Sanket Kalekar <kalekarsanket005@gmail.com>
Replace dots with underscores in custom field names to ensure OTLP attribute name compliance and prevent cardinality panics. Changes: - Line ~34-40: Sanitize customfields key using `strings.ReplaceAll(i, ".", "_")` - Store sanitized name in variable for reuse - Change log level from ErrorLvl to WarningLvl (sanitization is automatic now) - Update log message to show both original and sanitized field names Why: OTLP metric attribute names must match `^[a-zA-Z_:][a-zA-Z0-9_:]*$` regex. Dots cause validation failures and label count mismatches. Related: - Part of fix for issue #3748 - Complements prometheus and handlers.go fixes Signed-off-by: Sanket Kalekar <kalekarsanket005@gmail.com>
Replace dots with underscores when building OTLP attribute list to ensure attribute name compliance. Changes: - Line ~230-237: In `newFalcoPayload()` function - Sanitize key using `strings.ReplaceAll(key, ".", "_")` before: - Regex validation check - Creating attribute.String() with sanitized key Why: OTLP metric attributes must follow naming conventions. Without sanitization, custom fields with dots would be rejected, causing similar cardinality issues as Prometheus. Related: - Part of fix for issue #3748 - Complements otlp_metrics.go changes - Prevents OTLP-related panics Signed-off-by: Sanket Kalekar <kalekarsanket005@gmail.com>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: ooye-sanket The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Welcome @ooye-sanket! It looks like this is your first PR to falcosecurity/falcosidekick 🎉 |
|
Hey @ooye-sanket out of curiosity: is this patch AI generated? 🤔 |
|
Issues go stale after 90d of inactivity. Mark the issue as fresh with Stale issues rot after an additional 30d of inactivity and eventually close. If this issue is safe to close now please do so with Provide feedback via https://github.com/falcosecurity/community. /lifecycle stale |
What type of PR is this?
/kind bug
Any specific area of the project related to this PR?
/area config
/area outputs
What this PR does / why we need it:
Falco Sidekick currently panics when a custom field contains dots (e.g.,
k8s.cluster.name).Prometheus and OTLP both reject such attribute/label names, causing:
expected X values, got Y)The root cause was that custom fields were validated before sanitization.
✔ This PR fixes the issue by:
"." → "_"before validationhandlers.gostats_prometheus.gootlp_metrics.goOTLP.Metrics.ExtraAttributesListThis prevents crashes, ensures correct metric cardinality, and keeps behavior consistent across all backends.
Which issue(s) this PR fixes:
Fixes #3748
Special notes for your reviewer:
"Custom field 'k8s.cluster.name' (sanitized to 'k8s_cluster_name') is not valid and will be ignored"cc @maintainer