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
8 changes: 8 additions & 0 deletions sentry-ruby/lib/sentry/cron/configuration.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,14 @@ class Configuration
# @return [Integer, nil]
attr_accessor :default_max_runtime

# How many consecutive failed check-ins it takes to create an issue.
# @return [Integer, nil]
attr_accessor :default_failure_issue_threshold

# How many consecutive OK check-ins it takes to resolve an issue.
# @return [Integer, nil]
attr_accessor :default_recovery_threshold

# tz database style timezone string
# @return [String, nil]
attr_accessor :default_timezone
Expand Down
2 changes: 2 additions & 0 deletions sentry-ruby/lib/sentry/cron/monitor_check_ins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,8 @@ def sentry_monitor_check_ins(slug: nil, monitor_config: nil)
cron_config = Sentry.configuration.cron
monitor_config.checkin_margin ||= cron_config.default_checkin_margin
monitor_config.max_runtime ||= cron_config.default_max_runtime
monitor_config.failure_issue_threshold ||= cron_config.default_failure_issue_threshold
monitor_config.recovery_threshold ||= cron_config.default_recovery_threshold
monitor_config.timezone ||= cron_config.default_timezone
end

Expand Down
14 changes: 13 additions & 1 deletion sentry-ruby/lib/sentry/cron/monitor_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,24 @@ class MonitorConfig
# @return [Integer, nil]
attr_accessor :max_runtime

# How many consecutive failed check-ins it takes to create an issue.
# @return [Integer, nil]
attr_accessor :failure_issue_threshold

# How many consecutive OK check-ins it takes to resolve an issue.
# @return [Integer, nil]
attr_accessor :recovery_threshold

# tz database style timezone string
# @return [String, nil]
attr_accessor :timezone

def initialize(schedule, checkin_margin: nil, max_runtime: nil, timezone: nil)
def initialize(schedule, checkin_margin: nil, max_runtime: nil, failure_issue_threshold: nil, recovery_threshold: nil, timezone: nil)
@schedule = schedule
@checkin_margin = checkin_margin
@max_runtime = max_runtime
@failure_issue_threshold = failure_issue_threshold
@recovery_threshold = recovery_threshold
@timezone = timezone
end

Expand All @@ -45,6 +55,8 @@ def to_h
schedule: schedule.to_h,
checkin_margin: checkin_margin,
max_runtime: max_runtime,
failure_issue_threshold: failure_issue_threshold,
recovery_threshold: recovery_threshold,
timezone: timezone
}.compact
end
Expand Down
6 changes: 6 additions & 0 deletions sentry-ruby/spec/sentry/cron/monitor_check_ins_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -250,6 +250,8 @@ def perform(a, b = 42, c: 99)
perform_basic_setup do |config|
config.cron.default_checkin_margin = 10
config.cron.default_max_runtime = 20
config.cron.default_failure_issue_threshold = 3
config.cron.default_recovery_threshold = 5
config.cron.default_timezone = 'Europe/Vienna'
end

Expand Down Expand Up @@ -294,6 +296,8 @@ def perform(a, b = 42, c: 99)
expect(in_progress_event.status).to eq(:in_progress)
expect(in_progress_event.monitor_config.checkin_margin).to eq(10)
expect(in_progress_event.monitor_config.max_runtime).to eq(20)
expect(in_progress_event.monitor_config.failure_issue_threshold).to eq(3)
expect(in_progress_event.monitor_config.recovery_threshold).to eq(5)
expect(in_progress_event.monitor_config.timezone).to eq('Europe/Vienna')

ok_event = sentry_events.last
Expand All @@ -302,6 +306,8 @@ def perform(a, b = 42, c: 99)
expect(ok_event.status).to eq(:ok)
expect(ok_event.monitor_config.checkin_margin).to eq(10)
expect(ok_event.monitor_config.max_runtime).to eq(20)
expect(ok_event.monitor_config.failure_issue_threshold).to eq(3)
expect(ok_event.monitor_config.recovery_threshold).to eq(5)
expect(ok_event.monitor_config.timezone).to eq('Europe/Vienna')
end
end
Expand Down
23 changes: 23 additions & 0 deletions sentry-ruby/spec/sentry/cron/monitor_config_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,17 @@
'5 * * * *',
checkin_margin: 10,
max_runtime: 20,
failure_issue_threshold: 3,
recovery_threshold: 5,
timezone: 'Europe/Vienna'
)

expect(subject.schedule).to be_a(Sentry::Cron::MonitorSchedule::Crontab)
expect(subject.schedule.value).to eq('5 * * * *')
expect(subject.checkin_margin).to eq(10)
expect(subject.max_runtime).to eq(20)
expect(subject.failure_issue_threshold).to eq(3)
expect(subject.recovery_threshold).to eq(5)
expect(subject.timezone).to eq('Europe/Vienna')
end
end
Expand All @@ -31,6 +35,8 @@
:hour,
checkin_margin: 10,
max_runtime: 20,
failure_issue_threshold: 3,
recovery_threshold: 5,
timezone: 'Europe/Vienna'
)

Expand All @@ -39,6 +45,8 @@
expect(subject.schedule.unit).to eq(:hour)
expect(subject.checkin_margin).to eq(10)
expect(subject.max_runtime).to eq(20)
expect(subject.failure_issue_threshold).to eq(3)
expect(subject.recovery_threshold).to eq(5)
expect(subject.timezone).to eq('Europe/Vienna')
end
end
Expand All @@ -49,6 +57,8 @@
'5 * * * *',
checkin_margin: 10,
max_runtime: 20,
failure_issue_threshold: 3,
recovery_threshold: 5,
timezone: 'Europe/Vienna'
)

Expand All @@ -57,6 +67,8 @@
schedule: { type: :crontab, value: '5 * * * *' },
checkin_margin: 10,
max_runtime: 20,
failure_issue_threshold: 3,
recovery_threshold: 5,
timezone: 'Europe/Vienna'
})
end
Expand All @@ -67,6 +79,8 @@
:hour,
checkin_margin: 10,
max_runtime: 20,
failure_issue_threshold: 3,
recovery_threshold: 5,
timezone: 'Europe/Vienna'
)

Expand All @@ -75,8 +89,17 @@
schedule: { type: :interval, value: 5, unit: :hour },
checkin_margin: 10,
max_runtime: 20,
failure_issue_threshold: 3,
recovery_threshold: 5,
timezone: 'Europe/Vienna'
})
end

it 'omits nil attributes' do
subject = described_class.from_crontab('5 * * * *')

hash = subject.to_h
expect(hash).to eq({ schedule: { type: :crontab, value: '5 * * * *' } })
end
end
end