inst-jobs-statsd 2.1.2 → 3.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/inst-jobs-statsd.rb +2 -0
- data/lib/inst_jobs_statsd/jobs_tracker.rb +2 -0
- data/lib/inst_jobs_statsd/naming.rb +1 -13
- data/lib/inst_jobs_statsd/stats/counters/complete.rb +21 -0
- data/lib/inst_jobs_statsd/stats/counters/create.rb +21 -0
- data/lib/inst_jobs_statsd/version.rb +1 -1
- data/spec/factories/jobs.rb +1 -1
- data/spec/inst_jobs_statsd/ext/job_spec.rb +4 -2
- data/spec/inst_jobs_statsd/jobs_tracker_spec.rb +2 -0
- data/spec/inst_jobs_statsd/naming_spec.rb +3 -3
- data/spec/inst_jobs_statsd/stats/counters/complete_spec.rb +27 -0
- data/spec/inst_jobs_statsd/stats/counters/create_spec.rb +27 -0
- metadata +16 -16
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: efc6027a4283d4fbe37e336710c974dfd2ddd1ab273613fbd9936fb0cfca37e5
|
4
|
+
data.tar.gz: eef10d80500c432b596436e28422c5b1243c1ec48de44fd73ec1a208ccc58734
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c4c9cad4da6c5d3897239e390445c852230655cb47fc5d5ca97c045d8d6923e1b33a8a6b7f8c8a66dda12e2636a204b4df6b8b1ca3f5912ece8a8ec991e7470f
|
7
|
+
data.tar.gz: f94e0bf3044911fbfc165f2320a2a08bbd744746e98771c3aded317e210ab2884294bf093b31ff386d2c7d0a22751d2dd48085b7e5785fe15a2191df2621cd65
|
data/lib/inst-jobs-statsd.rb
CHANGED
@@ -9,7 +9,9 @@ require_relative 'inst_jobs_statsd/jobs_tracker'
|
|
9
9
|
require_relative 'inst_jobs_statsd/naming'
|
10
10
|
|
11
11
|
require_relative 'inst_jobs_statsd/stats/counters'
|
12
|
+
require_relative 'inst_jobs_statsd/stats/counters/create'
|
12
13
|
require_relative 'inst_jobs_statsd/stats/counters/run'
|
14
|
+
require_relative 'inst_jobs_statsd/stats/counters/complete'
|
13
15
|
|
14
16
|
require_relative 'inst_jobs_statsd/stats/periodic'
|
15
17
|
require_relative 'inst_jobs_statsd/stats/periodic/failed'
|
@@ -9,7 +9,9 @@ module InstJobsStatsd
|
|
9
9
|
end
|
10
10
|
|
11
11
|
def initialize(enable_periodic_queries: true)
|
12
|
+
Stats::Counters::Create.enable
|
12
13
|
Stats::Counters::Run.enable
|
14
|
+
Stats::Counters::Complete.enable
|
13
15
|
::Delayed::Job.prepend InstJobsStatsd::Ext::Job
|
14
16
|
|
15
17
|
if enable_periodic_queries
|
@@ -8,10 +8,6 @@ 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
|
-
|
15
11
|
def self.qualified_names(stat_name, job)
|
16
12
|
names = ["#{basename}.#{stat_name}"]
|
17
13
|
tagged = tagged_stat(names[0], job)
|
@@ -36,9 +32,7 @@ module InstJobsStatsd
|
|
36
32
|
|
37
33
|
def self.dd_job_tags(job)
|
38
34
|
tags = dd_region_tags
|
39
|
-
return tags unless job
|
40
|
-
tags = custom_tags(job, tags)
|
41
|
-
return tags unless job.tag
|
35
|
+
return tags unless job&.tag
|
42
36
|
return tags if job.tag =~ /Class:0x/
|
43
37
|
|
44
38
|
method_tag, obj_tag = split_to_tag(job)
|
@@ -48,12 +42,6 @@ module InstJobsStatsd
|
|
48
42
|
tags
|
49
43
|
end
|
50
44
|
|
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
|
55
|
-
end
|
56
|
-
|
57
45
|
# this converts Foo#bar" or "Foo.bar" into "Foo and "bar",
|
58
46
|
# and makes sure the values are valid to be used for statsd names
|
59
47
|
def self.job_tags(job)
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module InstJobsStatsd
|
2
|
+
module Stats
|
3
|
+
module Counters
|
4
|
+
module Complete
|
5
|
+
def self.enable
|
6
|
+
enable_complete_count
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.enable_complete_count
|
10
|
+
Delayed::Worker.lifecycle.after(:perform) do |_worker, job|
|
11
|
+
report_complete_count(job)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.report_complete_count(job)
|
16
|
+
Counters.report_count(:complete, 1, job: job)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module InstJobsStatsd
|
2
|
+
module Stats
|
3
|
+
module Counters
|
4
|
+
module Create
|
5
|
+
def self.enable
|
6
|
+
enable_create_count
|
7
|
+
end
|
8
|
+
|
9
|
+
def self.enable_create_count
|
10
|
+
Delayed::Worker.lifecycle.after(:create) do |_, result:|
|
11
|
+
report_create_count(result)
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.report_create_count(job)
|
16
|
+
Counters.report_count(:create, 1, job: job)
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/spec/factories/jobs.rb
CHANGED
@@ -5,11 +5,13 @@ RSpec.describe 'InstJobsStatsd::Ext::Job' do
|
|
5
5
|
end
|
6
6
|
let(:x) { Struct.new(:perform).new(true) }
|
7
7
|
it 'sends a stat' do
|
8
|
-
|
9
|
-
.with(array_including(/\.failed$/), 1, 1, short_stat: :failed, tags: {})
|
8
|
+
allow(InstStatsd::Statsd).to receive(:count)
|
10
9
|
|
11
10
|
x.delay.perform
|
12
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: {})
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -12,7 +12,9 @@ RSpec.describe InstJobsStatsd::JobsTracker do
|
|
12
12
|
|
13
13
|
describe '.initialize' do
|
14
14
|
it 'enables everything' do
|
15
|
+
expect(InstJobsStatsd::Stats::Counters::Create).to receive(:enable)
|
15
16
|
expect(InstJobsStatsd::Stats::Counters::Run).to receive(:enable)
|
17
|
+
expect(InstJobsStatsd::Stats::Counters::Complete).to receive(:enable)
|
16
18
|
|
17
19
|
expect(InstJobsStatsd::Stats::Periodic::Failed).to receive(:enable)
|
18
20
|
expect(InstJobsStatsd::Stats::Periodic::Queue).to receive(:enable)
|
@@ -43,12 +43,12 @@ RSpec.describe InstJobsStatsd::Naming do
|
|
43
43
|
|
44
44
|
describe '.dd_job_tags' do
|
45
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'
|
46
|
+
job = double(tag: 'Account.run_reports_later')
|
47
|
+
expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq(tag: 'Account.run_reports_later')
|
48
48
|
end
|
49
49
|
|
50
50
|
it 'properly munges job tags' do
|
51
|
-
job = double(tag: 'Quizzes::Quiz#do_something'
|
51
|
+
job = double(tag: 'Quizzes::Quiz#do_something')
|
52
52
|
expect(InstJobsStatsd::Naming.dd_job_tags(job)).to eq(tag: 'Quizzes-Quiz.do_something')
|
53
53
|
end
|
54
54
|
end
|
@@ -0,0 +1,27 @@
|
|
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
|
@@ -0,0 +1,27 @@
|
|
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
|
metadata
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inst-jobs-statsd
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeremy Slade
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-07-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: inst-jobs
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
19
|
+
version: 3.1.1
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '4.0'
|
@@ -24,9 +24,9 @@ dependencies:
|
|
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:
|
29
|
+
version: 3.1.1
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '4.0'
|
@@ -34,20 +34,14 @@ dependencies:
|
|
34
34
|
name: inst_statsd
|
35
35
|
requirement: !ruby/object:Gem::Requirement
|
36
36
|
requirements:
|
37
|
-
- - "
|
38
|
-
- !ruby/object:Gem::Version
|
39
|
-
version: 2.1.2
|
40
|
-
- - "<"
|
37
|
+
- - "~>"
|
41
38
|
- !ruby/object:Gem::Version
|
42
39
|
version: '3.0'
|
43
40
|
type: :runtime
|
44
41
|
prerelease: false
|
45
42
|
version_requirements: !ruby/object:Gem::Requirement
|
46
43
|
requirements:
|
47
|
-
- - "
|
48
|
-
- !ruby/object:Gem::Version
|
49
|
-
version: 2.1.2
|
50
|
-
- - "<"
|
44
|
+
- - "~>"
|
51
45
|
- !ruby/object:Gem::Version
|
52
46
|
version: '3.0'
|
53
47
|
- !ruby/object:Gem::Dependency
|
@@ -245,6 +239,8 @@ files:
|
|
245
239
|
- lib/inst_jobs_statsd/jobs_tracker.rb
|
246
240
|
- lib/inst_jobs_statsd/naming.rb
|
247
241
|
- lib/inst_jobs_statsd/stats/counters.rb
|
242
|
+
- lib/inst_jobs_statsd/stats/counters/complete.rb
|
243
|
+
- lib/inst_jobs_statsd/stats/counters/create.rb
|
248
244
|
- lib/inst_jobs_statsd/stats/counters/run.rb
|
249
245
|
- lib/inst_jobs_statsd/stats/periodic.rb
|
250
246
|
- lib/inst_jobs_statsd/stats/periodic/failed.rb
|
@@ -261,6 +257,8 @@ files:
|
|
261
257
|
- spec/inst_jobs_statsd/ext/job_spec.rb
|
262
258
|
- spec/inst_jobs_statsd/jobs_tracker_spec.rb
|
263
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
|
264
262
|
- spec/inst_jobs_statsd/stats/counters/run_spec.rb
|
265
263
|
- spec/inst_jobs_statsd/stats/periodic/failed_spec.rb
|
266
264
|
- spec/inst_jobs_statsd/stats/periodic/queue_spec.rb
|
@@ -286,14 +284,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
286
284
|
requirements:
|
287
285
|
- - ">="
|
288
286
|
- !ruby/object:Gem::Version
|
289
|
-
version: '2.
|
287
|
+
version: '2.7'
|
290
288
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
291
289
|
requirements:
|
292
290
|
- - ">="
|
293
291
|
- !ruby/object:Gem::Version
|
294
292
|
version: '0'
|
295
293
|
requirements: []
|
296
|
-
rubygems_version: 3.
|
294
|
+
rubygems_version: 3.1.6
|
297
295
|
signing_key:
|
298
296
|
specification_version: 4
|
299
297
|
summary: Stats reporting for inst-jobs
|
@@ -308,6 +306,8 @@ test_files:
|
|
308
306
|
- spec/inst_jobs_statsd/stats/timing/perform_spec.rb
|
309
307
|
- spec/inst_jobs_statsd/stats/periodic_spec.rb
|
310
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
311
|
- spec/inst_jobs_statsd/stats/timing_spec.rb
|
312
312
|
- spec/inst_jobs_statsd/jobs_tracker_spec.rb
|
313
313
|
- spec/spec_helper.rb
|