pg-locks-monitor 0.1.0 → 0.1.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/.github/workflows/ci.yml +5 -5
- data/README.md +7 -5
- data/lib/pg-locks-monitor.rb +3 -1
- data/lib/pg_locks_monitor/tasks/all.rake +1 -1
- data/lib/pg_locks_monitor/version.rb +1 -1
- metadata +2 -4
- data/spec/smoke_spec.rb +0 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d1cdcf1754671326b02e939ec99c90c2cd8d696bdcbdc82c6c84b378e0365f3b
|
4
|
+
data.tar.gz: ad862bd65e1db50465ee1456ac18619abeb9f9f10dded487f335348f036b5d1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f20cb497a1ba37843441cb244fb581ab26ad7181ea1310c4c8d1db75f243fdac3ea05c9ec0b460b1c9bfe23827cb46360885fb24fef8747879d57342d4ad28cd
|
7
|
+
data.tar.gz: 9e9493e65efff88e07b33c08f8c7886b7b42b45939d07afe904600c7a9036896255756bcb7a7451754482f03bd150feb89db052a4766e8716e9f230832ed4b61
|
data/.github/workflows/ci.yml
CHANGED
@@ -83,7 +83,7 @@ jobs:
|
|
83
83
|
POSTGRES_PASSWORD: secret
|
84
84
|
DATABASE_URL: postgresql://postgres:secret@localhost:5432/pg-locks-monitor-test
|
85
85
|
run: |
|
86
|
-
bundle exec
|
86
|
+
bundle exec rake test_all
|
87
87
|
- name: Run tests for PG 12
|
88
88
|
env:
|
89
89
|
PG_VERSION: 12
|
@@ -93,7 +93,7 @@ jobs:
|
|
93
93
|
POSTGRES_PASSWORD: secret
|
94
94
|
DATABASE_URL: postgresql://postgres:secret@localhost:5433/pg-locks-monitor-test
|
95
95
|
run: |
|
96
|
-
bundle exec
|
96
|
+
bundle exec rake test_all
|
97
97
|
- name: Run tests for PG 13
|
98
98
|
env:
|
99
99
|
PG_VERSION: 13
|
@@ -103,7 +103,7 @@ jobs:
|
|
103
103
|
POSTGRES_PASSWORD: secret
|
104
104
|
DATABASE_URL: postgresql://postgres:secret@localhost:5434/pg-locks-monitor-test
|
105
105
|
run: |
|
106
|
-
bundle exec
|
106
|
+
bundle exec rake test_all
|
107
107
|
- name: Run tests for PG 14
|
108
108
|
env:
|
109
109
|
PG_VERSION: 14
|
@@ -113,7 +113,7 @@ jobs:
|
|
113
113
|
POSTGRES_PASSWORD: secret
|
114
114
|
DATABASE_URL: postgresql://postgres:secret@localhost:5435/pg-locks-monitor-test
|
115
115
|
run: |
|
116
|
-
bundle exec
|
116
|
+
bundle exec rake test_all
|
117
117
|
- name: Run tests for PG 15
|
118
118
|
env:
|
119
119
|
PG_VERSION: 15
|
@@ -123,5 +123,5 @@ jobs:
|
|
123
123
|
POSTGRES_PASSWORD: secret
|
124
124
|
DATABASE_URL: postgresql://postgres:secret@localhost:5436/pg-locks-monitor-test
|
125
125
|
run: |
|
126
|
-
bundle exec
|
126
|
+
bundle exec rake test_all
|
127
127
|
|
data/README.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
This gem allows to observe database locks generated by a Rails application. By default, locks data is not persisted anywhere in the PostgreSQL logs, so the only way to monitor it is via analyzing the transient state of the `pg_locks` metadata table. `pg-locks-monitor` is a simple tool that makes this process quick to implement and adjust to each app's individual requirements.
|
4
4
|
|
5
|
+
You can read [this blogpost](https://pawelurbanek.com/rails-postgresql-locks) for more detailed info on database locks in the Rails apps.
|
6
|
+
|
7
|
+
**Shameless plug:** pg-locks-monitor is just one of the tools that I use when conducting [Rails performance audits](https://pawelurbanek.com/). Check out my offer if you need help with optimizing your application.
|
8
|
+
|
5
9
|
## Usage
|
6
10
|
|
7
11
|
`PgLocksMonitor` class provides a `snapshot!` method, which notifies selected channels about database locks that match configured criteria.
|
@@ -36,9 +40,9 @@ end
|
|
36
40
|
```
|
37
41
|
|
38
42
|
- `locks_limit` - specify the max number of locks to report in a single notification
|
39
|
-
- `
|
43
|
+
- `monitor_locks` - observe database locks even if they don't conflict with a different SQL query
|
40
44
|
- `locks_min_duration_ms` - notify about locks that execeed this duration threshold in milliseconds
|
41
|
-
- `
|
45
|
+
- `monitor_blocking` - observe database locks which cause other SQL query to wait from them to release
|
42
46
|
- `blocking_min_duration_ms` - notify about blocking locks that execeed this duration threshold in milliseconds
|
43
47
|
- `notify_logs` - send notifications about detected locks using `Rails.logger.info` method
|
44
48
|
- `notify_slack` - send notifications about detected locks to the configured Slack channel
|
@@ -49,7 +53,7 @@ end
|
|
49
53
|
|
50
54
|
## Testing the notification channels
|
51
55
|
|
52
|
-
Before
|
56
|
+
Before enabling a recurring invocation of the `snapshot!` method, it's recommended to first manually trigger the notification to test the configured channels.
|
53
57
|
|
54
58
|
You can generate an _"artificial"_ blocking lock and observe it by running the following code in the Rails console:
|
55
59
|
|
@@ -136,8 +140,6 @@ Here's a sample lock notification:
|
|
136
140
|
},
|
137
141
|
```
|
138
142
|
|
139
|
-
You can read [this blogpost](https://pawelurbanek.com/rails-postgresql-locks) for more detailed info on locks in the Rails apps.
|
140
|
-
|
141
143
|
## Background job config
|
142
144
|
|
143
145
|
This gem is intended to be used via a recurring background job, but it is agnostic to the background job provider. Here's a sample Sidekiq implementation:
|
data/lib/pg-locks-monitor.rb
CHANGED
@@ -10,7 +10,9 @@ module PgLocksMonitor
|
|
10
10
|
limit: configuration.locks_limit,
|
11
11
|
},
|
12
12
|
).select do |lock|
|
13
|
-
(
|
13
|
+
if (age = lock.fetch("age"))
|
14
|
+
(ActiveSupport::Duration.parse(age).to_f * 1000) > configuration.locks_min_duration_ms
|
15
|
+
end
|
14
16
|
end
|
15
17
|
|
16
18
|
if locks.present? && configuration.monitor_locks
|
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.1.
|
4
|
+
version: 0.1.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-09-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby-pg-extras
|
@@ -105,7 +105,6 @@ 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
|
109
108
|
- spec/spec_helper.rb
|
110
109
|
homepage: http://github.com/pawurb/pg-locks-monitor
|
111
110
|
licenses:
|
@@ -134,5 +133,4 @@ summary: Observe PostgreSQL database locks obtained by a Rails application.
|
|
134
133
|
test_files:
|
135
134
|
- spec/configuration_spec.rb
|
136
135
|
- spec/default_notifier_spec.rb
|
137
|
-
- spec/smoke_spec.rb
|
138
136
|
- spec/spec_helper.rb
|