pg-locks-monitor 0.1.0 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: dcbbfc8c0f63bbfd2f2c06abfb5db0e98ed2f5d6da39dc227089501f9734ec86
4
- data.tar.gz: 370e8706b301323367dd9685be5ac5e5e8fcb7c47a73c06e6a337cf590db331c
3
+ metadata.gz: d1cdcf1754671326b02e939ec99c90c2cd8d696bdcbdc82c6c84b378e0365f3b
4
+ data.tar.gz: ad862bd65e1db50465ee1456ac18619abeb9f9f10dded487f335348f036b5d1c
5
5
  SHA512:
6
- metadata.gz: e4ce44f0a435f65a9cbb3e69b185bcfe6939a7e4e44cb5ac687abeab7e2a7b83eb794b2407fae7fae34db152e5fd4b0332e65c01e895e851e5c2dc1a791d8a30
7
- data.tar.gz: 585cd6b764cc4a42582b8f0eca28ec4569f8e5cb9b7175df15745aef4af1a0e5634803c4dfe06af4737e759ad8cc4d2ea9d992ef39f6fa21e0b1ee4e8bd57186
6
+ metadata.gz: f20cb497a1ba37843441cb244fb581ab26ad7181ea1310c4c8d1db75f243fdac3ea05c9ec0b460b1c9bfe23827cb46360885fb24fef8747879d57342d4ad28cd
7
+ data.tar.gz: 9e9493e65efff88e07b33c08f8c7886b7b42b45939d07afe904600c7a9036896255756bcb7a7451754482f03bd150feb89db052a4766e8716e9f230832ed4b61
@@ -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 rspec spec/
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 rspec spec/
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 rspec spec/
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 rspec spec/
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 rspec spec/
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
- - `notify_locks` - observe database locks even if they don't conflict with a different SQL query
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
- - `notify_blocking` - observe database locks which cause other SQL query to wait from them to release
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 configuring a recurring invocation of the `snapshot!` method, it's recommended to first manually trigger the notification to test the configured channels.
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:
@@ -10,7 +10,9 @@ module PgLocksMonitor
10
10
  limit: configuration.locks_limit,
11
11
  },
12
12
  ).select do |lock|
13
- (ActiveSupport::Duration.parse(lock.fetch("age")).to_f * 1000) > configuration.locks_min_duration_ms
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
@@ -16,7 +16,7 @@ namespace :pg_locks_monitor do
16
16
  end
17
17
 
18
18
  desc "Check for currently active locks"
19
- task :snapshot do
19
+ task snapshot: :environment do
20
20
  PgLocksMonitor.snapshot!
21
21
  end
22
22
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgLocksMonitor
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.2"
5
5
  end
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.0
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-08-27 00:00:00.000000000 Z
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
data/spec/smoke_spec.rb DELETED
@@ -1,6 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "spec_helper"
4
-
5
- describe PgLocksMonitor do
6
- end