okcomputer 1.18.6 → 1.19.0

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: 834e3e304e55f2824d48769656b7fbfda10219d176d23fc445adfeaef01aaca8
4
+ data.tar.gz: 958d4a30a4a391f31734713f56dea8b492b7952b53bb7f339aa168a8e37d133f
5
5
  SHA512:
6
- metadata.gz: 4abc303ee824b255cd9f087b109b9420a1e06dbc2f5fcd35d11dd6c4ebb3538ac6c79f08d2fd7e04ff4209e6bb8741f53986680ea3578a70ddc18562b0a16015
7
- data.tar.gz: 48bb60d5dcded343a640272958eba7ebb38cb2a519b084969979e3a9ea8df680dfdbe2591640a8fd5577918cad20e9712db86e88e764da2b30472edff56a4827
6
+ metadata.gz: 64d45f7f723099e15f7fc54e305029c6893a16e81fdd1ac353343d0be1b8f3ee7a33c412591dd343c6ddc84c9495ae85bb79ad742804019ba0e627e8dffddae0
7
+ data.tar.gz: 92429b914eff4069011dfd05aeba9b4ab725816b1f43ceb0b16b1f4e6c12894776d0e0475afe2f75fdf29539d1b7d9047d37a9c42708f6b5bf385a9f6d2c0029
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,38 @@ 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.0
30
+ * 7.2
31
+ * 7.1
32
+ * 5.0
33
+ * 4.1
34
+ * 4.0
29
35
 
30
- [Grape]:https://github.com/ruby-grape/grape
31
- [okcomputer-grape]:https://github.com/bellycard/okcomputer-grape
36
+ #### Not using Rails?
37
+
38
+ If you use [Grape](https://github.com/ruby-grape/grape) instead of Rails, check out [okcomputer-grape](https://github.com/bellycard/okcomputer-grape).
32
39
 
33
40
  ## Installation
34
41
 
35
42
  Add this line to your application's Gemfile:
36
43
 
37
- gem 'okcomputer'
44
+ ```ruby
45
+ gem 'okcomputer'
46
+ ```
38
47
 
39
48
  And then execute:
40
49
 
41
- $ bundle
50
+ ```
51
+ $ bundle
52
+ ```
42
53
 
43
54
  Or install it yourself as:
44
55
 
45
- $ gem install okcomputer
56
+ ```
57
+ $ gem install okcomputer
58
+ ```
46
59
 
47
60
  ## Usage
48
61
 
@@ -86,7 +99,7 @@ you can configure it with:
86
99
 
87
100
  ```ruby
88
101
  # config/initializers/okcomputer.rb
89
- OkComputer.mount_at = 'health_checks' # mounts at /health_checks
102
+ OkComputer.mount_at = 'health_checks' # Mounts at /health_checks
90
103
  ```
91
104
 
92
105
  For more control of adding OkComputer to your routes, set `OkComputer.mount_at
@@ -109,7 +122,7 @@ Log check results by setting `OkComputer.logger`. Note: results will be logged a
109
122
  OkComputer.logger = Rails.logger
110
123
  ```
111
124
 
112
- ```sh
125
+ ```
113
126
  [okcomputer] mycheck: PASSED mymessage (0s)
114
127
  ```
115
128
 
@@ -124,6 +137,9 @@ OkComputer::Registry.register "resque_backed_up", OkComputer::ResqueBackedUpChec
124
137
 
125
138
  # This check works on 2.4.0 and above versions of resque-scheduler
126
139
  OkComputer::Registry.register "resque_scheduler_down", OkComputer::ResqueSchedulerCheck.new
140
+
141
+ # If you're using SolidCache instead of Memcached, use this check instead of CacheCheck
142
+ OkComputer::Registry.register "cache", OkComputer::CacheCheckSolidCache.new
127
143
  ```
128
144
 
129
145
  ### Registering Custom Checks
@@ -168,9 +184,7 @@ This check will run and report its status, but will not affect the HTTP status c
168
184
  The plain-text output flows through Rails' internationalization framework.
169
185
  Adjust the output as necessary by defining `okcomputer.check.passed` and
170
186
  `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
187
+ [in `okcomputer.en.yml`](https://github.com/emmahsax/okcomputer/blob/main/config/locales/okcomputer.en.yml).
174
188
 
175
189
  ## Running checks in parallel
176
190
 
@@ -198,7 +212,7 @@ as it will start to artificially bring your request time down.
198
212
 
199
213
  If you'd like to intentionally count OkComputer requests in your NewRelic analytics, set:
200
214
 
201
- ```
215
+ ```ruby
202
216
  # config/initializers/okcomputer.rb
203
217
  OkComputer.analytics_ignore = false
204
218
  ```
@@ -207,7 +221,7 @@ OkComputer.analytics_ignore = false
207
221
 
208
222
  ### Setup
209
223
 
210
- ```plaintext
224
+ ```
211
225
  $ bundle install
212
226
  ```
213
227
 
@@ -217,7 +231,7 @@ OkComputer tests are written with [RSpec](http://rspec.info/).
217
231
 
218
232
  To run the full test suite:
219
233
 
220
- ```plaintext
234
+ ```
221
235
  $ rake spec
222
236
  ```
223
237
 
@@ -227,10 +241,17 @@ bundle and run the tests with a specific version of Rails.
227
241
 
228
242
  ## Contributing
229
243
 
230
- 1. Fork it
244
+ 1. Fork this repository
231
245
  2. Create your feature branch (`git checkout -b my-new-feature`)
232
246
  3. Commit your changes (`git commit -am 'Add some feature'`)
233
247
  4. Push to the branch (`git push origin my-new-feature`)
234
- 5. Create new Pull Request
248
+ 5. Create a new pull request on upstream (this repository)
249
+ 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
250
+
251
+ ## Releasing
235
252
 
236
- [fitter-happier]:https://rubygems.org/gems/fitter-happier
253
+ 1. Ensure you have push permissions to [RubyGems](https://rubygems.org/gems/okcomputer)
254
+ 2. Merge all PRs so that `main` is up to date with the new version
255
+ 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
256
+ 4. Ensure you're on the `main` branch and you are locally up to date (`git checkout main && git pull`)
257
+ 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.0'
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.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick Byrne
@@ -12,68 +12,12 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2025-01-06 00:00:00.000000000 Z
16
- dependencies:
17
- - !ruby/object:Gem::Dependency
18
- name: coveralls
19
- requirement: !ruby/object:Gem::Requirement
20
- requirements:
21
- - - ">="
22
- - !ruby/object:Gem::Version
23
- version: '0'
24
- type: :development
25
- prerelease: false
26
- version_requirements: !ruby/object:Gem::Requirement
27
- requirements:
28
- - - ">="
29
- - !ruby/object:Gem::Version
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 "
15
+ date: 2025-02-11 00:00:00.000000000 Z
16
+ dependencies: []
17
+ description: Inspired by the simplicity of Fitter Happier, but frustrated by its lack
18
+ of flexibility, we built OkComputer. Create and register your own custom health
19
+ checks, or choose from the built-in library of checks to ensure your app is working
20
+ as intended.
77
21
  email:
78
22
  - code@patrickbyrne.net
79
23
  - anfleene@gmail.com
@@ -95,6 +39,7 @@ files:
95
39
  - lib/ok_computer/built_in_checks/active_record_migrations_check.rb
96
40
  - lib/ok_computer/built_in_checks/app_version_check.rb
97
41
  - lib/ok_computer/built_in_checks/cache_check.rb
42
+ - lib/ok_computer/built_in_checks/cache_check_solid_cache.rb
98
43
  - lib/ok_computer/built_in_checks/default_check.rb
99
44
  - lib/ok_computer/built_in_checks/delayed_job_backed_up_check.rb
100
45
  - lib/ok_computer/built_in_checks/directory_check.rb
@@ -140,14 +85,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
140
85
  requirements:
141
86
  - - ">="
142
87
  - !ruby/object:Gem::Version
143
- version: '0'
88
+ version: '2.1'
144
89
  required_rubygems_version: !ruby/object:Gem::Requirement
145
90
  requirements:
146
91
  - - ">="
147
92
  - !ruby/object:Gem::Version
148
93
  version: '0'
149
94
  requirements: []
150
- rubygems_version: 3.4.5
95
+ rubygems_version: 3.5.22
151
96
  signing_key:
152
97
  specification_version: 4
153
98
  summary: A simple, extensible health-check monitor