Skip to content
Open
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
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ tracing = "0.1.40"
tracing-subscriber = { version = "0.3.18", features = ["json"] }
tracing-test = "0.2.5"
console = "0.15.8"
sentry-kafka-schemas = "2.1.18"
sentry-kafka-schemas = "2.1.19"
serde_with = { version = "3.8.1", features = ["chrono"] }
rmp-serde = "1.3.0"
serde_repr = "0.1.19"
Expand Down
103 changes: 93 additions & 10 deletions src/assertions/compiled.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,28 @@ impl EvalResult {
}
}

pub fn extract_failure_data(
path: &EvalPath,
assert_op: &crate::assertions::Op,
) -> crate::assertions::Op {
match path {
EvalPath::Leaf => assert_op.clone(),
EvalPath::AllChildren => assert_op.clone(),
EvalPath::ChildIndex { index, child } => match assert_op {
crate::assertions::Op::And { children } => crate::assertions::Op::And {
children: vec![extract_failure_data(child, &children[*index])],
},
crate::assertions::Op::Or { children } => crate::assertions::Op::Or {
children: vec![extract_failure_data(child, &children[*index])],
},
crate::assertions::Op::Not { operand } => crate::assertions::Op::Not {
operand: extract_failure_data(child, operand).into(),
},
_ => panic!(),
},
}
}

struct Gas(u32);

impl Gas {
Expand Down Expand Up @@ -547,7 +569,7 @@ mod tests {
use http::{HeaderMap, HeaderValue};

use crate::assertions::{
compiled::{compile, CompilationError, EvalPath},
compiled::{compile, extract_failure_data, CompilationError, EvalPath},
Assertion, Comparison, GlobPattern, HeaderOperand, Op,
};

Expand Down Expand Up @@ -926,8 +948,8 @@ mod tests {
.into(),
},
};
let assert = compile(&assert).unwrap();
let eval = assert.eval(200, &hmap, b"").unwrap();
let c_assert = compile(&assert).unwrap();
let eval = c_assert.eval(200, &hmap, b"").unwrap();
assert!(!eval.result);
assert_eq!(
eval.reason_path,
Expand All @@ -939,7 +961,24 @@ mod tests {
}
.into()
}
)
);

let extracted_failure = extract_failure_data(&eval.reason_path, &assert.root);
match extracted_failure {
Op::Not { operand } => match *operand {
Op::Or { children } => assert_eq!(
children[0],
Op::HeaderCheck {
key_op: Comparison::Equals,
key_operand: HeaderOperand::Literal { value: "2".into() },
value_op: Comparison::Always,
value_operand: HeaderOperand::None,
}
),
_ => panic!(),
},
_ => panic!(),
}
}

#[test]
Expand Down Expand Up @@ -972,16 +1011,30 @@ mod tests {
],
},
};
let assert = compile(&assert).unwrap();
let eval = assert.eval(200, &hmap, b"").unwrap();
let c_assert = compile(&assert).unwrap();
let eval = c_assert.eval(200, &hmap, b"").unwrap();
assert!(!eval.result);
assert_eq!(
eval.reason_path,
EvalPath::ChildIndex {
index: 2,
child: EvalPath::Leaf.into()
}
)
);

let extracted_failure = extract_failure_data(&eval.reason_path, &assert.root);
match extracted_failure {
Op::And { children } => assert_eq!(
children[0],
Op::HeaderCheck {
key_op: Comparison::Equals,
key_operand: HeaderOperand::Literal { value: "4".into() },
value_op: Comparison::Always,
value_operand: HeaderOperand::None,
},
),
_ => panic!(),
}
}

#[test]
Expand Down Expand Up @@ -1032,8 +1085,8 @@ mod tests {
.into(),
},
};
let assert = compile(&assert).unwrap();
let eval = assert.eval(200, &hmap, b"").unwrap();
let c_assert = compile(&assert).unwrap();
let eval = c_assert.eval(200, &hmap, b"").unwrap();
assert!(!eval.result);
assert_eq!(
eval.reason_path,
Expand All @@ -1045,6 +1098,36 @@ mod tests {
}
.into()
}
)
);

let extracted_failure = extract_failure_data(&eval.reason_path, &assert.root);
match extracted_failure {
Op::Not { operand } => match *operand {
Op::Or { children } => match &children[0] {
Op::And { children } => assert_eq!(
*children,
vec![
Op::HeaderCheck {
key_op: Comparison::Equals,
key_operand: HeaderOperand::Literal { value: "1".into() },
value_op: Comparison::Always,
value_operand: HeaderOperand::None,
},
Op::HeaderCheck {
key_op: Comparison::NotEqual,
key_operand: HeaderOperand::Literal {
value: "123".into(),
},
value_op: Comparison::Always,
value_operand: HeaderOperand::None,
},
],
),
_ => panic!(),
},
_ => panic!(),
},
_ => panic!(),
}
}
}
18 changes: 18 additions & 0 deletions src/assertions/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,24 @@ mod tests {
"value": "2"
}
},
{
"op": "header_check",
"key_op": {
"cmp": "equals"
},
"key_operand": {
"header_op": "glob",
"pattern": {
"value": "x-header-[a-zA-Z]+-[1-9][0-9]*"
}
},
"value_op": {
"cmp": "always"
},
"value_operand": {
"header_op": "none"
}
},
{
"op": "status_code_check",
"value": 0,
Expand Down
22 changes: 20 additions & 2 deletions src/checker/reqwest_checker.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::ip_filter::is_external_ip;
use super::{make_trace_header, make_trace_id, Checker};
use crate::assertions::{self};
use crate::assertions::compiled::extract_failure_data;
use crate::assertions::{self, Assertion};
use crate::check_executor::ScheduledCheck;
use crate::types::result::{to_request_info_list, Check, RequestDurations, Timing};
use crate::types::{
Expand Down Expand Up @@ -497,6 +498,23 @@ impl Checker for ReqwestChecker {

let final_req = rinfos.last().unwrap().clone();

let assertion_failure_data = if let Some(path) = check_result.assert_path {
Assertion {
root: extract_failure_data(
&path,
&check
.get_config()
.assertion
.as_ref()
.expect("cannot have assertion failure data with an assertion")
.root,
),
}
.into()
} else {
None
};

CheckResult {
guid: trace_id,
subscription_id: check.get_config().subscription_id,
Expand All @@ -513,7 +531,7 @@ impl Checker for ReqwestChecker {
request_info: Some(final_req),
region,
request_info_list: rinfos,
assertion_failure_data: check_result.assert_path,
assertion_failure_data,
}
}

Expand Down
53 changes: 40 additions & 13 deletions src/types/result.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
use crate::assertions::compiled;
use crate::assertions::compiled::EvalPath;
use crate::assertions::Assertion;
use chrono::{DateTime, TimeDelta, Utc};
use http::StatusCode;
use hyper::rt::ConnectionStats;
Expand Down Expand Up @@ -374,7 +375,7 @@ pub struct CheckResult {

/// If an assertion was present, executed successfully, and didn't pass, this contains
/// the parts of the assertion that led to the failed status.
Comment on lines 376 to 377
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this comment accurate?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, this is correct

pub assertion_failure_data: Option<EvalPath>,
pub assertion_failure_data: Option<Assertion>,
}

pub(crate) struct Check {
Expand Down Expand Up @@ -464,6 +465,8 @@ impl From<Result<compiled::EvalResult, compiled::RuntimeError>> for Check {
mod tests {
use similar_asserts::assert_eq;

use crate::assertions::{self, GlobPattern};

use super::*;

#[test]
Expand Down Expand Up @@ -616,9 +619,41 @@ mod tests {
request_info: None,
request_info_list: vec![],
region: "default",
assertion_failure_data: EvalPath::ChildIndex {
index: 0,
child: EvalPath::AllChildren.into(),
assertion_failure_data: Assertion {
root: assertions::Op::And {
children: vec![
assertions::Op::HeaderCheck {
key_op: assertions::Comparison::Equals,
key_operand: assertions::HeaderOperand::Literal {
value: "hello".to_owned(),
},
value_op: assertions::Comparison::NotEqual,
value_operand: assertions::HeaderOperand::Glob {
pattern: GlobPattern {
value: "a*".to_owned(),
},
},
},
assertions::Op::HeaderCheck {
key_op: assertions::Comparison::LessThan,
key_operand: assertions::HeaderOperand::None,
value_op: assertions::Comparison::GreaterThan,
value_operand: assertions::HeaderOperand::None,
},
assertions::Op::HeaderCheck {
key_op: assertions::Comparison::Always,
key_operand: assertions::HeaderOperand::None,
value_op: assertions::Comparison::Never,
value_operand: assertions::HeaderOperand::None,
},
assertions::Op::Not {
operand: assertions::Op::JsonPath {
value: "asdf".to_owned(),
}
.into(),
},
],
},
}
.into(),
};
Expand Down Expand Up @@ -646,15 +681,7 @@ mod tests {
request_info: None,
request_info_list: vec![],
region: "default",
assertion_failure_data: EvalPath::ChildIndex {
index: 0,
child: EvalPath::ChildIndex {
index: 1,
child: EvalPath::Leaf.into(),
}
.into(),
}
.into(),
assertion_failure_data: None,
};

let json = serde_json::to_vec(&check_result).unwrap();
Expand Down
Loading