flapjack 1.2.0rc2 → 1.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: b10a01932fb4fd6a466e2b975764c3c6ff777e9c
4
- data.tar.gz: e25026116bccc9209d8ca98c05585e89dc4b7ce3
3
+ metadata.gz: 04d31109d0b39ced29a1b027a0894cab07b9d4c0
4
+ data.tar.gz: 86e20fc3b3f0d34acca6be7e33468fc3d609e868
5
5
  SHA512:
6
- metadata.gz: d1e4aeba827545b5b18bc56bd549adff1b93b43bf368cd426d37b847c2d2801ea4e83f22c1af4e87579e947cf8d911a2abcb6025d778d476abcaad4b2ac934ab
7
- data.tar.gz: e6956faf10c9a12bf9cd08bf56fbe87be986063967ec27e35e77b5ed313b8a3cff6b50ea14a5d58019b9b8f4c29f6bad483d0ecf739e7a0f609f26e3d9dedfeb
6
+ metadata.gz: a838f02684a7cee3ba40cc5be1ecfa2e3b15246912a7bff218944b323f14d43ef64ebce1e9ce978f37795b17d44acc4ec708f4a8768e9788df339a20619f1892
7
+ data.tar.gz: 93784a164826ef9af3bf84b947d0debdbf21acf3e601ee809c248534d52e0af2cbea643e5cd7ab2c4af4e14a7b8b6ced725883739ecd148ae11f3492a4771f4a
@@ -1,5 +1,9 @@
1
1
  ## Flapjack Changelog
2
2
 
3
+ # 1.2.0 - 2014-11-07
4
+ - Bug: multi blocks for safe redis connection pool usage #694 (@ali-graham)
5
+ - Bug: data migration to work around previous notification rule bug #699 (@ali-graham)
6
+
3
7
  # 1.2.0rc2 - 2014-10-17
4
8
  - Feature: Cache entity and check name <-> id lookups #682 (@ali-graham)
5
9
  - Chore: Add last_change field to status_reports in the API (closes: #678) #679 (@Hobbsee)
data/Dockerfile CHANGED
@@ -5,7 +5,7 @@ RUN apt-get install -y gnupg
5
5
  RUN gpg --keyserver keys.gnupg.net --recv-keys 803709B6
6
6
  RUN gpg -a --export 803709B6 | apt-key add -
7
7
 
8
- RUN echo "deb http://packages.flapjack.io/deb/1.0 trusty main" | tee /etc/apt/sources.list.d/flapjack.list
8
+ RUN echo "deb http://packages.flapjack.io/deb/v1 trusty main" | tee /etc/apt/sources.list.d/flapjack.list
9
9
  RUN apt-get update
10
10
  RUN apt-cache policy flapjack
11
11
  RUN apt-get install -y flapjack
data/Gemfile CHANGED
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  group :test do
10
10
  gem 'rspec', '~> 3.0'
11
- gem 'cucumber'
11
+ gem 'cucumber', '>= 2.0.0.beta.3'
12
12
  gem 'delorean'
13
13
  gem 'rack-test'
14
14
  gem 'pact'
@@ -22,8 +22,9 @@ group :test do
22
22
  gem 'fuubar'
23
23
  gem 'simplecov', :require => false
24
24
 
25
- if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
26
- gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
27
- gem 'perftools.rb'
28
- end
25
+ # # Not compiling under 1.9.3-p550 anyway
26
+ # if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
27
+ # gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
28
+ # gem 'perftools.rb'
29
+ # end
29
30
  end
@@ -8,7 +8,7 @@ end
8
8
 
9
9
  group :test do
10
10
  gem 'rspec', '~> 3.0'
11
- gem 'cucumber'
11
+ gem 'cucumber', '>= 2.0.0.beta.3'
12
12
  gem 'delorean'
13
13
  gem 'rack-test'
14
14
  gem 'pact'
@@ -22,8 +22,9 @@ group :test do
22
22
  gem 'fuubar'
23
23
  gem 'simplecov', :require => false
24
24
 
25
- if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
26
- gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
27
- gem 'perftools.rb'
28
- end
25
+ # # Not compiling under 1.9.3-p550 anyway
26
+ # if RUBY_VERSION.split('.')[0] == '1' && RUBY_VERSION.split('.')[1] == '9'
27
+ # gem 'debugger-ruby_core_source', '>= 1.3.4' # required for perftools.rb
28
+ # gem 'perftools.rb'
29
+ # end
29
30
  end
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flapjack (1.2.0rc2)
4
+ flapjack (1.2.0)
5
5
  activesupport (~> 3.2.14)
6
6
  blather (~> 0.8.3)
7
7
  chronic
@@ -31,7 +31,7 @@ PATH
31
31
  GEM
32
32
  remote: https://rubygems.org/
33
33
  specs:
34
- activesupport (3.2.19)
34
+ activesupport (3.2.20)
35
35
  i18n (~> 0.6, >= 0.6.4)
36
36
  multi_json (~> 1.0)
37
37
  addressable (2.3.6)
@@ -54,15 +54,17 @@ GEM
54
54
  cookiejar (0.3.2)
55
55
  crack (0.4.2)
56
56
  safe_yaml (~> 1.0.0)
57
- cucumber (1.3.17)
57
+ cucumber (2.0.0.beta.3)
58
58
  builder (>= 2.1.2)
59
+ cucumber-core (~> 1.0.0.beta.3)
59
60
  diff-lcs (>= 1.1.3)
60
61
  gherkin (~> 2.12)
61
62
  multi_json (>= 1.7.5, < 2.0)
62
63
  multi_test (>= 0.1.1)
64
+ cucumber-core (1.0.0.beta.3)
65
+ gherkin (~> 2.12.0)
63
66
  daemons (1.1.9)
64
67
  dante (0.2.0)
65
- debugger-ruby_core_source (1.3.5)
66
68
  delorean (2.1.0)
67
69
  chronic
68
70
  diff-lcs (1.2.5)
@@ -119,10 +121,10 @@ GEM
119
121
  rb-fsevent (>= 0.9.3)
120
122
  rb-inotify (>= 0.9)
121
123
  lumberjack (1.0.9)
122
- mail (2.6.1)
124
+ mail (2.6.3)
123
125
  mime-types (>= 1.16, < 3)
124
126
  method_source (0.8.2)
125
- mime-types (2.4.1)
127
+ mime-types (2.4.3)
126
128
  mini_portile (0.6.0)
127
129
  msgpack (0.5.9)
128
130
  multi_json (1.10.1)
@@ -132,7 +134,7 @@ GEM
132
134
  nokogiri (1.6.2.1)
133
135
  mini_portile (= 0.6.0)
134
136
  numerizer (0.1.1)
135
- oj (2.10.3)
137
+ oj (2.11.0)
136
138
  pact (1.3.3)
137
139
  awesome_print (~> 1.1)
138
140
  find_a_port (~> 1.0.1)
@@ -143,7 +145,6 @@ GEM
143
145
  term-ansicolor (~> 1.0)
144
146
  thor
145
147
  webrick
146
- perftools.rb (2.0.1)
147
148
  pry (0.10.1)
148
149
  coderay (~> 1.1.0)
149
150
  method_source (~> 0.8.1)
@@ -218,7 +219,7 @@ GEM
218
219
  tins (1.3.3)
219
220
  trollop (2.0)
220
221
  tzinfo (1.0.1)
221
- tzinfo-data (1.2014.8)
222
+ tzinfo-data (1.2014.9)
222
223
  tzinfo (>= 1.0.0)
223
224
  vegas (0.1.11)
224
225
  rack (>= 1.0.0)
@@ -232,8 +233,7 @@ PLATFORMS
232
233
 
233
234
  DEPENDENCIES
234
235
  async_rack_test (>= 0.0.5)
235
- cucumber
236
- debugger-ruby_core_source (>= 1.3.4)
236
+ cucumber (>= 2.0.0.beta.3)
237
237
  delorean
238
238
  flapjack!
239
239
  fuubar
@@ -241,7 +241,6 @@ DEPENDENCIES
241
241
  guard-cucumber
242
242
  guard-rspec
243
243
  pact
244
- perftools.rb
245
244
  rack-test
246
245
  rb-fsevent
247
246
  resque_spec
@@ -2,16 +2,16 @@
2
2
  # copied from flapjack-populator
3
3
  # TODO use Flapjack::Data::Contact.add
4
4
  def add_contact(contact = {})
5
- @redis.multi
6
- @redis.del("contact:#{contact['id']}")
7
- @redis.del("contact_media:#{contact['id']}")
8
- @redis.hset("contact:#{contact['id']}", 'first_name', contact['first_name'])
9
- @redis.hset("contact:#{contact['id']}", 'last_name', contact['last_name'])
10
- @redis.hset("contact:#{contact['id']}", 'email', contact['email'])
11
- contact['media'].each_pair {|medium, address|
12
- @redis.hset("contact_media:#{contact['id']}", medium, address)
13
- }
14
- @redis.exec
5
+ @redis.multi do |multi|
6
+ multi.del("contact:#{contact['id']}")
7
+ multi.del("contact_media:#{contact['id']}")
8
+ multi.hset("contact:#{contact['id']}", 'first_name', contact['first_name'])
9
+ multi.hset("contact:#{contact['id']}", 'last_name', contact['last_name'])
10
+ multi.hset("contact:#{contact['id']}", 'email', contact['email'])
11
+ contact['media'].each_pair {|medium, address|
12
+ multi.hset("contact_media:#{contact['id']}", medium, address)
13
+ }
14
+ end
15
15
  end
16
16
 
17
17
  Given /^the user wants to receive SMS notifications for entity '([\w\.\-]+)'$/ do |entity|
@@ -115,16 +115,13 @@ end
115
115
 
116
116
  config = Flapjack::Configuration.new
117
117
  redis_opts = config.load(FLAPJACK_CONFIG) ?
118
- config.for_redis :
118
+ config.for_redis.merge(:driver => :ruby) :
119
119
  {:db => 14, :driver => :ruby}
120
120
  redis = ::Redis.new(redis_opts)
121
121
  redis.flushdb
122
122
  RedisDelorean.before_all(:redis => redis)
123
123
  redis.quit
124
124
 
125
- # NB: this seems to execute outside the Before/After hooks
126
- # regardless of placement -- this is what we want, as the
127
- # @redis driver should be initialised in the sync block.
128
125
  Around do |scenario, blk|
129
126
  EM.synchrony do
130
127
  blk.call
@@ -140,7 +137,6 @@ After do
140
137
  @logger.messages = []
141
138
  end
142
139
 
143
-
144
140
  Before('@processor') do
145
141
  @processor = Flapjack::Processor.new(:logger => @logger,
146
142
  :redis_config => redis_opts, :config => {})
@@ -150,6 +146,7 @@ end
150
146
  After('@processor') do
151
147
  @redis.flushdb
152
148
  @redis.quit
149
+ @redis = nil
153
150
  end
154
151
 
155
152
  Before('@notifier') do
@@ -165,6 +162,7 @@ end
165
162
  After('@notifier') do
166
163
  @notifier_redis.flushdb
167
164
  @notifier_redis.quit
165
+ @notifier_redis = nil
168
166
  end
169
167
 
170
168
  Before('@resque') do
@@ -173,7 +171,7 @@ Before('@resque') do
173
171
  end
174
172
 
175
173
  Before('@time') do
176
- RedisDelorean.before_each(:redis => @redis)
174
+ RedisDelorean.before_each(:redis => @redis || @notifier_redis)
177
175
  end
178
176
 
179
177
  After('@time') do
@@ -21,10 +21,10 @@ Gem::Specification.new do |gem|
21
21
  gem.add_dependency 'dante'
22
22
  gem.add_dependency 'oj', '>= 2.9.0'
23
23
  gem.add_dependency 'eventmachine', '~> 1.0.0'
24
+ gem.add_dependency 'redis', '~> 3.0.6'
24
25
  gem.add_dependency 'hiredis'
25
26
  gem.add_dependency 'em-synchrony', '~> 1.0.2'
26
27
  gem.add_dependency 'em-http-request'
27
- gem.add_dependency 'redis', '~> 3.0.6'
28
28
  gem.add_dependency 'em-resque'
29
29
  gem.add_dependency 'resque', '~> 1.23.0'
30
30
  gem.add_dependency 'sinatra'
@@ -44,12 +44,17 @@ module Flapjack
44
44
 
45
45
  check_history_keys = redis.keys("#{existing_name}:*:states") +
46
46
  redis.keys("#{existing_name}:*:state") +
47
- redis.keys("#{existing_name}:*:summary") +
48
47
  redis.keys("#{existing_name}:*:sorted_state_timestamps")
49
48
 
50
49
  action_keys = redis.keys("#{existing_name}:*:actions")
51
50
 
52
- maint_keys = redis.keys("#{existing_name}:*:*scheduled_maintenance*") +
51
+ maint_keys = redis.keys("#{existing_name}:*:*scheduled_maintenance*")
52
+
53
+ all_summary_keys = redis.keys("#{existing_name}:*:summary")
54
+ maint_summary_keys = redis.keys("#{existing_name}:*:*scheduled_maintenance:summary")
55
+ check_summary_keys = all_summary_keys - maint_summary_keys
56
+
57
+ check_history_keys += check_summary_keys
53
58
 
54
59
  notif_keys = redis.keys("#{existing_name}:*:last_*_notification") +
55
60
  redis.keys("#{existing_name}:*:*_notifications")
@@ -100,54 +105,61 @@ module Flapjack
100
105
 
101
106
  block_keys = redis.keys("drop_alerts_for_contact:*:*:#{existing_name}:*:*")
102
107
 
103
- redis.multi
108
+ rename_all_checks = redis.exists("all_checks:#{existing_name}")
109
+ rename_current_checks = redis.exists("current_checks:#{existing_name}")
104
110
 
105
- yield if block_given? # entity id -> name update from add()
111
+ redis.multi do |multi|
106
112
 
107
- check_state_keys.each do |csk|
108
- redis.rename(csk, csk.sub(/^check:#{Regexp.escape(existing_name)}:/, "check:#{entity_name}:"))
109
- end
113
+ yield(multi) if block_given? # entity id -> name update from add()
110
114
 
111
- (check_history_keys + action_keys + maint_keys + notif_keys).each do |chk|
112
- redis.rename(chk, chk.sub(/^#{Regexp.escape(existing_name)}:/, "#{entity_name}:"))
113
- end
115
+ check_state_keys.each do |csk|
116
+ multi.rename(csk, csk.sub(/^check:#{Regexp.escape(existing_name)}:/, "check:#{entity_name}:"))
117
+ end
114
118
 
115
- all_checks.each_pair do |ch, score|
116
- redis.zrem('all_checks', "#{existing_name}:#{ch}")
117
- redis.zadd('all_checks', score, "#{entity_name}:#{ch}")
118
- end
119
+ (check_history_keys + action_keys + maint_keys + notif_keys).each do |chk|
120
+ multi.rename(chk, chk.sub(/^#{Regexp.escape(existing_name)}:/, "#{entity_name}:"))
121
+ end
119
122
 
120
- # currently failing checks
121
- failed_checks.each_pair do |ch, score|
122
- redis.zrem('failed_checks', "#{existing_name}:#{ch}")
123
- redis.zadd('failed_checks', score, "#{entity_name}:#{ch}")
124
- end
123
+ all_checks.each_pair do |ch, score|
124
+ multi.zrem('all_checks', "#{existing_name}:#{ch}")
125
+ multi.zadd('all_checks', score, "#{entity_name}:#{ch}")
126
+ end
125
127
 
126
- redis.rename("all_checks:#{existing_name}", "all_checks:#{entity_name}")
127
- redis.rename("current_checks:#{existing_name}", "current_checks:#{entity_name}")
128
+ # currently failing checks
129
+ failed_checks.each_pair do |ch, score|
130
+ multi.zrem('failed_checks', "#{existing_name}:#{ch}")
131
+ multi.zadd('failed_checks', score, "#{entity_name}:#{ch}")
132
+ end
128
133
 
129
- unless current_score.nil?
130
- redis.zrem('current_entities', existing_name)
131
- redis.zadd('current_entities', current_score, entity_name)
132
- end
134
+ if rename_all_checks
135
+ multi.rename("all_checks:#{existing_name}", "all_checks:#{entity_name}")
136
+ end
133
137
 
134
- block_keys.each do |blk|
135
- redis.rename(blk, blk.sub(/^drop_alerts_for_contact:(.+):([^:]+):#{Regexp.escape(existing_name)}:(.+):([^:]+)$/,
136
- "drop_alerts_for_contact:\\1:\\2:#{entity_name}:\\3:\\4"))
137
- end
138
+ if rename_current_checks
139
+ multi.rename("current_checks:#{existing_name}", "current_checks:#{entity_name}")
140
+ end
138
141
 
139
- hashes_to_remove.each {|hash| redis.hdel('checks_by_hash', hash) }
140
- hashes_to_add.each_pair {|hash, chk| redis.hset('checks_by_hash', hash, chk)}
142
+ unless current_score.nil?
143
+ multi.zrem('current_entities', existing_name)
144
+ multi.zadd('current_entities', current_score, entity_name)
145
+ end
141
146
 
142
- alerting_to_remove.each_pair do |alerting, chks|
143
- chks.each {|chk| redis.zrem(alerting, chk)}
144
- end
147
+ block_keys.each do |blk|
148
+ multi.rename(blk, blk.sub(/^drop_alerts_for_contact:(.+):([^:]+):#{Regexp.escape(existing_name)}:(.+):([^:]+)$/,
149
+ "drop_alerts_for_contact:\\1:\\2:#{entity_name}:\\3:\\4"))
150
+ end
145
151
 
146
- alerting_to_add.each_pair do |alerting, chks|
147
- chks.each_pair {|chk, score| redis.zadd(alerting, score, chk)}
148
- end
152
+ hashes_to_remove.each {|hash| multi.hdel('checks_by_hash', hash) }
153
+ hashes_to_add.each_pair {|hash, chk| multi.hset('checks_by_hash', hash, chk)}
154
+
155
+ alerting_to_remove.each_pair do |alerting, chks|
156
+ chks.each {|chk| multi.zrem(alerting, chk)}
157
+ end
149
158
 
150
- redis.exec
159
+ alerting_to_add.each_pair do |alerting, chks|
160
+ chks.each_pair {|chk, score| multi.zadd(alerting, score, chk)}
161
+ end
162
+ end
151
163
  end
152
164
 
153
165
  # NB only used by the 'entities:reparent' Rake task, but kept in this
@@ -213,8 +225,12 @@ module Flapjack
213
225
  ch_fail_score = redis.zscore("failed_checks", old_check)
214
226
  failed_checks_to_add[current_check] = ch_fail_score unless ch_fail_score.nil?
215
227
 
216
- keys_to_rename["check:#{old_check}"] = "check:#{current_check}"
217
- keys_to_rename[old_states] = new_states
228
+ if redis.exists("check:#{old_check}")
229
+ keys_to_rename["check:#{old_check}"] = "check:#{current_check}"
230
+ end
231
+ if redis.exists(old_states)
232
+ keys_to_rename[old_states] = new_states
233
+ end
218
234
  end
219
235
 
220
236
  notification_types.each do |notif|
@@ -229,7 +245,7 @@ module Flapjack
229
245
  end
230
246
 
231
247
  keys_to_delete << old_notif
232
- else
248
+ elsif redis.exists(old_notif)
233
249
  keys_to_rename[old_notif] = new_notif
234
250
  end
235
251
  end
@@ -258,13 +274,13 @@ module Flapjack
258
274
 
259
275
  if redis.exists("all_checks:#{current_name}")
260
276
  keys_to_delete << "all_checks:#{old_name}"
261
- else
277
+ elsif redis.exists("all_checks:#{old_name}")
262
278
  keys_to_rename["all_checks:#{old_name}"] = "all_checks:#{current_name}"
263
279
  end
264
280
 
265
281
  if redis.exists("current_checks:#{current_name}")
266
282
  keys_to_delete << "current_checks:#{old_name}"
267
- else
283
+ elsif redis.exists("current_checks:#{old_name}")
268
284
  keys_to_rename["current_checks:#{old_name}"] = "current_checks:#{current_name}"
269
285
  end
270
286
 
@@ -291,7 +307,7 @@ module Flapjack
291
307
  if redis.exists(current_actions)
292
308
  action_data[current_actions] = redis.hgetall(old_actions)
293
309
  keys_to_delete << old_actions
294
- else
310
+ elsif redis.exists(old_actions)
295
311
  keys_to_rename[old_actions] = current_actions
296
312
  end
297
313
  end
@@ -317,7 +333,7 @@ module Flapjack
317
333
  # TTL < 0 is a redis error code -- key not present, etc.
318
334
  if (old_ttl >= 0) && ((new_ttl < 0) ||
319
335
  ((old_time + old_ttl) > (new_time + new_ttl)))
320
- keys_to_rename[maint_key] = new_maint_key
336
+ keys_to_rename[maint_key] = new_maint_key if redis.exists(maint_key)
321
337
  maints_to_set[new_maint_key] = redis.zscore("#{maint_key}s", old_time)
322
338
  end
323
339
 
@@ -350,84 +366,83 @@ module Flapjack
350
366
 
351
367
  notif_keys = redis.keys("#{old_name}:*:last_*_notification")
352
368
 
353
- redis.multi
369
+ redis.multi do |multi|
354
370
 
355
- check_history_keys.each do |chk|
356
- redis.renamenx(chk, chk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:"))
357
- end
358
-
359
- check_timestamps_keys.each do |ctk|
360
- dest = ctk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
361
- redis.zunionstore(dest, [ctk, dest], :aggregate => :max)
362
- end
371
+ check_history_keys.each do |chk|
372
+ multi.renamenx(chk, chk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:"))
373
+ end
363
374
 
364
- all_checks_to_remove.each do |actr|
365
- redis.zrem('all_checks', actr)
366
- end
375
+ check_timestamps_keys.each do |ctk|
376
+ dest = ctk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
377
+ multi.zunionstore(dest, [ctk, dest], :aggregate => :max)
378
+ end
367
379
 
368
- all_checks_to_add.each_pair do |acta, score|
369
- redis.zadd('all_checks', score, acta)
370
- end
380
+ all_checks_to_remove.each do |actr|
381
+ multi.zrem('all_checks', actr)
382
+ end
371
383
 
372
- failed_checks_to_remove.each do |fctr|
373
- redis.zrem('failed_checks', fctr)
374
- end
384
+ all_checks_to_add.each_pair do |acta, score|
385
+ multi.zadd('all_checks', score, acta)
386
+ end
375
387
 
376
- failed_checks_to_add.each_pair do |fcta, score|
377
- redis.zadd('failed_checks', score, fcta)
378
- end
388
+ failed_checks_to_remove.each do |fctr|
389
+ multi.zrem('failed_checks', fctr)
390
+ end
379
391
 
380
- action_data.each_pair do |action_key, data|
381
- data.each_pair do |k, v|
382
- redis.hsetnx(action_key, k, v)
392
+ failed_checks_to_add.each_pair do |fcta, score|
393
+ multi.zadd('failed_checks', score, fcta)
383
394
  end
384
- end
385
395
 
386
- redis.zunionstore("current_checks:#{current_name}",
387
- ["current_checks:#{old_name}", "current_checks:#{current_name}"],
388
- :aggregate => :max)
396
+ action_data.each_pair do |action_key, data|
397
+ data.each_pair do |k, v|
398
+ multi.hsetnx(action_key, k, v)
399
+ end
400
+ end
389
401
 
390
- redis.zrem('current_entities', old_name)
391
- unless old_score.nil?
392
- redis.zadd('current_entities', old_score, current_name)
393
- end
402
+ multi.zunionstore("current_checks:#{current_name}",
403
+ ["current_checks:#{old_name}", "current_checks:#{current_name}"],
404
+ :aggregate => :max)
394
405
 
395
- maints_to_set.each_pair do |maint_key, score|
396
- redis.zadd("#{maint_key}s", score, current_name)
397
- end
406
+ multi.zrem('current_entities', old_name)
407
+ unless old_score.nil?
408
+ multi.zadd('current_entities', old_score, current_name)
409
+ end
398
410
 
399
- stored_maint_keys.each do |stored_maint_key|
400
- new_stored_maint_key = stored_maint_key.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
401
- redis.zunionstore(new_stored_maint_key,
402
- [stored_maint_key, new_stored_maint_key],
403
- :aggregate => :max)
404
- end
411
+ maints_to_set.each_pair do |maint_key, score|
412
+ multi.zadd("#{maint_key}s", score, current_name)
413
+ end
405
414
 
406
- notif_keys.each do |nk|
407
- dest = nk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
408
- redis.renamenx(nk, dest)
409
- redis.del(nk)
410
- end
415
+ stored_maint_keys.each do |stored_maint_key|
416
+ new_stored_maint_key = stored_maint_key.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
417
+ multi.zunionstore(new_stored_maint_key,
418
+ [stored_maint_key, new_stored_maint_key],
419
+ :aggregate => :max)
420
+ end
411
421
 
412
- alerting_to_remove.each_pair do |alerting, chks|
413
- chks.each {|chk| redis.zrem(alerting, chk)}
414
- end
422
+ notif_keys.each do |nk|
423
+ dest = nk.sub(/^#{Regexp.escape(old_name)}:/, "#{current_name}:")
424
+ multi.renamenx(nk, dest)
425
+ multi.del(nk)
426
+ end
415
427
 
416
- alerting_to_add.each_pair do |alerting, chks|
417
- chks.each_pair {|chk, score| redis.zadd(alerting, score, chk)}
418
- end
428
+ alerting_to_remove.each_pair do |alerting, chks|
429
+ chks.each {|chk| multi.zrem(alerting, chk)}
430
+ end
419
431
 
420
- blocks_to_set.each_pair do |block_key, (timestamp, value)|
421
- redis.setex(block_key, (timestamp - Time.now.to_i), value)
422
- end
432
+ alerting_to_add.each_pair do |alerting, chks|
433
+ chks.each_pair {|chk, score| multi.zadd(alerting, score, chk)}
434
+ end
423
435
 
424
- keys_to_rename.each_pair do |old_key, new_key|
425
- redis.rename(old_key, new_key)
426
- end
436
+ blocks_to_set.each_pair do |block_key, (timestamp, value)|
437
+ multi.setex(block_key, (timestamp - Time.now.to_i), value)
438
+ end
427
439
 
428
- redis.del(*keys_to_delete) unless keys_to_delete.empty?
440
+ keys_to_rename.each_pair do |old_key, new_key|
441
+ multi.rename(old_key, new_key)
442
+ end
429
443
 
430
- redis.exec
444
+ multi.del(*keys_to_delete) unless keys_to_delete.empty?
445
+ end
431
446
  end
432
447
 
433
448
  # NB: If entities are renamed in imported data before they are
@@ -467,10 +482,10 @@ module Flapjack
467
482
  if redis.hexists('all_entity_ids_by_name', entity_name)
468
483
  merge(existing_name, entity_name, :redis => redis)
469
484
  else
470
- rename(existing_name, entity_name, :redis => redis) {
471
- redis.hdel('all_entity_ids_by_name', existing_name)
472
- redis.hset('all_entity_ids_by_name', entity_name, entity_id)
473
- redis.hset('all_entity_names_by_id', entity_id, entity_name)
485
+ rename(existing_name, entity_name, :redis => redis) {|multi|
486
+ multi.hdel('all_entity_ids_by_name', existing_name)
487
+ multi.hset('all_entity_ids_by_name', entity_name, entity_id)
488
+ multi.hset('all_entity_names_by_id', entity_id, entity_name)
474
489
  }
475
490
  end
476
491
  end