cronitor 5.1.0 → 5.2.0

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: ac1824833468d92068ba5664ef8d667fbe2518b34caa8da2cae3a307a7a923e7
4
- data.tar.gz: 18ff6d1f48bd6da9686930585b6eaab3d296caedb33c171a5d668c26b69fdaba
3
+ metadata.gz: 55b057acd03a6a25b77974f2834d1f9d0a745e94089b5a8f1a7b19b74cdbd291
4
+ data.tar.gz: 6eea2063baf3f2a31a4f67ee27d419b70ac94127f18216fb5dcc555d042a8bc6
5
5
  SHA512:
6
- metadata.gz: 3d6e6aeaaaf3c0a8e5942132e833f53169756717dfa49d52d6641dc0a644f470cac6cc2124fdaebf12fb7814b485f9a14753c78a2a059541b94662c9127279a7
7
- data.tar.gz: e2d4da41d199b4ff8c01fa768f69f0a48303c98559a2766f537b0a25f6940df21c0ecd2c94d4318636623f230cd8ff7976b75a3219ece9cae419b6eafa8b10ff
6
+ metadata.gz: c88b28e6b24c779f522b93e6dd6a6b57da6bc7df615d393b3dec35f76c7577d5b5cf0710a0d8e54b5f73f88210543426362eee35fe0641f8c63aa63ff40f3331
7
+ data.tar.gz: f20d7064b7dde42ec30c6ee46bbeb7fa38323e17053737cc2fe127257aaf74e6a4ee67850bd77be4eb5d2f4454e2665f1e01a4141b2b424d0958be97f6dd2bd4
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
 
@@ -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,38 +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
 
141
+ # Define monitors as an array of hashes
135
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
- },
153
+ request: { url: 'https://cronitor.io' },
151
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
  ]
158
161
 
159
- Cronitor::Monitor.put(monitors)
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)
160
172
  ```
161
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
+
162
191
  ### Pause, Reset, Delete
163
192
 
164
193
  ```ruby
@@ -9,20 +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, :auto_discover_sidekiq
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)
25
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')
26
28
  self.logger = Logger.new($stdout)
27
29
  logger.level = Logger::INFO
28
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.1.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.1.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: 2023-03-14 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: []