sqreen 1.21.0.beta3 → 1.21.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (42) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +28 -15
  3. data/lib/sqreen/condition_evaluator.rb +5 -6
  4. data/lib/sqreen/conditionable.rb +6 -24
  5. data/lib/sqreen/ecosystem.rb +29 -2
  6. data/lib/sqreen/ecosystem/databases/database_connection_data.rb +23 -0
  7. data/lib/sqreen/ecosystem/databases/mongo.rb +39 -0
  8. data/lib/sqreen/ecosystem/databases/mysql.rb +54 -0
  9. data/lib/sqreen/ecosystem/databases/postgres.rb +51 -0
  10. data/lib/sqreen/ecosystem/databases/redis.rb +36 -0
  11. data/lib/sqreen/ecosystem/exception_reporting.rb +4 -2
  12. data/lib/sqreen/ecosystem/messaging/bunny.rb +61 -0
  13. data/lib/sqreen/ecosystem/messaging/kafka.rb +70 -0
  14. data/lib/sqreen/ecosystem/messaging/kinesis.rb +66 -0
  15. data/lib/sqreen/ecosystem/messaging/sqs.rb +68 -0
  16. data/lib/sqreen/ecosystem/module_api/message_producer.rb +9 -3
  17. data/lib/sqreen/ecosystem/module_api/tracing/consumer_data.rb +13 -0
  18. data/lib/sqreen/ecosystem/module_api/tracing/messaging_data.rb +35 -0
  19. data/lib/sqreen/ecosystem/module_api/tracing/producer_data.rb +13 -0
  20. data/lib/sqreen/ecosystem/module_registry.rb +5 -1
  21. data/lib/sqreen/ecosystem/tracing/modules/client.rb +7 -3
  22. data/lib/sqreen/ecosystem/tracing/modules/consumer.rb +35 -0
  23. data/lib/sqreen/ecosystem/tracing/modules/determine_ip.rb +28 -0
  24. data/lib/sqreen/ecosystem/tracing/modules/producer.rb +35 -0
  25. data/lib/sqreen/ecosystem/tracing/signals/tracing_consumer.rb +56 -0
  26. data/lib/sqreen/ecosystem/tracing/signals/tracing_producer.rb +56 -0
  27. data/lib/sqreen/ecosystem_integration.rb +1 -7
  28. data/lib/sqreen/ecosystem_integration/around_callbacks.rb +10 -20
  29. data/lib/sqreen/ecosystem_integration/instrumentation_service.rb +4 -8
  30. data/lib/sqreen/graft/call.rb +1 -21
  31. data/lib/sqreen/graft/hook.rb +75 -83
  32. data/lib/sqreen/kit/signals/specialized/sqreen_exception.rb +2 -0
  33. data/lib/sqreen/metrics.rb +0 -1
  34. data/lib/sqreen/rules/custom_error_cb.rb +1 -1
  35. data/lib/sqreen/rules/rule_cb.rb +2 -2
  36. data/lib/sqreen/runner.rb +12 -27
  37. data/lib/sqreen/version.rb +1 -1
  38. data/lib/sqreen/weave/budget.rb +14 -3
  39. data/lib/sqreen/weave/legacy/instrumentation.rb +94 -145
  40. metadata +22 -23
  41. data/lib/sqreen/ecosystem/redis/redis_connection.rb +0 -43
  42. data/lib/sqreen/metrics/req_detailed.rb +0 -41
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 88934827e2aa5f84ae21f96fb33afdada009fb118d94e8940fe61973812da4d4
4
- data.tar.gz: b30da2199b4dc96d0193c671872ac192396c988ef67845c26fc1ed36a7704bfd
3
+ metadata.gz: acfd752e97a36e2f1f2d0cb224e72a409334d379a6e8c3e05b002bade311e097
4
+ data.tar.gz: cb15f77dbc7e21faa5136a3cfc2493dd576164f2e49c532573c9f8adfa331e77
5
5
  SHA512:
6
- metadata.gz: 19942da7597a18aee5b46aa4ef664c5083eadf3a878c5f431f9dde83196fc15f3263509c6cda6537a5c823de310f117dbb7c600130478a0828d2dbc73f0bf53c
7
- data.tar.gz: c8b1293e8480043d3b494d6335725f649107c56e7bf282580592de7d680eaeb9475bd9091ea280ad2d2e473b100789a9b80c3dac93b9ddebbddb2f8ec4f3ced6
6
+ metadata.gz: a4025d0a2500ff46db50b33eb7f3340065ae687f3e8d218a14ca3f2690ccecee4412b4901a4dcd93fd67a7fc0036ee025f4f4cf08a6d254101741ddaf4bbcf07
7
+ data.tar.gz: 54755c74c6211c7aad3ae75aa8f2a5c307a074acef5ebf182ee31a5f50580a3115bd499be80d24cd5566ce16ef82c169f50ee9bed18531e7d0944e6864e7f610
@@ -1,18 +1,31 @@
1
- ## 1.21.0.beta3
2
-
3
- * Avoid fd leak in `custom_error_cb` (ARB-109)
4
- * Support `skip_rem_cbs` (ARB-107)
5
- * Fix instrumentation in Ruby 2.0
6
- * Fix encoding exception on `hash_key_include` (ARB-53)
7
- * Fix erroneous start in non-Rails context (SQREEN-880)
8
- * Make metrics thread-safe
9
- * Add restart command
10
- * Fix `overtime_cb`
11
- * Add `perf_level` 2
12
- * Several performance optimizations
13
- * WAF: rename `budget_in_ms` to `max_budget_ms`
14
- * Transport/Tracing with http module
15
- * Update the blocking page
1
+ ## 1.21.0
2
+
3
+ * Add support for transport and tracing facilities
4
+
5
+ ## 1.20.4
6
+
7
+ * Fix missing budget check
8
+ * Improve performance
9
+ * Align internal setting name for WAF
10
+ * Include response information in all payloads
11
+ * Improve robustness against invalid Unicode
12
+ * Prevent rule execution to pursue in early block cases
13
+
14
+ ## 1.20.4.beta1
15
+
16
+ * Add optional dynamic time budget
17
+ * Add advanced per request metrics
18
+ * Improve robustness against exception in instrumentation
19
+ * Improve metric engine thread safety
20
+ * Restrict deferred logger to final logger severity on agent boot
21
+
22
+ ## 1.20.3
23
+
24
+ * Fix signature check
25
+
26
+ ## 1.20.2
27
+
28
+ * Fix performance regression in instrumentation engine
16
29
 
17
30
  ## 1.20.1
18
31
 
@@ -81,12 +81,11 @@ module Sqreen
81
81
  if hkey.respond_to?(:empty?) && hkey.empty?
82
82
  false
83
83
  else
84
- key_incl =
85
- if values.is_a?(String)
86
- str_include? values, hkey.to_s
87
- else
88
- values.include?(hkey.to_s)
89
- end
84
+ key_incl = if values.is_a?(String)
85
+ str_include?(values, hkey.to_s)
86
+ else
87
+ values.include?(hkey.to_s)
88
+ end
90
89
 
91
90
  key_incl || hash_key_include?(values, hval, min_value_size, rem - 1)
92
91
  end
@@ -28,39 +28,21 @@ module Sqreen
28
28
  end
29
29
 
30
30
  def pre_with_conditions(inst, args, budget = nil, &block)
31
- return pre_without_conditions(inst, args, budget, &block) if pre_conditions.nil?
32
-
33
31
  eargs = [nil, framework, inst, args, @data, nil]
34
- return nil unless pre_conditions.evaluate(*eargs)
35
-
36
- res = pre_without_conditions(inst, args, budget, &block)
37
- return { passed_conditions: true } unless res.is_a?(Hash)
38
- res[:passed_conditions] = true
39
- res
32
+ return nil if !pre_conditions.nil? && !pre_conditions.evaluate(*eargs)
33
+ pre_without_conditions(inst, args, budget, &block)
40
34
  end
41
35
 
42
36
  def post_with_conditions(rv, inst, args, budget = nil, &block)
43
- return post_without_conditions(rv, inst, args, budget, &block) if post_conditions.nil?
44
-
45
37
  eargs = [nil, framework, inst, args, @data, rv]
46
- return nil unless post_conditions.evaluate(*eargs)
47
-
48
- res = post_without_conditions(rv, inst, args, budget, &block)
49
- return { passed_conditions: true } if res.nil?
50
- res[:passed_conditions] = true
51
- res
38
+ return nil if !post_conditions.nil? && !post_conditions.evaluate(*eargs)
39
+ post_without_conditions(rv, inst, args, budget, &block)
52
40
  end
53
41
 
54
42
  def failing_with_conditions(rv, inst, args, budget = nil, &block)
55
- return failing_without_conditions(rv, inst, args, budget, &block) if failing_conditions.nil?
56
-
57
43
  eargs = [nil, framework, inst, args, @data, rv]
58
- return nil unless failing_conditions.evaluate(*eargs)
59
-
60
- res = failing_without_conditions(rv, inst, args, budget, &block)
61
- return { passed_conditions: true } if res.nil?
62
- res[:passed_conditions] = true
63
- res
44
+ return nil if !failing_conditions.nil? && !failing_conditions.evaluate(*eargs)
45
+ failing_without_conditions(rv, inst, args, budget, &block)
64
46
  end
65
47
 
66
48
  protected
@@ -78,14 +78,41 @@ module Sqreen
78
78
  require_relative 'ecosystem/http/net_http'
79
79
  register Http::NetHttp.new
80
80
 
81
- require_relative 'ecosystem/redis/redis_connection'
82
- register Redis::RedisConnection.new
81
+ require_relative 'ecosystem/databases/postgres'
82
+ register Databases::Postgres.new
83
+
84
+ require_relative 'ecosystem/databases/mysql'
85
+ register Databases::Mysql.new
86
+
87
+ require_relative 'ecosystem/databases/mongo'
88
+ register Databases::Mongo.new
89
+
90
+ require_relative 'ecosystem/databases/redis'
91
+ register Databases::Redis.new
92
+
93
+ require_relative 'ecosystem/messaging/sqs'
94
+ register Messaging::Sqs.new
95
+
96
+ require_relative 'ecosystem/messaging/kinesis'
97
+ register Messaging::Kinesis.new
98
+
99
+ require_relative 'ecosystem/messaging/bunny'
100
+ register Messaging::Bunny.new
101
+
102
+ require_relative 'ecosystem/messaging/kafka'
103
+ register Messaging::Kafka.new
83
104
 
84
105
  require_relative 'ecosystem/tracing/modules/client'
85
106
  register Tracing::Modules::Client.new
86
107
 
87
108
  require_relative 'ecosystem/tracing/modules/server'
88
109
  register Tracing::Modules::Server.new
110
+
111
+ require_relative 'ecosystem/tracing/modules/producer'
112
+ register Tracing::Modules::Producer.new
113
+
114
+ require_relative 'ecosystem/tracing/modules/consumer'
115
+ register Tracing::Modules::Consumer.new
89
116
  end
90
117
 
91
118
  def register(mod)
@@ -0,0 +1,23 @@
1
+ require 'sqreen/ecosystem/module_api/tracing/client_data'
2
+
3
+ module Sqreen
4
+ module Ecosystem
5
+ module Databases
6
+ class DatabaseConnectionData
7
+ include ModuleApi::Tracing::ClientData
8
+
9
+ # @return [Integer]
10
+ attr_accessor :port
11
+
12
+ # @return [String]
13
+ attr_accessor :unix_socket
14
+
15
+ # @return [String]
16
+ attr_accessor :username
17
+
18
+ # @return [String]
19
+ attr_accessor :db
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,39 @@
1
+ require 'sqreen/ecosystem/module_api'
2
+ require 'sqreen/ecosystem/module_api/instrumentation'
3
+ require 'sqreen/ecosystem/module_api/message_producer'
4
+ require 'sqreen/ecosystem/databases/database_connection_data'
5
+
6
+ module Sqreen
7
+ module Ecosystem
8
+ module Databases
9
+ class Mongo
10
+ include ModuleApi::Instrumentation
11
+ include ModuleApi::MessageProducer
12
+
13
+ def setup
14
+ advice = wrap_for_interest(DatabaseConnectionData, &method(:after_advice))
15
+ instrument 'Mongo::Client#initialize', after: advice
16
+ end
17
+
18
+ private
19
+
20
+ # @param [Sqreen::Graft::CallbackCall] call
21
+ def after_advice(call, _ball)
22
+ return if call.raised
23
+
24
+ client = call.instance
25
+ server_addrs = client.cluster.servers.map(&:address)
26
+
27
+ server_addrs.map do |addr|
28
+ DatabaseConnectionData.new(
29
+ transport: :mongo,
30
+ host: addr.host,
31
+ port: addr.port,
32
+ db: client.database.name,
33
+ )
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,54 @@
1
+ require 'sqreen/ecosystem/module_api'
2
+ require 'sqreen/ecosystem/module_api/instrumentation'
3
+ require 'sqreen/ecosystem/module_api/message_producer'
4
+ require 'sqreen/ecosystem/module_api/tracing_id_generation'
5
+ require 'sqreen/ecosystem/module_api/tracing/client_data'
6
+
7
+ module Sqreen
8
+ module Ecosystem
9
+ module Databases
10
+ class Mysql
11
+ include ModuleApi::Instrumentation
12
+ include ModuleApi::MessageProducer
13
+
14
+ def setup
15
+ advice = wrap_for_interest(DatabaseConnectionData, &method(:after_advice))
16
+ instrument 'Mysql2::Client#connect', after: advice
17
+ end
18
+
19
+ private
20
+
21
+ # instance is of type +Mysql2::Client+
22
+ # VALUE rb_mysql_connect(VALUE self, VALUE user, VALUE pass, VALUE host, VALUE port, VALUE database,
23
+ # VALUE socket, VALUE flags, VALUE conn_attrs) {
24
+ # @param [Sqreen::Graft::CallbackCall]
25
+ def after_advice(call, _ball)
26
+ args = call.args
27
+
28
+ # build & submit signal
29
+ signal = DatabaseConnectionData.new(transport: :mysql)
30
+
31
+ user = args[0]
32
+ host = args[2]
33
+ port = args[3]
34
+ db = args[4]
35
+ socket = args[5]
36
+
37
+ if socket && !socket.empty?
38
+ signal.unix_socket = socket
39
+ signal.host = 'localhost'
40
+ signal.ip = '::1'
41
+ else
42
+ signal.host = host
43
+ end
44
+
45
+ signal.port = port if port != 0
46
+ signal.username = user
47
+ signal.db = db
48
+
49
+ signal
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
@@ -0,0 +1,51 @@
1
+ require 'sqreen/ecosystem/module_api'
2
+ require 'sqreen/ecosystem/module_api/instrumentation'
3
+ require 'sqreen/ecosystem/module_api/message_producer'
4
+ require 'sqreen/ecosystem/databases/database_connection_data'
5
+
6
+ module Sqreen
7
+ module Ecosystem
8
+ module Databases
9
+ class Postgres
10
+ include ModuleApi::Instrumentation
11
+ include ModuleApi::MessageProducer
12
+
13
+ def setup
14
+ advice = wrap_for_interest(DatabaseConnectionData, &method(:after_advice))
15
+ instrument 'PG::Connection#initialize', after: advice
16
+ end
17
+
18
+ private
19
+
20
+ # instance is of type +PG::Connection+
21
+ # > c = PG::Connection.new(host: '172.17.0.2', password: 'mysecretpassword', user: 'postgres')
22
+ # => #<PG::Connection:0x000055b44d077d10>
23
+ # > %i{host port user db}.map { |m| c.send m }
24
+ # => ["172.17.0.2", 5432, "postgres", "postgres"]
25
+ def after_advice(call, _ball)
26
+ conn = call.instance
27
+
28
+ # build & submit signal
29
+ signal = DatabaseConnectionData.new(transport: :postgres)
30
+
31
+ host = conn.host
32
+ if host
33
+ if host.include?('/')
34
+ signal.unix_socket = host
35
+ signal.host = 'localhost'
36
+ signal.ip = '::1'
37
+ else
38
+ signal.host = host
39
+ end
40
+ end
41
+
42
+ signal.port = conn.port
43
+ signal.username = conn.user
44
+ signal.db = conn.db
45
+
46
+ signal
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,36 @@
1
+ require 'sqreen/ecosystem/module_api'
2
+ require 'sqreen/ecosystem/module_api/instrumentation'
3
+ require 'sqreen/ecosystem/module_api/message_producer'
4
+ require 'sqreen/ecosystem/databases/database_connection_data'
5
+
6
+ module Sqreen
7
+ module Ecosystem
8
+ module Databases
9
+ class Redis
10
+ include ModuleApi::Instrumentation
11
+ include ModuleApi::MessageProducer
12
+
13
+ def setup
14
+ advice = wrap_for_interest(DatabaseConnectionData, &method(:after_advice))
15
+ instrument 'Redis#initialize', after: advice
16
+ end
17
+
18
+ private
19
+
20
+ # @param [Sqreen::Graft::CallbackCall] call
21
+ def after_advice(call, _ball)
22
+ return if call.raised
23
+
24
+ conn = call.instance.connection
25
+
26
+ DatabaseConnectionData.new(
27
+ transport: :redis,
28
+ host: conn[:host],
29
+ port: conn[:port],
30
+ db: conn[:db].to_s,
31
+ )
32
+ end
33
+ end
34
+ end
35
+ end
36
+ end
@@ -1,5 +1,6 @@
1
1
  require 'sqreen/ecosystem/dispatch_table'
2
2
  require 'sqreen/ecosystem/loggable'
3
+ require 'sqreen/kit/configuration'
3
4
  require 'sqreen/kit/signals/specialized/sqreen_exception'
4
5
 
5
6
  module Sqreen
@@ -16,10 +17,11 @@ module Sqreen
16
17
  logger.debug { e.backtrace.map { |x| " #{x}" }.join("\n") }
17
18
 
18
19
  signal = Sqreen::Kit::Signals::Specialized::SqreenException.new(
19
- ruby_exception: e
20
+ ruby_exception: e,
21
+ source: Sqreen::Kit::Configuration.default_source
20
22
  )
21
23
 
22
- DispatchTable.consume_signal signal
24
+ DispatchTable.consume_signal[signal]
23
25
  end
24
26
  end
25
27
  end
@@ -0,0 +1,61 @@
1
+ require 'sqreen/ecosystem/module_api'
2
+ require 'sqreen/ecosystem/module_api/instrumentation'
3
+ require 'sqreen/ecosystem/module_api/message_producer'
4
+ require 'sqreen/ecosystem/module_api/tracing/consumer_data'
5
+ require 'sqreen/ecosystem/module_api/tracing/producer_data'
6
+
7
+ module Sqreen
8
+ module Ecosystem
9
+ module Messaging
10
+ class Bunny
11
+ include ModuleApi::Loggable
12
+ include ModuleApi::Instrumentation
13
+ include ModuleApi::MessageProducer
14
+
15
+ def setup
16
+ advice_send = wrap_for_interest(ModuleApi::Tracing::ProducerData, &method(:after_send_advice))
17
+ advice_receive = wrap_for_interest(ModuleApi::Tracing::ConsumerData, &method(:after_receive_advice))
18
+ advice_receive_consumer = wrap_for_interest(ModuleApi::Tracing::ConsumerData, &method(:after_receive_advice_consumer))
19
+ instrument 'Bunny::Queue#publish', after: advice_send
20
+ instrument 'Bunny::Queue#pop', after: advice_receive
21
+ instrument 'Bunny::Consumer#call', after: advice_receive_consumer
22
+ end
23
+
24
+ private
25
+
26
+ # @param [Sqreen::Graft::CallbackCall] call
27
+ def after_send_advice(call, _ball)
28
+ return if call.raised
29
+
30
+ create_signal(call.instance, ModuleApi::Tracing::ProducerData)
31
+ end
32
+
33
+ # @param [Sqreen::Graft::CallbackCall] call
34
+ def after_receive_advice(call, _ball)
35
+ return if call.raised
36
+
37
+ create_signal(call.instance, ModuleApi::Tracing::ConsumerData)
38
+ end
39
+
40
+ # @param [Sqreen::Graft::CallbackCall] call
41
+ def after_receive_advice_consumer(call, _ball)
42
+ return if call.raised
43
+
44
+ queue = call.instance.queue
45
+ create_signal(queue, ModuleApi::Tracing::ConsumerData)
46
+ end
47
+
48
+ # @param [Bunny::Queue] q
49
+ def create_signal(q, clazz)
50
+ conn = q.channel.connection
51
+
52
+ clazz.new(
53
+ message_type: :amqp,
54
+ host: conn.host,
55
+ topic: q.name,
56
+ )
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end