Skip to content

Commit

Permalink
feat(crons): Add new fields to MonitorConfig type (#638)
Browse files Browse the repository at this point in the history
Need these fields to implement getsentry/sentry-cli#1919
  • Loading branch information
szokeasaurusrex authored Jan 29, 2024
1 parent ab38648 commit bd78e1e
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
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

0 comments on commit bd78e1e

Please sign in to comment.