cronitor 4.0.0 → 4.1.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: 0d5c6dc2547c52ed2ccee489b2ea5428c6badd902f996ea076cd196e6c4bb1c3
4
- data.tar.gz: 57b37c91645625096fbe19004d181a6ed375517e02379b6d8365676c4d33839b
3
+ metadata.gz: d91bccffc3a53dfe487e4740c00aa83b47fe31c4347a1bdc93e017bbb3467751
4
+ data.tar.gz: 5730c8a4742bab773c1e3582fa4f00298890171e91ef96b83fda8e0a6ebd6470
5
5
  SHA512:
6
- metadata.gz: 349711cfbefe7cb0519e872862f9f54fd24d877850ac63714db59b62f4d7f7008bc39008fb74bca22eebb85c72d1e90e0fdf7c1a5fcb5ace205af63611440579
7
- data.tar.gz: 10e8d151d5bd52f464aa92dcd737f1e29354699b66832f17f977b5608b4716532406ba21ac0d83e439732abad9558f46feb0fc0037e06b7ce79169622a36a283
6
+ metadata.gz: '054173538e57d465de2cc25786a42ccdb80c2be0532f0526634153de3fd7c46f428cdeaded4dd84e6169a9aa5717439bab0b1b4cc9672b56b93543ae58183ae3'
7
+ data.tar.gz: 311901851f90644a7d0c46eeed1b2bd821880816090799d1601008e29fa19a4cad2199905f317a9a08225296d579ba054bc87456dadf19fe427f3487c0ac42ce
data/.rubocop.yml CHANGED
@@ -9,6 +9,7 @@ inherit_mode:
9
9
 
10
10
  AllCops:
11
11
  NewCops: enable
12
+ TargetRubyVersion: 2.5
12
13
  Exclude:
13
14
  - 'spec/cronitor_spec.rb'
14
15
 
data/README.md CHANGED
@@ -4,10 +4,17 @@
4
4
  [![Gem Version](https://badge.fury.io/rb/cronitor.svg)](https://badge.fury.io/rb/cronitor)
5
5
 
6
6
 
7
- [Cronitor](https://cronitor.io/) provides dead simple monitoring for cron jobs, daemons, data pipelines, queue workers, and anything else that can send or receive an HTTP request. The Cronitor Ruby library provides convenient access to the Cronitor API from applications written in Ruby.
7
+ [Cronitor](https://cronitor.io/) provides dead simple monitoring for cron jobs, daemons, queue workers, websites, APIs, and anything else that can send or receive an HTTP request. The Cronitor Ruby library provides convenient access to the Cronitor API from applications written in Ruby. See our [API docs](https://cronitor.io/docs/api) for detailed references on configuring monitors and sending telemetry pings.
8
8
 
9
- ## Documentation
10
- See our [API docs](https://cronitor.io/docs/api) for a detailed reference information about the APIs this library uses for configuring monitors and sending telemetry pings.
9
+ In this guide:
10
+
11
+ - [Installation](##Installation)
12
+ - [Monitoring Background Jobs](##monitoring-background-jobs)
13
+ - [Sending Telemetry Events](##sending-telemetry-events)
14
+ - [Configuring Monitors](##configuring-monitors)
15
+ - [Package Configuration & Env Vars](##package-configuration)
16
+ - [Command Line Usage](##command-line-usage)
17
+ - [Contributing](##contributing)
11
18
 
12
19
  ## Installation
13
20
 
@@ -15,49 +22,31 @@ See our [API docs](https://cronitor.io/docs/api) for a detailed reference inform
15
22
  gem install cronitor
16
23
  ```
17
24
 
18
- ## Usage
19
-
20
- The package needs to be configured with your account's `API key`, which is available on the [account settings](https://cronitor.io/settings) page. You can also optionally specify an `API Version` (default: account default) and `Environment` (default: account default).
21
-
22
- These can be supplied using the environment variables `CRONITOR_API_KEY`, `CRONITOR_API_VERSION`, `CRONITOR_ENVIRONMENT` or set directly on the cronitor object.
23
-
24
- ```ruby
25
- require 'cronitor'
26
-
27
- Cronitor.api_key = 'apiKey123'
28
- Cronitor.api_version = '2020-10-01'
29
- Cronitor.environment = 'staging'
30
- ```
31
-
32
- You can also use a YAML config file to manage all of your monitors (_see Create and Update Monitors section below_). The path to this file can be supplied using the enviroment variable `CRONITOR_CONFIG` or call `cronitor.read_config()`.
33
-
34
- ```ruby
35
- require 'cronitor'
36
-
37
- Cronitor.read_config('./path/to/cronitor.yaml')
38
- ```
39
-
25
+ ## Monitoring Background Jobs
40
26
 
41
- ### Monitor Any Block
42
-
43
- The quickest way to start using this library is to wrap a block of code with the `#job` helper. It will report the start time, end time, and exit state to Cronitor. If an exception is raised, the stack trace will be included in the failure message.
27
+ The `Cronitor#job` helper will send telemetry events before calling your block and after it exits. If your block raises an exception a `fail` event will be sent (and the exception re-raised).
44
28
 
45
29
  ```ruby
46
30
  require 'cronitor'
31
+ Cronitor.api_key = 'api_key_123'
47
32
 
48
33
  Cronitor.job 'warehouse-replenishmenth-report' do
49
34
  ReplenishmentReport.new(Date.today).run()
50
35
  end
51
36
  ```
52
37
 
53
- ### Sending Telemetry Events
38
+ ### Integrating with Sidekiq
39
+ Cronitor provides a [separate library](https://github.com/cronitorio/cronitor-sidekiq) built with this SDK to make Sidekiq integration even easier.
40
+
41
+
42
+ ## Sending Telemetry Events
54
43
 
55
44
  If you want finer control over when/how [telemetry pings](https://cronitor.io/docs/telemetry-api) are sent,
56
45
  you can instantiate a monitor and call `#ping`.
57
46
 
58
47
  ```ruby
59
48
  require 'cronitor'
60
-
49
+ Cronitor.api_key = 'api_key_123'
61
50
 
62
51
  monitor = Cronitor::Monitor.new('heartbeat-monitor')
63
52
 
@@ -72,57 +61,14 @@ monitor.ping(state: 'run', env: 'staging') # a job/process has started in a stag
72
61
  monitor.ping(state: 'complete', metrics: {count: 1000, error_count: 17})
73
62
  ```
74
63
 
75
- ### Pause, Reset, Delete
76
-
77
- ```ruby
78
- require 'cronitor'
79
-
80
- monitor = Cronitor::Monitor.new('heartbeat-monitor')
81
-
82
- monitor.pause(24) # pause alerting for 24 hours
83
- monitor.unpause # alias for .pause(0)
84
- monitor.ok # manually reset to a passing state alias for monitor.ping({state: ok})
85
- monitor.delete # destroy the monitor
86
- ```
87
-
88
- ## Create and Update Monitors
89
-
90
- You can create monitors programatically using the `Monitor` object.
91
- For details on all of the attributes that can be set see the [Monitor API](https://cronitor.io/docs/monitor-api) documentation.
92
-
93
-
94
- ```ruby
95
- require 'cronitor'
96
-
97
- monitors = Cronitor::Monitor.put([
98
- {
99
- type: 'job',
100
- key: 'send-customer-invoices',
101
- schedule: '0 0 * * *',
102
- assertions: [
103
- 'metric.duration < 5 min'
104
- ],
105
- notify: ['devops-alerts-slack']
106
- },
107
- {
108
- type: 'synthetic',
109
- key: 'Orders Api Uptime',
110
- schedule: 'every 45 seconds',
111
- assertions: [
112
- 'response.code = 200',
113
- 'response.time < 1.5s',
114
- 'response.json "open_orders" < 2000'
115
- ]
116
- }
117
- ])
118
- ```
64
+ ## Configuring Monitors
119
65
 
120
- You can also manage all of your monitors via a YAML config file.
121
- This can be version controlled and synced to Cronitor as part of
122
- a deployment process or system update.
66
+ You can configure all of your monitors using a single YAML file. This can be version controlled and synced to Cronitor as part of
67
+ 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.
123
68
 
124
69
  ```ruby
125
70
  require 'cronitor'
71
+ Cronitor.api_key = 'api_key_123'
126
72
 
127
73
  # read config file and set credentials (if included).
128
74
  Cronitor.read_config('./cronitor.yaml')
@@ -135,17 +81,9 @@ Cronitor.apply_config
135
81
  Cronitor.validate_config
136
82
  ```
137
83
 
138
-
139
- The `cronitor.yaml` file accepts the following attributes:
84
+ The `cronitor.yaml` file includes three top level keys `jobs`, `checks`, `events`. You can configure monitors under each key by defining [monitors](https://cronitor.io/docs/monitor-api#attributes).
140
85
 
141
86
  ```yaml
142
- api_key: 'optionally read Cronitor api_key from here'
143
- api_version: 'optionally read Cronitor api_version from here'
144
- environment: 'optionally set an environment for telemetry pings'
145
-
146
- # configure all of your monitors with type "job"
147
- # you may omit the type attribute and the key
148
- # of each object will be set as the monitor key
149
87
  jobs:
150
88
  nightly-database-backup:
151
89
  schedule: 0 0 * * *
@@ -160,8 +98,7 @@ jobs:
160
98
  - metric.count > 0
161
99
  - metric.duration < 30 seconds
162
100
 
163
- # configure all of your monitors with type "synthetic"
164
- synthetics:
101
+ check:
165
102
  cronitor-homepage:
166
103
  request:
167
104
  url: https://cronitor.io
@@ -180,7 +117,7 @@ synthetics:
180
117
  - response.body contains ok
181
118
  - response.time < .25s
182
119
 
183
- events:
120
+ heartbeats:
184
121
  production-deploy:
185
122
  notify:
186
123
  alerts: ['deploys-slack']
@@ -188,6 +125,61 @@ events:
188
125
 
189
126
  ```
190
127
 
128
+ You can also create and update monitors by calling `Monitor.put`.
129
+
130
+ ```ruby
131
+ require 'cronitor'
132
+
133
+ monitors = Cronitor::Monitor.put([
134
+ {
135
+ type: 'job',
136
+ key: 'send-customer-invoices',
137
+ schedule: '0 0 * * *',
138
+ assertions: [
139
+ 'metric.duration < 5 min'
140
+ ],
141
+ notify: ['devops-alerts-slack']
142
+ },
143
+ {
144
+ type: 'check',
145
+ key: 'Cronitor Homepage',
146
+ request: {
147
+ url: 'https://cronitor.io'
148
+ },
149
+ schedule: 'every 45 seconds',
150
+ assertions: [
151
+ 'response.code = 200',
152
+ 'response.time < 600ms',
153
+ ]
154
+ }
155
+ ])
156
+ ```
157
+
158
+ ### Pause, Reset, Delete
159
+
160
+ ```ruby
161
+ require 'cronitor'
162
+
163
+ monitor = Cronitor::Monitor.new('heartbeat-monitor')
164
+
165
+ monitor.pause(24) # pause alerting for 24 hours
166
+ monitor.unpause # alias for .pause(0)
167
+ monitor.ok # manually reset to a passing state alias for monitor.ping({state: ok})
168
+ monitor.delete # destroy the monitor
169
+ ```
170
+
171
+ ## Package Configuration
172
+
173
+ The package needs to be configured with your account's `API key`, which is available on the [account settings](https://cronitor.io/settings) page. You can also optionally specify an `api_version` and an `environment`. If not provided, your account default is used. These can also be supplied using the environment variables `CRONITOR_API_KEY`, `CRONITOR_API_VERSION`, `CRONITOR_ENVIRONMENT`.
174
+
175
+ ```ruby
176
+ require 'cronitor'
177
+
178
+ # your api keys can found here - https://cronitor.io/settings
179
+ Cronitor.api_key = 'apiKey123'
180
+ Cronitor.api_version = '2020-10-01'
181
+ Cronitor.environment = 'cluster_1_prod'
182
+ ```
191
183
 
192
184
  ## Contributing
193
185
 
@@ -227,4 +219,4 @@ Push to your fork and [submit a pull request]( https://github.com/cronitorio/cro
227
219
  The bump gem makes this easy:
228
220
 
229
221
  1. `rake bump:(major|minor|patch|pre)`
230
- 2. `rake release`
222
+ 2. `rake release`
data/cronitor.gemspec CHANGED
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  spec.summary = 'An interface for the Cronitor API'
14
14
  spec.homepage = 'https://github.com/cronitorio/cronitor-ruby'
15
15
 
16
- spec.required_ruby_version = '>= 2.4'
16
+ spec.required_ruby_version = '>= 2.5'
17
17
 
18
18
  spec.files = `git ls-files -z`.split("\x0").reject do |f|
19
19
  f.match(%r{^(test|spec|features)/})
@@ -2,9 +2,9 @@
2
2
 
3
3
  module Cronitor
4
4
  TYPE_JOB = 'job'
5
- TYPE_EVENT = 'event'
6
- TYPE_SYNTHETIC = 'synthetic'
7
- MONITOR_TYPES = [TYPE_JOB, TYPE_EVENT, TYPE_SYNTHETIC].freeze
5
+ TYPE_HEARTBEAT = 'heartbeat'
6
+ TYPE_CHECK = 'check'
7
+ MONITOR_TYPES = [TYPE_JOB, TYPE_HEARTBEAT, TYPE_CHECK].freeze
8
8
  YAML_KEYS = %w[
9
9
  api_key
10
10
  api_version
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Cronitor
4
- VERSION = '4.0.0'
4
+ VERSION = '4.1.0'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cronitor
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 4.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jeff Byrnes
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2021-01-22 00:00:00.000000000 Z
12
+ date: 2021-05-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: httparty
@@ -202,7 +202,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
202
202
  requirements:
203
203
  - - ">="
204
204
  - !ruby/object:Gem::Version
205
- version: '2.4'
205
+ version: '2.5'
206
206
  required_rubygems_version: !ruby/object:Gem::Requirement
207
207
  requirements:
208
208
  - - ">="