Skip to content

Improve default slug generation for sidekiq-scheduler #2184

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
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

### Features

- Improve default slug generation for `sidekiq-scheduler` [#2184](https://github.com/getsentry/sentry-ruby/pull/2184)

### Bug Fixes

- Network errors raised in `Sentry::HTTPTransport` will no longer be reported to Sentry [#2178](https://github.com/getsentry/sentry-ruby/pull/2178)
Expand Down
2 changes: 1 addition & 1 deletion sentry-ruby/lib/sentry/cron/monitor_check_ins.rb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ def sentry_monitor_check_ins(slug: nil, monitor_config: nil)
prepend Patch
end

def sentry_monitor_slug
def sentry_monitor_slug(name: self.name)
@sentry_monitor_slug ||= begin
slug = name.gsub('::', '-').downcase
slug[-MAX_SLUG_LENGTH..-1] || slug
Expand Down
3 changes: 2 additions & 1 deletion sentry-sidekiq/lib/sentry/sidekiq-scheduler/scheduler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,9 @@ def new_job(name, interval_type, config, schedule, options)
# only patch if not explicitly included in job by user
unless klass_const.send(:ancestors).include?(Sentry::Cron::MonitorCheckIns)
klass_const.send(:include, Sentry::Cron::MonitorCheckIns)
slug = klass_const.send(:sentry_monitor_slug, name: name)
klass_const.send(:sentry_monitor_check_ins,
slug: name,
slug: slug,
monitor_config: monitor_config)

::Sidekiq.logger.info "Injected Sentry Crons monitor checkins into #{klass}"
Expand Down
2 changes: 2 additions & 0 deletions sentry-sidekiq/spec/fixtures/sidekiq-scheduler-schedule.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,6 @@
reports:
in: "2 hours"
class: "ReportingWorker"
VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job:
cron: "* * * * *"

10 changes: 7 additions & 3 deletions sentry-sidekiq/spec/sentry/sidekiq-scheduler/scheduler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,12 @@
expect(EveryHappyWorker.sentry_monitor_config.schedule.to_hash).to eq({value: 10, type: :interval, unit: :minute})
end

it "does not add monitors for a one-off job" do
expect(ReportingWorker.ancestors).not_to include(Sentry::Cron::MonitorCheckIns)
end
it 'truncates from the beginning and parameterizes slug' do
expect(VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job.ancestors).to include(Sentry::Cron::MonitorCheckIns)
expect(VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job.sentry_monitor_slug).to eq('ongoutermodule-veryveryveryverylonginnermodule-job')
expect(VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job.sentry_monitor_config).to be_a(Sentry::Cron::MonitorConfig)
expect(VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job.sentry_monitor_config.schedule).to be_a(Sentry::Cron::MonitorSchedule::Crontab)
expect(VeryLongOuterModule::VeryVeryVeryVeryLongInnerModule::Job.sentry_monitor_config.schedule.value).to eq('* * * * *')
end
end

7 changes: 7 additions & 0 deletions sentry-sidekiq/spec/spec_helper.rb
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,13 @@ def [](key)
end
end

module VeryLongOuterModule
module VeryVeryVeryVeryLongInnerModule
class Job
end
end
end

# Sidekiq 7 has a Config class, but for Sidekiq 6, we'll mock it.
def sidekiq_config(opts)
WITH_SIDEKIQ_7 ? ::Sidekiq::Config.new(opts) : SidekiqConfigMock.new(opts)
Expand Down