sqreen 1.21.0.beta1 → 1.22.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +40 -0
- data/lib/sqreen/actions/block_user.rb +1 -1
- data/lib/sqreen/actions/redirect_ip.rb +1 -1
- data/lib/sqreen/actions/redirect_user.rb +1 -1
- data/lib/sqreen/condition_evaluator.rb +8 -2
- data/lib/sqreen/configuration.rb +1 -1
- data/lib/sqreen/deferred_logger.rb +50 -14
- data/lib/sqreen/dependency/detector.rb +11 -3
- data/lib/sqreen/dependency/new_relic.rb +10 -1
- data/lib/sqreen/deprecation.rb +38 -0
- data/lib/sqreen/ecosystem.rb +55 -12
- data/lib/sqreen/ecosystem/databases/database_connection_data.rb +23 -0
- data/lib/sqreen/ecosystem/databases/mongo.rb +39 -0
- data/lib/sqreen/ecosystem/databases/mysql.rb +54 -0
- data/lib/sqreen/ecosystem/databases/postgres.rb +51 -0
- data/lib/sqreen/ecosystem/databases/redis.rb +36 -0
- data/lib/sqreen/ecosystem/exception_reporting.rb +28 -0
- data/lib/sqreen/ecosystem/http/net_http.rb +16 -17
- data/lib/sqreen/ecosystem/http/rack_request.rb +13 -12
- data/lib/sqreen/ecosystem/messaging/bunny.rb +61 -0
- data/lib/sqreen/ecosystem/messaging/kafka.rb +70 -0
- data/lib/sqreen/ecosystem/messaging/kinesis.rb +66 -0
- data/lib/sqreen/ecosystem/messaging/sqs.rb +68 -0
- data/lib/sqreen/ecosystem/module_api/message_producer.rb +57 -0
- data/lib/sqreen/ecosystem/module_api/signal_producer.rb +1 -3
- data/lib/sqreen/ecosystem/module_api/tracing.rb +45 -0
- data/lib/sqreen/ecosystem/module_api/tracing/client_data.rb +31 -0
- data/lib/sqreen/ecosystem/module_api/tracing/consumer_data.rb +13 -0
- data/lib/sqreen/ecosystem/module_api/tracing/messaging_data.rb +35 -0
- data/lib/sqreen/ecosystem/module_api/tracing/producer_data.rb +13 -0
- data/lib/sqreen/ecosystem/module_api/tracing/server_data.rb +27 -0
- data/lib/sqreen/ecosystem/module_api/tracing_id_generation.rb +16 -0
- data/lib/sqreen/ecosystem/module_registry.rb +9 -0
- data/lib/sqreen/ecosystem/tracing/modules/client.rb +35 -0
- data/lib/sqreen/ecosystem/tracing/modules/consumer.rb +35 -0
- data/lib/sqreen/ecosystem/tracing/modules/determine_ip.rb +28 -0
- data/lib/sqreen/ecosystem/tracing/modules/producer.rb +35 -0
- data/lib/sqreen/ecosystem/tracing/modules/server.rb +30 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_consumer.rb +56 -0
- data/lib/sqreen/ecosystem/tracing/signals/tracing_producer.rb +56 -0
- data/lib/sqreen/ecosystem/tracing_broker.rb +101 -0
- data/lib/sqreen/ecosystem/tracing_id_setup.rb +4 -4
- data/lib/sqreen/ecosystem/util/call_writers_from_init.rb +13 -0
- data/lib/sqreen/ecosystem_integration.rb +11 -0
- data/lib/sqreen/ecosystem_integration/request_lifecycle_tracking.rb +2 -0
- data/lib/sqreen/events/request_record.rb +0 -1
- data/lib/sqreen/frameworks/generic.rb +21 -0
- data/lib/sqreen/frameworks/rails.rb +0 -7
- data/lib/sqreen/frameworks/request_recorder.rb +2 -0
- data/lib/sqreen/graft/call.rb +78 -20
- data/lib/sqreen/graft/callback.rb +1 -1
- data/lib/sqreen/graft/hook.rb +192 -88
- data/lib/sqreen/graft/hook_point.rb +18 -11
- data/lib/sqreen/kit/signals/specialized/sqreen_exception.rb +2 -0
- data/lib/sqreen/legacy/instrumentation.rb +22 -10
- data/lib/sqreen/legacy/old_event_submission_strategy.rb +2 -1
- data/lib/sqreen/log.rb +3 -2
- data/lib/sqreen/log/loggable.rb +1 -0
- data/lib/sqreen/logger.rb +24 -0
- data/lib/sqreen/metrics_store.rb +11 -0
- data/lib/sqreen/null_logger.rb +22 -0
- data/lib/sqreen/remote_command.rb +1 -0
- data/lib/sqreen/rules.rb +8 -4
- data/lib/sqreen/rules/blacklist_ips_cb.rb +2 -2
- data/lib/sqreen/rules/custom_error_cb.rb +3 -3
- data/lib/sqreen/rules/rule_cb.rb +2 -0
- data/lib/sqreen/rules/waf_cb.rb +3 -3
- data/lib/sqreen/runner.rb +28 -2
- data/lib/sqreen/version.rb +1 -1
- data/lib/sqreen/weave/budget.rb +46 -0
- data/lib/sqreen/weave/legacy/instrumentation.rb +252 -109
- data/lib/sqreen/worker.rb +6 -2
- metadata +38 -14
- data/lib/sqreen/ecosystem/module_api/tracing_push_down.rb +0 -34
- data/lib/sqreen/ecosystem/redis/redis_connection.rb +0 -35
- data/lib/sqreen/encoding_sanitizer.rb +0 -27
@@ -0,0 +1,66 @@
|
|
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
|
+
# see https://aws.amazon.com/blogs/developer/announcing-amazon-kinesis-subscribetoshard-api-support-in-the-aws-sdk-for-ruby/
|
8
|
+
module Sqreen
|
9
|
+
module Ecosystem
|
10
|
+
module Messaging
|
11
|
+
class Kinesis
|
12
|
+
include ModuleApi::Loggable
|
13
|
+
include ModuleApi::Instrumentation
|
14
|
+
include ModuleApi::MessageProducer
|
15
|
+
|
16
|
+
def setup
|
17
|
+
advice_send = wrap_for_interest(ModuleApi::Tracing::ProducerData, &method(:after_send_advice))
|
18
|
+
advice_receive = wrap_for_interest(ModuleApi::Tracing::ConsumerData, &method(:after_receive_advice))
|
19
|
+
instrument 'Aws::Kinesis::Client#put_record', after: advice_send
|
20
|
+
instrument 'Aws::Kinesis::Client#put_records', after: advice_send
|
21
|
+
# more sophisticated usages (register_stream_consumer, possibly with AsyncClient)
|
22
|
+
# are not supported. They are more difficult to test, as kinesalite doesn't support them
|
23
|
+
instrument 'Aws::Kinesis::Client#get_shard_iterator', after: advice_receive
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
# @param [Sqreen::Graft::CallbackCall] call
|
29
|
+
def after_send_advice(call, _ball)
|
30
|
+
return if call.raised
|
31
|
+
unless call.args.length > 0 && call.args[0].is_a?(Hash)
|
32
|
+
logger.info "Unexpected arguments to put_record(s)"
|
33
|
+
return
|
34
|
+
end
|
35
|
+
|
36
|
+
create_signal(call.instance, call.args, ModuleApi::Tracing::ProducerData)
|
37
|
+
end
|
38
|
+
|
39
|
+
# @param [Sqreen::Graft::CallbackCall] call
|
40
|
+
def after_receive_advice(call, _ball)
|
41
|
+
return if call.raised
|
42
|
+
unless call.args.length > 0 && call.args[0].is_a?(Hash)
|
43
|
+
logger.info "Unexpected arguments to get_shared_iterator"
|
44
|
+
return
|
45
|
+
end
|
46
|
+
|
47
|
+
create_signal(call.instance, call.args, ModuleApi::Tracing::ConsumerData)
|
48
|
+
end
|
49
|
+
|
50
|
+
def create_signal(client, args, clazz)
|
51
|
+
hash = args[0]
|
52
|
+
stream_name = hash[:stream_name] || hash['stream_name']
|
53
|
+
return unless stream_name
|
54
|
+
|
55
|
+
endpoint = client.instance_variable_get(:@config).endpoint
|
56
|
+
|
57
|
+
clazz.new(
|
58
|
+
message_type: :'aws-kinesis',
|
59
|
+
host: endpoint.host,
|
60
|
+
topic: stream_name,
|
61
|
+
)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,68 @@
|
|
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 Sqs
|
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
|
+
instrument 'Aws::SQS::Client#send_message', after: advice_send
|
19
|
+
instrument 'Aws::SQS::Client#send_message_batch', after: advice_send
|
20
|
+
instrument 'Aws::SQS::Client#receive_message', after: advice_receive
|
21
|
+
end
|
22
|
+
|
23
|
+
private
|
24
|
+
|
25
|
+
# @param [Sqreen::Graft::CallbackCall] call
|
26
|
+
def after_send_advice(call, _ball)
|
27
|
+
return if call.raised
|
28
|
+
unless call.args.length > 0 && call.args[0].is_a?(Hash)
|
29
|
+
logger.info "Unexpected arguments to send_message(_batch)"
|
30
|
+
return
|
31
|
+
end
|
32
|
+
|
33
|
+
create_signal(call.args, ModuleApi::Tracing::ProducerData)
|
34
|
+
end
|
35
|
+
|
36
|
+
# @param [Sqreen::Graft::CallbackCall] call
|
37
|
+
def after_receive_advice(call, _ball)
|
38
|
+
return if call.raised
|
39
|
+
unless call.args.length > 0 && call.args[0].is_a?(Hash)
|
40
|
+
logger.info "Unexpected arguments to receive_message"
|
41
|
+
return
|
42
|
+
end
|
43
|
+
|
44
|
+
create_signal(call.args, ModuleApi::Tracing::ConsumerData)
|
45
|
+
end
|
46
|
+
|
47
|
+
def create_signal(args, clazz)
|
48
|
+
hash = args[0]
|
49
|
+
queue_url = hash[:queue_url] || hash['queue_url']
|
50
|
+
return unless queue_url
|
51
|
+
|
52
|
+
begin
|
53
|
+
uri = URI.parse(queue_url)
|
54
|
+
rescue URI::InvalidURIError
|
55
|
+
logger.info { "Invalid URI: #{uri}" }
|
56
|
+
return
|
57
|
+
end
|
58
|
+
|
59
|
+
clazz.new(
|
60
|
+
message_type: :'aws-sqs',
|
61
|
+
host: uri.host,
|
62
|
+
topic: ($1 if uri.path =~ /\A\/queue\/(?:[^\/]+\/)?([^\/]+)\z/),
|
63
|
+
)
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,57 @@
|
|
1
|
+
require 'sqreen/ecosystem/loggable'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
module Ecosystem
|
5
|
+
module ModuleApi
|
6
|
+
module MessageProducer
|
7
|
+
include Loggable
|
8
|
+
|
9
|
+
# method for ecosystem to inject the config
|
10
|
+
# @param [Sqreen::Ecosystem::TracingBroker]
|
11
|
+
attr_writer :tracing_broker
|
12
|
+
|
13
|
+
private
|
14
|
+
|
15
|
+
def determine_interest(type, hints = {})
|
16
|
+
@tracing_broker.interested_consumers(type, hints)
|
17
|
+
end
|
18
|
+
|
19
|
+
def publish(data, interested)
|
20
|
+
@tracing_broker.publish(data, interested)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Convenience wrapper.
|
24
|
+
# Wraps a callback, skipping it if there is no interest in the type
|
25
|
+
# produced and submitting the return value as a message to the
|
26
|
+
# tracing broker
|
27
|
+
def wrap_for_interest(type, gen_hints = nil, &block)
|
28
|
+
raise ArgumentError, 'no block passed' if block.nil?
|
29
|
+
|
30
|
+
proc do |*args|
|
31
|
+
hints = gen_hints[*args] if gen_hints
|
32
|
+
interested = determine_interest(type, hints || {})
|
33
|
+
|
34
|
+
unless interested
|
35
|
+
logger.debug { "No interested consumers in #{type}" }
|
36
|
+
next
|
37
|
+
end
|
38
|
+
|
39
|
+
res = block[*args]
|
40
|
+
|
41
|
+
next if res.nil?
|
42
|
+
|
43
|
+
if res.is_a?(Array)
|
44
|
+
res.each do |d|
|
45
|
+
raise "unexpected return type: #{d.class}" unless d.is_a?(type)
|
46
|
+
@tracing_broker.publish(d, interested)
|
47
|
+
end
|
48
|
+
else
|
49
|
+
raise "unexpected return type: #{res.class}" unless res.is_a?(type)
|
50
|
+
@tracing_broker.publish(res, interested)
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,13 +1,11 @@
|
|
1
1
|
require 'sqreen/ecosystem/dispatch_table'
|
2
|
-
require 'sqreen/ecosystem/module_api/transaction_storage'
|
3
2
|
|
4
3
|
module Sqreen
|
5
4
|
module Ecosystem
|
6
5
|
module ModuleApi
|
7
6
|
module SignalProducer
|
8
|
-
include TransactionStorage
|
9
|
-
|
10
7
|
# for injection
|
8
|
+
# callable taking no arguments and generating a tracing id
|
11
9
|
attr_writer :tracing_id_producer
|
12
10
|
|
13
11
|
private
|
@@ -0,0 +1,45 @@
|
|
1
|
+
require 'sqreen/ecosystem/module_api/signal_producer'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
module Ecosystem
|
5
|
+
module ModuleApi
|
6
|
+
module Tracing
|
7
|
+
include SignalProducer
|
8
|
+
|
9
|
+
def self.included(mod)
|
10
|
+
mod.extend(ClassMethods)
|
11
|
+
end
|
12
|
+
|
13
|
+
module ClassMethods
|
14
|
+
private
|
15
|
+
|
16
|
+
# @param [Module] type The type the including module is interested in
|
17
|
+
def consumes(type)
|
18
|
+
@consumes = type
|
19
|
+
end
|
20
|
+
|
21
|
+
# A fixed (non-virtual) scope for this tracing module
|
22
|
+
# @param [String] scope
|
23
|
+
def fixed_scope(scope)
|
24
|
+
@fixed_scope = scope
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def consumed_type
|
29
|
+
self.class.instance_variable_get(:@consumes) \
|
30
|
+
|| raise('@consumes not specified')
|
31
|
+
end
|
32
|
+
|
33
|
+
def scope(_hints = {})
|
34
|
+
self.class.instance_variable_get(:@fixed_scope) \
|
35
|
+
|| raise('@fixed_scope not set')
|
36
|
+
end
|
37
|
+
|
38
|
+
# including class must implement it
|
39
|
+
def receive(_data)
|
40
|
+
raise NotImplementedError
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'sqreen/ecosystem/util/call_writers_from_init'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
module Ecosystem
|
5
|
+
module ModuleApi
|
6
|
+
module Tracing
|
7
|
+
# The data the tracing module needs in order to populate
|
8
|
+
# +Sqreen::Ecosystem::Tracing::Signals::TracingClient::Payload+
|
9
|
+
#
|
10
|
+
# Signals are not produced by the data producers (transport)
|
11
|
+
# because of superior orders, as the only current use of this
|
12
|
+
# data is to generate signals.
|
13
|
+
module ClientData
|
14
|
+
include Util::CallWritersFromInit
|
15
|
+
|
16
|
+
# @return [Symbol]
|
17
|
+
attr_accessor :transport
|
18
|
+
|
19
|
+
# @return [String]
|
20
|
+
attr_accessor :host
|
21
|
+
|
22
|
+
# @return [String]
|
23
|
+
attr_accessor :ip
|
24
|
+
|
25
|
+
# @return [String]
|
26
|
+
attr_accessor :tracing_identifier
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'sqreen/ecosystem/util/call_writers_from_init'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
module Ecosystem
|
5
|
+
module ModuleApi
|
6
|
+
module Tracing
|
7
|
+
# The data the tracing module needs in order to populate
|
8
|
+
# +Sqreen::Ecosystem::Tracing::Signals::TracingConsumer::Payload+ and
|
9
|
+
# +Sqreen::Ecosystem::Tracing::Signals::TracingProducer::Payload+.
|
10
|
+
#
|
11
|
+
# Signals are not produced by the data producers (transport)
|
12
|
+
# because of superior orders, as the only current use of this
|
13
|
+
# data is to generate signals.
|
14
|
+
module MessagingData
|
15
|
+
include Util::CallWritersFromInit
|
16
|
+
|
17
|
+
# @return [Symbol]
|
18
|
+
attr_accessor :message_type
|
19
|
+
|
20
|
+
# @return [String]
|
21
|
+
attr_accessor :host
|
22
|
+
|
23
|
+
# @return [String]
|
24
|
+
attr_accessor :ip
|
25
|
+
|
26
|
+
# @return [String]
|
27
|
+
attr_accessor :topic
|
28
|
+
|
29
|
+
# @return [String]
|
30
|
+
attr_accessor :tracing_identifier
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'sqreen/ecosystem/util/call_writers_from_init'
|
2
|
+
|
3
|
+
module Sqreen
|
4
|
+
module Ecosystem
|
5
|
+
module ModuleApi
|
6
|
+
module Tracing
|
7
|
+
# The data the tracing module needs in order to populate
|
8
|
+
# +Sqreen::Ecosystem::Tracing::Signals::TracingServer::Payload+
|
9
|
+
module ServerData
|
10
|
+
include Util::CallWritersFromInit
|
11
|
+
|
12
|
+
# @return [Symbol]
|
13
|
+
attr_accessor :transport
|
14
|
+
|
15
|
+
# @return [String]
|
16
|
+
attr_accessor :client_ip
|
17
|
+
|
18
|
+
# @return [Array<String>]
|
19
|
+
attr_accessor :previous_hops
|
20
|
+
|
21
|
+
# @return [String]
|
22
|
+
attr_accessor :tracing_identifier
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -16,6 +16,11 @@ module Sqreen
|
|
16
16
|
def init_all
|
17
17
|
logger.info { "Initializing #{@mods.size} ecosystem modules" }
|
18
18
|
each_module do |mod|
|
19
|
+
unless mod.respond_to? :setup
|
20
|
+
logger.debug { "Module with type #{mod.class} requires no initialization" }
|
21
|
+
next
|
22
|
+
end
|
23
|
+
|
19
24
|
logger.debug { "Initializing module with type #{mod.class}" }
|
20
25
|
mod.setup
|
21
26
|
end
|
@@ -34,6 +39,10 @@ module Sqreen
|
|
34
39
|
selected_mods.each
|
35
40
|
end
|
36
41
|
end
|
42
|
+
|
43
|
+
def module_subset(type)
|
44
|
+
each_module(type).to_a
|
45
|
+
end
|
37
46
|
end
|
38
47
|
end
|
39
48
|
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'sqreen/ecosystem/tracing/modules/determine_ip'
|
2
|
+
require 'sqreen/ecosystem/tracing/signals/tracing_client'
|
3
|
+
require 'sqreen/ecosystem/loggable'
|
4
|
+
require 'sqreen/ecosystem/module_api'
|
5
|
+
require 'sqreen/ecosystem/module_api/tracing'
|
6
|
+
require 'sqreen/ecosystem/module_api/tracing/client_data'
|
7
|
+
|
8
|
+
module Sqreen
|
9
|
+
module Ecosystem
|
10
|
+
module Tracing
|
11
|
+
module Modules
|
12
|
+
class Client
|
13
|
+
include ModuleApi::Tracing
|
14
|
+
include ModuleApi::TracingIdGeneration
|
15
|
+
include ModuleApi::Loggable
|
16
|
+
|
17
|
+
consumes ModuleApi::Tracing::ClientData
|
18
|
+
fixed_scope 'client'
|
19
|
+
|
20
|
+
def receive(data)
|
21
|
+
signal = Tracing::Signals::TracingClient.new
|
22
|
+
signal.payload = Tracing::Signals::TracingClient::Payload.new(
|
23
|
+
transport: data.transport,
|
24
|
+
host: data.host || '',
|
25
|
+
ip: data.ip,
|
26
|
+
tracing_identifier: data.tracing_identifier || create_tracing_id
|
27
|
+
)
|
28
|
+
|
29
|
+
submit_signal signal
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|