circactivator 2.1.0 → 2.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
  SHA1:
3
- metadata.gz: efdaba283fa698f59a208157f064907b9e105c22
4
- data.tar.gz: a5050fe21799adfc191ad3425992d13718ee95cb
3
+ metadata.gz: 7ed95230a086d93a38c5d556f9a93888de6f145e
4
+ data.tar.gz: 1f7a81e4dc8fd9b277c5f435d55a7569b295ab32
5
5
  SHA512:
6
- metadata.gz: e3c5ac1e765dd68bc27f01251dfeec75f690bcf954f3dafc950a41246800940116030652f6f94f1a308e2dd9ae06f991ac7e6f5585aaec62d51ad8e4bfd4241a
7
- data.tar.gz: 2bcc98f08a5db48d5c220948ac3359cbfdbbdccedfdb95d4677e3bbec6f43f20c03564452eb33765e2c70d0bae557be1a99ca1b9df8657ebfce04c364dc67611
6
+ metadata.gz: 2227f9e39cf93fc7d4d92158fe78ae854a898f930b073e6d5302436e5931b65a7292d986f925b4ad90e945d272f45c66378a1fc85ae1bb1205f945dfdc01e1b3
7
+ data.tar.gz: eed823bf909864f64cf974ae22883b222c285c97c0a1a0f04f2125cf7704dd4b8a01e9c25553bde61bacae06e28d5b7bbc2c085a7235efa55cbaf80caffe12b8
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- circactivator (2.0.1)
4
+ circactivator (2.2.0)
5
5
  httparty (~> 0.13.3)
6
6
  mixlib-log (~> 1.6.0)
7
7
  settingslogic (~> 2.0.9)
data/README.md CHANGED
@@ -53,6 +53,8 @@ circonus:
53
53
  base_url: https://api.circonus.com/v2
54
54
  api_key: your-api-key-here
55
55
  api_app_name: circactivator
56
+ verify: false
57
+ attempts: 3
56
58
 
57
59
  monitoring:
58
60
  error_file: /path/to/log/file/circactivator.err
@@ -72,7 +74,7 @@ The `log` section of the config sets up the log file CircActivator uses to log i
72
74
 
73
75
  ### Circonus
74
76
 
75
- The `circonus` section of the config specifies which Circonus instance to use (which is especially useful if you are a Circonus Inside customer) and your API key and app name. See https://login.circonus.com/resources/api#authentication for more information.
77
+ The `circonus` section of the config specifies which Circonus instance to use (which is especially useful if you are a Circonus Inside customer) and your API key and app name. See https://login.circonus.com/resources/api#authentication for more information. Additionally, you may disable SSL validation with the `verify: false` config item (in the event you're running a Circonus Inside system using an untrusted CA), and how many times CircActivator will try an API call upon failure or timeout (defaults to 3).
76
78
 
77
79
  ### Monitoring
78
80
 
@@ -44,11 +44,33 @@ module CircActivator
44
44
  end
45
45
 
46
46
  def fetch
47
- response = HTTParty.get(url + '?query_broker=1', headers: http_headers, verify: false)
48
- raise_exceptions!(response)
47
+ response = call_circonus(:get, url + '?query_broker=1')
49
48
  @check_bundle = JSON.load(response.body)
50
49
  end
51
50
 
51
+ def update
52
+ response = call_circonus(:put, url, body: payload_hash.to_json)
53
+ end
54
+
55
+ def call_circonus(method, url, options={})
56
+ options[:headers] = http_headers
57
+ options[:verify] = CircActivator::Config.circonus.fetch('verify', true)
58
+
59
+ attempt = 0
60
+ begin
61
+ attempt += 1
62
+ response = HTTParty.send(method, url, options)
63
+ raise_exceptions!(response)
64
+ rescue Net::OpenTimeout, Net::ReadTimeout, CircActivator::Exception::CirconusError
65
+ raise if attempt >= attempts
66
+ retry
67
+ rescue CircActivator::Exception::CheckNotFound
68
+ raise
69
+ end
70
+
71
+ response
72
+ end
73
+
52
74
  def activate_metrics
53
75
  return if @check_bundle['metrics'].nil?
54
76
  updated_metrics = Array.new
@@ -65,11 +87,6 @@ module CircActivator
65
87
  @check_bundle.select { |k,v| k =~ /brokers|config|display_name|metrics|notes|period|status|tags|target|timeout|type/ }
66
88
  end
67
89
 
68
- def update
69
- response = HTTParty.put(url, headers: http_headers, body: payload_hash.to_json, verify: false)
70
- raise_exceptions!(response)
71
- end
72
-
73
90
  def raise_exceptions!(response)
74
91
  case response.code.to_s
75
92
  when /^2/
@@ -85,9 +102,15 @@ module CircActivator
85
102
  def run(logging=false)
86
103
  fetch
87
104
  updated_metrics = activate_metrics
88
- update
105
+ update if updated_metrics.length > 0
89
106
 
90
107
  updated_metrics
91
108
  end
109
+
110
+ private
111
+
112
+ def attempts
113
+ CircActivator::Config.circonus['attempts'] || 3
114
+ end
92
115
  end
93
116
  end
@@ -17,5 +17,5 @@
17
17
  #
18
18
 
19
19
  module CircActivator
20
- VERSION = '2.1.0'
20
+ VERSION = '2.2.0'
21
21
  end
@@ -125,14 +125,24 @@ describe CircActivator::CheckUpdater do
125
125
  @checkupdater.run
126
126
  end
127
127
 
128
- it "#run does not debug log if logging is disabled (disabled by default)" do
129
- expect(CircActivator::Log).to_not receive(:debug)
130
- @checkupdater.run
128
+ it 'retries the HTTP call in the event of a server failure' do
129
+ bad_response = double('bad_response', code: 500, body: 'server error')
130
+ good_response = double('good_response', code: 200, body: 'check data')
131
+
132
+ expect(HTTParty).to receive(:get).twice.and_return(bad_response, good_response)
133
+ @checkupdater.call_circonus(:get, '/test-url')
134
+ end
135
+
136
+ it 'raises an error after attempts exceeded' do
137
+ response = double('response', code: 500, body: 'server error')
138
+ expect(HTTParty).to receive(:get).exactly(3).times.and_return(response)
139
+ expect { @checkupdater.call_circonus(:get, '/test-url') }.to raise_error(CircActivator::Exception::CirconusError)
131
140
  end
132
141
 
133
- it '#run debug logs when logging is enabled' do
134
- expect(CircActivator::Log).to receive(:debug).exactly(3).times
135
- @checkupdater.run(logging=true)
142
+ it 'does not retry on a 404' do
143
+ response = double('response', code: 404)
144
+ expect(HTTParty).to receive(:get).once.and_return(response)
145
+ expect { @checkupdater.call_circonus(:get, '/test-url') }.to raise_error(CircActivator::Exception::CheckNotFound)
136
146
  end
137
147
  end
138
148
  end
@@ -1,5 +1,5 @@
1
1
  log:
2
- file: /Users/adam/tmp/circactivator.log
2
+ file: log/circactivator.log
3
3
  level: debug
4
4
  count: 7
5
5
 
@@ -7,9 +7,11 @@ circonus:
7
7
  base_url: https://api.circonus.com/v2
8
8
  api_key: a12345
9
9
  api_app_name: my_app
10
+ verify: false
11
+ attempts: 3
10
12
 
11
13
  monitoring:
12
- error_file: /Users/adam/tmp/circactivator.err
14
+ error_file: log/circactivator.err
13
15
 
14
16
  check_bundles:
15
17
  iad1-prod:
@@ -17,4 +19,4 @@ check_bundles:
17
19
  2: api-web
18
20
  iad1-nonprod:
19
21
  3: .*
20
- 4: .*
22
+ 4: .*
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: circactivator
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0
4
+ version: 2.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Leff
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-30 00:00:00.000000000 Z
11
+ date: 2015-05-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: httparty