lib/flapjack/processor.rb in flapjack-0.8.9 vs lib/flapjack/processor.rb in flapjack-0.8.10

- old
+ new

@@ -56,22 +56,23 @@ # FIXME: all of the below keys assume there is only ever one executive running; # we could generate a fuid and save it to disk, and prepend it from that # point on... # FIXME: add an administrative function to reset all event counters - if @redis.hget('event_counters', 'all').nil? - @redis.hset('event_counters', 'all', 0) - @redis.hset('event_counters', 'ok', 0) - @redis.hset('event_counters', 'failure', 0) - @redis.hset('event_counters', 'action', 0) - end - + + @redis.hset('event_counters', 'all', 0) if @redis.hget('event_counters', 'all').nil? + @redis.hset('event_counters', 'ok', 0) if @redis.hget('event_counters', 'ok').nil? + @redis.hset('event_counters', 'failure', 0) if @redis.hget('event_counters', 'failure').nil? + @redis.hset('event_counters', 'action', 0) if @redis.hget('event_counters', 'action').nil? + @redis.hset('event_counters', 'invalid', 0) if @redis.hget('event_counters', 'invalid').nil? + @redis.hset("executive_instance:#{@instance_id}", 'boot_time', boot_time.to_i) @redis.hset("event_counters:#{@instance_id}", 'all', 0) @redis.hset("event_counters:#{@instance_id}", 'ok', 0) @redis.hset("event_counters:#{@instance_id}", 'failure', 0) @redis.hset("event_counters:#{@instance_id}", 'action', 0) + @redis.hset("event_counters:#{@instance_id}", 'invalid', 0) touch_keys end # expire instance keys after one week # TODO: set up a separate EM timer to reset key expiry every minute @@ -103,11 +104,18 @@ @logger.warn "Shutting down as exit_on_queue_empty is true, and the queue is empty" Process.kill('INT', Process.pid) break end - process_event(event) unless event.nil? + if event.nil? + @redis.hincrby('event_counters', 'all', 1) + @redis.hincrby("event_counters:#{@instance_id}", 'all', 1) + @redis.hincrby('event_counters', 'invalid', 1) + @redis.hincrby("event_counters:#{@instance_id}", 'invalid', 1) + else + process_event(event) + end end @logger.info("Exiting main loop.") end @@ -164,11 +172,11 @@ result = true previous_state = nil event.counter = @redis.hincrby('event_counters', 'all', 1) @redis.hincrby("event_counters:#{@instance_id}", 'all', 1) - + # FIXME skip if entity_check.nil? # FIXME: validate that the event is sane before we ever get here # FIXME: create an event if there is dodgy data @@ -186,10 +194,14 @@ @redis.hincrby('event_counters', 'ok', 1) @redis.hincrby("event_counters:#{@instance_id}", 'ok', 1) elsif event.failure? @redis.hincrby('event_counters', 'failure', 1) @redis.hincrby("event_counters:#{@instance_id}", 'failure', 1) + else + @redis.hincrby('event_counters', 'invalid', 1) + @redis.hincrby("event_counters:#{@instance_id}", 'invalid', 1) + @logger.error("Invalid event received: #{event.inspect}") end @redis.exec previous_state = entity_check.state @@ -221,9 +233,13 @@ @redis.multi @redis.hset(event.id + ':actions', timestamp, event.state) @redis.hincrby('event_counters', 'action', 1) @redis.hincrby("event_counters:#{@instance_id}", 'action', 1) @redis.exec + else + @redis.hincrby('event_counters', 'invalid', 1) + @redis.hincrby("event_counters:#{@instance_id}", 'invalid', 1) + @logger.error("Invalid event received: #{event.inspect}") end [result, previous_state] end