tingyun_rpm 1.6.1 → 3.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/lib/ting_yun/agent.rb +9 -2
  3. data/lib/ting_yun/agent/agent.rb +3 -2
  4. data/lib/ting_yun/agent/collector/error_collector/noticed_error.rb +1 -1
  5. data/lib/ting_yun/agent/collector/sql_sampler.rb +2 -2
  6. data/lib/ting_yun/agent/collector/transaction_sampler.rb +2 -2
  7. data/lib/ting_yun/agent/collector/transaction_sampler/class_method.rb +22 -7
  8. data/lib/ting_yun/agent/collector/transaction_sampler/slowest_sample_buffer.rb +3 -3
  9. data/lib/ting_yun/agent/collector/transaction_sampler/transaction_sample_buffer_base.rb +15 -2
  10. data/lib/ting_yun/agent/cross_app/cross_app_monitor.rb +22 -19
  11. data/lib/ting_yun/agent/cross_app/cross_app_tracing.rb +48 -14
  12. data/lib/ting_yun/agent/database.rb +1 -1
  13. data/lib/ting_yun/agent/datastore.rb +13 -2
  14. data/lib/ting_yun/agent/datastore/metric_helper.rb +8 -7
  15. data/lib/ting_yun/agent/instance_methods/connect.rb +21 -8
  16. data/lib/ting_yun/agent/instance_methods/container_data_manager.rb +20 -8
  17. data/lib/ting_yun/agent/instance_methods/start.rb +3 -3
  18. data/lib/ting_yun/agent/instance_methods/start_worker_thread.rb +9 -4
  19. data/lib/ting_yun/agent/method_tracer_helpers.rb +29 -1
  20. data/lib/ting_yun/agent/transaction.rb +24 -6
  21. data/lib/ting_yun/agent/transaction/attributes.rb +17 -2
  22. data/lib/ting_yun/agent/transaction/class_method.rb +1 -0
  23. data/lib/ting_yun/agent/transaction/instance_method.rb +10 -4
  24. data/lib/ting_yun/agent/transaction/request_attributes.rb +42 -3
  25. data/lib/ting_yun/agent/transaction/trace.rb +53 -6
  26. data/lib/ting_yun/agent/transaction/trace_node.rb +48 -12
  27. data/lib/ting_yun/agent/transaction/traced_method_stack.rb +1 -1
  28. data/lib/ting_yun/agent/transaction/transaction_sample_builder.rb +12 -11
  29. data/lib/ting_yun/agent/transaction/transaction_state.rb +16 -5
  30. data/lib/ting_yun/agent/transaction/transaction_timings.rb +1 -1
  31. data/lib/ting_yun/configuration/default_source.rb +327 -16
  32. data/lib/ting_yun/configuration/manager.rb +0 -1
  33. data/lib/ting_yun/configuration/server_source.rb +8 -2
  34. data/lib/ting_yun/configuration/yaml_source.rb +1 -1
  35. data/lib/ting_yun/frameworks/instance_methods.rb +2 -2
  36. data/lib/ting_yun/frameworks/rails.rb +2 -2
  37. data/lib/ting_yun/http/abstract_request.rb +12 -0
  38. data/lib/ting_yun/http/curb_wrappers.rb +1 -1
  39. data/lib/ting_yun/http/excon_wrappers.rb +9 -1
  40. data/lib/ting_yun/http/http_client_request.rb +13 -2
  41. data/lib/ting_yun/http/net_http_request.rb +10 -2
  42. data/lib/ting_yun/http/typhoeus_wrappers.rb +1 -1
  43. data/lib/ting_yun/instrumentation/active_record.rb +3 -5
  44. data/lib/ting_yun/instrumentation/bunny.rb +48 -44
  45. data/lib/ting_yun/instrumentation/grape.rb +4 -2
  46. data/lib/ting_yun/instrumentation/http_client.rb +1 -1
  47. data/lib/ting_yun/instrumentation/kafka.rb +18 -15
  48. data/lib/ting_yun/instrumentation/middleware_proxy.rb +3 -2
  49. data/lib/ting_yun/instrumentation/mongo.rb +2 -2
  50. data/lib/ting_yun/instrumentation/mongo_command_log_subscriber.rb +9 -9
  51. data/lib/ting_yun/instrumentation/rails3/action_controller.rb +3 -3
  52. data/lib/ting_yun/instrumentation/rake.rb +2 -1
  53. data/lib/ting_yun/instrumentation/redis.rb +6 -0
  54. data/lib/ting_yun/instrumentation/sidekiq.rb +1 -1
  55. data/lib/ting_yun/instrumentation/sinatra/action.rb +1 -1
  56. data/lib/ting_yun/instrumentation/support/action_cable_subscriber.rb +2 -2
  57. data/lib/ting_yun/instrumentation/support/action_controller_subscriber.rb +4 -4
  58. data/lib/ting_yun/instrumentation/support/action_view_subscriber.rb +14 -1
  59. data/lib/ting_yun/instrumentation/support/active_record_helper.rb +6 -2
  60. data/lib/ting_yun/instrumentation/support/active_record_subscriber.rb +14 -7
  61. data/lib/ting_yun/instrumentation/support/event_formatter.rb +7 -2
  62. data/lib/ting_yun/instrumentation/support/external_error.rb +1 -1
  63. data/lib/ting_yun/instrumentation/support/external_helper.rb +27 -4
  64. data/lib/ting_yun/instrumentation/support/javascript_instrumentor.rb +1 -1
  65. data/lib/ting_yun/instrumentation/support/method_instrumentation.rb +6 -1
  66. data/lib/ting_yun/instrumentation/support/parameter_filtering.rb +1 -1
  67. data/lib/ting_yun/instrumentation/support/thrift_helper.rb +4 -3
  68. data/lib/ting_yun/instrumentation/thrift.rb +7 -7
  69. data/lib/ting_yun/logger/create_logger_helper.rb +1 -1
  70. data/lib/ting_yun/middleware/agent_middleware.rb +1 -1
  71. data/lib/ting_yun/middleware/browser_monitoring.rb +3 -2
  72. data/lib/ting_yun/support/collector.rb +7 -1
  73. data/lib/ting_yun/ting_yun_service.rb +38 -21
  74. data/lib/ting_yun/ting_yun_service/http.rb +5 -3
  75. data/lib/ting_yun/ting_yun_service/request.rb +32 -6
  76. data/lib/ting_yun/ting_yun_service/upload_service.rb +25 -3
  77. data/lib/ting_yun/version.rb +4 -3
  78. data/lib/tingyun_rpm.rb +0 -2
  79. data/tingyun_rpm.gemspec +1 -0
  80. metadata +2 -2
@@ -9,7 +9,7 @@ module TingYun
9
9
  def create_log(root, override_logger)
10
10
  if !override_logger.nil?
11
11
  @log = override_logger
12
- elsif ::TingYun::Agent.config[:'nbs.agent_enabled'] == false
12
+ elsif ::TingYun::Agent.config[:'agent_enabled'] == false
13
13
  create_null_logger
14
14
  else
15
15
  if wants_stdout?
@@ -19,7 +19,7 @@ module TingYun
19
19
 
20
20
  def build_transaction_name
21
21
  prefix = ::TingYun::Instrumentation::Support::TransactionNamer.prefix_for_category(nil, @category)
22
- "#{prefix}#{self.class.name}/call"
22
+ "#{prefix}#{self.class.name}"
23
23
  end
24
24
 
25
25
 
@@ -87,13 +87,14 @@ module TingYun
87
87
  def manufacture_cookie
88
88
  state = TingYun::Agent::TransactionState.tl_get
89
89
  timings = state.timings
90
- "%7B%22id%22%3A%22#{TingYun::Support::Coerce.url_encode(TingYun::Agent.config[:tingyunIdSecret].to_s)}%22%2C%22n%22%3A%22#{TingYun::Support::Coerce.url_encode(state.transaction_name.to_s)}%22%2C%22tid%22%3A%22#{state.trace_id}%22%2C%22q%22%3A#{timings.queue_time_in_millis}%2C%22a%22%3A#{timings.app_time_in_millis}%7D"
90
+ "%7B%22id%22%3A%22#{TingYun::Support::Coerce.url_encode(TingYun::Agent.config[:idSecret].to_s)
91
+ }%22%2C%22n%22%3A%22#{TingYun::Support::Coerce.url_encode(state.transaction_name.to_s)}%22%2C%22tid%22%3A%22#{state.trace_id}%22%2C%22q%22%3A#{timings.queue_time_in_millis}%2C%22a%22%3A#{timings.app_time_in_millis}%7D"
91
92
  end
92
93
  def browser_timing_config(state)
93
94
  timings = state.timings
94
95
 
95
96
  data = {
96
- :id => TingYun::Agent.config[:tingyunIdSecret],
97
+ :id => TingYun::Agent.config[:idSecret],
97
98
  :n => state.transaction_name ,
98
99
  :a => timings.app_time_in_millis,
99
100
  :q => timings.queue_time_in_millis,
@@ -12,6 +12,9 @@ module TingYun
12
12
  def collector
13
13
  @remote_collector ||= collector_from_host
14
14
  end
15
+ def collectorV3(host)
16
+ @remote_collector ||= collector_from_host(host)
17
+ end
15
18
 
16
19
  def api_collector
17
20
  @api_collector ||= Collector.new(TingYun::Agent.config[:api_host], TingYun::Agent.config[:api_port])
@@ -24,11 +27,14 @@ module TingYun
24
27
  args = hostname.split(':')
25
28
  Collector.new(args[0], args[1]||TingYun::Agent.config[:port])
26
29
  end
27
-
28
30
  end
29
31
 
32
+ def reset
33
+ @remote_collector = nil
34
+ end
30
35
  end
31
36
 
37
+
32
38
  extend CollectorMethods
33
39
 
34
40
  end
@@ -30,27 +30,31 @@ module TingYun
30
30
  :applicationId,
31
31
  :ssl_cert_store,
32
32
  :shared_tcp_connection,
33
- :quantile_cache
33
+ :quantile_cache,
34
+ :idSecret,
35
+ :config,
36
+ :attempts
34
37
 
35
38
 
36
- def initialize(license_key=nil)
37
39
 
40
+ def initialize(license_key=nil)
38
41
  @license_key = license_key || TingYun::Agent.config[:'license_key']
39
42
  @request_timeout = TingYun::Agent.config[:timeout]
40
- @data_version = "1.4"
43
+ @data_version = ::TingYun::VERSION::DATA
41
44
  @marshaller =TingYun::Support::Serialize::JsonMarshaller.new
42
45
  @metric_id_cache = {}
43
46
  @quantile_cache = {}
47
+ @hosts = TingYun::Agent.config[:collector_addresses].split(',')
44
48
  end
45
49
 
46
50
  def connect(settings={})
47
- if host = get_redirect_host
51
+ if host = get_redirect_hostV3
48
52
  @collector = TingYun::Support.collector_from_host(host)
49
53
  end
50
- response = invoke_remote(:initAgentApp, [settings])
51
- TingYun::Agent.logger.info("initAgentApp response: #{response}") if TingYun::Agent.config[:'nbs.audit_mode']
52
- @applicationId = response['applicationId']
53
- @appSessionKey = response['appSessionKey']
54
+ response = invoke_remote(:init, settings)
55
+ @applicationId = response['appId']
56
+ @appSessionKey = response['sessionKey'] unless response['sessionKey'].nil?
57
+ @idSecret = response['idSecret']
54
58
  response
55
59
  end
56
60
 
@@ -59,6 +63,27 @@ module TingYun
59
63
  invoke_remote(:getRedirectHost)
60
64
  end
61
65
 
66
+ def get_redirect_hostV3
67
+ @attempts = 0
68
+ max_attempts = @hosts.size
69
+ begin
70
+ @collector=TingYun::Support.collectorV3(@hosts[@attempts])
71
+ @attempts += 1
72
+ invoke_remote(:redirect)
73
+ rescue => e
74
+ if @attempts < max_attempts
75
+ TingYun::Agent.logger.error(e)
76
+ TingYun::Agent.logger.debug("Retrying request to #{@hosts[@attempts]}")
77
+ TingYun::Support.reset
78
+ retry
79
+ else
80
+ @attempts = 0
81
+ TingYun::Support.reset
82
+ retry
83
+ end
84
+ end
85
+ end
86
+
62
87
  def force_restart
63
88
  @applicationId = nil
64
89
  @appSessionKey = nil
@@ -75,10 +100,8 @@ module TingYun
75
100
 
76
101
  # private
77
102
 
78
- def invoke_remote(method, payload=[], options = {})
79
-
103
+ def invoke_remote(method, payload={}, options ={})
80
104
  data = nil
81
- payload = payload[0] if method == :initAgentApp
82
105
  begin
83
106
  data = @marshaller.dump(payload, options)
84
107
  rescue StandardError, SystemStackError => e
@@ -86,7 +109,7 @@ module TingYun
86
109
  end
87
110
  # serialize_finish_time = Time.now
88
111
  uri = remote_method_uri(method)
89
- full_uri = "#{@collector}#{uri}"
112
+ full_uri = "http://#{@collector}#{uri}"
90
113
 
91
114
  if audit_mode?
92
115
  TingYun::Agent.logger.info("the prepare data: #{data} to url: #{full_uri}")
@@ -94,11 +117,9 @@ module TingYun
94
117
  TingYun::Agent.logger.info("prepare to send data")
95
118
  end
96
119
 
97
- data, encoding = compress_request_if_needed(data)
98
-
99
- response = send_request(:data => data,
100
- :uri => uri,
101
- :encoding => encoding,
120
+ # data, encoding = compress_request_if_needed(data)
121
+ response = send_requestV3(:data => data,
122
+ :full_uri => full_uri,
102
123
  :collector => @collector)
103
124
 
104
125
  if audit_mode?
@@ -107,10 +128,6 @@ module TingYun
107
128
  TingYun::Agent.logger.info("the send-process end")
108
129
  end
109
130
  @marshaller.load(decompress_response(response))
110
- ensure
111
- # take the initiative to GC
112
- payload = nil
113
- data = nil
114
131
  end
115
132
 
116
133
  def audit_mode?
@@ -18,9 +18,11 @@ module TingYun
18
18
  include Connection
19
19
 
20
20
  def remote_method_uri(method)
21
- params = {'licenseKey'=> @license_key,'version' => @data_version}
22
- raise ::TingYun::Support::Exception::AppSessionKeyError.new("@appSessionKey is asked when the upload-method happen") if method==:upload && @appSessionKey.nil?
23
- params[:appSessionKey] = @appSessionKey
21
+ params = {'version'=> @data_version}
22
+ params[:license] = @license_key unless method == :trace
23
+ raise ::TingYun::Support::Exception::AppSessionKeyError.new("@appSessionKey is asked when the upload-method happen") if method==:trace && @appSessionKey.nil?
24
+ params[:sessionKey] = @appSessionKey
25
+ params[:format] = "json"
24
26
 
25
27
  uri = "/" + method.to_s
26
28
  uri << '?' + params.map do |k,v|
@@ -6,6 +6,34 @@ module TingYun
6
6
  class TingYunService
7
7
  module Request
8
8
 
9
+ #Posts to the specified server, retry every minute if ServerConnectionException
10
+ def send_requestV3(opts)
11
+ request = Net::HTTP::Post.new(URI(opts[:full_uri]))
12
+ request.content_type = "application/json"
13
+ request.body = opts[:data]
14
+ response = nil
15
+ begin
16
+ conn = http_connection
17
+ TingYun::Agent.logger.debug "Sending request to #{opts[:collector]}#{opts[:uri]}"
18
+ TingYun::Support::TimerLib.timeout(@request_timeout) do
19
+ response = conn.request(request)
20
+ end
21
+ rescue *CONNECTION_ERRORS => e
22
+ close_shared_connection
23
+ raise TingYun::Support::Exception::ServerConnectionException, "Recoverable error talking to #{@collector} after #{attempts} attempts: #{e}"
24
+ end
25
+ TingYun::Agent.logger.debug "Received response, status: #{response.code}, encoding: '#{response['content-encoding']}'"
26
+
27
+ case response
28
+ when Net::HTTPSuccess
29
+ true # do nothing
30
+ else
31
+ raise TingYun::Support::Exception::ServerConnectionException, "Unexpected response from server (#{response.code}): #{response.message}"
32
+ end
33
+ response
34
+ end
35
+
36
+
9
37
  #Posts to the specified server, retry every minute if ServerConnectionException
10
38
  def send_request(opts)
11
39
  request = Net::HTTP::Post.new(opts[:uri], 'CONTENT-ENCODING' => opts[:encoding], 'HOST' => opts[:collector].name)
@@ -34,16 +62,14 @@ module TingYun
34
62
  TingYun::Agent.logger.debug "Received response, status: #{response.code}, encoding: '#{response['content-encoding']}'"
35
63
 
36
64
  case response
37
- when Net::HTTPSuccess
38
- true # do nothing
39
- else
40
- raise TingYun::Support::Exception::ServerConnectionException, "Unexpected response from server (#{response.code}): #{response.message}"
65
+ when Net::HTTPSuccess
66
+ true # do nothing
67
+ else
68
+ raise TingYun::Support::Exception::ServerConnectionException, "Unexpected response from server (#{response.code}): #{response.message}"
41
69
  end
42
70
  response
43
71
  end
44
72
 
45
-
46
-
47
73
  def compress_request_if_needed(data)
48
74
  encoding = 'identity'
49
75
  if data.size > 64*1024
@@ -4,6 +4,7 @@ require 'ting_yun/metrics/metric_data'
4
4
  require 'ting_yun/support/serialize/encodes'
5
5
  require 'ting_yun/support/quantile_p2'
6
6
  require 'json'
7
+ require 'ting_yun/configuration/server_source'
7
8
 
8
9
  module TingYun
9
10
  class TingYunService
@@ -147,10 +148,9 @@ module TingYun
147
148
 
148
149
  def action_trace_data(traces)
149
150
  upload_data = {
150
- :type => 'actionTraceData',
151
- :actionTraces => traces
151
+ :traces => traces
152
152
  }
153
- invoke_remote(:upload, [upload_data], :encoder=> json)
153
+ invoke_remote(:trace, upload_data, :encoder=> json)
154
154
  end
155
155
 
156
156
 
@@ -164,6 +164,19 @@ module TingYun
164
164
 
165
165
  end
166
166
 
167
+ def getCmd
168
+
169
+ upload_data = {
170
+ :mTime => TingYun::Agent.config["mTime"],
171
+ }
172
+ result = invoke_remote(:getCmd, upload_data, :encoder=> json)
173
+
174
+ if !result.empty?
175
+ server_config = TingYun::Configuration::ServerSource.new(result["args"])
176
+ ::TingYun::Agent.config.replace_or_add_config(server_config)
177
+ end
178
+ end
179
+
167
180
  def external_error_data(traces)
168
181
  upload_data = {
169
182
  :type => 'externalErrorTraceData',
@@ -171,5 +184,14 @@ module TingYun
171
184
  }
172
185
  invoke_remote(:upload, [upload_data], :encoder=> json)
173
186
  end
187
+
188
+
189
+ def action_traceV3(traces)
190
+ upload_data = {
191
+ :type => 'externalErrorTraceData',
192
+ :errors => traces
193
+ }
194
+ invoke_remote(:trace, upload_data, :encoder=> json)
195
+ end
174
196
  end
175
197
  end
@@ -3,9 +3,10 @@
3
3
 
4
4
  module TingYun
5
5
  module VERSION
6
- MAJOR = 1
7
- MINOR = 6
8
- TINY = 1
6
+ MAJOR = 3
7
+ MINOR = 2
8
+ TINY = 0
9
9
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
10
+ DATA = "3.2.0"
10
11
  end
11
12
  end
@@ -22,9 +22,7 @@
22
22
  #
23
23
 
24
24
  require 'ting_yun/frameworks'
25
-
26
25
  #if the agent had started in manual , then shouldn't start in auto again
27
-
28
26
  if defined?(Rails::VERSION)
29
27
  if Rails::VERSION::MAJOR.to_i >= 3
30
28
  module TingYun
@@ -38,6 +38,7 @@ Gem::Specification.new do |s|
38
38
  s.add_development_dependency 'yard'
39
39
  s.add_development_dependency 'rubycritic'
40
40
 
41
+ # s.add_runtime_dependency 'google-protobuf', '~> 3.11.4'
41
42
 
42
43
  if RUBY_VERSION >= '1.9.3'
43
44
  s.add_development_dependency 'guard', '= 2.12.5'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tingyun_rpm
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.6.1
4
+ version: 3.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - tingyun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-10-26 00:00:00.000000000 Z
11
+ date: 2020-04-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake