cronitor 5.0.0 → 5.2.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: 1c33ade0ff17f4941318a1483b1255556d2b5d7b3c89c41fa70ffb9d6bc05a4b
4
- data.tar.gz: 2e2c69fe75cf72f65964d59994a3dce7e58266449bd21be76428b4c1f32d354a
3
+ metadata.gz: 55b057acd03a6a25b77974f2834d1f9d0a745e94089b5a8f1a7b19b74cdbd291
4
+ data.tar.gz: 6eea2063baf3f2a31a4f67ee27d419b70ac94127f18216fb5dcc555d042a8bc6
5
5
  SHA512:
6
- metadata.gz: 98a47cd2ded8d3661ea8527b4dfd4b457b6b6d92ed101fac6f58e5d43eb791564b7f074dbfed5019036f9b1a01ed3f6f0687d8bbd90c5c19f3a7cf21cbe5d5d0
7
- data.tar.gz: f69e2de58e9cfa009e4255c6613e5338d68babdac5bd3848e9b1aea8ee4e6411694750b4e933dadaa447a0033b51f4ef120801e5305f704785c7bfedb4ce79ee
6
+ metadata.gz: c88b28e6b24c779f522b93e6dd6a6b57da6bc7df615d393b3dec35f76c7577d5b5cf0710a0d8e54b5f73f88210543426362eee35fe0641f8c63aa63ff40f3331
7
+ data.tar.gz: f20d7064b7dde42ec30c6ee46bbeb7fa38323e17053737cc2fe127257aaf74e6a4ee67850bd77be4eb5d2f4454e2665f1e01a4141b2b424d0958be97f6dd2bd4
@@ -15,15 +15,14 @@ jobs:
15
15
  runs-on: ubuntu-latest
16
16
 
17
17
  steps:
18
- - uses: actions/checkout@v2
19
- - name: Set up Ruby 2.7
20
- uses: actions/setup-ruby@v1
18
+ - uses: actions/checkout@v3
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
21
  with:
22
- ruby-version: 2.7.x
22
+ ruby-version: 2.7
23
+ bundler-cache: true
23
24
  - name: Build and test with Rake
24
25
  run: |
25
- gem install bundler
26
- bundle install --jobs 4 --retry 3
27
26
  bundle exec rake release
28
27
  with:
29
28
  api_key: ${{secrets.RUBYGEMS_API_KEY}}
@@ -10,25 +10,25 @@ on:
10
10
  - master
11
11
 
12
12
  jobs:
13
- lint:
14
- strategy:
15
- fail-fast: false
16
- matrix:
17
- ruby:
18
- - '2.7'
19
- - '3.0'
13
+ # lint:
14
+ # strategy:
15
+ # fail-fast: false
16
+ # matrix:
17
+ # ruby:
18
+ # - '2.7'
19
+ # - '3.0'
20
20
 
21
- runs-on: ubuntu-latest
21
+ # runs-on: ubuntu-latest
22
22
 
23
- steps:
24
- - uses: actions/checkout@v2
25
- - name: Set up Ruby 2.7
26
- uses: ruby/setup-ruby@v1
27
- with:
28
- ruby-version: ${{ matrix.ruby }}
29
- bundler-cache: true
30
- - name: Run Rubocop
31
- run: bundle exec rake rubocop
23
+ # steps:
24
+ # - uses: actions/checkout@v2
25
+ # - name: Set up Ruby 2.7
26
+ # uses: ruby/setup-ruby@v1
27
+ # with:
28
+ # ruby-version: ${{ matrix.ruby }}
29
+ # bundler-cache: true
30
+ # - name: Run Rubocop
31
+ # run: bundle exec rake rubocop
32
32
 
33
33
  spec:
34
34
  strategy:
@@ -37,18 +37,18 @@ jobs:
37
37
  ruby:
38
38
  - '2.7'
39
39
  - '3.0'
40
+ - '3.1'
41
+ - '3.2'
40
42
 
41
43
  runs-on: ubuntu-latest
42
44
 
43
45
  steps:
44
- - uses: actions/checkout@v2
45
- - name: Set up Ruby 2.7
46
+ - uses: actions/checkout@v3
47
+ - name: Set up Ruby
46
48
  uses: ruby/setup-ruby@v1
47
49
  with:
48
50
  ruby-version: ${{ matrix.ruby }}
49
51
  bundler-cache: true
50
52
  - name: Build and test with Rake
51
53
  run: |
52
- gem install bundler
53
- bundle install --jobs 4 --retry 3
54
54
  bundle exec rake
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Cronitor Ruby Library
2
2
 
3
- ![Test](https://github.com/cronitorio/cronitor-ruby/workflows/Test/badge.svg)
3
+ ![Tests](https://github.com/cronitorio/cronitor-ruby/workflows/Test/badge.svg)
4
4
  [![Gem Version](https://badge.fury.io/rb/cronitor.svg)](https://badge.fury.io/rb/cronitor)
5
5
 
6
6
 
@@ -29,8 +29,8 @@ The `Cronitor#job` helper will send telemetry events before calling your block a
29
29
  require 'cronitor'
30
30
  Cronitor.api_key = 'api_key_123'
31
31
 
32
- Cronitor.job 'warehouse-replenishmenth-report' do
33
- ReplenishmentReport.new(Date.today).run()
32
+ Cronitor.job 'important-job' do
33
+ ImportantJob.new(Date.today).run()
34
34
  end
35
35
  ```
36
36
 
@@ -40,7 +40,7 @@ Cronitor provides a [separate library](https://github.com/cronitorio/cronitor-si
40
40
 
41
41
  ## Sending Telemetry Events
42
42
 
43
- If you want finer control over when/how [telemetry pings](https://cronitor.io/docs/telemetry-api) are sent,
43
+ If you want more control over when/how [telemetry pings](https://cronitor.io/docs/telemetry-api) are sent,
44
44
  you can instantiate a monitor and call `#ping`.
45
45
 
46
46
  ```ruby
@@ -62,6 +62,8 @@ monitor.ping(state: 'complete', metrics: {count: 1000, error_count: 17})
62
62
 
63
63
  ## Configuring Monitors
64
64
 
65
+ ### Using a YAML configuration file
66
+
65
67
  You can configure all of your monitors using a single YAML file. This can be version controlled and synced to Cronitor as part of
66
68
  a deployment or build process. For details on all of the attributes that can be set, see the [Monitor API](https://cronitor.io/docs/monitor-api) documentation.
67
69
 
@@ -127,36 +129,65 @@ heartbeats:
127
129
 
128
130
  ```
129
131
 
130
- You can also create and update monitors by calling `Monitor.put`.
132
+ ### Using `Cronitor::Monitor.put`
133
+
134
+ You can also create and update monitors by calling `Cronitor::Monitor.put`. This method can handle multiple monitors at once and supports various configurations and options.
135
+
131
136
 
137
+ #### Usage
132
138
  ```ruby
133
139
  require 'cronitor'
134
140
 
135
- monitors = Cronitor::Monitor.put([
141
+ # Define monitors as an array of hashes
142
+ monitors = [
136
143
  {
137
144
  type: 'job',
138
145
  key: 'send-customer-invoices',
139
146
  schedule: '0 0 * * *',
140
- assertions: [
141
- 'metric.duration < 5 min'
142
- ],
147
+ assertions: ['metric.duration < 5 min'],
143
148
  notify: ['devops-alerts-slack']
144
149
  },
145
150
  {
146
151
  type: 'check',
147
152
  key: 'Cronitor Homepage',
148
- request: {
149
- url: 'https://cronitor.io'
150
- },
151
- schedule: 'every 45 seconds',
153
+ request: { url: 'https://cronitor.io' },
154
+ schedule: 'every 60 seconds',
152
155
  assertions: [
153
- 'response.code = 200',
154
- 'response.time < 600ms',
156
+ 'response.code = 200',
157
+ 'response.time < 600ms'
155
158
  ]
156
159
  }
157
- ])
160
+ ]
161
+
162
+ # Options hash with monitors array
163
+ options = {
164
+ monitors: monitors,
165
+ format: 'json', # Optional, can be 'json' or 'yaml'
166
+ rollback: false, # Optional, default is false
167
+ timeout: 10 # Optional, specify request timeout in seconds
168
+ }
169
+
170
+ # Create or update monitors
171
+ Cronitor::Monitor.put(options)
158
172
  ```
159
173
 
174
+ #### Parameters
175
+ - `monitors`: An array of monitor configuration hashes.
176
+ - `options`: A hash containing:
177
+ - `:monitors`: An array of monitor hashes (required).
178
+ - `:format`: String, format of the request ('json' or 'yaml'). Default is 'json'.
179
+ - `:rollback`: Boolean, indicates whether to rollback on failure. Default is `false`.
180
+ - `:timeout`: Integer, request timeout in seconds. Falls back to `Cronitor.timeout` if not specified.
181
+
182
+ #### Return Value
183
+ Depending on the `:format` option, this method returns:
184
+ - For JSON: An array of `Cronitor::Monitor` instances or a single instance if only one monitor is provided.
185
+ - For YAML: The parsed response body.
186
+
187
+ #### Error Handling
188
+ - `ValidationError`: Raised when the API returns a 400 status code, indicating invalid monitor configurations.
189
+ - `Error`: Raised for other non-successful responses, indicating issues with connecting to the Cronitor API.
190
+
160
191
  ### Pause, Reset, Delete
161
192
 
162
193
  ```ruby
@@ -9,19 +9,22 @@ module Cronitor
9
9
  YAML_KEYS = MONITOR_TYPES.map { |t| "#{t}s" }
10
10
 
11
11
  class << self
12
- attr_accessor :api_key, :api_version, :environment, :logger, :config, :timeout, :ping_timeout
12
+ attr_accessor :api_key, :api_version, :environment, :logger, :config, :timeout, :ping_timeout, :auto_discover_sidekiq, :telemetry_domain
13
13
 
14
14
  def configure(&block)
15
15
  block.call(self)
16
16
  end
17
+
17
18
  end
18
19
 
19
20
  self.api_key = ENV.fetch('CRONITOR_API_KEY', nil)
20
21
  self.api_version = ENV.fetch('CRONITOR_API_VERSION', nil)
21
22
  self.environment = ENV.fetch('CRONITOR_ENVIRONMENT', nil)
22
- self.timeout = ENV.fetch('CRONITOR_TIMEOUT', nil) || 10
23
- self.ping_timeout = ENV.fetch('CRONITOR_PING_TIMEOUT', nil) || 5
23
+ self.timeout = ENV.fetch('CRONITOR_TIMEOUT', 10)
24
+ self.ping_timeout = ENV.fetch('CRONITOR_PING_TIMEOUT', 5)
24
25
  self.config = ENV.fetch('CRONITOR_CONFIG', nil)
26
+ self.auto_discover_sidekiq = ENV.fetch('CRONITOR_AUTO_DISCOVER_SIDEKIQ', 'true').casecmp('true').zero? # https://github.com/cronitorio/cronitor-sidekiq
27
+ self.telemetry_domain = ENV.fetch('CRONITOR_TELEMETRY_DOMAIN', 'cronitor.link')
25
28
  self.logger = Logger.new($stdout)
26
29
  logger.level = Logger::INFO
27
30
  end
@@ -4,7 +4,7 @@ module Cronitor
4
4
  class Monitor
5
5
  attr_reader :key, :api_key, :api_version, :env
6
6
 
7
- PING_RETRY_THRESHOLD = 5
7
+ PING_RETRY_THRESHOLD = 3
8
8
 
9
9
  module Formats
10
10
  ALL = [
@@ -24,19 +24,19 @@ module Cronitor
24
24
  })
25
25
  end
26
26
 
27
+
27
28
  def self.put(opts = {})
28
29
  rollback = opts[:rollback] || false
29
30
  opts.delete(:rollback)
30
31
 
31
32
  monitors = opts[:monitors] || [opts]
32
-
33
+ url = "https://cronitor.io/api/monitors"
33
34
  if opts[:format] == Cronitor::Monitor::Formats::YAML
34
- url = "#{Cronitor.monitor_api_url}.yaml"
35
+ url = "#{url}.yaml"
35
36
  monitors['rollback'] = true if rollback
36
37
  body = YAML.dump(monitors)
37
38
  headers = Cronitor::Monitor::Headers::YAML
38
39
  else
39
- url = Cronitor.monitor_api_url
40
40
  body = {
41
41
  monitors: monitors,
42
42
  rollback: rollback
@@ -120,8 +120,7 @@ module Cronitor
120
120
 
121
121
  begin
122
122
  ping_url = ping_api_url
123
- ping_url = fallback_ping_api_url if retry_count > (PING_RETRY_THRESHOLD / 2)
124
-
123
+ ping_url = fallback_ping_api_url if retry_count > Monitor::PING_RETRY_THRESHOLD
125
124
  response = HTTParty.get(
126
125
  ping_url,
127
126
  query: clean_params(params),
@@ -159,7 +158,7 @@ module Cronitor
159
158
  end
160
159
 
161
160
  def pause(hours = nil)
162
- pause_url = "#{monitor_api_url}/pause"
161
+ pause_url = "#{monitor_api_url}/#{key}/pause"
163
162
  pause_url += "/#{hours}" unless hours.nil?
164
163
 
165
164
  resp = HTTParty.get(
@@ -180,7 +179,7 @@ module Cronitor
180
179
  end
181
180
 
182
181
  def ping_api_url
183
- "https://cronitor.link/p/#{api_key}/#{key}"
182
+ "https://#{Cronitor.telemetry_domain}/p/#{api_key}/#{key}"
184
183
  end
185
184
 
186
185
  def fallback_ping_api_url
@@ -188,9 +187,10 @@ module Cronitor
188
187
  end
189
188
 
190
189
  def monitor_api_url
191
- "#{Cronitor.monitor_api_url}/#{key}"
190
+ "https://cronitor.io/api/monitors"
192
191
  end
193
192
 
193
+
194
194
  private
195
195
 
196
196
  def fetch
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cronitor
4
- VERSION = '5.0.0'
4
+ VERSION = '5.2.0'
5
5
  end
data/lib/cronitor.rb CHANGED
@@ -63,9 +63,6 @@ module Cronitor
63
63
  end
64
64
  end
65
65
 
66
- def self.monitor_api_url
67
- 'https://cronitor.io/api/monitors'
68
- end
69
66
  end
70
67
 
71
68
  Cronitor.read_config(Cronitor.config) unless Cronitor.config.nil?
metadata CHANGED
@@ -1,15 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.0.0
4
+ version: 5.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Byrnes
8
8
  - August Flanagan
9
- autorequire:
9
+ autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2022-05-02 00:00:00.000000000 Z
12
+ date: 2024-02-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -165,7 +165,7 @@ dependencies:
165
165
  - - "~>"
166
166
  - !ruby/object:Gem::Version
167
167
  version: '3.1'
168
- description:
168
+ description:
169
169
  email:
170
170
  - thejeffbyrnes@gmail.com
171
171
  - august@cronitor.io
@@ -194,7 +194,7 @@ files:
194
194
  homepage: https://github.com/cronitorio/cronitor-ruby
195
195
  licenses: []
196
196
  metadata: {}
197
- post_install_message:
197
+ post_install_message:
198
198
  rdoc_options: []
199
199
  require_paths:
200
200
  - lib
@@ -209,8 +209,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
209
209
  - !ruby/object:Gem::Version
210
210
  version: '0'
211
211
  requirements: []
212
- rubygems_version: 3.1.4
213
- signing_key:
212
+ rubygems_version: 3.0.3.1
213
+ signing_key:
214
214
  specification_version: 4
215
215
  summary: An interface for the Cronitor API
216
216
  test_files: []