Sha256: 8775d4f28e793fbb9c1121e17299fe763f99518fb333be8a6b451a03fb844d5b

Contents?: true

Size: 1.66 KB

Versions: 54

Compression:

Stored size: 1.66 KB

Contents

#!/usr/bin/env ruby

require 'flapjack/filters/base'

module Flapjack
  module Filters

    # * If the service event’s state is a failure, and the total number of failing client checks is
    #   over a threshold (e.g. 10 checks are failing), then set a meta flag noting the threshold has
    #   been tripped, and generate an event for this meta check
    # * If the service event’s state is ok, and the meta flag is set, and the total number of
    #   failing client checks is less than a threshold (eg 10), then unset the flag, and generate an
    #   event for this meta check
    class DetectMassClientFailures
      include Base

      def block?(event)
        client_mass_fail_threshold = 10
        timestamp = Time.now.to_i

        if event.type == 'service'
          client_fail_count = @persistence.zcount("failed_checks:#{event.client}", '-inf', '+inf')

          if client_fail_count >= client_mass_fail_threshold
            # set the flag
            # FIXME: perhaps implement this with tagging
            @persistence.add("mass_failed_client:#{event.client}", timestamp)
            @persistence.zadd("mass_failure_events_client:#{event.client}", 0, timestamp)
          else
            # unset the flag
            start_mf = @persistence.get("mass_failed_client:#{event.client}")
            duration = Time.now.to_i - start_mf.to_i
            @persistence.del("mass_failed_client:#{event.client}")
            @persistence.zadd("mass_failure_events_client:#{event.client}", duration, start_mf)
          end
        end

        result = false
        @log.debug("Filter: DetectMassClientFailures: #{result ? "block" : "pass"}")
        result
      end
    end
  end
end

Version data entries

54 entries across 54 versions & 1 rubygems

Version Path
flapjack-0.6.56 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.55 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.54 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.53 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.52 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.51 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.50 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.49 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.48 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.47 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.46 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.45 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.44 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.43 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.42 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.41 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.40 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.39 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.38 lib/flapjack/filters/detect_mass_client_failures.rb
flapjack-0.6.37 lib/flapjack/filters/detect_mass_client_failures.rb