Skip to content

Improve match logging - #387

Open
Taiki-San wants to merge 6 commits into
mainfrom
emilehugo.spir/better-metric-logging
Open

Improve match logging#387
Taiki-San wants to merge 6 commits into
mainfrom
emilehugo.spir/better-metric-logging

Conversation

@Taiki-San

Copy link
Copy Markdown
Contributor

The current logging emit a metric for every match, but with almost no metadata.
This makes fleet monitoring challenging since an increase in activity can't be tied to a precise rule, and the performance of a given rule can't easily be isolated.

This change introduce a new sds_rule_name tag with the category and name of the rule

@Taiki-San
Taiki-San requested a review from a team as a code owner August 28, 2026 14:33

@vinckama vinckama left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I added a few comments on the approach. I think the labels could stay generic and be associated to the rule when created. The business logic to select the label can be done upstream. This will allow to limit the impact on the metric cardinality.

Comment thread sds/src/scanner/mod.rs
Comment on lines +225 to +228
/// Precomputed `"{sensitive_data_category}/{sensitive_data}"` tag value derived from
/// the rule's `tags`, used to tag `scanning.match_count`. `None` when the rule has no
/// `sensitive_data` tag.
pub sds_rule_name: Option<String>,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

could it be kept generic with "labels" similarly to how these telemetry tags are attached to scanner?

Comment thread sds/src/scanner/mod.rs
"sds_rule_name",
sds_rule_name.to_string(),
)]));
counter!("scanning.match_count", labels).increment(count);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cardinality of this metric is already high and it will increase even more with this new tag.

To avoid cardinality issues, these additional labels must be enabled as opt-in when required, for instance for correctness validation.

If labels are forwarded when the rule is instantiated, the business logic to decide if they should be enabled or not could be done outside of the library.
Such logic could be defined in the SDS context, enabled per target and propagated to downstream consumers.

use metrics::{Counter, counter};

/// Looks up the value of a `"key:value"` tag entry by key, matching the format used by
/// standard rule definitions (e.g. `sensitive_data:travis_ci_access_token`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Minor: there is no concept of standard rules here, and in general the concept of sensitive_data tag is not associated to standard rule but is generic for all kind of rules.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants