sqreen 1.1.11481117869 → 1.1.21481714484

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 91392d998d033e2ad340e87c9fc4d6da258c7bfb
4
- data.tar.gz: a8fffe09a9eed7a0394abe65bbd7ab228fc33025
3
+ metadata.gz: 8905d51e03a06c6b055b278c05bd838b05d83a94
4
+ data.tar.gz: b1d6025eac52dbb97cfa082b065999c22c810fde
5
5
  SHA512:
6
- metadata.gz: 039484cddbbc0081a71107265af61c7e1d809d34252eba7635316ce8e294d000686909f034f10d377307256705bf43f444b776e430b2349651a717f13c003fe5
7
- data.tar.gz: a95939c4986594a0eee6403b6995df008446514f89f257113f1afc63fa69cea6c97c5360e3dfc5e61c97e5cc9bfc9aa2a932030a4151fa49c5dd92bc72eee380
6
+ metadata.gz: d9673ef509fce6642499f54e5663881c433e9e02924c53bcfa6fb4888a8fd7f56ae26e14a9adce3c9a1576913debb6c36f646bc07d2da861e6749710c0210918
7
+ data.tar.gz: a3f64e54167a755d772adcaf469fd411b7e5e2f1d7d8940a3a269aba79de81fe22ffea6db87d6603adf43c81b869b25167cc98f0d997298a7f9794b30ac5d69c
@@ -0,0 +1,67 @@
1
+ # Copyright (c) 2015 Sqreen. All Rights Reserved.
2
+ # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
+
4
+ module Sqreen
5
+ # A module that will dynamically had call_counts to the pre/post/failing
6
+ # callbacks
7
+ module CallCountable
8
+ # Hook the necessary callback function
9
+ # The module being decorated is expected to have a
10
+ # record_observation & rulespack_id & rule_name method available (like RuleCallback)
11
+ #
12
+ # @param count [Hash] hash of callback names => count
13
+ def count_callback_calls(count)
14
+ base = self.class
15
+ @call_count_interval = 0
16
+ return if count.to_i == 0
17
+ @call_counts = {}
18
+ @call_count_interval = count
19
+ @call_count_names = {}
20
+ %w(pre post failing).each do |cb|
21
+ next unless base.method_defined?(cb)
22
+ @call_counts[cb] = 0
23
+ @call_count_names[cb] = "#{rulespack_id}/#{rule_name}/#{cb}".freeze
24
+ defd = base.instance_variable_defined?("@call_count_hooked_#{cb}")
25
+ next if defd && base.instance_variable_get("@call_count_hooked_#{cb}")
26
+ base.send(:alias_method, "#{cb}_without_count", cb)
27
+ base.send(:alias_method, cb, "#{cb}_with_count")
28
+ base.instance_variable_set("@call_count_hooked_#{cb}", true)
29
+ end
30
+ end
31
+ PRE = 'pre'.freeze
32
+ POST = 'post'.freeze
33
+ FAILING = 'failing'.freeze
34
+ COUNT_CALLS = 'sqreen_calls_count'.freeze
35
+
36
+ def pre_with_count(inst, *args, &block)
37
+ ret = pre_without_count(inst, *args, &block)
38
+ count_calls('pre')
39
+ ret
40
+ end
41
+
42
+ def post_with_count(rv, inst, *args, &block)
43
+ ret = post_without_count(rv, inst, *args, &block)
44
+ count_calls('post')
45
+ ret
46
+ end
47
+
48
+ def failing_with_count(rv, inst, *args, &block)
49
+ ret = failing_without_count(rv, inst, *args, &block)
50
+ count_calls('failing')
51
+ ret
52
+ end
53
+
54
+ attr_reader :call_counts
55
+ attr_reader :call_count_interval
56
+
57
+ protected
58
+
59
+ def count_calls(what)
60
+ return unless @call_count_interval > 0
61
+ new_value = (@call_counts[what] += 1)
62
+ return unless new_value % call_count_interval == 0
63
+ @call_counts[what] = 0
64
+ record_observation(COUNT_CALLS, @call_count_names[what], new_value)
65
+ end
66
+ end
67
+ end
@@ -11,13 +11,12 @@ module Sqreen
11
11
  #
12
12
  # @param conditions [Hash] hash of callback names => conditions
13
13
  def condition_callbacks(conditions)
14
+ conditions = {} if conditions.nil?
14
15
  base = self.class
15
16
  %w(pre post failing).each do |cb|
16
- next unless conditions.key?(cb)
17
17
  conds = conditions[cb]
18
- next if conds.respond_to?(:empty?) && conds.empty?
19
18
  next unless base.method_defined?(cb)
20
- send("#{cb}_conditions=", ConditionEvaluator.new(conds))
19
+ send("#{cb}_conditions=", ConditionEvaluator.new(conds)) unless conds.nil?
21
20
  defd = base.instance_variable_defined?("@conditional_hooked_#{cb}")
22
21
  next if defd && base.instance_variable_get("@conditional_hooked_#{cb}")
23
22
  base.send(:alias_method, "#{cb}_without_conditions", cb)
@@ -6,6 +6,7 @@ require 'sqreen/log'
6
6
  require 'sqreen/stats'
7
7
  require 'sqreen/exception'
8
8
  require 'sqreen/performance_notifications'
9
+ require 'sqreen/call_countable'
9
10
  require 'sqreen/events/remote_exception'
10
11
  require 'sqreen/rules_signature'
11
12
  require 'set'
@@ -496,6 +497,11 @@ module Sqreen
496
497
 
497
498
  def initialize(metrics_engine = nil)
498
499
  self.metrics_engine = metrics_engine
500
+ unless metrics_engine.nil?
501
+ metrics_engine.create_metric('name' => CallCountable::COUNT_CALLS,
502
+ 'period' => 60,
503
+ 'kind' => 'Sum')
504
+ end
499
505
  end
500
506
  end
501
507
  end
@@ -23,6 +23,8 @@ module Sqreen
23
23
 
24
24
  # Currently ready samples
25
25
  attr_reader :store
26
+ # All known metrics
27
+ attr_reader :metrics
26
28
 
27
29
  def initialize
28
30
  @store = []
@@ -18,6 +18,7 @@ module Sqreen
18
18
  CALLBACK_CLASS = 'callback_class'.freeze
19
19
  METRICS = 'metrics'.freeze
20
20
  CONDITIONS = 'conditions'.freeze
21
+ CALL_COUNT_INTERVAL = 'call_count_interval'.freeze
21
22
 
22
23
  freeze
23
24
  end
@@ -3,6 +3,7 @@
3
3
 
4
4
  require 'sqreen/callbacks'
5
5
  require 'sqreen/conditionable'
6
+ require 'sqreen/call_countable'
6
7
  require 'sqreen/rule_attributes'
7
8
  require 'sqreen/events/attack'
8
9
  require 'sqreen/events/remote_exception'
@@ -14,6 +15,7 @@ module Sqreen
14
15
  # Base class for callback that are initialized by rules from Sqreen
15
16
  class RuleCB < CB
16
17
  include Conditionable
18
+ include CallCountable
17
19
  # If nothing was asked by the rule we will ask for all sections available
18
20
  # These information will be pruned later when exporting in #to_hash
19
21
  DEFAULT_PAYLOAD = PayloadCreator::METHODS.keys.freeze
@@ -32,8 +34,8 @@ module Sqreen
32
34
  @rule = rule_hash
33
35
  payload_tpl = @rule[Attrs::PAYLOAD] || DEFAULT_PAYLOAD
34
36
  @payload_generator = PayloadCreator.new(payload_tpl)
35
- conditions = @rule[Attrs::CONDITIONS]
36
- condition_callbacks(conditions) unless conditions.nil?
37
+ condition_callbacks(@rule[Attrs::CONDITIONS])
38
+ count_callback_calls(@rule[Attrs::CALL_COUNT_INTERVAL])
37
39
  end
38
40
 
39
41
  def rule_name
@@ -13,7 +13,6 @@ module Sqreen
13
13
  def pre(_inst, *_args, &_block)
14
14
  ua = framework.client_user_agent
15
15
  return unless ua
16
- ua = ua.freeze
17
16
  found = match(ua)
18
17
  return unless found
19
18
  Sqreen.log.debug { "Found UA #{ua} - found: #{found}" }
data/lib/sqreen/runner.rb CHANGED
@@ -17,6 +17,7 @@ require 'sqreen/deliveries/simple'
17
17
  require 'sqreen/deliveries/batch'
18
18
  require 'sqreen/performance_notifications/metrics'
19
19
  require 'sqreen/instrumentation'
20
+ require 'sqreen/call_countable'
20
21
 
21
22
  module Sqreen
22
23
  @features = {}
@@ -108,7 +109,6 @@ module Sqreen
108
109
 
109
110
  # Ensure a deliverer is there unless features have set it first
110
111
  self.deliverer ||= Deliveries::Simple.new(session)
111
-
112
112
  context_infos = {}
113
113
  %w(rules pack_id).each do |p|
114
114
  context_infos[p] = response[p] unless response[p].nil?
@@ -160,6 +160,14 @@ module Sqreen
160
160
  [rulespack_id, rules]
161
161
  end
162
162
 
163
+ def call_counts_metrics_period=(value)
164
+ value = value.to_i
165
+ return unless value > 0 # else disable collection?
166
+ metrics_engine.create_metric('name' => CallCountable::COUNT_CALLS,
167
+ 'period' => value,
168
+ 'kind' => 'Sum')
169
+ end
170
+
163
171
  def performance_metrics_period=(value)
164
172
  value = value.to_i
165
173
  if value > 0
@@ -214,6 +222,7 @@ module Sqreen
214
222
  Sqreen.update_features(features)
215
223
  session.request_compression = features['request_compression'] if session
216
224
  self.performance_metrics_period = features['performance_metrics_period']
225
+ self.call_counts_metrics_period = features['call_counts_metrics_period']
217
226
  hd = features['heartbeat_delay'].to_i
218
227
  self.heartbeat_delay = hd if hd > 0
219
228
  return if features['batch_size'].nil?
@@ -2,5 +2,5 @@
2
2
  # Please refer to our terms for more information: https://www.sqreen.io/terms.html
3
3
  # Warning This file is auto generated! DO NOT edit.
4
4
  module Sqreen
5
- VERSION = "1.1.11481117869".freeze
5
+ VERSION = "1.1.21481714484".freeze
6
6
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sqreen
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.11481117869
4
+ version: 1.1.21481714484
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sqreen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-07 00:00:00.000000000 Z
11
+ date: 2016-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: execjs
@@ -51,6 +51,7 @@ files:
51
51
  - lib/sqreen.rb
52
52
  - lib/sqreen/binding_accessor.rb
53
53
  - lib/sqreen/ca.crt
54
+ - lib/sqreen/call_countable.rb
54
55
  - lib/sqreen/callback_tree.rb
55
56
  - lib/sqreen/callbacks.rb
56
57
  - lib/sqreen/capped_queue.rb
@@ -130,7 +131,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
130
131
  version: '0'
131
132
  requirements: []
132
133
  rubyforge_project:
133
- rubygems_version: 2.6.4
134
+ rubygems_version: 2.6.8
134
135
  signing_key:
135
136
  specification_version: 4
136
137
  summary: Sqreen Ruby agent