inst-jobs-statsd 3.0.0 → 3.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (41) hide show
  1. checksums.yaml +4 -4
  2. data/lib/inst-jobs-statsd.rb +22 -20
  3. data/lib/inst_jobs_statsd/default_tracking.rb +3 -1
  4. data/lib/inst_jobs_statsd/ext/job.rb +2 -0
  5. data/lib/inst_jobs_statsd/jobs_tracker.rb +2 -0
  6. data/lib/inst_jobs_statsd/naming.rb +21 -14
  7. data/lib/inst_jobs_statsd/stats/counters/complete.rb +2 -0
  8. data/lib/inst_jobs_statsd/stats/counters/create.rb +2 -0
  9. data/lib/inst_jobs_statsd/stats/counters/run.rb +2 -0
  10. data/lib/inst_jobs_statsd/stats/counters.rb +2 -0
  11. data/lib/inst_jobs_statsd/stats/periodic/failed.rb +2 -0
  12. data/lib/inst_jobs_statsd/stats/periodic/queue.rb +3 -1
  13. data/lib/inst_jobs_statsd/stats/periodic/run.rb +3 -1
  14. data/lib/inst_jobs_statsd/stats/periodic.rb +6 -2
  15. data/lib/inst_jobs_statsd/stats/timing/failed.rb +2 -0
  16. data/lib/inst_jobs_statsd/stats/timing/perform.rb +2 -0
  17. data/lib/inst_jobs_statsd/stats/timing/pop.rb +2 -0
  18. data/lib/inst_jobs_statsd/stats/timing.rb +7 -3
  19. data/lib/inst_jobs_statsd/version.rb +3 -1
  20. metadata +73 -72
  21. data/spec/factories/jobs.rb +0 -9
  22. data/spec/factories/workers.rb +0 -9
  23. data/spec/gemfiles/60.gemfile +0 -7
  24. data/spec/inst_jobs_statsd/ext/job_spec.rb +0 -17
  25. data/spec/inst_jobs_statsd/jobs_tracker_spec.rb +0 -30
  26. data/spec/inst_jobs_statsd/naming_spec.rb +0 -56
  27. data/spec/inst_jobs_statsd/stats/counters/complete_spec.rb +0 -27
  28. data/spec/inst_jobs_statsd/stats/counters/create_spec.rb +0 -27
  29. data/spec/inst_jobs_statsd/stats/counters/run_spec.rb +0 -27
  30. data/spec/inst_jobs_statsd/stats/periodic/failed_spec.rb +0 -31
  31. data/spec/inst_jobs_statsd/stats/periodic/queue_spec.rb +0 -95
  32. data/spec/inst_jobs_statsd/stats/periodic/run_spec.rb +0 -53
  33. data/spec/inst_jobs_statsd/stats/periodic_spec.rb +0 -63
  34. data/spec/inst_jobs_statsd/stats/timing/failed_spec.rb +0 -25
  35. data/spec/inst_jobs_statsd/stats/timing/perform_spec.rb +0 -35
  36. data/spec/inst_jobs_statsd/stats/timing/pop_spec.rb +0 -34
  37. data/spec/inst_jobs_statsd/stats/timing_spec.rb +0 -35
  38. data/spec/inst_statsd/default_tracking_spec.rb +0 -16
  39. data/spec/matchers.rb +0 -3
  40. data/spec/setup_test_db.rb +0 -45
  41. data/spec/spec_helper.rb +0 -61
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: efc6027a4283d4fbe37e336710c974dfd2ddd1ab273613fbd9936fb0cfca37e5
4
- data.tar.gz: eef10d80500c432b596436e28422c5b1243c1ec48de44fd73ec1a208ccc58734
3
+ metadata.gz: d5760a670863e6b529a17f1443c45b360ed9762b35ad9fe432a4bd66c5b3e90d
4
+ data.tar.gz: 0efe20cd91f2dcb8cb55b5f4df13c372aa2f1b60ff2401c5379a453ed16e1bae
5
5
  SHA512:
6
- metadata.gz: c4c9cad4da6c5d3897239e390445c852230655cb47fc5d5ca97c045d8d6923e1b33a8a6b7f8c8a66dda12e2636a204b4df6b8b1ca3f5912ece8a8ec991e7470f
7
- data.tar.gz: f94e0bf3044911fbfc165f2320a2a08bbd744746e98771c3aded317e210ab2884294bf093b31ff386d2c7d0a22751d2dd48085b7e5785fe15a2191df2621cd65
6
+ metadata.gz: 1a35e512b5a4b8a1e87205fa97a03922d70b95298635dda6d5778e9bcd110bb02b74dfd36791a963ca169dddbaafcac448c2e33beb1d640b27955f793138d990
7
+ data.tar.gz: bd8808fa5e79266049f4cc9852df42c8bea046fc19d96c0402831df006e1c2a982a8d0475f12ac603bc0b0baf7224585546f78b79b3a650611f06d67cc1fe283
@@ -1,27 +1,29 @@
1
- require 'inst-jobs'
2
- require 'inst_statsd'
1
+ # frozen_string_literal: true
3
2
 
4
- require_relative 'inst_jobs_statsd/version'
3
+ require "inst-jobs"
4
+ require "inst_statsd"
5
5
 
6
- require_relative 'inst_jobs_statsd/default_tracking'
7
- require_relative 'inst_jobs_statsd/jobs_tracker'
6
+ require_relative "inst_jobs_statsd/version"
8
7
 
9
- require_relative 'inst_jobs_statsd/naming'
8
+ require_relative "inst_jobs_statsd/default_tracking"
9
+ require_relative "inst_jobs_statsd/jobs_tracker"
10
10
 
11
- require_relative 'inst_jobs_statsd/stats/counters'
12
- require_relative 'inst_jobs_statsd/stats/counters/create'
13
- require_relative 'inst_jobs_statsd/stats/counters/run'
14
- require_relative 'inst_jobs_statsd/stats/counters/complete'
11
+ require_relative "inst_jobs_statsd/naming"
15
12
 
16
- require_relative 'inst_jobs_statsd/stats/periodic'
17
- require_relative 'inst_jobs_statsd/stats/periodic/failed'
18
- require_relative 'inst_jobs_statsd/stats/periodic/queue'
19
- require_relative 'inst_jobs_statsd/stats/periodic/run'
13
+ require_relative "inst_jobs_statsd/stats/counters"
14
+ require_relative "inst_jobs_statsd/stats/counters/create"
15
+ require_relative "inst_jobs_statsd/stats/counters/run"
16
+ require_relative "inst_jobs_statsd/stats/counters/complete"
20
17
 
21
- require_relative 'inst_jobs_statsd/stats/timing'
22
- require_relative 'inst_jobs_statsd/stats/timing/failed'
23
- require_relative 'inst_jobs_statsd/stats/timing/perform'
24
- require_relative 'inst_jobs_statsd/stats/timing/pop'
25
- require_relative 'inst_jobs_statsd/ext/job'
18
+ require_relative "inst_jobs_statsd/stats/periodic"
19
+ require_relative "inst_jobs_statsd/stats/periodic/failed"
20
+ require_relative "inst_jobs_statsd/stats/periodic/queue"
21
+ require_relative "inst_jobs_statsd/stats/periodic/run"
26
22
 
27
- ::InstStatsd::DefaultTracking.include InstJobsStatsd::DefaultTracking
23
+ require_relative "inst_jobs_statsd/stats/timing"
24
+ require_relative "inst_jobs_statsd/stats/timing/failed"
25
+ require_relative "inst_jobs_statsd/stats/timing/perform"
26
+ require_relative "inst_jobs_statsd/stats/timing/pop"
27
+ require_relative "inst_jobs_statsd/ext/job"
28
+
29
+ InstStatsd::DefaultTracking.include InstJobsStatsd::DefaultTracking
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # Defines InstStatsd::DefaultTracking.track_jobs
2
4
  # to be consistent with InstStatsd::DefaultTracking.track_sql etc
3
5
  module InstJobsStatsd
@@ -8,7 +10,7 @@ module InstJobsStatsd
8
10
 
9
11
  module ClassMethods
10
12
  def track_jobs(enable_periodic_queries: true)
11
- @jobs_tracker ||= JobsTracker.new(enable_periodic_queries: enable_periodic_queries)
13
+ @jobs_tracker ||= JobsTracker.new(enable_periodic_queries: enable_periodic_queries) # rubocop:disable Naming/MemoizedInstanceVariableName
12
14
  end
13
15
  end
14
16
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Ext
3
5
  module Job
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  class JobsTracker
3
5
  def self.track(enable_periodic_queries: true)
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Naming
3
- BASENAME = 'delayedjob'.freeze
5
+ BASENAME = "delayedjob"
4
6
 
5
7
  # The root prefix for all stat names
6
8
  # TODO: Make this configurable
@@ -32,12 +34,18 @@ module InstJobsStatsd
32
34
 
33
35
  def self.dd_job_tags(job)
34
36
  tags = dd_region_tags
35
- return tags unless job&.tag
36
- return tags if job.tag =~ /Class:0x/
37
+ return tags unless job
38
+
39
+ tags[:cluster] = job.current_shard&.database_server&.id if job.respond_to?(:current_shard)
40
+ tags[:priority] = job.priority
41
+ tags.compact!
42
+
43
+ return tags unless job.tag
44
+ return tags if job.tag.include?("Class:0x")
37
45
 
38
46
  method_tag, obj_tag = split_to_tag(job)
39
47
  tag = obj_tag
40
- tag = [obj_tag, method_tag].join('.') if method_tag.present?
48
+ tag = [obj_tag, method_tag].join(".") if method_tag.present?
41
49
  tags[:tag] = tag
42
50
  tags
43
51
  end
@@ -47,7 +55,7 @@ module InstJobsStatsd
47
55
  def self.job_tags(job)
48
56
  return unless job
49
57
  return unless job.tag
50
- return if job.tag =~ /Class:0x/
58
+ return if job.tag.include?("Class:0x")
51
59
 
52
60
  method_tag, obj_tag = split_to_tag(job)
53
61
  tags = [obj_tag]
@@ -58,26 +66,25 @@ module InstJobsStatsd
58
66
  # We are using all existing stat names here because we do not want
59
67
  # to break existing dependencies on the non-regioned data
60
68
  def self.region_tags(stat_names)
61
- return unless ENV['INST_JOBS_STATSD_NAMESPACE']
69
+ return unless ENV["INST_JOBS_STATSD_NAMESPACE"]
62
70
 
63
71
  stat_names.map do |name|
64
72
  name
65
- .split('.')
66
- .insert(2, ENV['INST_JOBS_STATSD_NAMESPACE'])
67
- .join('.')
73
+ .split(".")
74
+ .insert(2, ENV["INST_JOBS_STATSD_NAMESPACE"])
75
+ .join(".")
68
76
  end
69
77
  end
70
78
 
71
79
  def self.dd_region_tags
72
- return {} unless ENV['INST_JOBS_STATSD_NAMESPACE']
73
- { namespace: ENV['INST_JOBS_STATSD_NAMESPACE'] }
74
- end
80
+ return {} unless ENV["INST_JOBS_STATSD_NAMESPACE"]
75
81
 
76
- private
82
+ { namespace: ENV["INST_JOBS_STATSD_NAMESPACE"] }
83
+ end
77
84
 
78
85
  def self.split_to_tag(job)
79
86
  obj_tag, method_tag = job.tag.split(/[\.#]/, 2).map do |v|
80
- InstStatsd::Statsd.escape(v).gsub('::', '-')
87
+ InstStatsd::Statsd.escape(v).gsub("::", "-")
81
88
  end
82
89
  [method_tag, obj_tag]
83
90
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Counters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Counters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Counters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Counters
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Periodic
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Periodic
@@ -35,7 +37,7 @@ module InstJobsStatsd
35
37
  jobs_run_at = queued_jobs_scope.limit(10_000).pluck(:run_at)
36
38
  age_secs = jobs_run_at.map { |t| Delayed::Job.db_time_now - t }
37
39
  Periodic.report_gauge(:queue_age_total, age_secs.sum)
38
- Periodic.report_gauge(:queue_age_max, age_secs.max)
40
+ Periodic.report_gauge(:queue_age_max, age_secs.max || 0)
39
41
  end
40
42
 
41
43
  def self.queued_jobs_scope
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Periodic
@@ -26,7 +28,7 @@ module InstJobsStatsd
26
28
  jobs_run_at = running_jobs_scope.limit(10_000).pluck(:run_at)
27
29
  age_secs = jobs_run_at.map { |t| Delayed::Job.db_time_now - t }
28
30
  Periodic.report_gauge(:run_age_total, age_secs.sum)
29
- Periodic.report_gauge(:run_age_max, age_secs.max)
31
+ Periodic.report_gauge(:run_age_max, age_secs.max || 0)
30
32
  end
31
33
 
32
34
  def self.running_jobs_scope
@@ -1,12 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Periodic
4
6
  def self.enable_callbacks
5
- @instance ||= Callbacks.new
7
+ @instance ||= Callbacks.new # rubocop:disable Naming/MemoizedInstanceVariableName
6
8
  end
7
9
 
8
10
  def self.add(proc)
9
11
  return unless @instance
12
+
10
13
  @instance.add(proc)
11
14
  end
12
15
 
@@ -72,6 +75,7 @@ module InstJobsStatsd
72
75
  # When the required interval of time has passed, execute the given block
73
76
  def tick
74
77
  return unless Delayed::Job.db_time_now >= @next_run
78
+
75
79
  update_next_run
76
80
  yield
77
81
  end
@@ -83,7 +87,7 @@ module InstJobsStatsd
83
87
  # from the target interval as much as possible
84
88
  def update_next_run
85
89
  ticks = ((Delayed::Job.db_time_now - @start_time) / @min_interval).floor
86
- @next_run = @start_time + (ticks + 1) * @min_interval
90
+ @next_run = @start_time + ((ticks + 1) * @min_interval)
87
91
  end
88
92
  end
89
93
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Timing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Timing
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Timing
@@ -1,11 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
4
  module Stats
3
5
  module Timing
4
- def self.report_timing(stat, job: nil, timing: nil, sample_rate: 1)
6
+ def self.report_timing(stat, job: nil, timing: nil, sample_rate: 1, &block)
5
7
  stats = Naming.qualified_names(stat, job)
6
8
 
7
- if block_given?
8
- InstStatsd::Statsd.time(stats, sample_rate, short_stat: stat, tags: Naming.dd_job_tags(job)) { yield }
9
+ if block
10
+ InstStatsd::Statsd.time(stats, sample_rate, short_stat: stat, tags: Naming.dd_job_tags(job), &block)
9
11
  else
10
12
  InstStatsd::Statsd.timing(stats, timing, sample_rate, short_stat: stat, tags: Naming.dd_job_tags(job))
11
13
  end
@@ -13,12 +15,14 @@ module InstJobsStatsd
13
15
 
14
16
  def self.report_job_timing_queued(job)
15
17
  return unless job
18
+
16
19
  time_in_queue = ((Delayed::Job.db_time_now - job.run_at) * 1000).round
17
20
  report_timing(:queue, job: job, timing: time_in_queue)
18
21
  end
19
22
 
20
23
  def self.report_job_timing_failed(job)
21
24
  return unless job
25
+
22
26
  time_to_failure = ((Delayed::Job.db_time_now - job.run_at) * 1000).round
23
27
  report_timing(:failed_after, job: job, timing: time_to_failure)
24
28
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module InstJobsStatsd
2
- VERSION = '3.0.0'.freeze
4
+ VERSION = "3.0.2"
3
5
  end
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: 3.0.0
4
+ version: 3.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeremy Slade
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-07-14 00:00:00.000000000 Z
11
+ date: 2023-10-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inst-jobs
@@ -45,7 +45,7 @@ dependencies:
45
45
  - !ruby/object:Gem::Version
46
46
  version: '3.0'
47
47
  - !ruby/object:Gem::Dependency
48
- name: bump
48
+ name: bundler
49
49
  requirement: !ruby/object:Gem::Requirement
50
50
  requirements:
51
51
  - - ">="
@@ -59,21 +59,21 @@ dependencies:
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
61
  - !ruby/object:Gem::Dependency
62
- name: bundler
62
+ name: database_cleaner
63
63
  requirement: !ruby/object:Gem::Requirement
64
64
  requirements:
65
- - - ">="
65
+ - - "~>"
66
66
  - !ruby/object:Gem::Version
67
- version: '0'
67
+ version: '2.0'
68
68
  type: :development
69
69
  prerelease: false
70
70
  version_requirements: !ruby/object:Gem::Requirement
71
71
  requirements:
72
- - - ">="
72
+ - - "~>"
73
73
  - !ruby/object:Gem::Version
74
- version: '0'
74
+ version: '2.0'
75
75
  - !ruby/object:Gem::Dependency
76
- name: byebug
76
+ name: debug
77
77
  requirement: !ruby/object:Gem::Requirement
78
78
  requirements:
79
79
  - - ">="
@@ -87,21 +87,7 @@ dependencies:
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  - !ruby/object:Gem::Dependency
90
- name: database_cleaner
91
- requirement: !ruby/object:Gem::Requirement
92
- requirements:
93
- - - "~>"
94
- - !ruby/object:Gem::Version
95
- version: '1.7'
96
- type: :development
97
- prerelease: false
98
- version_requirements: !ruby/object:Gem::Requirement
99
- requirements:
100
- - - "~>"
101
- - !ruby/object:Gem::Version
102
- version: '1.7'
103
- - !ruby/object:Gem::Dependency
104
- name: factory_girl
90
+ name: factory_bot
105
91
  requirement: !ruby/object:Gem::Requirement
106
92
  requirements:
107
93
  - - ">="
@@ -171,19 +157,75 @@ dependencies:
171
157
  - !ruby/object:Gem::Version
172
158
  version: '3.9'
173
159
  - !ruby/object:Gem::Dependency
174
- name: rubocop
160
+ name: rubocop-factory_bot
161
+ requirement: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - "~>"
164
+ - !ruby/object:Gem::Version
165
+ version: '2.24'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ requirements:
170
+ - - "~>"
171
+ - !ruby/object:Gem::Version
172
+ version: '2.24'
173
+ - !ruby/object:Gem::Dependency
174
+ name: rubocop-inst
175
+ requirement: !ruby/object:Gem::Requirement
176
+ requirements:
177
+ - - "~>"
178
+ - !ruby/object:Gem::Version
179
+ version: '1.0'
180
+ type: :development
181
+ prerelease: false
182
+ version_requirements: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - "~>"
185
+ - !ruby/object:Gem::Version
186
+ version: '1.0'
187
+ - !ruby/object:Gem::Dependency
188
+ name: rubocop-rails
189
+ requirement: !ruby/object:Gem::Requirement
190
+ requirements:
191
+ - - "~>"
192
+ - !ruby/object:Gem::Version
193
+ version: '2.21'
194
+ type: :development
195
+ prerelease: false
196
+ version_requirements: !ruby/object:Gem::Requirement
197
+ requirements:
198
+ - - "~>"
199
+ - !ruby/object:Gem::Version
200
+ version: '2.21'
201
+ - !ruby/object:Gem::Dependency
202
+ name: rubocop-rake
203
+ requirement: !ruby/object:Gem::Requirement
204
+ requirements:
205
+ - - "~>"
206
+ - !ruby/object:Gem::Version
207
+ version: '0.6'
208
+ type: :development
209
+ prerelease: false
210
+ version_requirements: !ruby/object:Gem::Requirement
211
+ requirements:
212
+ - - "~>"
213
+ - !ruby/object:Gem::Version
214
+ version: '0.6'
215
+ - !ruby/object:Gem::Dependency
216
+ name: rubocop-rspec
175
217
  requirement: !ruby/object:Gem::Requirement
176
218
  requirements:
177
219
  - - "~>"
178
220
  - !ruby/object:Gem::Version
179
- version: 0.48.0
221
+ version: '2.24'
180
222
  type: :development
181
223
  prerelease: false
182
224
  version_requirements: !ruby/object:Gem::Requirement
183
225
  requirements:
184
226
  - - "~>"
185
227
  - !ruby/object:Gem::Version
186
- version: 0.48.0
228
+ version: '2.24'
187
229
  - !ruby/object:Gem::Dependency
188
230
  name: simplecov
189
231
  requirement: !ruby/object:Gem::Requirement
@@ -251,31 +293,11 @@ files:
251
293
  - lib/inst_jobs_statsd/stats/timing/perform.rb
252
294
  - lib/inst_jobs_statsd/stats/timing/pop.rb
253
295
  - lib/inst_jobs_statsd/version.rb
254
- - spec/factories/jobs.rb
255
- - spec/factories/workers.rb
256
- - spec/gemfiles/60.gemfile
257
- - spec/inst_jobs_statsd/ext/job_spec.rb
258
- - spec/inst_jobs_statsd/jobs_tracker_spec.rb
259
- - spec/inst_jobs_statsd/naming_spec.rb
260
- - spec/inst_jobs_statsd/stats/counters/complete_spec.rb
261
- - spec/inst_jobs_statsd/stats/counters/create_spec.rb
262
- - spec/inst_jobs_statsd/stats/counters/run_spec.rb
263
- - spec/inst_jobs_statsd/stats/periodic/failed_spec.rb
264
- - spec/inst_jobs_statsd/stats/periodic/queue_spec.rb
265
- - spec/inst_jobs_statsd/stats/periodic/run_spec.rb
266
- - spec/inst_jobs_statsd/stats/periodic_spec.rb
267
- - spec/inst_jobs_statsd/stats/timing/failed_spec.rb
268
- - spec/inst_jobs_statsd/stats/timing/perform_spec.rb
269
- - spec/inst_jobs_statsd/stats/timing/pop_spec.rb
270
- - spec/inst_jobs_statsd/stats/timing_spec.rb
271
- - spec/inst_statsd/default_tracking_spec.rb
272
- - spec/matchers.rb
273
- - spec/setup_test_db.rb
274
- - spec/spec_helper.rb
275
296
  homepage: https://github.com/instructure/inst-jobs-statsd
276
297
  licenses:
277
298
  - MIT
278
- metadata: {}
299
+ metadata:
300
+ rubygems_mfa_required: 'true'
279
301
  post_install_message:
280
302
  rdoc_options: []
281
303
  require_paths:
@@ -291,29 +313,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
291
313
  - !ruby/object:Gem::Version
292
314
  version: '0'
293
315
  requirements: []
294
- rubygems_version: 3.1.6
316
+ rubygems_version: 3.4.19
295
317
  signing_key:
296
318
  specification_version: 4
297
319
  summary: Stats reporting for inst-jobs
298
- test_files:
299
- - spec/inst_jobs_statsd/ext/job_spec.rb
300
- - spec/inst_jobs_statsd/naming_spec.rb
301
- - spec/inst_jobs_statsd/stats/periodic/failed_spec.rb
302
- - spec/inst_jobs_statsd/stats/periodic/run_spec.rb
303
- - spec/inst_jobs_statsd/stats/periodic/queue_spec.rb
304
- - spec/inst_jobs_statsd/stats/timing/failed_spec.rb
305
- - spec/inst_jobs_statsd/stats/timing/pop_spec.rb
306
- - spec/inst_jobs_statsd/stats/timing/perform_spec.rb
307
- - spec/inst_jobs_statsd/stats/periodic_spec.rb
308
- - spec/inst_jobs_statsd/stats/counters/run_spec.rb
309
- - spec/inst_jobs_statsd/stats/counters/create_spec.rb
310
- - spec/inst_jobs_statsd/stats/counters/complete_spec.rb
311
- - spec/inst_jobs_statsd/stats/timing_spec.rb
312
- - spec/inst_jobs_statsd/jobs_tracker_spec.rb
313
- - spec/spec_helper.rb
314
- - spec/setup_test_db.rb
315
- - spec/matchers.rb
316
- - spec/gemfiles/60.gemfile
317
- - spec/factories/workers.rb
318
- - spec/factories/jobs.rb
319
- - spec/inst_statsd/default_tracking_spec.rb
320
+ test_files: []
@@ -1,9 +0,0 @@
1
- FactoryGirl.define do
2
- class JobFixture
3
- attr_accessor :tag, :run_at
4
- end
5
-
6
- factory :job_fixture, aliases: [:job] do
7
- tag 'Test::Job.perform'
8
- end
9
- end
@@ -1,9 +0,0 @@
1
- FactoryGirl.define do
2
- class WorkerFixture
3
- attr_accessor :name
4
- end
5
-
6
- factory :worker_fixture, aliases: [:worker] do
7
- sequence(:name) { |n| "worker-#{n}" }
8
- end
9
- end
@@ -1,7 +0,0 @@
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"
@@ -1,17 +0,0 @@
1
- RSpec.describe 'InstJobsStatsd::Ext::Job' do
2
- describe 'sends count on job failure' do
3
- before do
4
- InstJobsStatsd::JobsTracker.new
5
- end
6
- let(:x) { Struct.new(:perform).new(true) }
7
- it 'sends a stat' do
8
- allow(InstStatsd::Statsd).to receive(:count)
9
-
10
- x.delay.perform
11
- Delayed::Job.first.fail!
12
-
13
- expect(InstStatsd::Statsd).to have_received(:count)
14
- .with(array_including(/\.failed$/), 1, 1, short_stat: :failed, tags: {})
15
- end
16
- end
17
- end
@@ -1,30 +0,0 @@
1
- RSpec.describe InstJobsStatsd::JobsTracker do
2
- describe '.track' do
3
- it 'calls the block' do
4
- @done_in_block = false
5
- expect do
6
- InstJobsStatsd::JobsTracker.track do
7
- @done_in_block = true
8
- end
9
- end.to(change { @done_in_block })
10
- end
11
- end
12
-
13
- describe '.initialize' do
14
- it 'enables everything' do
15
- expect(InstJobsStatsd::Stats::Counters::Create).to receive(:enable)
16
- expect(InstJobsStatsd::Stats::Counters::Run).to receive(:enable)
17
- expect(InstJobsStatsd::Stats::Counters::Complete).to receive(:enable)
18
-
19
- expect(InstJobsStatsd::Stats::Periodic::Failed).to receive(:enable)
20
- expect(InstJobsStatsd::Stats::Periodic::Queue).to receive(:enable)
21
- expect(InstJobsStatsd::Stats::Periodic::Run).to receive(:enable)
22
-
23
- expect(InstJobsStatsd::Stats::Timing::Failed).to receive(:enable)
24
- expect(InstJobsStatsd::Stats::Timing::Perform).to receive(:enable)
25
- expect(InstJobsStatsd::Stats::Timing::Pop).to receive(:enable)
26
-
27
- InstJobsStatsd::JobsTracker.new
28
- end
29
- end
30
- end
@@ -1,56 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Naming do
2
- describe '.qualified_names' do
3
- subject { InstJobsStatsd::Naming.qualified_names(stat_name, job) }
4
- let(:stat_name) { :wut }
5
-
6
- context 'when no job is given' do
7
- let(:job) { nil }
8
- it { should eq ['delayedjob.wut'] }
9
- end
10
-
11
- context 'when job is given' do
12
- let(:job) { build :job }
13
- it { should include 'delayedjob.wut.tag.Test-Job.perform' }
14
-
15
- context 'job tag is unusual' do
16
- let(:job) { build :job, tag: 'periodic__Something_on_a_schedule' }
17
- it { should include 'delayedjob.wut.tag.periodic__Something_on_a_schedule' }
18
- end
19
-
20
- context 'job tag is dynamic' do
21
- let(:job) { build :job, tag: '<Class:0x00000004f575b8>#perform' }
22
- it { should eq ['delayedjob.wut'] }
23
- end
24
- end
25
-
26
- context 'with region tags' do
27
- before do
28
- @jobs_namespace = ENV['INST_JOBS_STATSD_NAMESPACE']
29
- ENV['INST_JOBS_STATSD_NAMESPACE'] = 'region_name'
30
- end
31
-
32
- after do
33
- ENV['INST_JOBS_STATSD_NAMESPACE'] = @jobs_namespace
34
- end
35
-
36
- let(:job) { build :job, tag: 'a_tag_name' }
37
-
38
- it { should include 'delayedjob.wut' }
39
- it { should include 'delayedjob.wut.tag.a_tag_name' }
40
- it { should include 'delayedjob.wut.region_name' }
41
- it { should include 'delayedjob.wut.region_name.tag.a_tag_name' }
42
- end
43
-
44
- describe '.dd_job_tags' do
45
- it 'works' do
46
- job = double(tag: 'Account.run_reports_later')
47
- expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq(tag: 'Account.run_reports_later')
48
- end
49
-
50
- it 'properly munges job tags' do
51
- job = double(tag: 'Quizzes::Quiz#do_something')
52
- expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq(tag: 'Quizzes-Quiz.do_something')
53
- end
54
- end
55
- end
56
- end
@@ -1,27 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Counters::Complete do
2
- describe '.enable' do
3
- it 'enables all the things' do
4
- expect(InstJobsStatsd::Stats::Counters::Complete).to receive(:enable_complete_count)
5
- InstJobsStatsd::Stats::Counters::Complete.enable
6
- end
7
- end
8
-
9
- describe '.report_complete_count' do
10
- let(:x) { Struct.new(:perform).new(true) }
11
-
12
- before do
13
- Delayed::Worker.lifecycle.reset!
14
- InstJobsStatsd::Stats::Counters::Complete.enable
15
-
16
- 2.times { x.delay.perform }
17
- end
18
-
19
- it "increments the counter" do
20
- expect(InstStatsd::Statsd).to receive(:count)
21
- .twice.with(array_including(/\.complete$/), 1, 1, short_stat: anything, tags: {})
22
- Delayed::Job.all.each do |job|
23
- Delayed::Worker.lifecycle.run_callbacks(:perform, {}, job) {}
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Counters::Create do
2
- describe '.enable' do
3
- it 'enables all the things' do
4
- expect(InstJobsStatsd::Stats::Counters::Create).to receive(:enable_create_count)
5
- InstJobsStatsd::Stats::Counters::Create.enable
6
- end
7
- end
8
-
9
- describe '.report_create_count' do
10
- let(:x) { Struct.new(:perform).new(true) }
11
-
12
- before do
13
- Delayed::Worker.lifecycle.reset!
14
- InstJobsStatsd::Stats::Counters::Create.enable
15
-
16
- 2.times { x.delay.perform }
17
- end
18
-
19
- it "increments the counter" do
20
- expect(InstStatsd::Statsd).to receive(:count)
21
- .twice.with(array_including(/\.create$/), 1, 1, short_stat: anything, tags: {})
22
- Delayed::Job.all.each do |job|
23
- Delayed::Worker.lifecycle.run_callbacks(:create, job) {}
24
- end
25
- end
26
- end
27
- end
@@ -1,27 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Counters::Run do
2
- describe '.enable' do
3
- it 'enables all the things' do
4
- expect(InstJobsStatsd::Stats::Counters::Run).to receive(:enable_run_count)
5
- InstJobsStatsd::Stats::Counters::Run.enable
6
- end
7
- end
8
-
9
- describe '.report_run_count' do
10
- let(:x) { Struct.new(:perform).new(true) }
11
-
12
- before do
13
- Delayed::Worker.lifecycle.reset!
14
- InstJobsStatsd::Stats::Counters::Run.enable
15
-
16
- 2.times { x.delay.perform }
17
- end
18
-
19
- it do
20
- expect(InstStatsd::Statsd).to receive(:count)
21
- .twice.with(array_including(/\.run$/), 1, 1, short_stat: anything, tags: {})
22
- Delayed::Job.all.each do |job|
23
- Delayed::Worker.lifecycle.run_callbacks(:perform, {}, job) {}
24
- end
25
- end
26
- end
27
- end
@@ -1,31 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Periodic::Failed do
2
- before do
3
- InstJobsStatsd::Stats::Periodic.instance_variable_set(:@instance, nil)
4
- end
5
-
6
- describe '.enable' do
7
- it 'enables all the things' do
8
- expect(InstJobsStatsd::Stats::Periodic::Failed).to receive(:enable_failed_depth)
9
- InstJobsStatsd::Stats::Periodic::Failed.enable
10
- end
11
- end
12
-
13
- describe '.report_failed_depth' do
14
- let(:x) { Struct.new(:perform).new(true) }
15
- let(:now) { Delayed::Job.db_time_now }
16
-
17
- before do
18
- InstJobsStatsd::Stats::Periodic.enable_callbacks
19
- InstJobsStatsd::Stats::Periodic::Failed.enable_failed_depth
20
-
21
- x.delay.perform
22
- Delayed::Job.first.fail!
23
- end
24
-
25
- it do
26
- expect(InstStatsd::Statsd).to receive(:gauge)
27
- .with(array_including(/\.failed_depth$/), 1, 1, short_stat: anything, tags: {})
28
- InstJobsStatsd::Stats::Periodic::Failed.report_failed_depth
29
- end
30
- end
31
- end
@@ -1,95 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Periodic::Queue do
2
- before do
3
- InstJobsStatsd::Stats::Periodic.instance_variable_set(:@instance, nil)
4
- end
5
-
6
- describe '.enable' do
7
- it 'enables all the things' do
8
- expect(InstJobsStatsd::Stats::Periodic::Queue).to receive(:enable_queue_depth)
9
- expect(InstJobsStatsd::Stats::Periodic::Queue).to receive(:enable_queue_age)
10
- InstJobsStatsd::Stats::Periodic::Queue.enable
11
- end
12
- end
13
-
14
- describe '.report_queue_depth' do
15
- let(:x) { Struct.new(:perform).new(true) }
16
- let(:now) { Delayed::Job.db_time_now }
17
-
18
- before do
19
- InstJobsStatsd::Stats::Periodic::Queue.enable_queue_depth
20
-
21
- x.delay.perform
22
- Delayed::Job.first.update(locked_at: Delayed::Job.db_time_now, locked_by: 'test')
23
-
24
- x.delay.perform
25
- x.delay(run_at: now + 1.minute).perform
26
- x.delay(run_at: now + 10.minutes).perform
27
- end
28
-
29
- it do
30
- expect(InstStatsd::Statsd).to receive(:gauge)
31
- .with(array_including(/\.queue_depth$/), 1, 1, short_stat: anything, tags: {})
32
- InstJobsStatsd::Stats::Periodic::Queue.report_queue_depth
33
- end
34
-
35
- it do
36
- expect(InstStatsd::Statsd).to receive(:gauge)
37
- .with(array_including(/\.queue_depth$/), 2, 1, short_stat: anything, tags: {})
38
- Timecop.freeze(2.minutes.from_now) do
39
- InstJobsStatsd::Stats::Periodic::Queue.report_queue_depth
40
- end
41
- end
42
-
43
- it do
44
- expect(InstStatsd::Statsd).to receive(:gauge)
45
- .with(array_including(/\.queue_depth$/), 3, 1, short_stat: anything, tags: {})
46
- Timecop.freeze(20.minutes.from_now) do
47
- InstJobsStatsd::Stats::Periodic::Queue.report_queue_depth
48
- end
49
- end
50
- end
51
-
52
- describe '.report_queue_age' do
53
- let(:x) { Struct.new(:perform).new(true) }
54
- let(:now) { Delayed::Job.db_time_now }
55
-
56
- before do
57
- InstJobsStatsd::Stats::Periodic::Queue.enable_queue_age
58
-
59
- x.delay.perform
60
- Delayed::Job.first.update(locked_at: Delayed::Job.db_time_now, locked_by: 'test')
61
-
62
- x.delay.perform
63
- x.delay(run_at: now + 1.minute).perform
64
- x.delay(run_at: now + 10.minutes).perform
65
- end
66
-
67
- it do
68
- expect(InstStatsd::Statsd).to receive(:gauge)
69
- .ordered.with(array_including(/\.queue_age_total$/), number_near(0), 1, short_stat: anything, tags: {})
70
- expect(InstStatsd::Statsd).to receive(:gauge)
71
- .ordered.with(array_including(/\.queue_age_max$/), number_near(0), 1, short_stat: anything, tags: {})
72
- InstJobsStatsd::Stats::Periodic::Queue.report_queue_age
73
- end
74
-
75
- it do
76
- expect(InstStatsd::Statsd).to receive(:gauge)
77
- .ordered.with(array_including(/\.queue_age_total$/), number_near(180), 1, short_stat: anything, tags: {})
78
- expect(InstStatsd::Statsd).to receive(:gauge)
79
- .ordered.with(array_including(/\.queue_age_max$/), number_near(120), 1, short_stat: anything, tags: {})
80
- Timecop.freeze(2.minutes.from_now) do
81
- InstJobsStatsd::Stats::Periodic::Queue.report_queue_age
82
- end
83
- end
84
-
85
- it do
86
- expect(InstStatsd::Statsd).to receive(:gauge)
87
- .ordered.with(array_including(/\.queue_age_total$/), number_near(2940), 1, short_stat: anything, tags: {})
88
- expect(InstStatsd::Statsd).to receive(:gauge)
89
- .ordered.with(array_including(/\.queue_age_max$/), number_near(1200), 1, short_stat: anything, tags: {})
90
- Timecop.freeze(20.minutes.from_now) do
91
- InstJobsStatsd::Stats::Periodic::Queue.report_queue_age
92
- end
93
- end
94
- end
95
- end
@@ -1,53 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Periodic::Run do
2
- before do
3
- InstJobsStatsd::Stats::Periodic.instance_variable_set(:@instance, nil)
4
- end
5
-
6
- describe '.enable' do
7
- it 'enables all the things' do
8
- expect(InstJobsStatsd::Stats::Periodic::Run).to receive(:enable_run_depth)
9
- expect(InstJobsStatsd::Stats::Periodic::Run).to receive(:enable_run_age)
10
- InstJobsStatsd::Stats::Periodic::Run.enable
11
- end
12
- end
13
-
14
- describe '.report_run_depth' do
15
- let(:x) { Struct.new(:perform).new(true) }
16
- let(:now) { Delayed::Job.db_time_now }
17
-
18
- before do
19
- InstJobsStatsd::Stats::Periodic::Run.enable_run_depth
20
-
21
- x.delay.perform
22
- x.delay.perform
23
- Delayed::Job.first.update(locked_at: Delayed::Job.db_time_now, locked_by: 'test')
24
- end
25
-
26
- it do
27
- expect(InstStatsd::Statsd).to receive(:gauge)
28
- .with(array_including(/\.run_depth$/), 1, 1, short_stat: anything, tags: {})
29
- InstJobsStatsd::Stats::Periodic::Run.report_run_depth
30
- end
31
- end
32
-
33
- describe '.report_run_age' do
34
- let(:x) { Struct.new(:perform).new(true) }
35
- let(:now) { Delayed::Job.db_time_now }
36
-
37
- before do
38
- InstJobsStatsd::Stats::Periodic::Run.enable_run_age
39
-
40
- x.delay.perform
41
- x.delay.perform
42
- Delayed::Job.first.update(locked_at: now, locked_by: 'test')
43
- end
44
-
45
- it do
46
- expect(InstStatsd::Statsd).to receive(:gauge)
47
- .ordered.with(array_including(/\.run_age_total$/), number_near(0), 1, short_stat: anything, tags: {})
48
- expect(InstStatsd::Statsd).to receive(:gauge)
49
- .ordered.with(array_including(/\.run_age_max$/), number_near(0), 1, short_stat: anything, tags: {})
50
- InstJobsStatsd::Stats::Periodic::Run.report_run_age
51
- end
52
- end
53
- end
@@ -1,63 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Periodic do
2
- before(:each) do
3
- Delayed::Worker.lifecycle.reset!
4
- InstJobsStatsd::Stats::Periodic.instance_variable_set(:@instance, nil)
5
- end
6
-
7
- describe '.enable_callbacks' do
8
- it 'only happens once' do
9
- expect(InstJobsStatsd::Stats::Periodic::Callbacks).to receive(:new).once.and_call_original
10
- 2.times { InstJobsStatsd::Stats::Periodic.enable_callbacks }
11
- end
12
- end
13
-
14
- describe '.add' do
15
- it 'does nothing if not enabled' do
16
- expect_any_instance_of(InstJobsStatsd::Stats::Periodic::Callbacks).not_to receive(:add)
17
- InstJobsStatsd::Stats::Periodic.add(-> {})
18
- end
19
-
20
- it 'does something if enabled' do
21
- expect_any_instance_of(InstJobsStatsd::Stats::Periodic::Callbacks)
22
- .to receive(:add).and_call_original
23
- InstJobsStatsd::Stats::Periodic.enable_callbacks
24
- InstJobsStatsd::Stats::Periodic.add(-> {})
25
- end
26
- end
27
-
28
- describe 'Callbacks' do
29
- before(:each) do
30
- InstJobsStatsd::Stats::Periodic.instance_variable_set(:@instance, nil)
31
- end
32
-
33
- it 'calls the procs at the interval' do
34
- InstJobsStatsd::Stats::Periodic.enable_callbacks
35
-
36
- @count = 0
37
- InstJobsStatsd::Stats::Periodic.add(-> { @count += 1 })
38
- InstJobsStatsd::Stats::Periodic.add(-> { @count += 2 })
39
-
40
- Timecop.freeze(Delayed::Job.db_time_now + 60.seconds) do
41
- Delayed::Worker.lifecycle.run_callbacks(:work_queue_pop, nil, nil) {}
42
- end
43
-
44
- expect(@count).to eq 3
45
- end
46
- end
47
-
48
- describe 'Timer' do
49
- before(:each) { @did_block = false }
50
-
51
- it 'does not call the block too soon' do
52
- t = InstJobsStatsd::Stats::Periodic::Timer.new(60)
53
- expect { t.tick { @did_block = true } }.not_to(change { @did_block })
54
- end
55
-
56
- it 'calls the block after the interval elapses' do
57
- t = InstJobsStatsd::Stats::Periodic::Timer.new(60)
58
- Timecop.freeze(Delayed::Job.db_time_now + 60.seconds) do
59
- expect { t.tick { @did_block = true } }.to(change { @did_block })
60
- end
61
- end
62
- end
63
- end
@@ -1,25 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Timing::Failed do
2
- let(:worker) { build :worker }
3
- let(:job) { build :job, run_at: 1.minute.ago }
4
-
5
- before(:each) { Delayed::Worker.lifecycle.reset! }
6
-
7
- describe '.enable' do
8
- it 'enables all the things' do
9
- expect(InstJobsStatsd::Stats::Timing::Failed).to receive(:enable_failure_timing)
10
- InstJobsStatsd::Stats::Timing::Failed.enable
11
- end
12
- end
13
-
14
- describe '.enable_failure_timing' do
15
- it 'reports failure time' do
16
- expect(InstStatsd::Statsd).to receive(:timing)
17
- .once.with(array_including(/\.failed_after$/), any_args)
18
- InstJobsStatsd::Stats::Timing::Failed.enable_failure_timing
19
- Delayed::Worker.lifecycle.run_callbacks(
20
- :error, worker, job, Exception.new('test')
21
- ) { @in_block = true }
22
- expect(@in_block).to be_truthy
23
- end
24
- end
25
- end
@@ -1,35 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Timing::Perform do
2
- let(:worker) { build :worker }
3
- let(:job) { build :job, run_at: 1.minute.ago }
4
-
5
- before(:each) { Delayed::Worker.lifecycle.reset! }
6
-
7
- describe '.enable' do
8
- it 'enables all the things' do
9
- expect(InstJobsStatsd::Stats::Timing::Perform).to receive(:enable_batching)
10
- expect(InstJobsStatsd::Stats::Timing::Perform).to receive(:enable_perform_timing)
11
- InstJobsStatsd::Stats::Timing::Perform.enable
12
- end
13
- end
14
-
15
- describe '.enable_batching' do
16
- it 'does batching' do
17
- expect(InstStatsd::Statsd).to receive(:batch).and_call_original
18
- InstJobsStatsd::Stats::Timing::Perform.enable_batching
19
- Delayed::Worker.lifecycle.run_callbacks(:perform, worker, job) { @in_block = true }
20
- expect(@in_block).to be_truthy
21
- end
22
- end
23
-
24
- describe '.enable_perform_timing' do
25
- it 'reports queu and perform time' do
26
- expect(InstStatsd::Statsd).to receive(:timing)
27
- .once.ordered.with(array_including(/\.queue$/), any_args)
28
- expect(InstStatsd::Statsd).to receive(:timing)
29
- .once.ordered.with(array_including(/\.perform$/), any_args)
30
- InstJobsStatsd::Stats::Timing::Perform.enable_perform_timing
31
- Delayed::Worker.lifecycle.run_callbacks(:perform, worker, job) { @in_block = true }
32
- expect(@in_block).to be_truthy
33
- end
34
- end
35
- end
@@ -1,34 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Timing::Pop do
2
- let(:worker) { build :worker }
3
- let(:job) { build :job, run_at: 1.minute.ago }
4
-
5
- before(:each) { Delayed::Worker.lifecycle.reset! }
6
-
7
- describe '.enable' do
8
- it 'enables all the things' do
9
- expect(InstJobsStatsd::Stats::Timing::Pop).to receive(:enable_pop_timing)
10
- expect(InstJobsStatsd::Stats::Timing::Pop).to receive(:enable_workqueue_pop_timing)
11
- InstJobsStatsd::Stats::Timing::Pop.enable
12
- end
13
- end
14
-
15
- describe '.enable_pop_timing' do
16
- it 'reports pop time' do
17
- expect(InstStatsd::Statsd).to receive(:timing)
18
- .once.ordered.with(array_including(/\.pop$/), any_args)
19
- InstJobsStatsd::Stats::Timing::Pop.enable_pop_timing
20
- Delayed::Worker.lifecycle.run_callbacks(:pop, worker) { @in_block = true }
21
- expect(@in_block).to be_truthy
22
- end
23
- end
24
-
25
- describe '.enable_workqueue_pop_timing' do
26
- it 'reports pop time' do
27
- expect(InstStatsd::Statsd).to receive(:timing)
28
- .once.ordered.with(array_including(/\.workqueuepop$/), any_args)
29
- InstJobsStatsd::Stats::Timing::Pop.enable_workqueue_pop_timing
30
- Delayed::Worker.lifecycle.run_callbacks(:work_queue_pop, worker, {}) { @in_block = true }
31
- expect(@in_block).to be_truthy
32
- end
33
- end
34
- end
@@ -1,35 +0,0 @@
1
- RSpec.describe InstJobsStatsd::Stats::Timing do
2
- let(:job) { build :job, run_at: 1.minute.ago }
3
-
4
- describe 'report_tinming' do
5
- context 'with a block' do
6
- it 'reports the elapsed time' do
7
- expect(InstStatsd::Statsd).to receive(:time)
8
- InstJobsStatsd::Stats::Timing.report_timing('test', job: job) { sleep 0.001 }
9
- end
10
- end
11
-
12
- context 'without a block' do
13
- it 'reports the given time' do
14
- expect(InstStatsd::Statsd).to receive(:timing)
15
- InstJobsStatsd::Stats::Timing.report_timing('test', job: job, timing: 123)
16
- end
17
- end
18
- end
19
-
20
- describe 'report_job_timing_queued' do
21
- it 'reports the stat' do
22
- expect(InstStatsd::Statsd).to receive(:timing)
23
- .with(array_including(/\.queue$/), any_args)
24
- InstJobsStatsd::Stats::Timing.report_job_timing_queued(job)
25
- end
26
- end
27
-
28
- describe 'report_job_timing_failed' do
29
- it 'reports the stat' do
30
- expect(InstStatsd::Statsd).to receive(:timing)
31
- .with(array_including(/\.failed_after$/), any_args)
32
- InstJobsStatsd::Stats::Timing.report_job_timing_failed(job)
33
- end
34
- end
35
- end
@@ -1,16 +0,0 @@
1
- RSpec.describe InstStatsd::DefaultTracking do
2
- it 'includes methods defined in the base gem' do
3
- expect(InstStatsd::DefaultTracking.respond_to?(:track_sql)).to be_truthy
4
- end
5
-
6
- describe 'track_job_stats' do
7
- it 'defines :track_jobs' do
8
- expect(InstStatsd::DefaultTracking.respond_to?(:track_jobs)).to be_truthy
9
- end
10
-
11
- it 'only does it once' do
12
- expect(InstJobsStatsd::JobsTracker).to receive(:new).once.and_call_original
13
- 2.times { InstStatsd::DefaultTracking.track_jobs }
14
- end
15
- end
16
- end
data/spec/matchers.rb DELETED
@@ -1,3 +0,0 @@
1
- RSpec::Matchers.define :number_near do |target, max_delta = 0.5|
2
- match { |actual| (actual - target).abs <= max_delta }
3
- end
@@ -1,45 +0,0 @@
1
- # All the below is essentially copied from inst-jobs spec_helper.rb,
2
- # to create the test db, run migrations, etc
3
- ENV['TEST_ENV_NUMBER'] ||= '1'
4
- ENV['TEST_DB_HOST'] ||= 'localhost'
5
- ENV['TEST_DB_DATABASE'] ||= "inst-jobs-test-#{ENV['TEST_ENV_NUMBER']}"
6
-
7
- connection_config = {
8
- adapter: :postgresql,
9
- host: ENV['TEST_DB_HOST'].presence,
10
- encoding: 'utf8',
11
- username: ENV['TEST_DB_USERNAME'],
12
- database: ENV['TEST_DB_DATABASE']
13
- }
14
-
15
- if ::Rails.version < '5'
16
- class ActiveRecord::Migration
17
- class << self
18
- def [](_version); self; end
19
- end
20
- end
21
- end
22
-
23
- # create the test db if it does not exist, to help out wwtd
24
- ActiveRecord::Base.establish_connection(connection_config.merge(database: 'postgres'))
25
- begin
26
- ActiveRecord::Base.connection.create_database(connection_config[:database])
27
- rescue ActiveRecord::StatementInvalid
28
- end
29
- ActiveRecord::Base.establish_connection(connection_config)
30
- # TODO reset db and migrate again, to test migrations
31
-
32
- # Apply the migrations from the inst-jobs gem
33
- inst_jobs_spec = Gem::Specification.find_by_name('inst-jobs')
34
- if ::Rails.version >= '6'
35
- sm = ActiveRecord::Base.connection.schema_migration
36
- migrations = ActiveRecord::MigrationContext.new(inst_jobs_spec.gem_dir + '/db/migrate', sm).migrations
37
- ActiveRecord::Migrator.new(:up, migrations, sm).migrate
38
- migrations = ActiveRecord::MigrationContext.new(inst_jobs_spec.gem_dir + '/spec/migrate', sm).migrations
39
- ActiveRecord::Migrator.new(:up, migrations, sm).migrate
40
- else
41
- ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/db/migrate')
42
- ActiveRecord::Migrator.migrate(inst_jobs_spec.gem_dir + '/spec/migrate')
43
- end
44
- Delayed::Backend::ActiveRecord::Job.reset_column_information
45
- Delayed::Backend::ActiveRecord::Job::Failed.reset_column_information
data/spec/spec_helper.rb DELETED
@@ -1,61 +0,0 @@
1
- if /^2\.7/ =~ RUBY_VERSION && /60\./ =~ ENV['BUNDLE_GEMFILE'] # Limit coverage to one build
2
- require 'simplecov'
3
-
4
- SimpleCov.start do
5
- add_filter 'lib/inst_jobs_statsd/version.rb'
6
- add_filter 'spec'
7
- track_files 'lib/**/*.rb'
8
- end
9
- end
10
-
11
- require 'inst-jobs-statsd'
12
- require 'delayed/testing'
13
-
14
- require 'byebug'
15
- require 'database_cleaner'
16
- require 'factory_girl'
17
- require 'pry'
18
- require 'timecop'
19
-
20
- # No reason to add default sleep time to specs:
21
- Delayed::Settings.sleep_delay = 0
22
- Delayed::Settings.sleep_delay_stagger = 0
23
-
24
- RSpec.configure do |config|
25
- config.expect_with(:rspec) do |c|
26
- c.syntax = %i[should expect]
27
- end
28
-
29
- config.include FactoryGirl::Syntax::Methods
30
- config.before(:suite) do
31
- FactoryGirl.find_definitions
32
- end
33
-
34
- config.before(:suite) do
35
- DatabaseCleaner.strategy = :transaction
36
- DatabaseCleaner.clean_with(:truncation)
37
- end
38
-
39
- config.before(:each) do |example|
40
- DatabaseCleaner.strategy = (example.metadata[:sinatra] ? :truncation : :transaction)
41
- DatabaseCleaner.start
42
- end
43
-
44
- config.after(:each) do
45
- DatabaseCleaner.clean
46
- end
47
-
48
- # Seed global randomization in this process using the `--seed` CLI option.
49
- # Setting this allows you to use `--seed` to deterministically reproduce
50
- # test failures related to randomization by passing the same `--seed` value
51
- # as the one that triggered the failure.
52
- config.order = :random
53
- Kernel.srand config.seed
54
- end
55
-
56
- require_relative 'setup_test_db'
57
-
58
- Time.zone = 'UTC'
59
- Rails.logger = Logger.new(nil)
60
-
61
- require_relative 'matchers'