Skip to content

feat(crons): Add new fields to MonitorConfig type #638

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jan 29, 2024
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
33 changes: 33 additions & 0 deletions sentry-types/src/protocol/envelope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,8 @@ mod test {
checkin_margin: Some(5),
max_runtime: Some(30),
timezone: Some("UTC".into()),
failure_issue_threshold: None,
recovery_threshold: None,
}),
};
let envelope: Envelope = check_in.into();
Expand All @@ -715,6 +717,37 @@ mod test {
)
}

#[test]
fn test_monitor_checkin_with_thresholds() {
let check_in_id = Uuid::parse_str("22d00b3f-d1b1-4b5d-8d20-49d138cd8a9c").unwrap();

let check_in = MonitorCheckIn {
check_in_id,
monitor_slug: "my-monitor".into(),
status: MonitorCheckInStatus::Ok,
duration: Some(123.4),
environment: Some("production".into()),
monitor_config: Some(MonitorConfig {
schedule: MonitorSchedule::Crontab {
value: "12 0 * * *".into(),
},
checkin_margin: Some(5),
max_runtime: Some(30),
timezone: Some("UTC".into()),
failure_issue_threshold: Some(4),
recovery_threshold: Some(7),
}),
};
let envelope: Envelope = check_in.into();
assert_eq!(
to_str(envelope),
r#"{}
{"type":"check_in","length":310}
{"check_in_id":"22d00b3fd1b14b5d8d2049d138cd8a9c","monitor_slug":"my-monitor","status":"ok","environment":"production","duration":123.4,"monitor_config":{"schedule":{"type":"crontab","value":"12 0 * * *"},"checkin_margin":5,"max_runtime":30,"timezone":"UTC","failure_issue_threshold":4,"recovery_threshold":7}}
"#
)
}

#[test]
fn test_event_with_attachment() {
let event_id = Uuid::parse_str("22d00b3f-d1b1-4b5d-8d20-49d138cd8a9c").unwrap();
Expand Down
8 changes: 8 additions & 0 deletions sentry-types/src/protocol/monitor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,14 @@ pub struct MonitorConfig {
/// tz database style timezone string
#[serde(default, skip_serializing_if = "Option::is_none")]
pub timezone: Option<String>,

/// The number of consecutive failed/error check-ins that triggers issue creation.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub failure_issue_threshold: Option<u64>,

/// The number of consecutive successful check-ins that triggers issue resolution.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub recovery_threshold: Option<u64>,
}

fn serialize_id<S: Serializer>(uuid: &Uuid, serializer: S) -> Result<S::Ok, S::Error> {
Expand Down