-
-
Notifications
You must be signed in to change notification settings - Fork 496
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add new Sentry.capture_check_in API for Cron monitoring
* New `CheckInEvent` class for the envelope payload * New `Cron::MonitorConfig` class that holds the monitor configuration * New `Cron::MonitorSchedule` module that holds two types of schedules `Crontab` and `Interval`
- Loading branch information
1 parent
ba29bb8
commit fb9bc77
Showing
14 changed files
with
507 additions
and
9 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
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,60 @@ | ||
# frozen_string_literal | ||
|
||
require 'securerandom' | ||
require 'sentry/cron/monitor_config' | ||
|
||
module Sentry | ||
class CheckInEvent < Event | ||
TYPE = 'check_in' | ||
|
||
# uuid to identify this check-in. | ||
# @return [String] | ||
attr_accessor :check_in_id | ||
|
||
# Identifier of the monitor for this check-in. | ||
# @return [String] | ||
attr_accessor :monitor_slug | ||
|
||
# Duration of this check since it has started in seconds. | ||
# @return [Integer, nil] | ||
attr_accessor :duration | ||
|
||
# Monitor configuration to support upserts. | ||
# @return [Cron::MonitorConfig, nil] | ||
attr_accessor :monitor_config | ||
|
||
# Status of this check-in. | ||
# @return [Symbol] | ||
attr_accessor :status | ||
|
||
VALID_STATUSES = %i(ok in_progress error) | ||
|
||
def initialize( | ||
slug:, | ||
status:, | ||
duration: nil, | ||
monitor_config: nil, | ||
check_in_id: nil, | ||
**options | ||
) | ||
super(**options) | ||
|
||
self.monitor_slug = slug | ||
self.status = status | ||
self.duration = duration | ||
self.monitor_config = monitor_config | ||
self.check_in_id = check_in_id || SecureRandom.uuid.delete('-') | ||
end | ||
|
||
# @return [Hash] | ||
def to_hash | ||
data = super | ||
data[:check_in_id] = check_in_id | ||
data[:monitor_slug] = monitor_slug | ||
data[:status] = status | ||
data[:duration] = duration if duration | ||
data[:monitor_config] = monitor_config.to_hash if monitor_config | ||
data | ||
end | ||
end | ||
end |
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,53 @@ | ||
# frozen_string_literal | ||
|
||
require 'sentry/cron/monitor_schedule' | ||
|
||
module Sentry | ||
module Cron | ||
class MonitorConfig | ||
# The monitor schedule configuration | ||
# @return [MonitorSchedule::Crontab, MonitorSchedule::Interval] | ||
attr_accessor :schedule | ||
|
||
# How long (in minutes) after the expected checkin time will we wait | ||
# until we consider the checkin to have been missed. | ||
# @return [Integer, nil] | ||
attr_accessor :checkin_margin | ||
|
||
# How long (in minutes) is the checkin allowed to run for in in_progress | ||
# before it is considered failed. | ||
# @return [Integer, nil] | ||
attr_accessor :max_runtime | ||
|
||
# tz database style timezone string | ||
# @return [String, nil] | ||
attr_accessor :timezone | ||
|
||
def initialize(schedule, checkin_margin: nil, max_runtime: nil, timezone: nil) | ||
@schedule = schedule | ||
@checkin_margin = checkin_margin | ||
@max_runtime = max_runtime | ||
@timezone = timezone | ||
end | ||
|
||
def self.from_crontab(crontab, **options) | ||
new(MonitorSchedule::Crontab.new(crontab), **options) | ||
end | ||
|
||
def self.from_interval(num, unit, **options) | ||
return nil unless MonitorSchedule::Interval::VALID_UNITS.include?(unit) | ||
|
||
new(MonitorSchedule::Interval.new(num, unit), **options) | ||
end | ||
|
||
def to_hash | ||
{ | ||
schedule: schedule.to_hash, | ||
checkin_margin: checkin_margin, | ||
max_runtime: max_runtime, | ||
timezone: timezone | ||
}.compact | ||
end | ||
end | ||
end | ||
end |
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,42 @@ | ||
# frozen_string_literal | ||
|
||
module Sentry | ||
module Cron | ||
module MonitorSchedule | ||
class Crontab | ||
# A crontab formatted string such as "0 * * * *". | ||
# @return [String] | ||
attr_accessor :value | ||
|
||
def initialize(value) | ||
@value = value | ||
end | ||
|
||
def to_hash | ||
{ type: :crontab, value: value } | ||
end | ||
end | ||
|
||
class Interval | ||
# The number representing duration of the interval. | ||
# @return [Integer] | ||
attr_accessor :value | ||
|
||
# The unit representing duration of the interval. | ||
# @return [Symbol] | ||
attr_accessor :unit | ||
|
||
VALID_UNITS = %i(year month week day hour minute) | ||
|
||
def initialize(value, unit) | ||
@value = value | ||
@unit = unit | ||
end | ||
|
||
def to_hash | ||
{ type: :interval, value: value, unit: unit } | ||
end | ||
end | ||
end | ||
end | ||
end |
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
Oops, something went wrong.