Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

馃敪 [SDS-247] Add metric regarding multi-pass v0 #40

Merged
merged 8 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
17 changes: 17 additions & 0 deletions sds/src/scanner/metrics.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
use crate::labels::Labels;
use metrics::{counter, Counter};

pub struct Metrics {
pub false_positive_excluded_attributes: Counter,
}

impl Metrics {
pub fn new(labels: &Labels) -> Self {
Metrics {
false_positive_excluded_attributes: counter!(
"false_positive.multipass.excluded_match",
labels.clone()
),
}
}
}
28 changes: 18 additions & 10 deletions sds/src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,13 @@ use regex_automata::meta::Regex as MetaRegex;
use std::sync::Arc;

use self::cache_pool::{CachePool, CachePoolBuilder, CachePoolGuard};
use self::metrics::Metrics;
use ahash::AHashSet;
use regex_automata::{Input, Match};

pub(crate) mod cache_pool;
pub mod error;
mod metrics;

pub struct StringMatch {
start: usize,
Expand Down Expand Up @@ -62,6 +64,7 @@ pub struct RegexCompiledRule {
pub proximity_keywords: CompiledProximityKeywords,
pub validator: Option<Arc<dyn Validator>>,
pub rule_cache_index: usize,
metrics: Metrics,
}

impl CompiledRuleTrait for RegexCompiledRule {
Expand Down Expand Up @@ -104,6 +107,8 @@ impl CompiledRuleTrait for RegexCompiledRule {
start: regex_match.start(),
end: regex_match.end(),
});
} else {
self.metrics.false_positive_excluded_attributes.increment(1)
}
}

Expand Down Expand Up @@ -176,6 +181,7 @@ impl RuleConfigTrait for RegexRuleConfig {
.clone()
.map(|x| Arc::new(x) as Arc<dyn Validator>),
rule_cache_index: cache_index,
metrics: Metrics::new(&rule_labels),
}))
}
}
Expand Down Expand Up @@ -540,7 +546,9 @@ mod test {

use super::CompiledRuleTrait;
use super::RuleConfigTrait;

pub struct DumbRuleConfig {}

pub struct DumbCompiledRule {
pub match_action: MatchAction,
pub scope: Scope,
Expand Down Expand Up @@ -973,7 +981,7 @@ mod test {
replacement_type: crate::ReplacementType::PartialStart,
start_index: 0,
end_index_exclusive: 3,
shift_offset: 0
shift_offset: 0,
}
);

Expand All @@ -985,7 +993,7 @@ mod test {
replacement_type: crate::ReplacementType::PartialStart,
start_index: 3,
end_index_exclusive: 6,
shift_offset: 0
shift_offset: 0,
}
);

Expand All @@ -997,7 +1005,7 @@ mod test {
replacement_type: crate::ReplacementType::PartialStart,
start_index: 6,
end_index_exclusive: 9,
shift_offset: 0
shift_offset: 0,
}
);
}
Expand Down Expand Up @@ -1038,7 +1046,7 @@ mod test {
replacement_type: crate::ReplacementType::Placeholder,
start_index: 0,
end_index_exclusive: 3,
shift_offset: 0
shift_offset: 0,
}
);

Expand All @@ -1050,7 +1058,7 @@ mod test {
replacement_type: crate::ReplacementType::Placeholder,
start_index: 3,
end_index_exclusive: 6,
shift_offset: 0
shift_offset: 0,
}
);

Expand All @@ -1062,7 +1070,7 @@ mod test {
replacement_type: crate::ReplacementType::Placeholder,
start_index: 6,
end_index_exclusive: 9,
shift_offset: 0
shift_offset: 0,
}
);
}
Expand Down Expand Up @@ -1097,7 +1105,7 @@ mod test {
replacement_type: crate::ReplacementType::Placeholder,
start_index: 1,
end_index_exclusive: 4,
shift_offset: 0
shift_offset: 0,
}
);
}
Expand Down Expand Up @@ -1130,7 +1138,7 @@ mod test {
replacement_type: crate::ReplacementType::None,
start_index: 0,
end_index_exclusive: 3,
shift_offset: 0
shift_offset: 0,
}
);
}
Expand Down Expand Up @@ -1163,7 +1171,7 @@ mod test {
replacement_type: crate::ReplacementType::None,
start_index: 0,
end_index_exclusive: 4,
shift_offset: 0
shift_offset: 0,
}
);
}
Expand Down Expand Up @@ -1196,7 +1204,7 @@ mod test {
replacement_type: crate::ReplacementType::None,
start_index: 0,
end_index_exclusive: 3,
shift_offset: 0
shift_offset: 0,
}
);
}
Expand Down