-
Notifications
You must be signed in to change notification settings - Fork 213
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
308 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,110 @@ | ||
package sentry | ||
|
||
type CheckInStatus string | ||
|
||
const ( | ||
CheckInStatusInProgress CheckInStatus = "in_progress" | ||
CheckInStatusOK CheckInStatus = "ok" | ||
CheckInStatusError CheckInStatus = "error" | ||
) | ||
|
||
type checkInScheduleType string | ||
|
||
const ( | ||
checkInScheduleTypeCrontab checkInScheduleType = "crontab" | ||
checkInScheduleTypeInterval checkInScheduleType = "interval" | ||
) | ||
|
||
type MonitorSchedule interface { | ||
scheduleType() checkInScheduleType | ||
} | ||
|
||
type crontabSchedule struct { | ||
Type string `json:"type"` | ||
Value string `json:"value"` | ||
} | ||
|
||
func (c crontabSchedule) scheduleType() checkInScheduleType { | ||
return checkInScheduleTypeCrontab | ||
} | ||
|
||
// CrontabSchedule defines the MonitorSchedule with a cron format. | ||
// Example: "8 * * * *". | ||
func CrontabSchedule(scheduleString string) MonitorSchedule { | ||
return crontabSchedule{ | ||
Type: string(checkInScheduleTypeCrontab), | ||
Value: scheduleString, | ||
} | ||
} | ||
|
||
type intervalSchedule struct { | ||
Type string `json:"type"` | ||
Value int64 `json:"value"` | ||
Unit string `json:"unit"` | ||
} | ||
|
||
func (i intervalSchedule) scheduleType() checkInScheduleType { | ||
return checkInScheduleTypeInterval | ||
} | ||
|
||
type MonitorScheduleUnit string | ||
|
||
const ( | ||
MonitorScheduleUnitMinute MonitorScheduleUnit = "minute" | ||
MonitorScheduleUnitHour MonitorScheduleUnit = "hour" | ||
MonitorScheduleUnitDay MonitorScheduleUnit = "day" | ||
MonitorScheduleUnitWeek MonitorScheduleUnit = "week" | ||
MonitorScheduleUnitMonth MonitorScheduleUnit = "month" | ||
MonitorScheduleUnitYear MonitorScheduleUnit = "year" | ||
) | ||
|
||
// IntervalSchedule defines the MonitorSchedule with an interval format. | ||
// | ||
// Example: | ||
// | ||
// IntervalSchedule(1, sentry.MonitorScheduleUnitDay) | ||
func IntervalSchedule(value int64, unit MonitorScheduleUnit) MonitorSchedule { | ||
return intervalSchedule{ | ||
Type: string(checkInScheduleTypeInterval), | ||
Value: value, | ||
Unit: string(unit), | ||
} | ||
} | ||
|
||
type MonitorConfig struct { //nolint: maligned // prefer readability over optimal memory layout | ||
Schedule MonitorSchedule `json:"schedule,omitempty"` | ||
// The allowed allowed margin of minutes after the expected check-in time that | ||
// the monitor will not be considered missed for. | ||
CheckInMargin int64 `json:"check_in_margin,omitempty"` | ||
// The allowed allowed duration in minutes that the monitor may be `in_progress` | ||
// for before being considered failed due to timeout. | ||
MaxRuntime int64 `json:"max_runtime,omitempty"` | ||
// A tz database string representing the timezone which the monitor's execution schedule is in. | ||
// See: https://en.wikipedia.org/wiki/List_of_tz_database_time_zones | ||
Timezone string `json:"timezone,omitempty"` | ||
} | ||
|
||
type CheckIn struct { //nolint: maligned // prefer readability over optimal memory layout | ||
// The distinct slug of the monitor. | ||
MonitorSlug string `json:"monitor_slug"` | ||
// The status of the check-in. | ||
Status CheckInStatus `json:"status"` | ||
// The duration of the check-in in seconds. Will only take effect if the status is ok or error. | ||
Duration int64 `json:"duration,omitempty"` | ||
} | ||
|
||
// serializedCheckIn is used by checkInMarshalJSON method on Event struct. | ||
// See https://develop.sentry.dev/sdk/check-ins/ | ||
type serializedCheckIn struct { //nolint: maligned | ||
// Check-In ID (unique and client generated). | ||
CheckInID string `json:"check_in_id"` | ||
// The distinct slug of the monitor. | ||
MonitorSlug string `json:"monitor_slug"` | ||
// The status of the check-in. | ||
Status CheckInStatus `json:"status"` | ||
// The duration of the check-in in seconds. Will only take effect if the status is ok or error. | ||
Duration int64 `json:"duration,omitempty"` | ||
Release string `json:"release,omitempty"` | ||
Environment string `json:"environment,omitempty"` | ||
MonitorConfig *MonitorConfig `json:"monitor_config,omitempty"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
{ | ||
"check_in_id": "c2f0ce1334c74564bf6631f6161173f5", | ||
"monitor_slug": "my-monitor", | ||
"status": "ok", | ||
"duration": 10, | ||
"release": "1.0.0", | ||
"environment": "dev" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"check_in_id": "0cde0b4e725d4504b2d07c303c2a06d5", | ||
"monitor_slug": "my-monitor", | ||
"status": "ok", | ||
"duration": 10, | ||
"release": "1.0.0", | ||
"environment": "dev", | ||
"monitor_config": { | ||
"schedule": { | ||
"type": "interval", | ||
"value": 1, | ||
"unit": "day" | ||
}, | ||
"check_in_margin": 5, | ||
"max_runtime": 30, | ||
"timezone": "America/Los_Angeles" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
{ | ||
"check_in_id": "6fa9f5f4da114025b5bf681d63716f6d", | ||
"monitor_slug": "my-monitor", | ||
"status": "ok", | ||
"duration": 10, | ||
"release": "1.0.0", | ||
"environment": "dev", | ||
"monitor_config": { | ||
"schedule": { | ||
"type": "crontab", | ||
"value": "0 * * * *" | ||
}, | ||
"check_in_margin": 5, | ||
"max_runtime": 30, | ||
"timezone": "America/Los_Angeles" | ||
} | ||
} |