sqreen 1.1.11481117869-java → 1.1.21481714484-java

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: 0380f38a3af0fbb87e91fb92c71261300ac8e705
4
- data.tar.gz: e26603f5e01edd06550f54bb66ae4b202b24e5fc
3
+ metadata.gz: f03f4a7d74cf483d5876f295673eab4441ebda4f
4
+ data.tar.gz: 5ef683e47e23b38df0ccc8974d5b596be9436370
5
5
  SHA512:
6
- metadata.gz: b274e896a689f03dbc034ee62ffb06761dfa7361665606bd7d31261a8fdfcc978361e832ad221ab2ceaf767a99eeb7b2bd49b6727b6c578b0c0d545795b48e1e
7
- data.tar.gz: 5de74d338c25967869f36a2f6a6da4700d342ea544b0c3db30d7738bc0d0f0cfd490322e12e4f1a35964712f2e6338a817266243888848156fe8946807aaebaa
6
+ metadata.gz: 8273d011709cc1edc9d1203e6c31f5d4beb70d43d3cc936ad2635534ded5f512ad4f7bf8b9059847b93d76fc9c80fbba4363ca83a08dd5d16c83c40933b4bc91
7
+ data.tar.gz: 97ff17c99a5f914f75db942d81a8b9f17fb63eea1d7e2e51c89f6d1021c4799688847f561458016cd3fd02bfc069f7b144ed8df19c0bf6eeb59db8d654bb3e19
@@ -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}" }
@@ -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: java
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
@@ -50,6 +50,7 @@ files:
50
50
  - lib/sqreen.rb
51
51
  - lib/sqreen/binding_accessor.rb
52
52
  - lib/sqreen/ca.crt
53
+ - lib/sqreen/call_countable.rb
53
54
  - lib/sqreen/callback_tree.rb
54
55
  - lib/sqreen/callbacks.rb
55
56
  - lib/sqreen/capped_queue.rb
@@ -129,7 +130,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
130
  version: '0'
130
131
  requirements: []
131
132
  rubyforge_project:
132
- rubygems_version: 2.6.4
133
+ rubygems_version: 2.6.8
133
134
  signing_key:
134
135
  specification_version: 4
135
136
  summary: Sqreen Ruby agent