Sha256: 125892eea4c57e5795882cf7a39bd2711b24870e74c5dcecf2a43324e69ef413

Contents?: true

Size: 1.38 KB

Versions: 9

Compression:

Stored size: 1.38 KB

Contents

# Copyright (c) 2015 Sqreen. All Rights Reserved.
# Please refer to our terms for more information: https://www.sqreen.com/terms.html

require 'sqreen/rules/attrs'
require 'sqreen/rules/rule_cb'
require 'sqreen/safe_json'

module Sqreen
  module Rules
    # Save request context for handling further down
    class CountHTTPCodes < RuleCB
      METRIC_CATEGORY = 'http_code'.freeze
      def initialize(*args)
        super(*args)
        @overtimeable = false
      end

      def post(rv, _inst, _args, _budget = nil, &_block)
        return unless rv.is_a?(Array) && !rv.empty?
        record_observation(METRIC_CATEGORY, rv[0], 1)
        advise_action(nil)
      end
    end

    # Count 1 for each things located by the binding accessor
    class BindingAccessorCounter < RuleCB
      def initialize(klass, method, rule_hash)
        super(klass, method, rule_hash)
        @accessors = @data['values'].map do |expr|
          BindingAccessor.new(expr, true)
        end
        @metric_category = rule_hash[Attrs::METRICS].first['name']
      end

      def post(rv, inst, args, _budget = nil, &_block)
        return unless rv.is_a?(Array) && !rv.empty?
        key = @accessors.map do |accessor|
          accessor.resolve(binding, framework, inst, args, @data, rv)
        end
        record_observation(@metric_category, SafeJSON.dump(key), 1)
        advise_action(nil)
      end
    end
  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
sqreen-1.18.6-java lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.6 lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.5-java lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.5 lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.4-java lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.4 lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.3-java lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.3 lib/sqreen/rules/count_http_codes.rb
sqreen-1.18.3.beta2 lib/sqreen/rules/count_http_codes.rb