interferon 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: cf3a434f94d6e961434e2d3011613ff875c07e83
4
+ data.tar.gz: 56ed577469d6d97ea2a7798e12e7d0ab3f4e59a8
5
+ SHA512:
6
+ metadata.gz: eb304b434ad6417a9d8184bea6292bbbb80cf45edba557f34df78f7a6376bc58079257fcaa1f3d04f4826dadf991a608fed508f514a7a68d49b41295be5c46b5
7
+ data.tar.gz: dcd28c67b74e92a5c2a43f470ed4845a292a1d2915eeb2d7d3710e5868a17f858eeb298b42139f85c41b14408ee2882039d51d5270f011bc2b35c9d57e0e5ab0
@@ -1,3 +1,3 @@
1
1
  module Interferon
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/interferon.rb CHANGED
@@ -26,9 +26,14 @@ module Interferon
26
26
  @groups_sources = groups_sources
27
27
  @host_sources = host_sources
28
28
  @destinations = destinations
29
+ @request_shutdown = false
29
30
  end
30
31
 
31
32
  def run(dry_run = false)
33
+ Signal.trap("TERM") do
34
+ log.info "SIGTERM received. shutting down gracefully..."
35
+ @request_shutdown = true
36
+ end
32
37
  run_desc = dry_run ? 'dry run' : 'run'
33
38
  log.info "beginning alerts #{run_desc}"
34
39
 
@@ -44,7 +49,11 @@ module Interferon
44
49
 
45
50
  update_alerts(@destinations, hosts, alerts, groups)
46
51
 
47
- log.info "interferon #{run_desc} complete"
52
+ if @request_shutdown
53
+ log.info "interferon #{run_desc} shut down by SIGTERM"
54
+ else
55
+ log.info "interferon #{run_desc} complete"
56
+ end
48
57
  end
49
58
 
50
59
  def read_alerts
@@ -57,6 +66,7 @@ module Interferon
57
66
  unless Dir.exists?(path)
58
67
 
59
68
  Dir.glob(File.join(path, '*.rb')) do |alert_file|
69
+ break if @request_shutdown
60
70
  begin
61
71
  alert = Alert.new(alert_file)
62
72
  rescue StandardError => e
@@ -80,6 +90,7 @@ module Interferon
80
90
  groups = {}
81
91
  loader = GroupSourcesLoader.new([@alerts_repo_path])
82
92
  loader.get_all(sources).each do |source|
93
+ break if @request_shutdown
83
94
  source_groups = source.list_groups
84
95
 
85
96
  # add all people to groups
@@ -108,6 +119,7 @@ module Interferon
108
119
  hosts = []
109
120
  loader = HostSourcesLoader.new([@alerts_repo_path])
110
121
  loader.get_all(sources).each do |source|
122
+ break if @request_shutdown
111
123
  source_hosts = source.list_hosts
112
124
  hosts << source_hosts
113
125
 
@@ -124,6 +136,7 @@ module Interferon
124
136
  def update_alerts(destinations, hosts, alerts, groups)
125
137
  loader = DestinationsLoader.new([@alerts_repo_path])
126
138
  loader.get_all(destinations).each do |dest|
139
+ break if @request_shutdown
127
140
  log.info "updating alerts on #{dest.class.name}"
128
141
 
129
142
  # track some counters/stats per destination
@@ -136,6 +149,7 @@ module Interferon
136
149
  # create or update alerts; mark when we've done that
137
150
  alerts_queue = Hash.new
138
151
  alerts.each do |alert|
152
+ break if @request_shutdown
139
153
  counters = {
140
154
  :errors => 0,
141
155
  :evals => 0,
@@ -207,34 +221,43 @@ module Interferon
207
221
  # flush queue
208
222
  alerts_to_create = alerts_queue.keys
209
223
  concurrency = dest.concurrency || 10
210
- threads = concurrency.times.map do
211
- t = Thread.new do
212
- while name = alerts_to_create.shift
213
- cur_alert, people = alerts_queue[name]
214
-
215
- log.debug "creating alert for #{cur_alert[:name]}"
216
- alert_key = dest.create_alert(cur_alert, people)
217
-
218
- # don't delete alerts we still have defined
219
- existing_alerts[alert_key]['still_exists'] = true if existing_alerts.include?(alert_key)
224
+ unless @request_shutdown
225
+ threads = concurrency.times.map do |i|
226
+ log.info "thread #{i} created"
227
+ t = Thread.new do
228
+ while name = alerts_to_create.shift
229
+ break if @request_shutdown
230
+ cur_alert, people = alerts_queue[name]
231
+
232
+ log.debug "creating alert for #{cur_alert[:name]}"
233
+ alert_key = dest.create_alert(cur_alert, people)
234
+
235
+ # don't delete alerts we still have defined
236
+ existing_alerts[alert_key]['still_exists'] = true if existing_alerts.include?(alert_key)
237
+ end
220
238
  end
239
+ t.abort_on_exception = true
240
+ t
221
241
  end
222
- t.abort_on_exception = true
223
- t
242
+ threads.map(&:join)
224
243
  end
225
- threads.map(&:join)
226
244
 
227
245
  # remove existing alerts that shouldn't exist
228
246
  to_delete = existing_alerts.reject{ |key, existing_alert| existing_alert['still_exists'] }
229
- to_delete.each{ |key, alert| dest.remove_alert(alert) }
247
+ to_delete.each do |key, alert|
248
+ break if @request_shutdown
249
+ dest.remove_alert(alert)
250
+ end
230
251
 
231
- # run time summary
232
- run_time = Time.new.to_f - start_time
233
- statsd.histogram('destinations.run_time', run_time, :tags => ["destination:#{dest.class.name}"])
234
- log.info "#{dest.class.name} : run completed in %.2f seconds" % (run_time)
252
+ unless @request_shutdown
253
+ # run time summary
254
+ run_time = Time.new.to_f - start_time
255
+ statsd.histogram('destinations.run_time', run_time, :tags => ["destination:#{dest.class.name}"])
256
+ log.info "#{dest.class.name} : run completed in %.2f seconds" % (run_time)
235
257
 
236
- # report destination stats
237
- dest.report_stats
258
+ # report destination stats
259
+ dest.report_stats
260
+ end
238
261
  end
239
262
  end
240
263
  end
metadata CHANGED
@@ -1,86 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: interferon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.6
5
- prerelease:
4
+ version: 0.0.7
6
5
  platform: ruby
7
6
  authors:
8
7
  - Igor Serebryany
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2015-12-02 00:00:00.000000000 Z
11
+ date: 2016-01-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: dogapi
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
17
  - - ~>
20
18
  - !ruby/object:Gem::Version
21
19
  version: '1.11'
22
- - - ! '>='
20
+ - - '>='
23
21
  - !ruby/object:Gem::Version
24
22
  version: 1.11.1
25
23
  type: :runtime
26
24
  prerelease: false
27
25
  version_requirements: !ruby/object:Gem::Requirement
28
- none: false
29
26
  requirements:
30
27
  - - ~>
31
28
  - !ruby/object:Gem::Version
32
29
  version: '1.11'
33
- - - ! '>='
30
+ - - '>='
34
31
  - !ruby/object:Gem::Version
35
32
  version: 1.11.1
36
33
  - !ruby/object:Gem::Dependency
37
34
  name: aws-sdk
38
35
  requirement: !ruby/object:Gem::Requirement
39
- none: false
40
36
  requirements:
41
37
  - - ~>
42
38
  - !ruby/object:Gem::Version
43
39
  version: '1.35'
44
- - - ! '>='
40
+ - - '>='
45
41
  - !ruby/object:Gem::Version
46
42
  version: 1.35.1
47
43
  type: :runtime
48
44
  prerelease: false
49
45
  version_requirements: !ruby/object:Gem::Requirement
50
- none: false
51
46
  requirements:
52
47
  - - ~>
53
48
  - !ruby/object:Gem::Version
54
49
  version: '1.35'
55
- - - ! '>='
50
+ - - '>='
56
51
  - !ruby/object:Gem::Version
57
52
  version: 1.35.1
58
53
  - !ruby/object:Gem::Dependency
59
54
  name: dogstatsd-ruby
60
55
  requirement: !ruby/object:Gem::Requirement
61
- none: false
62
56
  requirements:
63
57
  - - ~>
64
58
  - !ruby/object:Gem::Version
65
59
  version: '1.4'
66
- - - ! '>='
60
+ - - '>='
67
61
  - !ruby/object:Gem::Version
68
62
  version: 1.4.1
69
63
  type: :runtime
70
64
  prerelease: false
71
65
  version_requirements: !ruby/object:Gem::Requirement
72
- none: false
73
66
  requirements:
74
67
  - - ~>
75
68
  - !ruby/object:Gem::Version
76
69
  version: '1.4'
77
- - - ! '>='
70
+ - - '>='
78
71
  - !ruby/object:Gem::Version
79
72
  version: 1.4.1
80
73
  - !ruby/object:Gem::Dependency
81
74
  name: rspec
82
75
  requirement: !ruby/object:Gem::Requirement
83
- none: false
84
76
  requirements:
85
77
  - - ~>
86
78
  - !ruby/object:Gem::Version
@@ -88,7 +80,6 @@ dependencies:
88
80
  type: :development
89
81
  prerelease: false
90
82
  version_requirements: !ruby/object:Gem::Requirement
91
- none: false
92
83
  requirements:
93
84
  - - ~>
94
85
  - !ruby/object:Gem::Version
@@ -96,7 +87,6 @@ dependencies:
96
87
  - !ruby/object:Gem::Dependency
97
88
  name: pry
98
89
  requirement: !ruby/object:Gem::Requirement
99
- none: false
100
90
  requirements:
101
91
  - - ~>
102
92
  - !ruby/object:Gem::Version
@@ -104,7 +94,6 @@ dependencies:
104
94
  type: :development
105
95
  prerelease: false
106
96
  version_requirements: !ruby/object:Gem::Requirement
107
- none: false
108
97
  requirements:
109
98
  - - ~>
110
99
  - !ruby/object:Gem::Version
@@ -156,27 +145,26 @@ files:
156
145
  homepage: https://www.github.com/airbnb/interferon
157
146
  licenses:
158
147
  - MIT
148
+ metadata: {}
159
149
  post_install_message:
160
150
  rdoc_options: []
161
151
  require_paths:
162
152
  - lib
163
153
  required_ruby_version: !ruby/object:Gem::Requirement
164
- none: false
165
154
  requirements:
166
- - - ! '>='
155
+ - - '>='
167
156
  - !ruby/object:Gem::Version
168
157
  version: '0'
169
158
  required_rubygems_version: !ruby/object:Gem::Requirement
170
- none: false
171
159
  requirements:
172
- - - ! '>='
160
+ - - '>='
173
161
  - !ruby/object:Gem::Version
174
162
  version: '0'
175
163
  requirements: []
176
164
  rubyforge_project:
177
- rubygems_version: 1.8.23.2
165
+ rubygems_version: 2.0.14
178
166
  signing_key:
179
- specification_version: 3
167
+ specification_version: 4
180
168
  summary: ': Store metrics alerts in code!'
181
169
  test_files:
182
170
  - spec/fixtures/loaders/host_sources/test_host_source.rb