Simplify test helper

This commit is contained in:
Hugh Kaznowski
2026-09-07 01:53:16 +01:00
parent d0ce524e95
commit 55820982b1
3 changed files with 27 additions and 41 deletions
-2
View File
@@ -122,9 +122,7 @@ impl EngineSnapshot {
_ => None, _ => None,
}) })
} }
}
impl EngineSnapshot {
pub(crate) fn from_index(index: BTreeMap<IndexKey, DataValue>) -> Self { pub(crate) fn from_index(index: BTreeMap<IndexKey, DataValue>) -> Self {
let mut snapshot = EngineSnapshot { index, ..Default::default() }; let mut snapshot = EngineSnapshot { index, ..Default::default() };
snapshot.rebuild_regex_caches(); snapshot.rebuild_regex_caches();
-2
View File
@@ -25,8 +25,6 @@ use std::collections::BTreeMap;
pub(crate) fn handle_query( pub(crate) fn handle_query(
snapshot: &EngineSnapshot, snapshot: &EngineSnapshot,
query: EngineQuery, query: EngineQuery,
_approx_bytes_total: u64,
_ingest_lag_high_watermark_ms: i64,
sort_helper_indexes: &mut HashMap<String, SortHelperIndexEntry>, sort_helper_indexes: &mut HashMap<String, SortHelperIndexEntry>,
) -> EngineResponse { ) -> EngineResponse {
handle_query_inner(snapshot, query, SortHelperAccess::Mutable(sort_helper_indexes)) handle_query_inner(snapshot, query, SortHelperAccess::Mutable(sort_helper_indexes))
+27 -37
View File
@@ -206,7 +206,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
); );
} }
let entries = match handle_query(&index, logs_query_sorted("PID", Some(false)), 0, 0, &mut HashMap::new()) { let entries = match handle_query(&index, logs_query_sorted("PID", Some(false)), &mut HashMap::new()) {
EngineResponse::Logs(entries) => entries, EngineResponse::Logs(entries) => entries,
_ => panic!("expected Logs response"), _ => panic!("expected Logs response"),
}; };
@@ -1668,8 +1668,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
start_ms: None, start_ms: None,
end_ms: None, end_ms: None,
}, },
0,
0,
&mut HashMap::new(), &mut HashMap::new(),
); );
match response { match response {
@@ -1691,8 +1689,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
start_ms: None, start_ms: None,
end_ms: None, end_ms: None,
}, },
0,
0,
&mut HashMap::new(), &mut HashMap::new(),
); );
match response { match response {
@@ -1785,8 +1781,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
let response = handle_query( let response = handle_query(
&index, &index,
EngineQuery::Promql { query: "count(ottyl_seq)".to_string(), start_ms: None, end_ms: None }, EngineQuery::Promql { query: "count(ottyl_seq)".to_string(), start_ms: None, end_ms: None },
0,
0,
&mut HashMap::new(), &mut HashMap::new(),
); );
match response { match response {
@@ -1847,7 +1841,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 1, "level=info msg=hello"); ingest_log(&mut index, 1, "level=info msg=hello");
ingest_log(&mut index, 2, "just plain prose"); ingest_log(&mut index, 2, "just plain prose");
match handle_query(&index, logs_query(None), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(None), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let formats: Vec<Option<&MetricPrimitive>> = entries.iter().map(|e| e.params.get("ottyl_fmt")).collect(); let formats: Vec<Option<&MetricPrimitive>> = entries.iter().map(|e| e.params.get("ottyl_fmt")).collect();
assert_eq!(formats[0], Some(&MetricPrimitive::String("json".to_string()))); assert_eq!(formats[0], Some(&MetricPrimitive::String("json".to_string())));
@@ -1866,7 +1860,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 2, "still fine"); ingest_log(&mut index, 2, "still fine");
ingest_log(&mut index, 3, "another error here"); ingest_log(&mut index, 3, "another error here");
match handle_query(&index, logs_query(Some(r#"regex("error")"#)), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some(r#"regex("error")"#)), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![1, 3]); assert_eq!(sequences, vec![1, 3]);
@@ -1882,7 +1876,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, i, &format!("line {i}")); ingest_log(&mut index, i, &format!("line {i}"));
} }
match handle_query(&index, logs_query(Some("ottyl_seq<2")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("ottyl_seq<2")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![0, 1]); assert_eq!(sequences, vec![0, 1]);
@@ -1902,7 +1896,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
); );
} }
match handle_query(&index, logs_query(Some("ottyl_ts>2000")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("ottyl_ts>2000")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![3, 4]); assert_eq!(sequences, vec![3, 4]);
@@ -1926,7 +1920,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 1, "priority=1 boom"); ingest_log(&mut index, 1, "priority=1 boom");
ingest_log(&mut index, 2, "priority=2 boom"); ingest_log(&mut index, 2, "priority=2 boom");
match handle_query(&index, logs_query_sorted("priority", None), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query_sorted("priority", None), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![1, 2, 0]); assert_eq!(sequences, vec![1, 2, 0]);
@@ -1950,7 +1944,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 2, "priority=1 boom"); ingest_log(&mut index, 2, "priority=1 boom");
ingest_log(&mut index, 3, "also missing"); ingest_log(&mut index, 3, "also missing");
match handle_query(&index, logs_query_sorted("priority", Some(true)), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query_sorted("priority", Some(true)), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![2, 0, 1, 3]); assert_eq!(sequences, vec![2, 0, 1, 3]);
@@ -1974,7 +1968,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 2, "priority=1 boom"); ingest_log(&mut index, 2, "priority=1 boom");
ingest_log(&mut index, 3, "also missing"); ingest_log(&mut index, 3, "also missing");
match handle_query(&index, logs_query_sorted("priority", Some(false)), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query_sorted("priority", Some(false)), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![2, 0]); assert_eq!(sequences, vec![2, 0]);
@@ -1988,7 +1982,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
let mut index = EngineSnapshot::default(); let mut index = EngineSnapshot::default();
ingest_log(&mut index, 0, "hello"); ingest_log(&mut index, 0, "hello");
match handle_query(&index, logs_query_sorted("does_not_exist", None), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query_sorted("does_not_exist", None), &mut HashMap::new()) {
EngineResponse::Error(err) => assert!(err.contains("does_not_exist")), EngineResponse::Error(err) => assert!(err.contains("does_not_exist")),
_ => panic!("expected EngineResponse::Error"), _ => panic!("expected EngineResponse::Error"),
} }
@@ -2009,7 +2003,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 2, "priority=1 boom"); ingest_log(&mut index, 2, "priority=1 boom");
ingest_log(&mut index, 3, "also missing"); ingest_log(&mut index, 3, "also missing");
match handle_query(&index, logs_query(None), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(None), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![0, 1, 2, 3]); assert_eq!(sequences, vec![0, 1, 2, 3]);
@@ -2036,7 +2030,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
let mut sort_helper_indexes = HashMap::new(); let mut sort_helper_indexes = HashMap::new();
assert!(!sort_helper_indexes.contains_key("priority")); assert!(!sort_helper_indexes.contains_key("priority"));
match handle_query(&index, logs_query_sorted("priority", None), 0, 0, &mut sort_helper_indexes) { match handle_query(&index, logs_query_sorted("priority", None), &mut sort_helper_indexes) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![1, 2, 0]); assert_eq!(sequences, vec![1, 2, 0]);
@@ -2057,7 +2051,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
std::mem::swap(&mut index.sort_helper_indexes, &mut sort_helper_indexes); std::mem::swap(&mut index.sort_helper_indexes, &mut sort_helper_indexes);
assert_eq!(sort_helper_indexes["priority"].index.len(), 5); assert_eq!(sort_helper_indexes["priority"].index.len(), 5);
match handle_query(&index, logs_query_sorted("priority", None), 0, 0, &mut sort_helper_indexes) { match handle_query(&index, logs_query_sorted("priority", None), &mut sort_helper_indexes) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![3, 1, 2, 0, 4]); assert_eq!(sequences, vec![3, 1, 2, 0, 4]);
@@ -2113,12 +2107,12 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 2, "priority=2 boom"); ingest_log(&mut index, 2, "priority=2 boom");
let mut sort_helper_indexes = HashMap::new(); let mut sort_helper_indexes = HashMap::new();
let _ = handle_query(&index, logs_query_sorted("priority", None), 0, 0, &mut sort_helper_indexes); let _ = handle_query(&index, logs_query_sorted("priority", None), &mut sort_helper_indexes);
assert!(sort_helper_indexes.contains_key("priority")); assert!(sort_helper_indexes.contains_key("priority"));
sort_helper_indexes.remove("priority"); sort_helper_indexes.remove("priority");
match handle_query(&index, logs_query_sorted("priority", None), 0, 0, &mut sort_helper_indexes) { match handle_query(&index, logs_query_sorted("priority", None), &mut sort_helper_indexes) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![1, 2, 0]); assert_eq!(sequences, vec![1, 2, 0]);
@@ -2136,7 +2130,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 2, "just some plain prose here"); ingest_log(&mut index, 2, "just some plain prose here");
ingest_log(&mut index, 3, r#"{"level":"info","code":200}"#); ingest_log(&mut index, 3, r#"{"level":"info","code":200}"#);
match handle_query(&index, logs_query(Some("ottyl_fmt==json")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("ottyl_fmt==json")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![0, 3]); assert_eq!(sequences, vec![0, 3]);
@@ -2144,7 +2138,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
_ => panic!("expected Logs response"), _ => panic!("expected Logs response"),
} }
match handle_query(&index, logs_query(Some("ottyl_fmt==logfmt")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("ottyl_fmt==logfmt")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![1]); assert_eq!(sequences, vec![1]);
@@ -2152,7 +2146,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
_ => panic!("expected Logs response"), _ => panic!("expected Logs response"),
} }
match handle_query(&index, logs_query(Some("ottyl_fmt==none")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("ottyl_fmt==none")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![2]); assert_eq!(sequences, vec![2]);
@@ -2168,7 +2162,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 1, r#"{"level":"info","code":200}"#); ingest_log(&mut index, 1, r#"{"level":"info","code":200}"#);
ingest_log(&mut index, 2, "not json at all"); ingest_log(&mut index, 2, "not json at all");
match handle_query(&index, logs_query(Some(r#"json[level]==error"#)), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some(r#"json[level]==error"#)), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![0]); assert_eq!(sequences, vec![0]);
@@ -2176,7 +2170,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
_ => panic!("expected Logs response"), _ => panic!("expected Logs response"),
} }
match handle_query(&index, logs_query(Some("json[code]>=300")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("json[code]>=300")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![0]); assert_eq!(sequences, vec![0]);
@@ -2199,8 +2193,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
match handle_query( match handle_query(
&index, &index,
logs_query(Some(r#"regex("boom") and requests[level]==error"#)), logs_query(Some(r#"regex("boom") and requests[level]==error"#)),
0,
0,
&mut HashMap::new(), &mut HashMap::new(),
) { ) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
@@ -2213,8 +2205,6 @@ use std::collections::{BTreeMap, HashMap, HashSet};
match handle_query( match handle_query(
&index, &index,
logs_query(Some(r#"regex("boom") or requests[level]==error"#)), logs_query(Some(r#"regex("boom") or requests[level]==error"#)),
0,
0,
&mut HashMap::new(), &mut HashMap::new(),
) { ) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
@@ -2232,7 +2222,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 0, "level=info hello"); ingest_log(&mut index, 0, "level=info hello");
ingest_log(&mut index, 1, "no match here"); ingest_log(&mut index, 1, "no match here");
let EngineResponse::Logs(entries) = handle_query(&index, logs_query(None), 0, 0, &mut HashMap::new()) else { let EngineResponse::Logs(entries) = handle_query(&index, logs_query(None), &mut HashMap::new()) else {
panic!("expected Logs response"); panic!("expected Logs response");
}; };
@@ -2254,7 +2244,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 0, "an ERROR occurred"); ingest_log(&mut index, 0, "an ERROR occurred");
ingest_log(&mut index, 1, "everything is fine"); ingest_log(&mut index, 1, "everything is fine");
let EngineResponse::Logs(entries) = handle_query(&index, logs_query(None), 0, 0, &mut HashMap::new()) else { let EngineResponse::Logs(entries) = handle_query(&index, logs_query(None), &mut HashMap::new()) else {
panic!("expected Logs response"); panic!("expected Logs response");
}; };
@@ -2270,7 +2260,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 1, "an error occurred"); ingest_log(&mut index, 1, "an error occurred");
ingest_log(&mut index, 2, "another error here"); ingest_log(&mut index, 2, "another error here");
match handle_query(&index, timeline_query(Some(r#"regex("error")"#), 1_000_000), 0, 0, &mut HashMap::new()) { match handle_query(&index, timeline_query(Some(r#"regex("error")"#), 1_000_000), &mut HashMap::new()) {
EngineResponse::Timeline(buckets) => { EngineResponse::Timeline(buckets) => {
let total: u64 = buckets.iter().map(|b| b.count).sum(); let total: u64 = buckets.iter().map(|b| b.count).sum();
assert_eq!(total, 2); assert_eq!(total, 2);
@@ -2284,12 +2274,12 @@ use std::collections::{BTreeMap, HashMap, HashSet};
let mut index = EngineSnapshot::default(); let mut index = EngineSnapshot::default();
ingest_log(&mut index, 0, "hello"); ingest_log(&mut index, 0, "hello");
match handle_query(&index, logs_query(Some("@@@ not a valid filter @@@")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("@@@ not a valid filter @@@")), &mut HashMap::new()) {
EngineResponse::Error(message) => assert!(!message.is_empty()), EngineResponse::Error(message) => assert!(!message.is_empty()),
_ => panic!("expected an Error response for a malformed filter string"), _ => panic!("expected an Error response for a malformed filter string"),
} }
match handle_query(&index, timeline_query(Some("@@@ not a valid filter @@@"), 1000), 0, 0, &mut HashMap::new()) { match handle_query(&index, timeline_query(Some("@@@ not a valid filter @@@"), 1000), &mut HashMap::new()) {
EngineResponse::Error(message) => assert!(!message.is_empty()), EngineResponse::Error(message) => assert!(!message.is_empty()),
_ => panic!("expected an Error response for a malformed filter string"), _ => panic!("expected an Error response for a malformed filter string"),
} }
@@ -2303,7 +2293,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
index.declare_metric(metric_request("requests", pattern, vec!["level"])).unwrap(); index.declare_metric(metric_request("requests", pattern, vec!["level"])).unwrap();
ingest_log(&mut index, 0, "level=error"); ingest_log(&mut index, 0, "level=error");
match handle_query(&index, logs_query(Some("requests==5")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("requests==5")), &mut HashMap::new()) {
EngineResponse::Error(message) => assert!(message.contains("param")), EngineResponse::Error(message) => assert!(message.contains("param")),
_ => panic!("expected an Error response for a metric comparison without [param]"), _ => panic!("expected an Error response for a metric comparison without [param]"),
} }
@@ -2318,7 +2308,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
index.declare_metric(metric_request("requests", pattern, vec!["level", "duration"])).unwrap(); index.declare_metric(metric_request("requests", pattern, vec!["level", "duration"])).unwrap();
ingest_log(&mut index, 0, "level=error duration=5"); ingest_log(&mut index, 0, "level=error duration=5");
match handle_query(&index, logs_query(Some("requests[nonexistent_param]==\"x\"")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("requests[nonexistent_param]==\"x\"")), &mut HashMap::new()) {
EngineResponse::Error(message) => { EngineResponse::Error(message) => {
assert!( assert!(
message.contains("nonexistent_param"), message.contains("nonexistent_param"),
@@ -2348,7 +2338,7 @@ use std::collections::{BTreeMap, HashMap, HashSet};
ingest_log(&mut index, 0, "level=error duration=5"); ingest_log(&mut index, 0, "level=error duration=5");
ingest_log(&mut index, 1, "level=info duration=2"); ingest_log(&mut index, 1, "level=info duration=2");
match handle_query(&index, logs_query(Some("requests[level]==error")), 0, 0, &mut HashMap::new()) { match handle_query(&index, logs_query(Some("requests[level]==error")), &mut HashMap::new()) {
EngineResponse::Logs(entries) => { EngineResponse::Logs(entries) => {
let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect(); let sequences: Vec<u64> = entries.iter().map(|e| e.sequence).collect();
assert_eq!(sequences, vec![0]); assert_eq!(sequences, vec![0]);