activerecord-connection_pool_instrumenter 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cd5d23f327f81d5a1f2cae36bc88b7a65c86816e792d0405f4ce36f2fd3427ef
4
- data.tar.gz: 8f9d3356d36c370a54c753358dba6379d9780c2ed42f18460b20944ac8042449
3
+ metadata.gz: 118b1e8a5cf9c83767e96e24d40e480c5ce2c28df6975e4d81b2407041cd5ec4
4
+ data.tar.gz: f7246ca731a40be3845f3febaaf6a788cca80363788afe124368bc9ad07ddd1e
5
5
  SHA512:
6
- metadata.gz: 3d5ad9fb65cec3e256af887ccda58d95d4b6db3e97b1f06a535a44be522d6fd41f6d1d75f4ec399eaff5d2ec4643e75862419c688ea1a13ccda4944bd898c137
7
- data.tar.gz: 278b9044823659f706b591f03611263ac139f2fd1934af00dc585dcaa142049a6404fa0c6e62272f0f08bee3dbcd093ac4e4d7ea02177436294e9bbbe7eadae5
6
+ metadata.gz: 18bdd9ac3f018f8c976b81a3e93a07caa1f743caab42c24907fa117b6b4449ee63ce5a5c2792a2304a854af7edfc00aedd259284e796135a4af753d9e1656c25
7
+ data.tar.gz: ce84ece3337bba6463d5ea46ecb57987779b73deba33ee0ed80da8f71cf6bd80cfc25691d5ff298a1c5950895d94b0d12fde7d4cda60d12401a56a35683f08ea
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Activerecord::ConnectionPoolInstrumenter
1
+ # ActiveRecord::ConnectionPoolInstrumenter
2
2
 
3
3
  ## Installation
4
4
 
@@ -15,8 +15,8 @@ And then execute `bundle install`
15
15
  Include in your application:
16
16
 
17
17
  ```
18
- require 'activerecord/connection_pool_instrumenter'
19
- Activerecord::ConnectionPoolInstrumenter.instrument(statsd: statsd, prefix: 'your_app.db.connection_pool')
18
+ require 'active_record/connection_pool_instrumenter'
19
+ ActiveRecord::ConnectionPoolInstrumenter.instrument(statsd: statsd, prefix: 'your_app.db.connection_pool')
20
20
  ```
21
21
 
22
22
  ## Development
data/Rakefile CHANGED
@@ -1,2 +1,6 @@
1
- require "bundler/gem_tasks"
2
- task :default => :spec
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task default: :spec
@@ -1,10 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative 'lib/activerecord/connection_pool_instrumenter/version'
3
+ require_relative 'lib/active_record/connection_pool_instrumenter/version'
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = 'activerecord-connection_pool_instrumenter'
7
- spec.version = Activerecord::ConnectionPoolInstrumenter::VERSION
7
+ spec.version = ActiveRecord::ConnectionPoolInstrumenter::VERSION
8
8
  spec.authors = ['Glia TechMovers']
9
9
  spec.email = ['techmovers@glia.com']
10
10
  spec.summary = 'Metrics about the activerecord connection pool usage'
@@ -15,5 +15,10 @@ Gem::Specification.new do |spec|
15
15
  spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
16
16
  spec.require_paths = ['lib']
17
17
 
18
+ spec.add_dependency 'activerecord'
18
19
  spec.add_dependency 'concurrent-ruby', '~> 1.1'
20
+
21
+ spec.add_development_dependency 'rspec', '~> 3.9'
22
+ spec.add_development_dependency 'statsd-ruby', '~> 1.4'
23
+ spec.add_development_dependency 'sqlite3', '~> 1.4'
19
24
  end
@@ -1,8 +1,8 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require 'activerecord/connection_pool_instrumenter/version'
3
+ require 'active_record/connection_pool_instrumenter/version'
4
4
 
5
- module Activerecord
5
+ module ActiveRecord
6
6
  module ConnectionPoolInstrumenter
7
7
  def self.instrument(
8
8
  statsd:,
@@ -13,7 +13,8 @@ module Activerecord
13
13
  )
14
14
  Concurrent::TimerTask.execute(
15
15
  execution_interval: execution_interval,
16
- timeout_interval: execution_timeout
16
+ timeout_interval: execution_timeout,
17
+ run_now: true
17
18
  ) do
18
19
  # ActiveRecord::Base.connection_pool.stat returns
19
20
  # { size: 15, connections: 1, busy: 1, dead: 0, idle: 0, waiting: 0, checkout_timeout: 5 }
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- module Activerecord
3
+ module ActiveRecord
4
4
  module ConnectionPoolInstrumenter
5
- VERSION = '0.1.0'
5
+ VERSION = '0.2.0'
6
6
  end
7
7
  end
@@ -0,0 +1,33 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'active_record'
4
+ require 'active_record/connection_pool_instrumenter'
5
+ require 'statsd'
6
+
7
+ RSpec.describe ActiveRecord::ConnectionPoolInstrumenter do
8
+ let(:prefix) { 'db.test.pool' }
9
+ let(:connection_pool) { ActiveRecord::Base.connection_pool }
10
+ let(:statsd) { instance_spy(Statsd) }
11
+
12
+ before do
13
+ ActiveRecord::Base.establish_connection(adapter: 'sqlite3', database: 'test.sqlite3')
14
+ end
15
+
16
+ it 'sends DB connection pool metrics as gauges' do
17
+ %i[size connections busy dead idle waiting].each do |metric|
18
+ expect(statsd).to receive(:gauge).with("#{prefix}.#{metric}", instance_of(Integer))
19
+ end
20
+
21
+ task = described_class.instrument(
22
+ connection_pool: connection_pool,
23
+ statsd: statsd,
24
+ prefix: prefix,
25
+ execution_interval: 10.seconds
26
+ )
27
+
28
+ # Small sleep to allow timer thread to execute its code
29
+ sleep 0.01
30
+
31
+ task.shutdown
32
+ end
33
+ end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: activerecord-connection_pool_instrumenter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Glia TechMovers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-06-08 00:00:00.000000000 Z
11
+ date: 2020-06-09 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activerecord
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: concurrent-ruby
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,48 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.9'
55
+ - !ruby/object:Gem::Dependency
56
+ name: statsd-ruby
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.4'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.4'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.4'
27
83
  description:
28
84
  email:
29
85
  - techmovers@glia.com
@@ -36,8 +92,9 @@ files:
36
92
  - README.md
37
93
  - Rakefile
38
94
  - activerecord-connection_pool_instrumenter.gemspec
39
- - lib/activerecord/connection_pool_instrumenter.rb
40
- - lib/activerecord/connection_pool_instrumenter/version.rb
95
+ - lib/active_record/connection_pool_instrumenter.rb
96
+ - lib/active_record/connection_pool_instrumenter/version.rb
97
+ - spec/active_record/connection_pool_instrumenter_spec.rb
41
98
  homepage: https://github.com/salemove/activerecord-connection_pool_instrumenter
42
99
  licenses: []
43
100
  metadata: {}
@@ -60,4 +117,5 @@ rubygems_version: 3.0.3
60
117
  signing_key:
61
118
  specification_version: 4
62
119
  summary: Metrics about the activerecord connection pool usage
63
- test_files: []
120
+ test_files:
121
+ - spec/active_record/connection_pool_instrumenter_spec.rb