pg-locks-monitor 0.1.1 → 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: b9127ef19c571c1eda59fa9962c694c6a416f4d2875d6660091cb72479e09d98
4
- data.tar.gz: 56a1e90355cad04a9834e2a6eafeb76c9633596a9e786ce639af838757c1e87e
3
+ metadata.gz: d1cdcf1754671326b02e939ec99c90c2cd8d696bdcbdc82c6c84b378e0365f3b
4
+ data.tar.gz: ad862bd65e1db50465ee1456ac18619abeb9f9f10dded487f335348f036b5d1c
5
5
  SHA512:
6
- metadata.gz: e9d94a09139dd75cfc5672aa863e288ed6654fa4953cf00dbbd62a6ec63e63feb60c99208f0aa0dda2ce01ccadd9cd92b3b58d05200be53bb75579e44bf85f9d
7
- data.tar.gz: 6f57a40ce88babd6fcdd176371462c4b6fa40c248da5472ae1cfdcdad685bc17f0a5a3bbf0f152e7de50d48dbc84a18a8443d1ce6ce90bf112278b506e81a839
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PgLocksMonitor
4
- VERSION = "0.1.1"
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.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-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