inst-jobs-statsd 1.2.2 → 1.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f299ba77daf29bef9b9a2f8f52710fd23029d3f122d723ec8c19518389ba10cf
4
- data.tar.gz: 38df7c0062ee2c19622e19e24377d853e05c55eb3d59253f470fb40668afb2c1
3
+ metadata.gz: a5903c772d523ffc042f3c178230cfb16973ca1d233c3b00c2e1c7b15ce05889
4
+ data.tar.gz: a6b313b2539a309361b8d40c0d30b9f7e4de617aa014abe6499503e7cbec147f
5
5
  SHA512:
6
- metadata.gz: f45e0aea9f8e01b3e592754fd596d03a1123d74958803f3b6250964adbaa132fe1d5467fad6a9ac330b68f9df0225e9a1851662a08f29834d769d5020c3b3c47
7
- data.tar.gz: a1376daa61d0e4db5911c707dc2524af23fabca7788ee626cbfa7d0ca06fd6f77003d7ea2cbda9acff13bd4c0283f52f89ba4b3d64d9608a4a921db2eff96811
6
+ metadata.gz: 02c42027da50b1ab69fdfc8a4045ce106efd6b9d1b17d6df122c443136fd4541f70e1632f79855db0e6e19a2b4bf1d09db7aa33747f27d99f2960d1ca57f0f52
7
+ data.tar.gz: 7a873df94b01d909e262ca4d53b6a632d77c606771da12cebb83e905e251f32c6627cce1da50c7a630ddbcc05372b24ff72432d6aeef804dd56ff867d24837b9
@@ -10,7 +10,6 @@ require_relative 'inst_jobs_statsd/naming'
10
10
 
11
11
  require_relative 'inst_jobs_statsd/stats/counters'
12
12
  require_relative 'inst_jobs_statsd/stats/counters/failed'
13
- require_relative 'inst_jobs_statsd/stats/counters/orphaned'
14
13
  require_relative 'inst_jobs_statsd/stats/counters/run'
15
14
 
16
15
  require_relative 'inst_jobs_statsd/stats/periodic'
@@ -7,8 +7,8 @@ module InstJobsStatsd
7
7
  end
8
8
 
9
9
  module ClassMethods
10
- def track_jobs
11
- @jobs_tracker ||= JobsTracker.new
10
+ def track_jobs(enable_periodic_queries: true)
11
+ @jobs_tracker ||= JobsTracker.new(enable_periodic_queries: enable_periodic_queries)
12
12
  end
13
13
  end
14
14
  end
@@ -1,21 +1,22 @@
1
1
  module InstJobsStatsd
2
2
  class JobsTracker
3
- def self.track
4
- @current_tracking = new
3
+ def self.track(enable_periodic_queries: true)
4
+ @current_tracking = new(enable_periodic_queries: enable_periodic_queries)
5
5
  yield
6
6
  tracking = @current_tracking
7
7
  @current_tracking = nil
8
8
  tracking
9
9
  end
10
10
 
11
- def initialize
11
+ def initialize(enable_periodic_queries: true)
12
12
  Stats::Counters::Failed.enable
13
- Stats::Counters::Orphaned.enable
14
13
  Stats::Counters::Run.enable
15
14
 
16
- Stats::Periodic::Failed.enable
17
- Stats::Periodic::Queue.enable
18
- Stats::Periodic::Run.enable
15
+ if enable_periodic_queries
16
+ Stats::Periodic::Failed.enable
17
+ Stats::Periodic::Queue.enable
18
+ Stats::Periodic::Run.enable
19
+ end
19
20
 
20
21
  Stats::Timing::Failed.enable
21
22
  Stats::Timing::Perform.enable
@@ -8,6 +8,10 @@ module InstJobsStatsd
8
8
  BASENAME
9
9
  end
10
10
 
11
+ def self.configure(strand_filter: nil)
12
+ @strand_filter = strand_filter
13
+ end
14
+
11
15
  def self.qualified_names(stat_name, job)
12
16
  names = ["#{basename}.#{stat_name}"]
13
17
  tagged = tagged_stat(names[0], job)
@@ -31,14 +35,23 @@ module InstJobsStatsd
31
35
  end
32
36
 
33
37
  def self.dd_job_tags(job)
34
- return {} unless job
35
- return {} unless job.tag
36
- return {} if job.tag =~ /Class:0x/
38
+ tags = dd_region_tags
39
+ return tags unless job
40
+ tags = custom_tags(job, tags)
41
+ return tags unless job.tag
42
+ return tags if job.tag =~ /Class:0x/
37
43
 
38
44
  method_tag, obj_tag = split_to_tag(job)
39
45
  tag = obj_tag
40
46
  tag = [obj_tag, method_tag].join('.') if method_tag.present?
41
- {tag: tag}
47
+ tags[:tag] = tag
48
+ tags
49
+ end
50
+
51
+ def self.custom_tags(job, tags)
52
+ tags[:jobshard] = job.shard.id if job.respond_to?(:shard)
53
+ tags[:strand] = job.strand if job&.strand && @strand_filter&.call(job)
54
+ tags
42
55
  end
43
56
 
44
57
  # this converts Foo#bar" or "Foo.bar" into "Foo and "bar",
@@ -67,6 +80,11 @@ module InstJobsStatsd
67
80
  end
68
81
  end
69
82
 
83
+ def self.dd_region_tags
84
+ return {} unless ENV['INST_JOBS_STATSD_NAMESPACE']
85
+ {namespace: ENV['INST_JOBS_STATSD_NAMESPACE']}
86
+ end
87
+
70
88
  private
71
89
 
72
90
  def self.split_to_tag(job)
@@ -1,3 +1,3 @@
1
1
  module InstJobsStatsd
2
- VERSION = '1.2.2'.freeze
2
+ VERSION = '1.4.1'.freeze
3
3
  end
@@ -1,6 +1,6 @@
1
1
  FactoryGirl.define do
2
2
  class JobFixture
3
- attr_accessor :tag, :run_at
3
+ attr_accessor :tag, :run_at, :strand
4
4
  end
5
5
 
6
6
  factory :job_fixture, aliases: [:job] do
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec :path=>"../../"
4
4
 
5
- gem "rails", "~> 4.2.5"
6
- gem "after_transaction_commit", "<2"
7
- gem 'test_after_commit', '0.4.1'
5
+ gem "rails", "~> 4.2.11"
6
+ gem "pg", "~> 0.21.0"
7
+ gem "after_transaction_commit", "< 2"
8
+ gem "test_after_commit", "1.1.0"
@@ -2,6 +2,7 @@ source "https://rubygems.org"
2
2
 
3
3
  gemspec :path=>"../../"
4
4
 
5
- gem "rails", "~> 5.1.0"
6
- gem 'sinatra', "2.0.0.beta2"
7
- gem 'sinatra-contrib', "2.0.0.beta2"
5
+ gem "rails", "~> 5.1.7"
6
+ gem "sinatra", "~> 2.0.8"
7
+ gem "sinatra-contrib", "~> 2.0.8"
8
+ gem "sprockets", "~> 3.7" # 4.0+ requires Ruby 2.5
@@ -0,0 +1,7 @@
1
+ source "https://rubygems.org"
2
+
3
+ gemspec :path=>"../../"
4
+
5
+ gem "rails", "~> 6.0"
6
+ gem "sinatra", "~> 2.0.8"
7
+ gem "sinatra-contrib", "~> 2.0.8"
@@ -13,7 +13,6 @@ RSpec.describe InstJobsStatsd::JobsTracker do
13
13
  describe '.initialize' do
14
14
  it 'enables everything' do
15
15
  expect(InstJobsStatsd::Stats::Counters::Failed).to receive(:enable)
16
- expect(InstJobsStatsd::Stats::Counters::Orphaned).to receive(:enable)
17
16
  expect(InstJobsStatsd::Stats::Counters::Run).to receive(:enable)
18
17
 
19
18
  expect(InstJobsStatsd::Stats::Periodic::Failed).to receive(:enable)
@@ -40,5 +40,17 @@ RSpec.describe InstJobsStatsd::Naming do
40
40
  it { should include 'delayedjob.wut.region_name' }
41
41
  it { should include 'delayedjob.wut.region_name.tag.a_tag_name' }
42
42
  end
43
+
44
+ describe '.dd_job_tags' do
45
+ it 'works' do
46
+ job = double(tag: 'Account.run_reports_later', shard: double(id: 101), strand: 'special')
47
+ expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq({ tag: 'Account.run_reports_later', jobshard: 101})
48
+ end
49
+
50
+ it 'properly munges job tags' do
51
+ job = double(tag: 'Quizzes::Quiz#do_something', strand: nil)
52
+ expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq({ tag: 'Quizzes-Quiz.do_something'})
53
+ end
54
+ end
43
55
  end
44
56
  end
@@ -35,7 +35,15 @@ ActiveRecord::Base.establish_connection(connection_config)
35
35
 
36
36
  # Apply the migrations from the inst-jobs gem
37
37
  inst_jobs_spec = Gem::Specification.find_by_name('inst-jobs')
38
- ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/db/migrate')
39
- ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/spec/migrate')
38
+ if ::Rails.version >= '6'
39
+ sm = ActiveRecord::Base.connection.schema_migration
40
+ migrations = ActiveRecord::MigrationContext.new(inst_jobs_spec.gem_dir + '/db/migrate', sm).migrations
41
+ ActiveRecord::Migrator.new(:up, migrations, sm).migrate
42
+ migrations = ActiveRecord::MigrationContext.new(inst_jobs_spec.gem_dir + '/spec/migrate', sm).migrations
43
+ ActiveRecord::Migrator.new(:up, migrations, sm).migrate
44
+ else
45
+ ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/db/migrate')
46
+ ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/spec/migrate')
47
+ end
40
48
  Delayed::Backend::ActiveRecord::Job.reset_column_information
41
49
  Delayed::Backend::ActiveRecord::Job::Failed.reset_column_information
@@ -1,4 +1,4 @@
1
- if /^2\.4/ =~ RUBY_VERSION && /50\./ =~ ENV['BUNDLE_GEMFILE'] # Limit coverage to one build
1
+ if /^2\.5/ =~ RUBY_VERSION && /51\./ =~ ENV['BUNDLE_GEMFILE'] # Limit coverage to one build
2
2
  require 'simplecov'
3
3
 
4
4
  SimpleCov.start do
@@ -6,8 +6,6 @@ if /^2\.4/ =~ RUBY_VERSION && /50\./ =~ ENV['BUNDLE_GEMFILE'] # Limit coverage t
6
6
  add_filter 'spec'
7
7
  track_files 'lib/**/*.rb'
8
8
  end
9
-
10
- SimpleCov.minimum_coverage(100)
11
9
  end
12
10
 
13
11
  require 'inst-jobs-statsd'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: inst-jobs-statsd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Slade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-25 00:00:00.000000000 Z
11
+ date: 2020-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs
@@ -16,20 +16,20 @@ dependencies:
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '0.13'
19
+ version: '0.15'
20
20
  - - "<"
21
21
  - !ruby/object:Gem::Version
22
- version: '0.16'
22
+ version: '0.17'
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
28
28
  - !ruby/object:Gem::Version
29
- version: '0.13'
29
+ version: '0.15'
30
30
  - - "<"
31
31
  - !ruby/object:Gem::Version
32
- version: '0.16'
32
+ version: '0.17'
33
33
  - !ruby/object:Gem::Dependency
34
34
  name: inst_statsd
35
35
  requirement: !ruby/object:Gem::Requirement
@@ -96,16 +96,16 @@ dependencies:
96
96
  name: database_cleaner
97
97
  requirement: !ruby/object:Gem::Requirement
98
98
  requirements:
99
- - - '='
99
+ - - "~>"
100
100
  - !ruby/object:Gem::Version
101
- version: 1.6.1
101
+ version: '1.7'
102
102
  type: :development
103
103
  prerelease: false
104
104
  version_requirements: !ruby/object:Gem::Requirement
105
105
  requirements:
106
- - - '='
106
+ - - "~>"
107
107
  - !ruby/object:Gem::Version
108
- version: 1.6.1
108
+ version: '1.7'
109
109
  - !ruby/object:Gem::Dependency
110
110
  name: factory_girl
111
111
  requirement: !ruby/object:Gem::Requirement
@@ -124,16 +124,16 @@ dependencies:
124
124
  name: pg
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - '='
127
+ - - "~>"
128
128
  - !ruby/object:Gem::Version
129
- version: 0.21.0
129
+ version: '1.2'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - '='
134
+ - - "~>"
135
135
  - !ruby/object:Gem::Version
136
- version: 0.21.0
136
+ version: '1.2'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: pry
139
139
  requirement: !ruby/object:Gem::Requirement
@@ -166,44 +166,44 @@ dependencies:
166
166
  name: rspec
167
167
  requirement: !ruby/object:Gem::Requirement
168
168
  requirements:
169
- - - '='
169
+ - - "~>"
170
170
  - !ruby/object:Gem::Version
171
- version: 3.4.0
171
+ version: '3.9'
172
172
  type: :development
173
173
  prerelease: false
174
174
  version_requirements: !ruby/object:Gem::Requirement
175
175
  requirements:
176
- - - '='
176
+ - - "~>"
177
177
  - !ruby/object:Gem::Version
178
- version: 3.4.0
178
+ version: '3.9'
179
179
  - !ruby/object:Gem::Dependency
180
180
  name: rubocop
181
181
  requirement: !ruby/object:Gem::Requirement
182
182
  requirements:
183
183
  - - "~>"
184
184
  - !ruby/object:Gem::Version
185
- version: '0'
185
+ version: 0.48.0
186
186
  type: :development
187
187
  prerelease: false
188
188
  version_requirements: !ruby/object:Gem::Requirement
189
189
  requirements:
190
190
  - - "~>"
191
191
  - !ruby/object:Gem::Version
192
- version: '0'
192
+ version: 0.48.0
193
193
  - !ruby/object:Gem::Dependency
194
194
  name: simplecov
195
195
  requirement: !ruby/object:Gem::Requirement
196
196
  requirements:
197
197
  - - "~>"
198
198
  - !ruby/object:Gem::Version
199
- version: '0.14'
199
+ version: '0.17'
200
200
  type: :development
201
201
  prerelease: false
202
202
  version_requirements: !ruby/object:Gem::Requirement
203
203
  requirements:
204
204
  - - "~>"
205
205
  - !ruby/object:Gem::Version
206
- version: '0.14'
206
+ version: '0.17'
207
207
  - !ruby/object:Gem::Dependency
208
208
  name: timecop
209
209
  requirement: !ruby/object:Gem::Requirement
@@ -224,14 +224,14 @@ dependencies:
224
224
  requirements:
225
225
  - - "~>"
226
226
  - !ruby/object:Gem::Version
227
- version: 1.3.0
227
+ version: 1.4.0
228
228
  type: :development
229
229
  prerelease: false
230
230
  version_requirements: !ruby/object:Gem::Requirement
231
231
  requirements:
232
232
  - - "~>"
233
233
  - !ruby/object:Gem::Version
234
- version: 1.3.0
234
+ version: 1.4.0
235
235
  description:
236
236
  email:
237
237
  - jslade@instructure.com
@@ -245,7 +245,6 @@ files:
245
245
  - lib/inst_jobs_statsd/naming.rb
246
246
  - lib/inst_jobs_statsd/stats/counters.rb
247
247
  - lib/inst_jobs_statsd/stats/counters/failed.rb
248
- - lib/inst_jobs_statsd/stats/counters/orphaned.rb
249
248
  - lib/inst_jobs_statsd/stats/counters/run.rb
250
249
  - lib/inst_jobs_statsd/stats/periodic.rb
251
250
  - lib/inst_jobs_statsd/stats/periodic/failed.rb
@@ -259,12 +258,11 @@ files:
259
258
  - spec/factories/jobs.rb
260
259
  - spec/factories/workers.rb
261
260
  - spec/gemfiles/42.gemfile
262
- - spec/gemfiles/50.gemfile
263
261
  - spec/gemfiles/51.gemfile
262
+ - spec/gemfiles/60.gemfile
264
263
  - spec/inst_jobs_statsd/jobs_tracker_spec.rb
265
264
  - spec/inst_jobs_statsd/naming_spec.rb
266
265
  - spec/inst_jobs_statsd/stats/counters/failed_spec.rb
267
- - spec/inst_jobs_statsd/stats/counters/orphaned_spec.rb
268
266
  - spec/inst_jobs_statsd/stats/counters/run_spec.rb
269
267
  - spec/inst_jobs_statsd/stats/periodic/failed_spec.rb
270
268
  - spec/inst_jobs_statsd/stats/periodic/queue_spec.rb
@@ -290,15 +288,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
290
288
  requirements:
291
289
  - - ">="
292
290
  - !ruby/object:Gem::Version
293
- version: '2.3'
291
+ version: '2.4'
294
292
  required_rubygems_version: !ruby/object:Gem::Requirement
295
293
  requirements:
296
294
  - - ">="
297
295
  - !ruby/object:Gem::Version
298
296
  version: '0'
299
297
  requirements: []
300
- rubyforge_project:
301
- rubygems_version: 2.7.6
298
+ rubygems_version: 3.0.3
302
299
  signing_key:
303
300
  specification_version: 4
304
301
  summary: Stats reporting for inst-jobs
@@ -313,14 +310,13 @@ test_files:
313
310
  - spec/inst_jobs_statsd/stats/periodic_spec.rb
314
311
  - spec/inst_jobs_statsd/stats/counters/failed_spec.rb
315
312
  - spec/inst_jobs_statsd/stats/counters/run_spec.rb
316
- - spec/inst_jobs_statsd/stats/counters/orphaned_spec.rb
317
313
  - spec/inst_jobs_statsd/stats/timing_spec.rb
318
314
  - spec/inst_jobs_statsd/jobs_tracker_spec.rb
319
315
  - spec/spec_helper.rb
320
316
  - spec/setup_test_db.rb
321
317
  - spec/matchers.rb
318
+ - spec/gemfiles/60.gemfile
322
319
  - spec/gemfiles/42.gemfile
323
- - spec/gemfiles/50.gemfile
324
320
  - spec/gemfiles/51.gemfile
325
321
  - spec/factories/workers.rb
326
322
  - spec/factories/jobs.rb
@@ -1,34 +0,0 @@
1
- module InstJobsStatsd
2
- module Stats
3
- module Counters
4
- module Orphaned
5
- def self.enable
6
- enable_orphaned_count
7
- end
8
-
9
- # The idea of the orphaned count: when a job finishes, if there
10
- # are other jobs locked_by the *same* worker, they must have been
11
- # orphaned, because they are not going to be picked up and run by
12
- # the worker -- the work queue is designed to only have one job
13
- # locked_by a worker at a time.
14
- # This is based on the symptom seen in AMS-447, where mutliple
15
- # rows of the jobs table can be (incorrectly) updated by the same
16
- # query.
17
- def self.enable_orphaned_count
18
- Delayed::Worker.lifecycle.before(:perform) do |_worker, job|
19
- report_orphaned_count(job)
20
- end
21
- end
22
-
23
- def self.report_orphaned_count(job)
24
- scope = Delayed::Job.where(
25
- 'locked_by = ? AND locked_at = ? AND id <> ?',
26
- job.locked_by, job.locked_at, job.id
27
- )
28
- count = scope.count
29
- Counters.report_count(:orphaned, count, job: job) unless count.zero?
30
- end
31
- end
32
- end
33
- end
34
- end
@@ -1,7 +0,0 @@
1
- source "https://rubygems.org"
2
-
3
- gemspec :path=>"../../"
4
-
5
- gem "rails", "~> 5.0.0"
6
- gem 'sinatra', "2.0.0.beta2"
7
- gem 'sinatra-contrib', "2.0.0.beta2"
@@ -1,27 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Counters::Orphaned do
2
- describe '.enable' do
3
- it 'enables all the things' do
4
- expect(InstJobsStatsd::Stats::Counters::Orphaned).to receive(:enable_orphaned_count)
5
- InstJobsStatsd::Stats::Counters::Orphaned.enable
6
- end
7
- end
8
-
9
- describe '.report_orphaned_count' do
10
- let(:x) { Struct.new(:perform).new(true) }
11
-
12
- before do
13
- Delayed::Worker.lifecycle.reset!
14
- InstJobsStatsd::Stats::Counters::Orphaned.enable
15
-
16
- 4.times { x.send_later(:perform) }
17
- Delayed::Job.order(:id).limit(3)
18
- .update_all(locked_by: 'test', locked_at: Delayed::Job.db_time_now)
19
- end
20
-
21
- it do
22
- expect(InstStatsd::Statsd).to receive(:count)
23
- .with(array_including(/\.orphaned$/), 2, 1, { short_stat: anything, tags: {} })
24
- Delayed::Worker.lifecycle.run_callbacks(:perform, nil, Delayed::Job.first) {}
25
- end
26
- end
27
- end