Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 4 additions & 8 deletions bd-log-filter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
mod filter_chain_test;

use anyhow::{Context, Result, anyhow};
use bd_log_primitives::tiny_set::TinyMap;
use bd_log_primitives::{
FieldsRef,
LOG_FIELD_NAME_LEVEL,
Expand Down Expand Up @@ -88,13 +87,10 @@ impl FilterChain {
pub fn process(&self, log: &mut Log) {
for filter in &self.filters {
let fields_ref = FieldsRef::new(&log.fields, &log.matching_fields);
if !filter.matcher.do_match(
log.log_level,
log.log_type,
&log.message,
fields_ref,
&TinyMap::default(),
) {
if !filter
.matcher
.do_match(log.log_level, log.log_type, &log.message, fields_ref, None)
{
continue;
}

Expand Down
9 changes: 1 addition & 8 deletions bd-log-matcher/src/legacy_matcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

use crate::matcher::Tree;
use assert_matches::assert_matches;
use bd_log_primitives::tiny_set::TinyMap;
use bd_log_primitives::{
EMPTY_FIELDS,
FieldsRef,
Expand Down Expand Up @@ -80,13 +79,7 @@ fn match_test_runner(config: LegacyLogMatcher, cases: Vec<(Input<'_>, bool)>) {

assert_eq!(
should_match,
match_tree.do_match(
log_level,
log_type,
&message,
fields_ref,
&TinyMap::default()
),
match_tree.do_match(log_level, log_type, &message, fields_ref, None),
"{input:?} should result in {should_match} but did not",
);
}
Expand Down
17 changes: 10 additions & 7 deletions bd-log-matcher/src/matcher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ use base_log_matcher::tag_match::Value_match::{
SemVerValueMatch,
StringValueMatch,
};
use bd_log_primitives::tiny_set::TinyMap;
use bd_log_primitives::{FieldsRef, LogLevel, LogMessage, LogType};
use bd_proto::protos::config::v1::config::log_matcher::base_log_matcher::StringMatchType;
use bd_proto::protos::config::v1::config::log_matcher::{
Expand All @@ -47,6 +46,7 @@ use log_matcher::log_matcher::base_log_matcher::{
use log_matcher::log_matcher::{BaseLogMatcher, Matcher, base_log_matcher};
use regex::Regex;
use std::borrow::Cow;
use std::collections::BTreeMap;
use std::ops::Deref;

const LOG_LEVEL_KEY: &str = "log_level";
Expand Down Expand Up @@ -79,11 +79,14 @@ impl<T> From<T> for ValueOrSavedFieldId<T> {
}

impl<'a, T: MakeValueOrRef<'a, T>> ValueOrSavedFieldId<T> {
fn load(&'a self, extracted_fields: &'a TinyMap<String, String>) -> Option<ValueOrRef<'a, T>> {
fn load(
&'a self,
extracted_fields: Option<&'a BTreeMap<String, String>>,
) -> Option<ValueOrRef<'a, T>> {
match self {
Self::Value(v) => Some(ValueOrRef::Ref(v)),
Self::SaveFieldId(field_id) => extracted_fields
.get(field_id)
.and_then(|extracted_fields| extracted_fields.get(field_id))
.and_then(|v| T::make_value_or_ref(v)),
}
}
Expand Down Expand Up @@ -204,7 +207,7 @@ impl Tree {
log_type: LogType,
message: &LogMessage,
fields: FieldsRef<'_>,
extracted_fields: &TinyMap<String, String>,
extracted_fields: Option<&BTreeMap<String, String>>,
) -> bool {
match self {
Self::Base(base_matcher) => match base_matcher {
Expand Down Expand Up @@ -265,7 +268,7 @@ impl IntMatch {
}
}

fn evaluate(&self, candidate: i32, extracted_fields: &TinyMap<String, String>) -> bool {
fn evaluate(&self, candidate: i32, extracted_fields: Option<&BTreeMap<String, String>>) -> bool {
let Some(value) = self.value.load(extracted_fields) else {
return false;
};
Expand Down Expand Up @@ -314,7 +317,7 @@ impl DoubleMatch {
}
}

fn evaluate(&self, candidate: f64, extracted_fields: &TinyMap<String, String>) -> bool {
fn evaluate(&self, candidate: f64, extracted_fields: Option<&BTreeMap<String, String>>) -> bool {
let candidate = NanEqualFloat(candidate);
let Some(value) = self.value.load(extracted_fields) else {
return false;
Expand Down Expand Up @@ -383,7 +386,7 @@ impl StringMatch {
})
}

fn evaluate(&self, candidate: &str, extracted_fields: &TinyMap<String, String>) -> bool {
fn evaluate(&self, candidate: &str, extracted_fields: Option<&BTreeMap<String, String>>) -> bool {
let Some(value) = self.value.load(extracted_fields) else {
return false;
};
Expand Down
20 changes: 10 additions & 10 deletions bd-log-matcher/src/matcher_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@

use crate::matcher::Tree;
use crate::matcher::base_log_matcher::tag_match::Value_match::DoubleValueMatch;
use bd_log_primitives::tiny_set::TinyMap;
use bd_log_primitives::{
EMPTY_FIELDS,
FieldsRef,
Expand All @@ -34,6 +33,7 @@ use log_matcher::base_log_matcher::tag_match::Value_match::{
use log_matcher::{BaseLogMatcher, Matcher, MatcherList, base_log_matcher};
use pretty_assertions::assert_eq;
use protobuf::MessageField;
use std::collections::BTreeMap;

type Input<'a> = (LogType, LogLevel, LogMessage, LogFields);

Expand Down Expand Up @@ -230,7 +230,7 @@ fn test_extracted_string_matcher() {
(log_tag("keyx", "exact"), false),
(log_msg("no fields"), false),
],
&TinyMap::default(),
None,
);

match_test_runner_with_extractions(
Expand All @@ -240,7 +240,7 @@ fn test_extracted_string_matcher() {
(log_tag("keyx", "exact"), false),
(log_msg("no fields"), false),
],
&[("id1".to_string(), "exact".to_string())].into(),
Some(&BTreeMap::from([("id1".to_string(), "exact".to_string())])),
);
}

Expand Down Expand Up @@ -309,20 +309,20 @@ fn test_extracted_double_matcher() {
(log_tag("key", "13.0"), false),
(log_tag("key", "13"), false),
],
&TinyMap::default(),
None,
);
match_test_runner_with_extractions(
config.clone(),
vec![
(log_tag("key", "13.0"), false),
(log_tag("key", "13"), false),
],
&[("id1".to_string(), "bad".to_string())].into(),
Some(&BTreeMap::from([("id1".to_string(), "bad".to_string())])),
);
match_test_runner_with_extractions(
config,
vec![(log_tag("key", "13.0"), true), (log_tag("key", "13"), true)],
&[("id1".to_string(), "13".to_string())].into(),
Some(&BTreeMap::from([("id1".to_string(), "13".to_string())])),
);
}

Expand Down Expand Up @@ -419,13 +419,13 @@ fn test_extracted_int_matcher() {
(log_tag("key", "13"), false),
(log_tag("key", "13.0"), false),
],
&TinyMap::default(),
None,
);

match_test_runner_with_extractions(
config,
vec![(log_tag("key", "13"), true), (log_tag("key", "13.0"), true)],
&[("id1".to_string(), "13".to_string())].into(),
Some(&BTreeMap::from([("id1".to_string(), "13".to_string())])),
);
}

Expand Down Expand Up @@ -856,14 +856,14 @@ fn make_message_match(operator: Operator, match_value: &str) -> base_log_matcher

#[allow(clippy::needless_pass_by_value)]
fn match_test_runner(config: LogMatcher, cases: Vec<(Input<'_>, bool)>) {
match_test_runner_with_extractions(config, cases, &TinyMap::default());
match_test_runner_with_extractions(config, cases, None);
}

#[allow(clippy::needless_pass_by_value)]
fn match_test_runner_with_extractions(
config: LogMatcher,
cases: Vec<(Input<'_>, bool)>,
extracted_fields: &TinyMap<String, String>,
extracted_fields: Option<&BTreeMap<String, String>>,
) {
let match_tree = Tree::new(&config).unwrap();

Expand Down
3 changes: 1 addition & 2 deletions bd-log-matcher/src/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt

use crate::matcher::Tree;
use bd_log_primitives::tiny_set::TinyMap;
use bd_log_primitives::{FieldsRef, LogMessage, LogType, StringOrBytes, TypedLogLevel};
use bd_proto::protos::log_matcher::log_matcher::LogMatcher;
use std::collections::HashMap;
Expand Down Expand Up @@ -42,7 +41,7 @@ impl TestMatcher {
log_type,
&message.into(),
FieldsRef::new(&fields, &matching_fields),
&TinyMap::default(),
None,
)
}
}
1 change: 0 additions & 1 deletion bd-log-primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
)]

pub mod size;
pub mod tiny_set;

use crate::size::MemorySized;
use ahash::AHashMap;
Expand Down
Loading
Loading