pg-locks-monitor 0.3.0 → 0.3.2
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 +4 -4
- data/README.md +0 -5
- data/lib/pg-locks-monitor.rb +13 -22
- data/lib/pg_locks_monitor/version.rb +1 -1
- data/pg-locks-monitor.gemspec +1 -1
- data/spec/smoke_spec.rb +6 -2
- data/spec/spec_helper.rb +7 -6
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3c123754d01da5acc5a517511066987515ec3167c0063a59c67b272ba0fd39ac
|
4
|
+
data.tar.gz: c85d88f96b9593ebb04a849e6cc79958a3040eb119980d17585cb69fdea1733b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1f98b1c258f99a3943e178d81f370b664be38b1841edb302364f0796c06302b2487819bb09d66d3c6dd5161999af21ecb1e4e769f7ff0a3be287620774811f3
|
7
|
+
data.tar.gz: 340ae2e8bf451994e1f960a5c8196bd1739790b2e7634ded97c1990fb12d0c121078a301e8fcb9408a7bf63ce8f096730d8f038817fd18eb29a2114c7f6eeca0
|
data/README.md
CHANGED
data/lib/pg-locks-monitor.rb
CHANGED
@@ -2,25 +2,32 @@
|
|
2
2
|
|
3
3
|
require "uri"
|
4
4
|
require "pg"
|
5
|
-
require "
|
5
|
+
require "rails-pg-extras"
|
6
|
+
require "active_record"
|
6
7
|
|
7
8
|
module PgLocksMonitor
|
8
9
|
def self.snapshot!
|
9
|
-
locks =
|
10
|
+
locks = RailsPgExtras.locks(
|
10
11
|
in_format: :hash,
|
11
12
|
).select do |lock|
|
12
13
|
if (age = lock.fetch("age"))
|
13
|
-
|
14
|
+
(ActiveSupport::Duration.parse(age).to_f * 1000) > configuration.locks_min_duration_ms
|
14
15
|
end
|
15
|
-
end.select
|
16
|
+
end.select do |lock|
|
17
|
+
# meta locks with duplicate data
|
18
|
+
lock.fetch("locktype") != "virtualxid"
|
19
|
+
end
|
20
|
+
.select(&configuration.locks_filter_proc)
|
16
21
|
.first(configuration.locks_limit)
|
17
22
|
|
18
23
|
if locks.count > 0 && configuration.monitor_locks
|
19
24
|
configuration.notifier_class.call(locks)
|
20
25
|
end
|
21
26
|
|
22
|
-
blocking =
|
23
|
-
|
27
|
+
blocking = RailsPgExtras.blocking(in_format: :hash).select do |block|
|
28
|
+
if (age = block.fetch("blocking_duration"))
|
29
|
+
(ActiveSupport::Duration.parse(age).to_f * 1000) > configuration.blocking_min_duration_ms
|
30
|
+
end
|
24
31
|
end.select(&configuration.blocking_filter_proc)
|
25
32
|
.first(configuration.locks_limit)
|
26
33
|
|
@@ -41,22 +48,6 @@ module PgLocksMonitor
|
|
41
48
|
def self.configure
|
42
49
|
yield(configuration)
|
43
50
|
end
|
44
|
-
|
45
|
-
class DurationHelper
|
46
|
-
require "date"
|
47
|
-
|
48
|
-
def self.parse_to_ms(duration_str)
|
49
|
-
time = DateTime.strptime(duration_str, "%H:%M:%S.%N")
|
50
|
-
hours = time.hour
|
51
|
-
minutes = time.minute
|
52
|
-
seconds = time.second
|
53
|
-
nanoseconds = time.second_fraction * (10 ** 9)
|
54
|
-
|
55
|
-
total_ms = (hours * 3600 * 1000) + (minutes * 60 * 1000) + (seconds * 1000) + (nanoseconds / 1_000_000).to_i
|
56
|
-
|
57
|
-
total_ms
|
58
|
-
end
|
59
|
-
end
|
60
51
|
end
|
61
52
|
|
62
53
|
require "pg_locks_monitor/default_notifier"
|
data/pg-locks-monitor.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |s|
|
|
15
15
|
s.test_files = s.files.grep(%r{^(spec)/})
|
16
16
|
s.require_paths = ["lib"]
|
17
17
|
s.license = "MIT"
|
18
|
-
s.add_dependency "
|
18
|
+
s.add_dependency "rails-pg-extras"
|
19
19
|
s.add_dependency "slack-notifier"
|
20
20
|
s.add_development_dependency "rake"
|
21
21
|
s.add_development_dependency "rspec"
|
data/spec/smoke_spec.rb
CHANGED
@@ -5,8 +5,8 @@ require "spec_helper"
|
|
5
5
|
describe PgLocksMonitor do
|
6
6
|
def spawn_update
|
7
7
|
Thread.new do
|
8
|
-
conn =
|
9
|
-
conn.
|
8
|
+
conn = RailsPgExtras.connection
|
9
|
+
conn.execute("
|
10
10
|
BEGIN;
|
11
11
|
UPDATE pg_locks_monitor_users SET name = 'Updated';
|
12
12
|
select pg_sleep(2);
|
@@ -25,6 +25,10 @@ describe PgLocksMonitor do
|
|
25
25
|
it "returns correct locks data" do
|
26
26
|
spawn_update
|
27
27
|
spawn_update
|
28
|
+
result = PgLocksMonitor.snapshot!
|
29
|
+
expect(result.fetch(:locks).count).to eq(0)
|
30
|
+
expect(result.fetch(:blocking).count).to eq(0)
|
31
|
+
|
28
32
|
sleep 1
|
29
33
|
|
30
34
|
result = PgLocksMonitor.snapshot!
|
data/spec/spec_helper.rb
CHANGED
@@ -35,14 +35,15 @@ RSpec.configure do |config|
|
|
35
35
|
end
|
36
36
|
|
37
37
|
config.before(:suite) do
|
38
|
-
|
39
|
-
conn
|
40
|
-
conn.
|
41
|
-
conn.
|
38
|
+
ActiveRecord::Base.establish_connection(ENV["DATABASE_URL"])
|
39
|
+
conn = RailsPgExtras.connection
|
40
|
+
conn.execute("CREATE TABLE IF NOT EXISTS pg_locks_monitor_users (id SERIAL PRIMARY KEY, name VARCHAR(255) NOT NULL);")
|
41
|
+
conn.execute("INSERT INTO pg_locks_monitor_users (name) VALUES ('Alice');")
|
42
|
+
conn.execute("INSERT INTO pg_locks_monitor_users (name) VALUES ('Bob');")
|
42
43
|
end
|
43
44
|
|
44
45
|
config.after(:suite) do
|
45
|
-
conn =
|
46
|
-
conn.
|
46
|
+
conn = RailsPgExtras.connection
|
47
|
+
conn.execute("DROP TABLE IF EXISTS pg_locks_monitor_users;")
|
47
48
|
end
|
48
49
|
end
|
metadata
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg-locks-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- pawurb
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: rails-pg-extras
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
17
|
- - ">="
|