diff --git a/Makefile b/Makefile index dbfb297a..ee29731b 100644 --- a/Makefile +++ b/Makefile @@ -47,3 +47,10 @@ install: # Install systemd user service mkdir -p $(DESTDIR)$(PREFIX)/lib/systemd/user install -m 644 aw-server.service $(DESTDIR)$(PREFIX)/lib/systemd/user/aw-server.service + +coverage: + export CARGO_INCREMENTAL=0 + export RUSTFLAGS="-Zprofile -Ccodegen-units=1 -Copt-level=0 -Clink-dead-code -Coverflow-checks=off -Zpanic_abort_tests -Cpanic=abort" + export RUSTDOCFLAGS="-Cpanic=abort" + cargo build --verbose $(cargoflag) + cargo test --verbose $(cargoflag) diff --git a/aw-query/benches/benchmark.rs b/aw-query/benches/benchmark.rs index b1971044..440db3ab 100644 --- a/aw-query/benches/benchmark.rs +++ b/aw-query/benches/benchmark.rs @@ -70,7 +70,7 @@ mod query_benchmarks { } // let mut event_list = Vec::new(); - for i in 0..3000 { + for i in 0..30000 { let e = Event { id: None, timestamp: chrono::Utc::now() + Duration::seconds(i), diff --git a/aw-query/src/ast.rs b/aw-query/src/ast.rs index bba16557..0d9526bc 100644 --- a/aw-query/src/ast.rs +++ b/aw-query/src/ast.rs @@ -24,6 +24,7 @@ pub enum Expr_ { Equal(Box, Box), Var(String), + VarRef(String), Assign(String, Box), Function(String, Box), If(Vec<(Box, Vec)>), diff --git a/aw-query/src/interpret.rs b/aw-query/src/interpret.rs index 48ba212c..ccf41121 100644 --- a/aw-query/src/interpret.rs +++ b/aw-query/src/interpret.rs @@ -182,11 +182,17 @@ fn interpret_expr( env.insert(var, val); Ok(DataType::None()) } - // FIXME: avoid clone, it's slow - Var(var) => match env.get(&var) { - Some(v) => Ok(v.clone()), + Var(var) => match env.remove(&var) { + Some(v) => Ok(v), None => Err(QueryError::VariableNotDefined(var.to_string())), }, + VarRef(var) => { + // TODO: Remove clone + match env.get(&var) { + Some(v) => Ok(v.clone()), + None => Err(QueryError::VariableNotDefined(var.to_string())), + } + } Bool(lit) => Ok(DataType::Bool(lit)), Number(lit) => Ok(DataType::Number(lit)), String(litstr) => Ok(DataType::String(litstr.to_string())), diff --git a/aw-query/src/lexer.rs b/aw-query/src/lexer.rs index 1701790e..02cbac52 100644 --- a/aw-query/src/lexer.rs +++ b/aw-query/src/lexer.rs @@ -13,6 +13,7 @@ pub enum Token { Number(f64), String(String), Plus, + Ampersand, Minus, Star, Slash, @@ -69,6 +70,7 @@ lexer! { r#"=="# => (Token::Equals, text), r#"="# => (Token::Assign, text), + r#"\&"# => (Token::Ampersand, text), r#"\+"# => (Token::Plus, text), r#"-"# => (Token::Minus, text), r#"\*"# => (Token::Star, text), diff --git a/aw-query/src/parser.rs b/aw-query/src/parser.rs index b7541a1c..b64ebb26 100644 --- a/aw-query/src/parser.rs +++ b/aw-query/src/parser.rs @@ -246,6 +246,10 @@ parser! { span: span!(), node: Expr_::Var(v), }, + Ampersand Ident(v) => Expr { + span: span!(), + node: Expr_::VarRef(v), + }, Bool(b) => Expr { span: span!(), node: Expr_::Bool(b), diff --git a/aw-query/tests/query.rs b/aw-query/tests/query.rs index 1ecac21b..71f91381 100644 --- a/aw-query/tests/query.rs +++ b/aw-query/tests/query.rs @@ -232,7 +232,7 @@ mod query_tests { let code = String::from( " a=True; n=1; - if a { n=2; } + if &a { n=2; } return n;", ); match aw_query::query(&code, &interval, &ds).unwrap() { @@ -269,8 +269,8 @@ mod query_tests { let code = String::from( " a=False; b=True; n=1; - if a { n=2; } - elif b { n=3; } + if &a { n=2; } + elif &b { n=3; } return n;", ); match aw_query::query(&code, &interval, &ds).unwrap() { @@ -282,8 +282,8 @@ mod query_tests { let code = String::from( " a=False; b=True; n=1; - if a { n=2; } - elif a { n=3; } + if &a { n=2; } + elif &a { n=3; } else { n=4; } return n;", ); @@ -296,7 +296,7 @@ mod query_tests { let code = String::from( " a=True; n=1; - if a { if a { n = 2; } } + if &a { if &a { n = 2; } } return n;", ); match aw_query::query(&code, &interval, &ds).unwrap() { @@ -359,16 +359,16 @@ mod query_tests { events = concat(events, query_bucket("{}")); events = categorize(events, [[["test"], {{ "type": "regex", "regex": "value$" }}], [["test", "testing"], {{ "type": "regex", "regex": "value$" }}]]); events = tag(events, [["testtag", {{ "type": "regex", "regex": "test$" }}], ["another testtag", {{ "type": "regex", "regex": "test-pat$" }}]]); - total_duration = sum_durations(events); + total_duration = sum_durations(&events); bucketnames = query_bucket_names(); print("test", "test2"); - url_events = split_url_events (events); - filtered_events = filter_period_intersect(events, events); - filtered_events = filter_keyvals(events, "$category", [["Uncategorized"]]); - filtered_events = filter_keyvals_regex(events, "key", "regex"); - chunked_events = chunk_events_by_key(events, "key"); - merged_events = merge_events_by_keys(events, ["key"]); - return merged_events;"#, + events = split_url_events (events); + events = filter_period_intersect(&events, &events); + events = filter_keyvals(events, "$category", [["Uncategorized"]]); + events = filter_keyvals_regex(events, "key", "regex"); + events = chunk_events_by_key(events, "key"); + events = merge_events_by_keys(events, ["key"]); + return events;"#, "testid", "testid" ); match aw_query::query(&code, &interval, &ds).unwrap() { diff --git a/aw-webui b/aw-webui index 1a969b3e..9247aedb 160000 --- a/aw-webui +++ b/aw-webui @@ -1 +1 @@ -Subproject commit 1a969b3e3bdec7ee5338a3e54238370cbdd9be97 +Subproject commit 9247aedb2a62ee1dd84c812ba5de04f400fdcbf2