pg-locks-monitor 0.2.0 → 0.2.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 +7 -3
- data/lib/pg-locks-monitor.rb +5 -4
- data/lib/pg_locks_monitor/version.rb +1 -1
- data/spec/smoke_spec.rb +13 -0
- metadata +4 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 170cb606bd1459b6b1a7525ed08ce17f2aab0757703ec9a33f64dadeafdebf7c
|
4
|
+
data.tar.gz: 503f92da91e4ca9d03999c45abb50507f8888b209df33c4a0e8b87e4cfdcb6b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27d0ac7d4340b0de7739b6383ec203830ab92eb5b952cbc41b9447c6d41aa540d52522f067bd1cdd857802c6c8a49a16ddaff9b95f2c51beed0f3e3b8dae6022
|
7
|
+
data.tar.gz: b4594194b88910f3fcc2e9c7e79205147076ff0fcd6ccf79ca2bc0e7e4290a3d5167e041f7660e72ecdfff1e7fe598684f103256a976582c83c884b8639dc77d
|
data/README.md
CHANGED
@@ -133,14 +133,18 @@ Here's a sample lock notification:
|
|
133
133
|
"transactionid": null,
|
134
134
|
# bool indicating if the lock is already granted
|
135
135
|
"granted": true,
|
136
|
-
#
|
136
|
+
# mode of the acquired lock
|
137
137
|
"mode": "RowExclusiveLock",
|
138
138
|
# SQL query which acquired the lock
|
139
139
|
"query_snippet": "UPDATE \"users\" SET \"updated_at\" = $1 WHERE \"users\".\"id\" = $2 from/sidekiq_job:UserUpdater/",
|
140
140
|
# age of the lock
|
141
141
|
"age": "PT0.94945S",
|
142
142
|
# app that acquired the lock
|
143
|
-
"application": "bin/sidekiq"
|
143
|
+
"application": "bin/sidekiq",
|
144
|
+
# ID of the database where lock was acquired
|
145
|
+
"database": "84759327",
|
146
|
+
# type of the acquired lock
|
147
|
+
"locktype": "relation",
|
144
148
|
},
|
145
149
|
```
|
146
150
|
|
@@ -204,7 +208,7 @@ PgLocksMonitor.configure do |config|
|
|
204
208
|
# ...
|
205
209
|
|
206
210
|
config.blocking_filter_proc = -> (lock) {
|
207
|
-
lock.fetch("blocked_sql_app").downcase.include?("sidekiq")
|
211
|
+
!lock.fetch("blocked_sql_app").downcase.include?("sidekiq")
|
208
212
|
}
|
209
213
|
end
|
210
214
|
```
|
data/lib/pg-locks-monitor.rb
CHANGED
@@ -2,10 +2,11 @@
|
|
2
2
|
|
3
3
|
require "uri"
|
4
4
|
require "pg"
|
5
|
+
require "ruby-pg-extras"
|
5
6
|
|
6
7
|
module PgLocksMonitor
|
7
8
|
def self.snapshot!
|
8
|
-
locks =
|
9
|
+
locks = RubyPgExtras.locks(
|
9
10
|
in_format: :hash,
|
10
11
|
).select do |lock|
|
11
12
|
if (age = lock.fetch("age"))
|
@@ -14,16 +15,16 @@ module PgLocksMonitor
|
|
14
15
|
end.select(&configuration.locks_filter_proc)
|
15
16
|
.first(configuration.locks_limit)
|
16
17
|
|
17
|
-
if locks.
|
18
|
+
if locks.count > 0 && configuration.monitor_locks
|
18
19
|
configuration.notifier_class.call(locks)
|
19
20
|
end
|
20
21
|
|
21
|
-
blocking =
|
22
|
+
blocking = RubyPgExtras.blocking(in_format: :hash).select do |block|
|
22
23
|
(ActiveSupport::Duration.parse(block.fetch("blocking_duration")).to_f * 1000) > configuration.blocking_min_duration_ms
|
23
24
|
end.select(&configuration.blocking_filter_proc)
|
24
25
|
.first(configuration.locks_limit)
|
25
26
|
|
26
|
-
if blocking.
|
27
|
+
if blocking.count > 0 && configuration.monitor_blocking
|
27
28
|
configuration.notifier_class.call(blocking)
|
28
29
|
end
|
29
30
|
end
|
data/spec/smoke_spec.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pg-locks-monitor
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.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-
|
11
|
+
date: 2024-10-02 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-pg-extras
|
@@ -105,6 +105,7 @@ files:
|
|
105
105
|
- pg-locks-monitor.gemspec
|
106
106
|
- spec/configuration_spec.rb
|
107
107
|
- spec/default_notifier_spec.rb
|
108
|
+
- spec/smoke_spec.rb
|
108
109
|
- spec/spec_helper.rb
|
109
110
|
homepage: http://github.com/pawurb/pg-locks-monitor
|
110
111
|
licenses:
|
@@ -133,4 +134,5 @@ summary: Observe PostgreSQL database locks obtained by a Rails application.
|
|
133
134
|
test_files:
|
134
135
|
- spec/configuration_spec.rb
|
135
136
|
- spec/default_notifier_spec.rb
|
137
|
+
- spec/smoke_spec.rb
|
136
138
|
- spec/spec_helper.rb
|