Skip to content

Commit 778876a

Browse files
authored
Revert "workflows: use TinySet/TinyMap in the workflow engine (#269)" (#271)
This reverts commit 7518add. There are places at the engine level where the set/maps can legitamelty become larger. I need to rethink some of this so I'm just going to revert the entire thing for now and come back to it. Signed-off-by: Matt Klein <[email protected]>
1 parent 24c6c23 commit 778876a

File tree

22 files changed

+307
-550
lines changed

22 files changed

+307
-550
lines changed

bd-log-filter/src/lib.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
mod filter_chain_test;
2020

2121
use anyhow::{Context, Result, anyhow};
22-
use bd_log_primitives::tiny_set::TinyMap;
2322
use bd_log_primitives::{
2423
FieldsRef,
2524
LOG_FIELD_NAME_LEVEL,
@@ -88,13 +87,10 @@ impl FilterChain {
8887
pub fn process(&self, log: &mut Log) {
8988
for filter in &self.filters {
9089
let fields_ref = FieldsRef::new(&log.fields, &log.matching_fields);
91-
if !filter.matcher.do_match(
92-
log.log_level,
93-
log.log_type,
94-
&log.message,
95-
fields_ref,
96-
&TinyMap::default(),
97-
) {
90+
if !filter
91+
.matcher
92+
.do_match(log.log_level, log.log_type, &log.message, fields_ref, None)
93+
{
9894
continue;
9995
}
10096

bd-log-matcher/src/legacy_matcher_test.rs

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
1010
use crate::matcher::Tree;
1111
use assert_matches::assert_matches;
12-
use bd_log_primitives::tiny_set::TinyMap;
1312
use bd_log_primitives::{
1413
EMPTY_FIELDS,
1514
FieldsRef,
@@ -80,13 +79,7 @@ fn match_test_runner(config: LegacyLogMatcher, cases: Vec<(Input<'_>, bool)>) {
8079

8180
assert_eq!(
8281
should_match,
83-
match_tree.do_match(
84-
log_level,
85-
log_type,
86-
&message,
87-
fields_ref,
88-
&TinyMap::default()
89-
),
82+
match_tree.do_match(log_level, log_type, &message, fields_ref, None),
9083
"{input:?} should result in {should_match} but did not",
9184
);
9285
}

bd-log-matcher/src/matcher.rs

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ use base_log_matcher::tag_match::Value_match::{
2424
SemVerValueMatch,
2525
StringValueMatch,
2626
};
27-
use bd_log_primitives::tiny_set::TinyMap;
2827
use bd_log_primitives::{FieldsRef, LogLevel, LogMessage, LogType};
2928
use bd_proto::protos::config::v1::config::log_matcher::base_log_matcher::StringMatchType;
3029
use bd_proto::protos::config::v1::config::log_matcher::{
@@ -47,6 +46,7 @@ use log_matcher::log_matcher::base_log_matcher::{
4746
use log_matcher::log_matcher::{BaseLogMatcher, Matcher, base_log_matcher};
4847
use regex::Regex;
4948
use std::borrow::Cow;
49+
use std::collections::BTreeMap;
5050
use std::ops::Deref;
5151

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

8181
impl<'a, T: MakeValueOrRef<'a, T>> ValueOrSavedFieldId<T> {
82-
fn load(&'a self, extracted_fields: &'a TinyMap<String, String>) -> Option<ValueOrRef<'a, T>> {
82+
fn load(
83+
&'a self,
84+
extracted_fields: Option<&'a BTreeMap<String, String>>,
85+
) -> Option<ValueOrRef<'a, T>> {
8386
match self {
8487
Self::Value(v) => Some(ValueOrRef::Ref(v)),
8588
Self::SaveFieldId(field_id) => extracted_fields
86-
.get(field_id)
89+
.and_then(|extracted_fields| extracted_fields.get(field_id))
8790
.and_then(|v| T::make_value_or_ref(v)),
8891
}
8992
}
@@ -204,7 +207,7 @@ impl Tree {
204207
log_type: LogType,
205208
message: &LogMessage,
206209
fields: FieldsRef<'_>,
207-
extracted_fields: &TinyMap<String, String>,
210+
extracted_fields: Option<&BTreeMap<String, String>>,
208211
) -> bool {
209212
match self {
210213
Self::Base(base_matcher) => match base_matcher {
@@ -265,7 +268,7 @@ impl IntMatch {
265268
}
266269
}
267270

268-
fn evaluate(&self, candidate: i32, extracted_fields: &TinyMap<String, String>) -> bool {
271+
fn evaluate(&self, candidate: i32, extracted_fields: Option<&BTreeMap<String, String>>) -> bool {
269272
let Some(value) = self.value.load(extracted_fields) else {
270273
return false;
271274
};
@@ -314,7 +317,7 @@ impl DoubleMatch {
314317
}
315318
}
316319

317-
fn evaluate(&self, candidate: f64, extracted_fields: &TinyMap<String, String>) -> bool {
320+
fn evaluate(&self, candidate: f64, extracted_fields: Option<&BTreeMap<String, String>>) -> bool {
318321
let candidate = NanEqualFloat(candidate);
319322
let Some(value) = self.value.load(extracted_fields) else {
320323
return false;
@@ -383,7 +386,7 @@ impl StringMatch {
383386
})
384387
}
385388

386-
fn evaluate(&self, candidate: &str, extracted_fields: &TinyMap<String, String>) -> bool {
389+
fn evaluate(&self, candidate: &str, extracted_fields: Option<&BTreeMap<String, String>>) -> bool {
387390
let Some(value) = self.value.load(extracted_fields) else {
388391
return false;
389392
};

bd-log-matcher/src/matcher_test.rs

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use crate::matcher::Tree;
99
use crate::matcher::base_log_matcher::tag_match::Value_match::DoubleValueMatch;
10-
use bd_log_primitives::tiny_set::TinyMap;
1110
use bd_log_primitives::{
1211
EMPTY_FIELDS,
1312
FieldsRef,
@@ -34,6 +33,7 @@ use log_matcher::base_log_matcher::tag_match::Value_match::{
3433
use log_matcher::{BaseLogMatcher, Matcher, MatcherList, base_log_matcher};
3534
use pretty_assertions::assert_eq;
3635
use protobuf::MessageField;
36+
use std::collections::BTreeMap;
3737

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

@@ -230,7 +230,7 @@ fn test_extracted_string_matcher() {
230230
(log_tag("keyx", "exact"), false),
231231
(log_msg("no fields"), false),
232232
],
233-
&TinyMap::default(),
233+
None,
234234
);
235235

236236
match_test_runner_with_extractions(
@@ -240,7 +240,7 @@ fn test_extracted_string_matcher() {
240240
(log_tag("keyx", "exact"), false),
241241
(log_msg("no fields"), false),
242242
],
243-
&[("id1".to_string(), "exact".to_string())].into(),
243+
Some(&BTreeMap::from([("id1".to_string(), "exact".to_string())])),
244244
);
245245
}
246246

@@ -309,20 +309,20 @@ fn test_extracted_double_matcher() {
309309
(log_tag("key", "13.0"), false),
310310
(log_tag("key", "13"), false),
311311
],
312-
&TinyMap::default(),
312+
None,
313313
);
314314
match_test_runner_with_extractions(
315315
config.clone(),
316316
vec![
317317
(log_tag("key", "13.0"), false),
318318
(log_tag("key", "13"), false),
319319
],
320-
&[("id1".to_string(), "bad".to_string())].into(),
320+
Some(&BTreeMap::from([("id1".to_string(), "bad".to_string())])),
321321
);
322322
match_test_runner_with_extractions(
323323
config,
324324
vec![(log_tag("key", "13.0"), true), (log_tag("key", "13"), true)],
325-
&[("id1".to_string(), "13".to_string())].into(),
325+
Some(&BTreeMap::from([("id1".to_string(), "13".to_string())])),
326326
);
327327
}
328328

@@ -419,13 +419,13 @@ fn test_extracted_int_matcher() {
419419
(log_tag("key", "13"), false),
420420
(log_tag("key", "13.0"), false),
421421
],
422-
&TinyMap::default(),
422+
None,
423423
);
424424

425425
match_test_runner_with_extractions(
426426
config,
427427
vec![(log_tag("key", "13"), true), (log_tag("key", "13.0"), true)],
428-
&[("id1".to_string(), "13".to_string())].into(),
428+
Some(&BTreeMap::from([("id1".to_string(), "13".to_string())])),
429429
);
430430
}
431431

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

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

862862
#[allow(clippy::needless_pass_by_value)]
863863
fn match_test_runner_with_extractions(
864864
config: LogMatcher,
865865
cases: Vec<(Input<'_>, bool)>,
866-
extracted_fields: &TinyMap<String, String>,
866+
extracted_fields: Option<&BTreeMap<String, String>>,
867867
) {
868868
let match_tree = Tree::new(&config).unwrap();
869869

bd-log-matcher/src/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
// https://polyformproject.org/wp-content/uploads/2020/06/PolyForm-Shield-1.0.0.txt
77

88
use crate::matcher::Tree;
9-
use bd_log_primitives::tiny_set::TinyMap;
109
use bd_log_primitives::{FieldsRef, LogMessage, LogType, StringOrBytes, TypedLogLevel};
1110
use bd_proto::protos::log_matcher::log_matcher::LogMatcher;
1211
use std::collections::HashMap;
@@ -42,7 +41,7 @@ impl TestMatcher {
4241
log_type,
4342
&message.into(),
4443
FieldsRef::new(&fields, &matching_fields),
45-
&TinyMap::default(),
44+
None,
4645
)
4746
}
4847
}

bd-log-primitives/src/lib.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
)]
1616

1717
pub mod size;
18-
pub mod tiny_set;
1918

2019
use crate::size::MemorySized;
2120
use ahash::AHashMap;

0 commit comments

Comments
 (0)