okcomputer 1.18.6 → 1.19.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0b6e5540ab36865e49a7a6986c35dead38e31d4b20838a5818425cf3069c7129
4
- data.tar.gz: 95c4133f1277ed3042bc41d33905aafc4ba774b50fb49a94b2202b7000aa81db
3
+ metadata.gz: e5ade929cbb75c7478c1f46b7eaaf9ae49b94e2bf92ce3c6cdc74dc78fadc834
4
+ data.tar.gz: c6a9e9d2fa50c6c16018f3fda2184e834e9797443a37a3b5d0c26a838f17c193
5
5
  SHA512:
6
- metadata.gz: 4abc303ee824b255cd9f087b109b9420a1e06dbc2f5fcd35d11dd6c4ebb3538ac6c79f08d2fd7e04ff4209e6bb8741f53986680ea3578a70ddc18562b0a16015
7
- data.tar.gz: 48bb60d5dcded343a640272958eba7ebb38cb2a519b084969979e3a9ea8df680dfdbe2591640a8fd5577918cad20e9712db86e88e764da2b30472edff56a4827
6
+ metadata.gz: f7c37e6892f310730e5a7cf1ca868c7ec193f5a642bfc3bce8c9772b5c9e8d7c3917199a9d1ed82af4d32f416a6bdbe7641d2c96e83499ebf8666473f19cae28
7
+ data.tar.gz: a83d9c79e33b0c77665b42ecd6e581940b8ad0456fc640b50ba08285d961bbd3ef83a6754d840166cff0adbeae093dc03ccacb9a3f1a3693c936a78e5853ab1e
data/MIT-LICENSE CHANGED
@@ -1,4 +1,5 @@
1
- Copyright 2017 SportsEngine
1
+ Copyright 2024 Emma Sax
2
+ Copyright 2017-2024 SportsEngine
2
3
 
3
4
  Permission is hereby granted, free of charge, to any person obtaining
4
5
  a copy of this software and associated documentation files (the
data/README.markdown CHANGED
@@ -1,20 +1,21 @@
1
- [![Code Climate](https://codeclimate.com/github/sportngin/okcomputer.svg)](https://codeclimate.com/github/sportngin/okcomputer)
2
- [![Build Status](https://github.com/sportngin/okcomputer/workflows/CI/badge.svg)](https://github.com/sportngin/okcomputer/actions?query=workflow%3ACI)
1
+ [![Gem Version](https://badge.fury.io/rb/okcomputer.svg)](https://badge.fury.io/rb/okcomputer)
2
+ [![Downloads](https://img.shields.io/gem/dt/okcomputer.svg)](https://rubygems.org/gems/okcomputer)
3
+ [![License](https://img.shields.io/github/license/emmahsax/okcomputer.svg)](LICENSE)
4
+ [![Ruby Versions](https://img.shields.io/badge/Ruby-%3E%3D%202.1-brightgreen.svg)](https://www.ruby-lang.org)
5
+ [![Build Status](https://github.com/emmahsax/okcomputer/actions/workflows/ci.yml/badge.svg)](https://github.com/emmahsax/okcomputer/actions/workflows/ci.yml)
3
6
 
4
- # OK Computer
7
+ # OkComputer
5
8
 
6
- Inspired by the ease of installing and setting up [fitter-happier] as a Rails
9
+ Inspired by the ease of installing and setting up [fitter-happier](https://rubygems.org/gems/fitter-happier) as a Rails
7
10
  application's health check, but frustrated by its lack of flexibility, OK
8
11
  Computer was born. It provides a robust endpoint to perform server health
9
12
  checks with a set of built-in plugins, as well as a simple interface to add
10
13
  your own custom checks.
11
14
 
12
15
  For more insight into why we built this, check out [our blog post introducing
13
- OK Computer][blog].
16
+ OkComputer](http://pulse.sportngin.com/news_article/show/267646?referrer_id=543230).
14
17
 
15
- [blog]:http://pulse.sportngin.com/news_article/show/267646?referrer_id=543230
16
-
17
- OkComputer currently supports the following Rails versions:
18
+ OkComputer currently fully supports the following Rails versions:
18
19
 
19
20
  * 7.0
20
21
  * 6.1
@@ -23,26 +24,39 @@ OkComputer currently supports the following Rails versions:
23
24
  * 5.1
24
25
  * 4.2
25
26
 
26
- #### Not using Rails?
27
+ In addition, the CI tests are passing on, but is not guaranteed to work with, the following Rails versions:
27
28
 
28
- If you use [Grape] instead of Rails, check out [okcomputer-grape].
29
+ * 8.1
30
+ * 8.0
31
+ * 7.2
32
+ * 7.1
33
+ * 5.0
34
+ * 4.1
35
+ * 4.0
29
36
 
30
- [Grape]:https://github.com/ruby-grape/grape
31
- [okcomputer-grape]:https://github.com/bellycard/okcomputer-grape
37
+ #### Not using Rails?
38
+
39
+ If you use [Grape](https://github.com/ruby-grape/grape) instead of Rails, check out [okcomputer-grape](https://github.com/bellycard/okcomputer-grape).
32
40
 
33
41
  ## Installation
34
42
 
35
43
  Add this line to your application's Gemfile:
36
44
 
37
- gem 'okcomputer'
45
+ ```ruby
46
+ gem 'okcomputer'
47
+ ```
38
48
 
39
49
  And then execute:
40
50
 
41
- $ bundle
51
+ ```
52
+ $ bundle
53
+ ```
42
54
 
43
55
  Or install it yourself as:
44
56
 
45
- $ gem install okcomputer
57
+ ```
58
+ $ gem install okcomputer
59
+ ```
46
60
 
47
61
  ## Usage
48
62
 
@@ -86,7 +100,7 @@ you can configure it with:
86
100
 
87
101
  ```ruby
88
102
  # config/initializers/okcomputer.rb
89
- OkComputer.mount_at = 'health_checks' # mounts at /health_checks
103
+ OkComputer.mount_at = 'health_checks' # Mounts at /health_checks
90
104
  ```
91
105
 
92
106
  For more control of adding OkComputer to your routes, set `OkComputer.mount_at
@@ -109,7 +123,7 @@ Log check results by setting `OkComputer.logger`. Note: results will be logged a
109
123
  OkComputer.logger = Rails.logger
110
124
  ```
111
125
 
112
- ```sh
126
+ ```
113
127
  [okcomputer] mycheck: PASSED mymessage (0s)
114
128
  ```
115
129
 
@@ -124,6 +138,9 @@ OkComputer::Registry.register "resque_backed_up", OkComputer::ResqueBackedUpChec
124
138
 
125
139
  # This check works on 2.4.0 and above versions of resque-scheduler
126
140
  OkComputer::Registry.register "resque_scheduler_down", OkComputer::ResqueSchedulerCheck.new
141
+
142
+ # If you're using SolidCache instead of Memcached, use this check instead of CacheCheck
143
+ OkComputer::Registry.register "cache", OkComputer::CacheCheckSolidCache.new
127
144
  ```
128
145
 
129
146
  ### Registering Custom Checks
@@ -168,9 +185,7 @@ This check will run and report its status, but will not affect the HTTP status c
168
185
  The plain-text output flows through Rails' internationalization framework.
169
186
  Adjust the output as necessary by defining `okcomputer.check.passed` and
170
187
  `okcomputer.check.failed` keys in your setup. The default values are available
171
- [in `okcomputer.en.yml`][i18n].
172
-
173
- [i18n]:https://github.com/sportngin/okcomputer/blob/eb0be05cc1527e083edd63cfbb0a071f7892c822/config/locales/okcomputer.en.yml#L1-L5
188
+ [in `okcomputer.en.yml`](https://github.com/emmahsax/okcomputer/blob/main/config/locales/okcomputer.en.yml).
174
189
 
175
190
  ## Running checks in parallel
176
191
 
@@ -198,7 +213,7 @@ as it will start to artificially bring your request time down.
198
213
 
199
214
  If you'd like to intentionally count OkComputer requests in your NewRelic analytics, set:
200
215
 
201
- ```
216
+ ```ruby
202
217
  # config/initializers/okcomputer.rb
203
218
  OkComputer.analytics_ignore = false
204
219
  ```
@@ -207,7 +222,7 @@ OkComputer.analytics_ignore = false
207
222
 
208
223
  ### Setup
209
224
 
210
- ```plaintext
225
+ ```
211
226
  $ bundle install
212
227
  ```
213
228
 
@@ -217,7 +232,7 @@ OkComputer tests are written with [RSpec](http://rspec.info/).
217
232
 
218
233
  To run the full test suite:
219
234
 
220
- ```plaintext
235
+ ```
221
236
  $ rake spec
222
237
  ```
223
238
 
@@ -227,10 +242,17 @@ bundle and run the tests with a specific version of Rails.
227
242
 
228
243
  ## Contributing
229
244
 
230
- 1. Fork it
245
+ 1. Fork this repository
231
246
  2. Create your feature branch (`git checkout -b my-new-feature`)
232
247
  3. Commit your changes (`git commit -am 'Add some feature'`)
233
248
  4. Push to the branch (`git push origin my-new-feature`)
234
- 5. Create new Pull Request
249
+ 5. Create a new pull request on upstream (this repository)
250
+ 6. Update [`CHANGELOG.markdown`](https://github.com/emmahsax/okcomputer/blob/main/CHANGELOG.markdown) under an `Unreleased` tag version (create a new one at the top if needed) with summarized changes and link to the pull request
251
+
252
+ ## Releasing
235
253
 
236
- [fitter-happier]:https://rubygems.org/gems/fitter-happier
254
+ 1. Ensure you have push permissions to [RubyGems](https://rubygems.org/gems/okcomputer)
255
+ 2. Merge all PRs so that `main` is up to date with the new version
256
+ 3. Determine the new version ([`lib/ok_computer/version`](https://github.com/emmahsax/okcomputer/blob/main/lib/ok_computer/version.rb) has the current latest one) by following [semantic versioning](https://semver.org/) guidelines
257
+ 4. Ensure you're on the `main` branch and you are locally up to date (`git checkout main && git pull`)
258
+ 5. Run the release script and pass in the new version (`bin/release vX.X.X`... the `v` at the beginning is optional)
data/Rakefile CHANGED
@@ -23,4 +23,3 @@ begin
23
23
  end
24
24
  rescue LoadError
25
25
  end
26
-
@@ -2,36 +2,37 @@ module OkComputer
2
2
  class ActiveRecordMigrationsCheck < Check
3
3
  # Public: Check if migrations are pending or not
4
4
  def check
5
- return unsupported unless supported?
5
+ return mark_message(page_load_message) if check_on_page_load?
6
6
 
7
- if needs_migration?
8
- mark_failure
9
- mark_message "Pending migrations"
10
- else
11
- mark_message "NO pending migrations"
12
- end
13
- end
7
+ error_if_pending_migrations(Rails.version)
14
8
 
15
- def needs_migration?
16
- if ActiveRecord::Migrator.respond_to?(:needs_migration?) # Rails <= 5.1
17
- ActiveRecord::Migrator.needs_migration?
18
- else # Rails >= 5.2
19
- ActiveRecord::Base.connection.migration_context.needs_migration?
20
- end
9
+ mark_message "NO pending migrations"
10
+ rescue ActiveRecord::PendingMigrationError
11
+ mark_failure
12
+ mark_message "Pending migrations"
21
13
  end
22
14
 
23
- def supported?
24
- ActiveRecord::Migrator.respond_to?(:needs_migration?) ||
25
- (ActiveRecord::Base.connection.respond_to?(:migration_context) &&
26
- ActiveRecord::Base.connection.migration_context.respond_to?(:needs_migration?))
15
+ private
16
+
17
+ # this check is only valid if config.active_record.migration_error is set to false rather than :page_load
18
+ # :page_load adds a Middleware check that throws an error before the call reaches ok_computer
19
+ # we only run this check when :page_load is set if there are no pending migrations
20
+ # :page_load is the default in development, otherwise this is false
21
+ # see https://github.com/rails/rails/blob/d39db5d1891f7509cde2efc425c9d69bbb77e670/activerecord/lib/active_record/railtie.rb#L103
22
+ def check_on_page_load?
23
+ Rails.configuration.active_record.migration_error
27
24
  end
28
25
 
29
- private
26
+ def error_if_pending_migrations(version_string)
27
+ if Gem::Version.new(version_string) >= Gem::Version.new("7.1")
28
+ ActiveRecord::Migration.check_all_pending!
29
+ else
30
+ ActiveRecord::Migration.check_pending!
31
+ end
32
+ end
30
33
 
31
- # Private: Fail the check if ActiveRecord cannot check migration status
32
- def unsupported
33
- mark_failure
34
- mark_message "This version of ActiveRecord does not support checking whether migrations are pending"
34
+ def page_load_message
35
+ "NOTE: pending migrations are checked on page_load"
35
36
  end
36
37
  end
37
38
  end
@@ -0,0 +1,49 @@
1
+ module OkComputer
2
+ # Verifies that Rails cache is set up and can speak with SolidCache
3
+ class CacheCheckSolidCache < Check
4
+ # Public: Check whether the cache is active
5
+ def check
6
+ mark_message "Cache is available (#{stats})"
7
+ rescue ConnectionFailed => e
8
+ mark_failure
9
+ mark_message "Error: '#{e}'"
10
+ end
11
+
12
+ # Public: Outputs stats string for cache
13
+ def stats
14
+ return "" unless Rails.cache.respond_to? :stats
15
+
16
+ stats = Rails.cache.stats
17
+ connection_stats = stats[:connection_stats][SolidCache::Entry.current_shard]
18
+
19
+ max_entries = connection_stats[:max_entries]
20
+ current_entries = connection_stats[:entries]
21
+ max_age = connection_stats[:max_age]
22
+ oldest_age = connection_stats[:oldest_age]
23
+
24
+ age_text = if oldest_age
25
+ "oldest: #{format_duration(oldest_age)}, max: #{format_duration(max_age)}"
26
+ else
27
+ "no entries"
28
+ end
29
+
30
+ "entries: #{current_entries}/#{max_entries}, #{age_text}, #{stats[:connections]} connections"
31
+ rescue => e
32
+ raise ConnectionFailed, e
33
+ end
34
+
35
+ private
36
+
37
+ def format_duration(seconds)
38
+ if seconds < 60
39
+ "#{seconds.round}s"
40
+ elsif seconds < 3600
41
+ "#{(seconds / 60).round}m"
42
+ else
43
+ "#{(seconds / 3600).round}h"
44
+ end
45
+ end
46
+
47
+ ConnectionFailed = Class.new(StandardError)
48
+ end
49
+ end
@@ -1,3 +1,3 @@
1
1
  module OkComputer
2
- VERSION = '1.18.6'
2
+ VERSION = '1.19.1'
3
3
  end
data/lib/okcomputer.rb CHANGED
@@ -15,6 +15,7 @@ require "ok_computer/built_in_checks/active_record_check"
15
15
  require "ok_computer/built_in_checks/active_record_migrations_check"
16
16
  require "ok_computer/built_in_checks/app_version_check"
17
17
  require "ok_computer/built_in_checks/cache_check"
18
+ require "ok_computer/built_in_checks/cache_check_solid_cache"
18
19
  require "ok_computer/built_in_checks/default_check"
19
20
  require "ok_computer/built_in_checks/delayed_job_backed_up_check"
20
21
  require "ok_computer/built_in_checks/directory_check"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: okcomputer
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.18.6
4
+ version: 1.19.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne
@@ -12,68 +12,26 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2025-01-06 00:00:00.000000000 Z
15
+ date: 2025-11-23 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
- name: coveralls
18
+ name: benchmark
19
19
  requirement: !ruby/object:Gem::Requirement
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
23
  version: '0'
24
- type: :development
24
+ type: :runtime
25
25
  prerelease: false
26
26
  version_requirements: !ruby/object:Gem::Requirement
27
27
  requirements:
28
28
  - - ">="
29
29
  - !ruby/object:Gem::Version
30
30
  version: '0'
31
- - !ruby/object:Gem::Dependency
32
- name: rspec-rails
33
- requirement: !ruby/object:Gem::Requirement
34
- requirements:
35
- - - "~>"
36
- - !ruby/object:Gem::Version
37
- version: '4.0'
38
- type: :development
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- requirements:
42
- - - "~>"
43
- - !ruby/object:Gem::Version
44
- version: '4.0'
45
- - !ruby/object:Gem::Dependency
46
- name: sequel
47
- requirement: !ruby/object:Gem::Requirement
48
- requirements:
49
- - - ">="
50
- - !ruby/object:Gem::Version
51
- version: '0'
52
- type: :development
53
- prerelease: false
54
- version_requirements: !ruby/object:Gem::Requirement
55
- requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '0'
59
- - !ruby/object:Gem::Dependency
60
- name: sqlite3
61
- requirement: !ruby/object:Gem::Requirement
62
- requirements:
63
- - - "~>"
64
- - !ruby/object:Gem::Version
65
- version: 1.3.6
66
- type: :development
67
- prerelease: false
68
- version_requirements: !ruby/object:Gem::Requirement
69
- requirements:
70
- - - "~>"
71
- - !ruby/object:Gem::Version
72
- version: 1.3.6
73
- description: "\n Inspired by the simplicity of Fitter Happier, but frustrated by
74
- its lack of\n flexibility, we built OK Computer. Create and register your own
75
- custom\n health checks, or choose from the built-in library of checks to ensure
76
- your\n app is working as intended.\n "
31
+ description: Inspired by the simplicity of Fitter Happier, but frustrated by its lack
32
+ of flexibility, we built OkComputer. Create and register your own custom health
33
+ checks, or choose from the built-in library of checks to ensure your app is working
34
+ as intended.
77
35
  email:
78
36
  - code@patrickbyrne.net
79
37
  - anfleene@gmail.com
@@ -95,6 +53,7 @@ files:
95
53
  - lib/ok_computer/built_in_checks/active_record_migrations_check.rb
96
54
  - lib/ok_computer/built_in_checks/app_version_check.rb
97
55
  - lib/ok_computer/built_in_checks/cache_check.rb
56
+ - lib/ok_computer/built_in_checks/cache_check_solid_cache.rb
98
57
  - lib/ok_computer/built_in_checks/default_check.rb
99
58
  - lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb
100
59
  - lib/ok_computer/built_in_checks/directory_check.rb
@@ -129,6 +88,7 @@ homepage: https://github.com/emmahsax/okcomputer
129
88
  licenses:
130
89
  - MIT
131
90
  metadata:
91
+ homepage_uri: https://github.com/emmahsax/okcomputer
132
92
  bug_tracker_uri: https://github.com/emmahsax/okcomputer/issues
133
93
  changelog_uri: https://github.com/emmahsax/okcomputer/blob/main/CHANGELOG.markdown
134
94
  source_code_uri: https://github.com/emmahsax/okcomputer
@@ -140,14 +100,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
100
  requirements:
141
101
  - - ">="
142
102
  - !ruby/object:Gem::Version
143
- version: '0'
103
+ version: '2.1'
144
104
  required_rubygems_version: !ruby/object:Gem::Requirement
145
105
  requirements:
146
106
  - - ">="
147
107
  - !ruby/object:Gem::Version
148
108
  version: '0'
149
109
  requirements: []
150
- rubygems_version: 3.4.5
110
+ rubygems_version: 3.5.22
151
111
  signing_key:
152
112
  specification_version: 4
153
113
  summary: A simple, extensible health-check monitor