oneapm_rpm 1.3.7 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (74) hide show
  1. checksums.yaml +5 -13
  2. data/.gitignore +3 -2
  3. data/Gemfile +1 -1
  4. data/lib/one_apm/agent.rb +17 -10
  5. data/lib/one_apm/agent/agent/connect.rb +9 -3
  6. data/lib/one_apm/agent/agent/container_data_manager.rb +20 -3
  7. data/lib/one_apm/agent/agent/cross_app_samples_sender.rb +22 -0
  8. data/lib/one_apm/agent/agent/rule_fetcher.rb +15 -0
  9. data/lib/one_apm/agent/agent/start.rb +15 -3
  10. data/lib/one_apm/agent/agent/start_worker_thread.rb +8 -2
  11. data/lib/one_apm/agent/cross_app/cross_app_monitor.rb +7 -6
  12. data/lib/one_apm/agent/cross_app/cross_app_tracing.rb +45 -9
  13. data/lib/one_apm/agent/cross_app/cross_app_tracing_message.rb +130 -0
  14. data/lib/one_apm/agent/database/active_record_helper.rb +104 -50
  15. data/lib/one_apm/agent/datastore.rb +8 -0
  16. data/lib/one_apm/agent/datastore/metric_helper.rb +37 -6
  17. data/lib/one_apm/agent/synthetics_monitor.rb +1 -1
  18. data/lib/one_apm/collector/collector/helper.rb +5 -1
  19. data/lib/one_apm/collector/collector/http_connection.rb +16 -8
  20. data/lib/one_apm/collector/collector_service.rb +6 -4
  21. data/lib/one_apm/collector/containers/transaction_event_aggregator.rb +52 -75
  22. data/lib/one_apm/collector/containers/transaction_sampler.rb +6 -2
  23. data/lib/one_apm/configuration.rb +8 -4
  24. data/lib/one_apm/configuration/default_source.rb +24 -3
  25. data/lib/one_apm/configuration/server_source.rb +1 -1
  26. data/lib/one_apm/inst/http_clients/curb.rb +4 -1
  27. data/lib/one_apm/inst/http_clients/thrift.rb +57 -20
  28. data/lib/one_apm/inst/nosql/memcache.rb +21 -2
  29. data/lib/one_apm/inst/nosql/mongo2.rb +11 -8
  30. data/lib/one_apm/inst/nosql/redis.rb +8 -3
  31. data/lib/one_apm/inst/orm/active_record.rb +13 -7
  32. data/lib/one_apm/inst/rails4/active_record_subscriber.rb +16 -13
  33. data/lib/one_apm/inst/transaction_base.rb +0 -1
  34. data/lib/one_apm/logger/audit_logger.rb +19 -2
  35. data/lib/one_apm/manager.rb +1 -0
  36. data/lib/one_apm/probe/instance_methods.rb +0 -1
  37. data/lib/one_apm/rack/middleware_tracing.rb +1 -0
  38. data/lib/one_apm/support/event_buffer/sampled_buffer.rb +4 -0
  39. data/lib/one_apm/support/helper.rb +16 -0
  40. data/lib/one_apm/support/http_clients/curb_wrappers.rb +20 -0
  41. data/lib/one_apm/support/http_clients/excon_wrappers.rb +25 -0
  42. data/lib/one_apm/support/http_clients/httpclient_wrappers.rb +20 -0
  43. data/lib/one_apm/support/http_clients/net_http_wrappers.rb +20 -0
  44. data/lib/one_apm/support/http_clients/thrift_tracer.rb +64 -0
  45. data/lib/one_apm/support/http_clients/typhoeus_wrappers.rb +21 -1
  46. data/lib/one_apm/support/http_clients/uri_util.rb +1 -0
  47. data/lib/one_apm/support/ip.rb +15 -0
  48. data/lib/one_apm/support/rename_rules_engine.rb +39 -0
  49. data/lib/one_apm/support/rename_rules_engine/external_rename_rule.rb +84 -0
  50. data/lib/one_apm/support/rename_rules_engine/match_expression/base.rb +46 -0
  51. data/lib/one_apm/support/rename_rules_engine/match_expression/engine.rb +35 -0
  52. data/lib/one_apm/support/rename_rules_engine/match_expression/method.rb +20 -0
  53. data/lib/one_apm/support/rename_rules_engine/match_expression/split_object.rb +19 -0
  54. data/lib/one_apm/support/rename_rules_engine/match_expression/url.rb +19 -0
  55. data/lib/one_apm/support/rename_rules_engine/rename/base.rb +25 -0
  56. data/lib/one_apm/support/rename_rules_engine/rename/engine.rb +36 -0
  57. data/lib/one_apm/support/rename_rules_engine/rename/header.rb +17 -0
  58. data/lib/one_apm/support/rename_rules_engine/rename/parameter.rb +18 -0
  59. data/lib/one_apm/support/rename_rules_engine/rename/segment.rb +41 -0
  60. data/lib/one_apm/transaction.rb +11 -2
  61. data/lib/one_apm/transaction/class_methods.rb +3 -3
  62. data/lib/one_apm/transaction/event_analytic_data.rb +51 -0
  63. data/lib/one_apm/transaction/event_analytic_sample.rb +35 -0
  64. data/lib/one_apm/transaction/instance_helpers.rb +1 -1
  65. data/lib/one_apm/transaction/sample_buffer/cross_sample_buffer.rb +47 -0
  66. data/lib/one_apm/transaction/segment.rb +2 -1
  67. data/lib/one_apm/transaction/transaction_finish_append.rb +4 -0
  68. data/lib/one_apm/transaction/transaction_name.rb +1 -1
  69. data/lib/one_apm/transaction/transaction_sample.rb +12 -7
  70. data/lib/one_apm/version.rb +2 -2
  71. data/lib/sequel/extensions/oneapm_instrumentation.rb +16 -9
  72. data/lib/sequel/plugins/oneapm_instrumentation.rb +3 -2
  73. data/oneapm_rpm.gemspec +2 -1
  74. metadata +41 -21
@@ -0,0 +1,64 @@
1
+ module OneApm
2
+ module Support
3
+ module HTTPClients
4
+ module ThriftTracer
5
+ def self.included clazz
6
+ clazz.class_eval do
7
+
8
+ def is_cross_app=(is_cross_app)
9
+ @is_cross_app = is_cross_app
10
+ end
11
+
12
+ def is_cross_app?
13
+ @is_cross_app
14
+ end
15
+
16
+ def write_field_stop_with_oneapm
17
+ is_write_fielded = false
18
+ begin
19
+ state = OneApm::TransactionState.tl_get
20
+ message = OneApm::Agent::CrossAppTracingMessage.request_data(state)
21
+ if message
22
+ write_field_begin('oneapm_message', ::Thrift::Types::STRING, -32768)
23
+ is_write_fielded = true
24
+ write_string("####{message}###")
25
+ end
26
+ rescue => e
27
+ OneApm::Manager.logger.error "Thrift write_field_stop error: #{e}"
28
+ ensure
29
+ write_field_end if is_write_fielded
30
+ end
31
+ write_field_stop_without_oneapm
32
+ end
33
+ alias :write_field_stop_without_oneapm :write_field_stop
34
+ alias :write_field_stop :write_field_stop_with_oneapm
35
+
36
+ def read_field_begin_with_oneapm
37
+ name, type, id = read_field_begin_without_oneapm
38
+ begin
39
+ is_cross_app = true if type == ::Thrift::Types::STRING && id == -32768
40
+ rescue => e
41
+ OneApm::Manager.logger.error "Thrift read_field_begin error: #{e}"
42
+ end
43
+ [name, type, id]
44
+ end
45
+ alias :read_field_begin_without_oneapm :read_field_begin
46
+ alias :read_field_begin :read_field_begin_with_oneapm
47
+
48
+ def read_string_with_oneapm
49
+ string = read_string_without_oneapm
50
+ if string && is_cross_app?
51
+ if /###(?<message>.*)###/ =~ string
52
+ OneApm::Agent::CrossAppTracingMessage.process_request(message)
53
+ end
54
+ end
55
+ string
56
+ end
57
+ alias :read_string_without_oneapm :read_string
58
+ alias :read_string :read_string_with_oneapm
59
+ end
60
+ end
61
+ end
62
+ end
63
+ end
64
+ end
@@ -47,7 +47,11 @@ module OneApm
47
47
  end
48
48
 
49
49
  def host
50
- self['host'] || self['Host'] || @uri.host
50
+ @uri.host
51
+ end
52
+
53
+ def port
54
+ @uri.port
51
55
  end
52
56
 
53
57
  def method
@@ -67,6 +71,22 @@ module OneApm
67
71
  def uri
68
72
  @uri
69
73
  end
74
+
75
+ def query
76
+ @uri.query.nil?? {} : CGI.parse(@uri.query)
77
+ end
78
+
79
+ def body
80
+ @request.options[:body]
81
+ end
82
+
83
+ def post_params
84
+ body.nil?? {} : CGI.parse(body)
85
+ end
86
+
87
+ def params
88
+ post_params.merge(query)
89
+ end
70
90
  end
71
91
  end
72
92
  end
@@ -29,6 +29,7 @@ module OneApm
29
29
  address.normalize!
30
30
  URI.parse(address.to_s)
31
31
  else
32
+ 'http://'
32
33
  URI.parse(url)
33
34
  end
34
35
  end
@@ -0,0 +1,15 @@
1
+ # encoding: utf-8
2
+ module OneApm
3
+ module Agent
4
+ module IP
5
+
6
+ def self.get
7
+ ipinfo = `/sbin/ifconfig | grep 'inet ' | grep -v '127.0.0.1' | awk '{print $2}'`.split("\n")[0].sub(/addr:|地址:|\s+/, '')
8
+ ipinfo.split("\n")[0].sub(/addr:|地址:|\s+/, '')
9
+ rescue => e
10
+ nil
11
+ end
12
+
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+ require 'one_apm/support/rename_rules_engine/external_rename_rule'
3
+ module OneApm
4
+ module Support
5
+ class RenameRulesEngine
6
+
7
+ class << self
8
+
9
+ def create_or_update_external_rules(connect_response)
10
+ unpacked_rules = unpack_rules(connect_response)
11
+ if unpacked_rules.nil?
12
+ nil
13
+ elsif current_external_rename_rules.nil?
14
+ OneApm::Manager.agent.external_rename_rules = ExternalRenameRule.new(unpacked_rules)
15
+ elsif need_update?(unpacked_rules)
16
+ OneApm::Manager.agent.external_rename_rules = ExternalRenameRule.new(unpacked_rules)
17
+ OneApm::Manager.logger.debug "Updated RenameRules from version : #{unpacked_rules['hash_value']}"
18
+ end
19
+ end
20
+
21
+ # There are two kinds of response
22
+ # First one from connect data, another one from event_loop
23
+ def unpack_rules(connect_response)
24
+ return nil if connect_response.nil?
25
+ connect_response['btm_value'].nil? ? connect_response : connect_response['btm_value']
26
+ end
27
+
28
+ def need_update?(unpacked_rules)
29
+ current_external_rename_rules.hash_value.to_i < unpacked_rules['hash_value'].to_i
30
+ end
31
+
32
+ def current_external_rename_rules
33
+ OneApm::Manager.agent.external_rename_rules
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,84 @@
1
+ # encoding: utf-8
2
+ require 'one_apm/support/rename_rules_engine/match_expression/engine'
3
+ require 'one_apm/support/rename_rules_engine/rename/engine'
4
+
5
+ module OneApm
6
+ module Support
7
+ class RenameRulesEngine
8
+ class ExternalRenameRule
9
+ OA_RENAME_SEPARATOR = '/'.freeze
10
+
11
+ attr_accessor :hash_value, :rules
12
+
13
+ def initialize(hash={})
14
+ @hash_value = hash['hash_value']
15
+ rules = hash['rules'] || []
16
+ rules = rules.select { |r| r['type'] == "remote" }
17
+ rules = rules.sort_by { |r| r['priority'] }
18
+ rules = rules.map { |r| Rule.new(r) }
19
+ rules = rules.reverse
20
+ @rules = rules
21
+ end
22
+
23
+ def rename(request)
24
+ selected_rule = select_rule(request)
25
+ OneApm::Manager.logger.debug "request", request.inspect
26
+ OneApm::Manager.logger.debug "selected_rule", selected_rule.inspect
27
+ res = if selected_rule.nil?
28
+ default_rename(request)
29
+ else
30
+ selected_rule.apply(request)
31
+ end
32
+ "External/HTTP/#{request.host}:#{request.port}/#{res}"
33
+ end
34
+
35
+ def default_rename(request)
36
+ path = request.uri.path.split(OA_RENAME_SEPARATOR)
37
+ path.delete('')
38
+ if path.size <= 1
39
+ "#{path.first}/"
40
+ else
41
+ "#{path[0..1].join(OA_RENAME_SEPARATOR)}"
42
+ end
43
+ end
44
+
45
+ def select_rule(request)
46
+ OneApm::Manager.logger.debug "@rules", @rules.inspect
47
+ @rules.select { |r| r.enable?&&r.should_rename?(request) }.first
48
+ end
49
+
50
+ end
51
+
52
+ class Rule
53
+ OA_RENAME_SEPARATOR = '/'.freeze
54
+ attr_accessor :replacement, :state, :ignore, :priority, :match_expressions, :rename_rules
55
+
56
+ def initialize(hash)
57
+ @replacement = hash['replacement']
58
+ @state = hash['state'].to_i
59
+ @ignore = hash['ignore']
60
+ @priority = hash['priority'].to_i
61
+ @match_expressions = hash['match_expression'].map { |match_expression| MatchExpression::Engine.create_match_expression(match_expression) }
62
+ @rename_rules = hash['rename'].map { |rename| Rename::Engine.create_rename_rules(rename) }
63
+ end
64
+
65
+ def should_rename?(request)
66
+ match_expressions.map do |match_expression|
67
+ match_expression.match?(request)
68
+ end.all?
69
+ end
70
+
71
+ def enable?
72
+ !ignore && state == 0
73
+ end
74
+
75
+ def apply(request)
76
+ rename_rules.map do |rename_rule|
77
+ rename_rule.segment(request)
78
+ end.join(OA_RENAME_SEPARATOR)
79
+ end
80
+ end
81
+
82
+ end
83
+ end
84
+ end
@@ -0,0 +1,46 @@
1
+ # encoding: utf-8
2
+
3
+ module OneApm
4
+ module Support
5
+ class RenameRulesEngine
6
+ module MatchExpression
7
+
8
+ class Base
9
+ attr_accessor :is_not, :match_value, :operate, :state
10
+
11
+ def initialize(expression)
12
+ @is_not = expression[:is_not]
13
+ @match_value = expression[:match_value]
14
+ @operate = expression[:operate]
15
+ @state = expression[:state]==0 ? true : false
16
+ end
17
+
18
+ def type_match?(type, expression, sample)
19
+ case type
20
+ when 'equals'
21
+ sample.eql?(expression)
22
+ when 'endwith'
23
+ sample.end_with?(expression)
24
+ when 'startswith'
25
+ sample.start_with?(expression)
26
+ when 'contains'
27
+ sample.include?(expression)
28
+ when 'in'
29
+ expression = expression.split(',')
30
+ expression.include?(sample)
31
+ when 'existence', 'isnotempty'
32
+ !(sample.nil? || sample.to_s.empty?)
33
+ else
34
+ false
35
+ end
36
+ end
37
+
38
+ def match?(request)
39
+ false
40
+ end
41
+
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,35 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'one_apm/support/rename_rules_engine/match_expression/split_object'
5
+ require 'one_apm/support/rename_rules_engine/match_expression/url'
6
+ require 'one_apm/support/rename_rules_engine/match_expression/method'
7
+ require 'one_apm/support/dotted_hash'
8
+
9
+ module OneApm
10
+ module Support
11
+ class RenameRulesEngine
12
+ module MatchExpression
13
+ module Engine
14
+
15
+ extend self
16
+
17
+ def create_match_expression(expression)
18
+ expression = DottedHash.new(expression)
19
+ case expression[:name].downcase
20
+ when 'splitobject'
21
+ SplitObject.new(expression)
22
+ when 'method'
23
+ Method.new(expression)
24
+ when 'url'
25
+ Url.new(expression)
26
+ else
27
+ Base.new(expression)
28
+ end
29
+ end
30
+ end
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,20 @@
1
+ require 'one_apm/support/rename_rules_engine/match_expression/base'
2
+
3
+ module OneApm
4
+ module Support
5
+ class RenameRulesEngine
6
+
7
+ module MatchExpression
8
+ class Method < Base
9
+
10
+ def match?(request)
11
+ return true if !state
12
+ match_result = type_match?(operate.downcase,match_value.to_s,request.method.to_s)
13
+ is_not ? !match_result : match_result
14
+ end
15
+ end
16
+
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,19 @@
1
+ require 'one_apm/support/rename_rules_engine/match_expression/base'
2
+ module OneApm
3
+ module Support
4
+ class RenameRulesEngine
5
+ module MatchExpression
6
+ class SplitObject < Base
7
+
8
+ def match?(request)
9
+ return true if match_value.downcase=='all'
10
+ return true if !state
11
+ match_result = type_match?(operate.downcase, match_value, "#{request.uri.host}:#{request.port}")
12
+ is_not ? !match_result : match_result
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'one_apm/support/rename_rules_engine/match_expression/base'
2
+
3
+ module OneApm
4
+ module Support
5
+ class RenameRulesEngine
6
+
7
+ module MatchExpression
8
+ class Url < Base
9
+ def match?(request)
10
+ return true if !state
11
+ match_result = type_match?(operate.downcase, match_value, request.uri.path)
12
+ is_not ? (!match_result) : (match_result)
13
+ end
14
+ end
15
+
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,25 @@
1
+ # encoding: utf-8
2
+
3
+ module OneApm
4
+ module Support
5
+ class RenameRulesEngine
6
+ module Rename
7
+ class Base
8
+
9
+ attr_accessor :state,:value
10
+
11
+ def initialize(rename_hash)
12
+ @value = rename_hash[:value]
13
+ @state = rename_hash[:state]==0 ? true : false
14
+ end
15
+
16
+
17
+ def segment(request)
18
+ ''
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+
4
+ require 'one_apm/support/rename_rules_engine/rename/base'
5
+ require 'one_apm/support/rename_rules_engine/rename/header'
6
+ require 'one_apm/support/rename_rules_engine/rename/parameter'
7
+ require 'one_apm/support/rename_rules_engine/rename/segment'
8
+ require 'one_apm/support/dotted_hash'
9
+
10
+ module OneApm
11
+ module Support
12
+ class RenameRulesEngine
13
+ module Rename
14
+ module Engine
15
+
16
+ extend self
17
+
18
+ def create_rename_rules(rename_hash)
19
+ rename_hash = DottedHash.new(rename_hash)
20
+ case rename_hash[:type].downcase
21
+ when 'segments'
22
+ Segment.new(rename_hash)
23
+ when 'parameter'
24
+ Parameter.new(rename_hash)
25
+ when 'header'
26
+ Header.new(rename_hash)
27
+ else
28
+ Base.new(rename_hash)
29
+ end
30
+ end
31
+ end
32
+
33
+ end
34
+ end
35
+ end
36
+ end