tingyun_rpm 1.1.0 → 1.1.1

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: 3c697d815d0c4dfa694eec1b5c600254f77c0a33
4
- data.tar.gz: 7c0f3e329a156431014ee6ca7855ed0869059ac9
3
+ metadata.gz: 03acd867faa468e8cf34e5db0c625be623e83b40
4
+ data.tar.gz: ff2a3e050fa55b6691e24a6d095d76d1095c983b
5
5
  SHA512:
6
- metadata.gz: 32c38d249c36946077cecaa0e2483ece0b034a446da3a46ac1664d2d2c9c13a41b347caa962145140de7a6ab2630c752334d809787c6e1e35249fd8a93290da7
7
- data.tar.gz: 406227f1aee1ae7ce1e7aa533c29624c6e41be7a1259ce036c673b99a2f3f3af41235ef7b0a0881865d3db738baf9571ffa9463d285c3cb097d6647360fd1fca
6
+ metadata.gz: ed68cd19c263c869ee5a013e3c94043f74c71d93b34e613e11503fc10ab9f6c58d8adce2360ad90ba7cfc47262b44f184cbe6b2c9e8159adc6098e9793a72c7e
7
+ data.tar.gz: 3f1dca653319d616cff3c65af9e88082c6a9560617a063a46a90db1cd2ed09e3680a714a155f0a24e72b60867d2f3738714338bf2235e834bf6cab416e003f84
@@ -129,7 +129,7 @@ module TingYun
129
129
  query_plan_string = lines.join("\n")
130
130
  end
131
131
 
132
- unless record_sql_method == :raw
132
+ unless record_sql_method("nbs.action_tracer.record_sql") == :raw
133
133
  query_plan_string = Obfuscator.instance.obfuscate_postgres_explain(query_plan_string)
134
134
  end
135
135
  values = query_plan_string.split("\n").map { |line| [line] }
@@ -125,9 +125,11 @@ module TingYun
125
125
  rescue => e
126
126
  TingYun::Agent.logger.info("Unable to send #{endpoint} data, will try again later. Error: ", e)
127
127
  container.merge!(items)
128
- raise
128
+ ensure
129
+ items = nil # take the initiative to GC
129
130
  end
130
131
 
132
+
131
133
  end
132
134
 
133
135
  end
@@ -52,7 +52,8 @@ module TingYun
52
52
  :response_content_type,
53
53
  :error_recorded,
54
54
  :guid,
55
- :attributes
55
+ :attributes,
56
+ :request_attributes
56
57
 
57
58
 
58
59
  def initialize(category, options)
@@ -8,11 +8,12 @@ module TingYun
8
8
  class RequestAttributes
9
9
 
10
10
  attr_reader :request_path, :referer, :accept, :content_length, :host,
11
- :port, :user_agent, :request_method, :query_string
11
+ :port, :user_agent, :request_method, :query_string, :header, :cookie
12
12
 
13
13
  HTTP_ACCEPT_HEADER_KEY = 'HTTP_ACCEPT'.freeze
14
14
 
15
15
  def initialize request
16
+ @header = request.env
16
17
  @request_path = path_from_request request
17
18
  @referer = referer_from_request request
18
19
  @accept = attribute_from_env request, HTTP_ACCEPT_HEADER_KEY
@@ -22,6 +23,7 @@ module TingYun
22
23
  @user_agent = attribute_from_request request, :user_agent
23
24
  @request_method = attribute_from_request request, :request_method
24
25
  @query_string = attribute_from_request request, :query_string
26
+ @cookie = set_cookie(request)
25
27
  end
26
28
 
27
29
  def assign_agent_attributes(txn)
@@ -120,6 +122,16 @@ module TingYun
120
122
  end
121
123
  end
122
124
 
125
+ def set_cookie(request)
126
+ cookie = {}
127
+ _c = attribute_from_env(request, 'HTTP_COOKIE')
128
+ _c.split(';').each do |i|
129
+ _k, _v = i.split('=')
130
+ cookie[_k.strip] = _v.strip
131
+ end unless _c.nil?
132
+ cookie
133
+ end
134
+
123
135
  end
124
136
  end
125
137
  end
@@ -9,7 +9,7 @@ module TingYun
9
9
  class TransactionState
10
10
 
11
11
  # Request data
12
- attr_accessor :request, :transaction_sample_builder
12
+ attr_accessor :transaction_sample_builder
13
13
  attr_reader :current_transaction, :traced_method_stack
14
14
  # Sql Sampler Transaction Data
15
15
  attr_accessor :sql_sampler_transaction_data,
@@ -68,7 +68,6 @@ module TingYun
68
68
  # We purposefully don't reset @untraced, @record_tt and @record_sql
69
69
  # since those are managed by TingYun::Agent.disable_* calls explicitly
70
70
  # and (more importantly) outside the scope of a transaction
71
- @request = nil
72
71
  @current_transaction = transaction
73
72
  @traced_method_stack.clear
74
73
  @transaction_sample_builder = nil
@@ -67,6 +67,10 @@ module TingYun
67
67
  }
68
68
  end
69
69
 
70
+ def self.empty_array
71
+ Proc.new { [] }
72
+ end
73
+
70
74
 
71
75
  def default_values
72
76
  result = {}
@@ -210,7 +214,7 @@ module TingYun
210
214
  :public => true,
211
215
  :type => String,
212
216
  :allowed_from_server => true,
213
- :description => ''
217
+ :description => 'Specify a comma-delimited list of error classes that the agent should ignore'
214
218
  },
215
219
  :"nbs.error_collector.record_db_errors" => {
216
220
  :default => true,
@@ -311,22 +315,7 @@ module TingYun
311
315
  :public => false,
312
316
  :type => String,
313
317
  :allowed_from_server => true,
314
- :description => ''
315
- },
316
- :'nbs.action_tracer.action_name_functions' => {
317
- :default => '',
318
- :allow_nil => true,
319
- :public => false,
320
- :type => String,
321
- :allowed_from_server => true,
322
- :description => ''
323
- },
324
- :'nbs.action_tracer.remove_trailing_path' => {
325
- :default => false,
326
- :public => false,
327
- :type => Boolean,
328
- :allowed_from_server => true,
329
- :description => ''
318
+ :description => 'obfuscate the special sql fields'
330
319
  },
331
320
  :'nbs.action_tracer.stack_trace_threshold' => {
332
321
  :default => 500,
@@ -342,13 +331,6 @@ module TingYun
342
331
  :allowed_from_server => true,
343
332
  :description => 'Enable or disable Specifies External request parameters '
344
333
  },
345
- :'nbs.web_action_uri_params_captured' => {
346
- :default => '',
347
- :public => true,
348
- :type => String,
349
- :allowed_from_server => true,
350
- :description => 'Enable or disable Specifies WebAction request parameters '
351
- },
352
334
  :agent_log_file_path => {
353
335
  :default => 'log/',
354
336
  :public => true,
@@ -634,11 +616,11 @@ module TingYun
634
616
  :description => 'trace ID of crossing apps'
635
617
  },
636
618
  :'nbs.naming.rules' => {
637
- :default => '',
619
+ :default => "[]",
638
620
  :public => true,
639
621
  :type => String,
640
622
  :allowed_from_server => true,
641
- :description => 'the rule of name the webaction name containing match & split ways'
623
+ :description => 'defined nme rule '
642
624
  }
643
625
  }.freeze
644
626
  end
@@ -45,10 +45,19 @@ module TingYun
45
45
  end
46
46
  end
47
47
 
48
+ def capture_request(state, env)
49
+ if env.is_a? Hash
50
+
51
+ end
52
+ end
53
+
48
54
  def call(env)
49
55
  first_middleware = note_transaction_started(env)
50
56
 
51
57
  state = TingYun::Agent::TransactionState.tl_get
58
+ if first_middleware
59
+ capture_request(state, env)
60
+ end
52
61
  begin
53
62
  TingYun::Agent::Transaction.start(state, category, build_transaction_options(env, first_middleware))
54
63
  events.notify(:before_call, env) if first_middleware
@@ -2,26 +2,33 @@
2
2
  require 'ting_yun/agent'
3
3
  require 'ting_yun/instrumentation/support/controller_instrumentation'
4
4
  require 'ting_yun/instrumentation/support/parameter_filtering'
5
+ require 'ting_yun/instrumentation/support/split_controller'
5
6
 
6
7
  module TingYun
7
8
  module Instrumentation
8
9
  module Rails3
9
10
  module ActionController
10
11
 
11
- def tingyun_metric_path(action_name_override = nil)
12
+ include TingYun::Instrumentation::Support::SplitController
13
+
12
14
 
13
- return self.env["PATH_INFO"] unless TingYun::Agent.config[:'nbs.auto_action_naming']
14
15
 
15
- action = action_name_override || action_name
16
- if action_name_override || self.class.action_methods.include?(action)
17
- "Rails3/#{self.class.controller_path}%2F#{action}"
16
+ def tingyun_metric_path(action_name_override = nil)
17
+ if find_rule(request.request_method.upcase, request.path, request.env, request.filtered_parameters)
18
+ return "Rails3/#{namespace}/#{name(request.path.slice(1..-1), request.env, request.filtered_parameters, request.cookies)}"
18
19
  else
19
- "Rails3/#{self.class.controller_path}%2F(other)"
20
+ return self.env["PATH_INFO"] unless TingYun::Agent.config[:'nbs.auto_action_naming']
21
+
22
+ action = action_name_override || action_name
23
+ if action_name_override || self.class.action_methods.include?(action)
24
+ "Rails3/#{self.class.controller_path}%2F#{action}"
25
+ else
26
+ "Rails3/#{self.class.controller_path}%2F(other)"
27
+ end
20
28
  end
21
29
  end
22
30
 
23
31
 
24
-
25
32
  def process_action(*args)
26
33
  params = TingYun::Instrumentation::Support::ParameterFiltering.filter_rails_request_parameters(request.filtered_parameters)
27
34
  perform_action_with_tingyun_trace(:category => :controller,
@@ -4,6 +4,7 @@ require 'ting_yun/instrumentation/support/queue_time'
4
4
  require 'ting_yun/agent/transaction/transaction_state'
5
5
  require 'ting_yun/instrumentation/support/evented_subscriber'
6
6
  require 'ting_yun/agent/transaction'
7
+ require 'ting_yun/instrumentation/support/split_controller'
7
8
 
8
9
  module TingYun
9
10
  module Instrumentation
@@ -11,7 +12,7 @@ module TingYun
11
12
  class ActionControllerSubscriber < TingYun::Instrumentation::Support::EventedSubscriber
12
13
  def start(name, id, payload) #THREAD_LOCAL_ACCES
13
14
  state = TingYun::Agent::TransactionState.tl_get
14
- request = state.request
15
+ request = state.current_transaction.request_attributes rescue nil
15
16
  event = ControllerEvent.new(name, Time.now, nil, id, payload, request)
16
17
  push_event(event)
17
18
  # if state.execution_traced?
@@ -51,11 +52,14 @@ module TingYun
51
52
  end
52
53
 
53
54
  class ControllerEvent < TingYun::Instrumentation::Support::Event
55
+
56
+ include TingYun::Instrumentation::Support::SplitController
57
+
54
58
  attr_accessor :parent
55
59
  attr_reader :queue_start, :request
56
60
 
57
61
  def initialize(name, start, ending, transaction_id, payload, request)
58
- # We have a different initialize parameter list, so be explicit
62
+ # We have a different initialize parameter[[j]] list, so be explicit
59
63
  super(name, start, ending, transaction_id, payload, nil)
60
64
 
61
65
  @request = request
@@ -68,13 +72,25 @@ module TingYun
68
72
  end
69
73
 
70
74
  def metric_name
71
- if TingYun::Agent.config[:'nbs.auto_action_naming']
72
- @metric_name ||= "WebAction/Rails/#{metric_path}%2F#{metric_action}"
75
+ if find_rule(method, uri, request.header, params)
76
+ @metric_name = "WebAction/Rails/#{namespace}/#{name(uri, request.header, params, request.cookie)}"
73
77
  else
74
- path
78
+ if TingYun::Agent.config[:'nbs.auto_action_naming']
79
+ @metric_name ||= "WebAction/Rails/#{metric_path}%2F#{metric_action}"
80
+ else
81
+ path
82
+ end
75
83
  end
76
84
  end
77
85
 
86
+ def method
87
+ payload[:params]['_method'].upcase rescue nil || payload[:method]
88
+ end
89
+
90
+ def params
91
+ payload[:params]
92
+ end
93
+
78
94
  def metric_path
79
95
  @controller_class.controller_path
80
96
  end
@@ -87,6 +103,12 @@ module TingYun
87
103
  payload[:action]
88
104
  end
89
105
 
106
+ #expect the params
107
+ def uri
108
+ path.split('?').first
109
+ end
110
+ #contain the params
111
+
90
112
  def path
91
113
  payload[:path]
92
114
  end
@@ -17,10 +17,9 @@ module TingYun
17
17
 
18
18
  state = TingYun::Agent::TransactionState.tl_get
19
19
 
20
- state.request = self.request
21
20
  trace_options = args.last.is_a?(Hash) ? args.last : NR_DEFAULT_OPTIONS
22
21
  category = trace_options[:category] || :controller
23
- txn_options = create_transaction_options(trace_options, category, state)
22
+ txn_options = create_transaction_options(trace_options, category)
24
23
 
25
24
  begin
26
25
  txn = TingYun::Agent::Transaction.start(state, category, txn_options)
@@ -37,7 +36,7 @@ module TingYun
37
36
 
38
37
  private
39
38
 
40
- def create_transaction_options(trace_options, category, state)
39
+ def create_transaction_options(trace_options, category)
41
40
  txn_options = {}
42
41
 
43
42
  txn_options[:request] ||= request if respond_to?(:request)
@@ -2,48 +2,139 @@ module TingYun
2
2
  module Instrumentation
3
3
  module Support
4
4
  module SplitController
5
- # HTTP = {
6
- # 'GET' => 1,
7
- # 'POST' => 2,
8
- # 'PUT' => 3,
9
- # 'DELETE' => 4,
10
- # 'HEAD' => 5
11
- # }
12
- #
13
- # RULE = {
14
- # 1=> :eql?,
15
- # 2=> :start_with?,
16
- # 3=> :end_with?,
17
- # 4=> :include?
18
- # }
19
- #
20
- # def match?(event)
21
- # rules.each do |rule|
22
- # if method_match?(event.method, rule[:match]['method'])
23
- # if url_match?(event.path,rule[:match][:match], rule[:match]['value'])
24
- #
25
- # end
26
- # end
27
- # end
28
- # end
29
- #
30
- #
31
- #
32
- # def rules
33
- # TingYun::Agent.config[:'']
34
- # end
35
- #
36
- # def method_match?(method, rule)
37
- # rule[:match]['method'] == 0 || rule == HTTP[method]
38
- # end
39
- #
40
- # def url_match?(url, rule, value)
41
- # url.send(RULE[rule], value)
42
- # end
43
- #
44
- # def params_match?
45
- #
46
- # end
5
+ attr_accessor :rule, :tingyun_http_verb
6
+ HTTP = {
7
+ 'GET' => 1,
8
+ 'POST' => 2,
9
+ 'PUT' => 3,
10
+ 'DELETE' => 4,
11
+ 'HEAD' => 5,
12
+ 'PATCH' => 3
13
+ }
14
+
15
+ RULE = {
16
+ 1=> :eql?,
17
+ 2=> :start_with?,
18
+ 3=> :end_with?,
19
+ 4=> :include?,
20
+ 5=> :match
21
+ }
22
+
23
+ def find_rule(method, path, header, params)
24
+ @tingyun_http_verb = method
25
+ @rule = rules.detect do |_r|
26
+ method_match?(method, _r["match"]["method"]) and
27
+ url_match?(path, _r["match"]["match"], _r["match"]["value"]) and
28
+ params_match?(header, dot_flattened(params), _r["match"]["params"])
29
+ end
30
+ end
31
+
32
+ def namespace
33
+ @rule["name"]
34
+ end
35
+
36
+ def rules
37
+ require 'ting_yun/support/serialize/json_wrapper'
38
+ TingYun::Support::Serialize::JSONWrapper.load(TingYun::Agent.config[:'nbs.naming.rules'])
39
+ end
40
+
41
+ def method_match?(method, _r)
42
+ _r == 0 || _r == HTTP[method]
43
+ end
44
+
45
+ def url_match?(url, _r, value)
46
+ (!value.nil?) and (!value.strip.empty? rescue true) and url.send(RULE[_r], value.downcase)
47
+ end
48
+
49
+ def params_match?(header, params, _rs)
50
+ return true if _rs.empty?
51
+ begin
52
+ _rs.each do |_r|
53
+ next if _r["name"].nil? || _r["name"].strip.empty?
54
+ if _r["type"] == 2
55
+ raise_error(header["HTTP_#{_r["name"].upcase}"], RULE[_r["match"]], _r["value"], _r["type"])
56
+ else
57
+ raise_error(params[_r["name"].downcase], RULE[_r["match"]], _r["value"], _r["type"])
58
+ end
59
+ end
60
+ rescue
61
+ return false
62
+ end
63
+ return true
64
+ end
65
+
66
+ def raise_error(_v, _r, _v2, _t)
67
+ raise 'this param unexist so the rule is unmatched' if _v.nil? or _v2.nil? or _v2.strip.empty? rescue false
68
+ unless _t == 0
69
+ raise 'this param is unmatched with the rule' unless _v.send(_r, _v2)
70
+ end
71
+ end
72
+
73
+
74
+ def name(path, header, params, cookie)
75
+ return nil if @rule.nil?
76
+
77
+ name = ""
78
+ name << split_url(path.split('/'))
79
+ name << "?"
80
+ name << split_params(@rule["split"]["urlParams"], params)
81
+ name << split_params(@rule["split"]["bodyParams"], params)
82
+ name << split_params(@rule["split"]["cookieParams"], cookie)
83
+ name << split_header(@rule["split"]["headerParams"], header)
84
+ name = name[0..-2] << split_method
85
+ name.strip
86
+ end
87
+
88
+ def split_url(url)
89
+ uri = @rule["split"]["uri"]
90
+ return '' if uri.nil? or uri.strip.empty?
91
+ if uri.include? ','
92
+ _i = uri.split(',').map{|n|n.to_i}
93
+ url.values_at(*_i).join('/')
94
+ else
95
+ _i = uri.to_i
96
+ if _i > 0
97
+ url.values_at(1.._i).join('/')
98
+ else
99
+ url.values_at(_i..-1).join('/')
100
+ end
101
+ end
102
+ end
103
+
104
+ def split_method
105
+ if @rule["split"]["method"]
106
+ "(#{tingyun_http_verb})"
107
+ else
108
+ ''
109
+ end
110
+ end
111
+
112
+ def split_params(_r, params)
113
+ return '' if _r.nil? or _r.strip.empty?
114
+ query_string =''
115
+ _r.split(',').each {|_i|query_string +="#{_i}=#{params[_i]}&"}
116
+ query_string
117
+ end
118
+
119
+ def split_header(_r, header)
120
+ return '' if _r.nil? or _r.strip.empty?
121
+ query_string =''
122
+ _r.split(',').each {|_i|query_string +="#{_i}=#{header["HTTP_#{_i.upcase}"]}&"}
123
+ query_string
124
+ end
125
+
126
+ # turns {'a' => {'b' => 'c'}} into {'b' => 'c'}
127
+ def dot_flattened(nested_hash, result={})
128
+ nested_hash.each do |key, val|
129
+ next if val == nil
130
+ if val.respond_to?(:has_key?)
131
+ dot_flattened(val, result)
132
+ else
133
+ result[key] = val
134
+ end
135
+ end
136
+ result
137
+ end
47
138
  end
48
139
  end
49
140
  end
@@ -24,7 +24,7 @@ module TingYun
24
24
 
25
25
  def started_time_and_node(operate)
26
26
  _op_ = operations.delete(operate)
27
- time = (_op_ && _op_[:started_time]) or Time.now.to_f
27
+ time = (_op_ && _op_[:started_time]) || Time.now.to_f
28
28
  node = _op_ && _op_[:node]
29
29
  [time, node]
30
30
  end
@@ -261,7 +261,7 @@ TingYun::Support::LibraryDetection.defer do
261
261
 
262
262
  def send_message_with_tingyun(name, args_class, args = {})
263
263
 
264
- tag = "#{args_class.to_s.split('::').first.downcase}.#{name}"
264
+ tag = "#{args_class.to_s.split('::').first}.#{name}".downcase
265
265
  t0 = Time.now.to_f
266
266
  operations[tag] = {:started_time => t0}
267
267
  state = TingYun::Agent::TransactionState.tl_get
@@ -277,7 +277,7 @@ TingYun::Support::LibraryDetection.defer do
277
277
  alias :send_message :send_message_with_tingyun
278
278
 
279
279
  def send_oneway_message_with_tingyun(name, args_class, args = {})
280
- tag = "#{args_class.to_s.split('::').first.downcase}.#{name}"
280
+ tag = "#{args_class.to_s.split('::').first}.#{name}".downcase
281
281
  op_started = Time.now.to_f
282
282
  base, *other_metrics = metrics(tag)
283
283
  result = send_oneway_message_without_tingyun(name, args_class, args)
@@ -105,6 +105,10 @@ module TingYun
105
105
  TingYun::Agent.logger.info("the send-process end")
106
106
  end
107
107
  @marshaller.load(decompress_response(response))
108
+ ensure
109
+ # take the initiative to GC
110
+ payload = nil
111
+ data = nil
108
112
  end
109
113
 
110
114
  def handle_serialization_error(method, e)
@@ -7,7 +7,7 @@ module TingYun
7
7
  MAJOR = 1
8
8
 
9
9
  MINOR = 1
10
- TINY = 0
10
+ TINY = 1
11
11
 
12
12
  STRING = [MAJOR, MINOR, TINY].compact.join('.')
13
13
 
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.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - tingyun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-07-05 00:00:00.000000000 Z
11
+ date: 2016-07-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake
@@ -268,7 +268,6 @@ files:
268
268
  - lib/ting_yun/agent/collector/transaction_sampler.rb
269
269
  - lib/ting_yun/agent/collector/transaction_sampler/slowest_sample_buffer.rb
270
270
  - lib/ting_yun/agent/collector/transaction_sampler/transaction_sample_buffer_base.rb
271
- - lib/ting_yun/agent/container_data_manager.rb
272
271
  - lib/ting_yun/agent/cross_app/cross_app_monitor.rb
273
272
  - lib/ting_yun/agent/cross_app/cross_app_tracing.rb
274
273
  - lib/ting_yun/agent/cross_app/inbound_request_monitor.rb
@@ -1,94 +0,0 @@
1
- # encoding: utf-8
2
- require 'ting_yun/support/exception'
3
- require 'ting_yun/agent/collector/stats_engine'
4
- require 'ting_yun/agent/collector/error_collector'
5
-
6
- module TingYun
7
- module Agent
8
- module ContainerDataManager
9
-
10
- attr_reader :stats_engine, :error_collector, :transaction_sampler
11
-
12
- def drop_buffered_data
13
- @stats_engine.reset!
14
- end
15
-
16
- # private
17
-
18
- def init_containers
19
- @stats_engine = TingYun::Agent::Collector::StatsEngine.new
20
- @error_collector = TingYun::Agent::Collector::ErrorCollector.new
21
- end
22
-
23
- def container_for_endpoint(endpoint)
24
- case endpoint
25
- when :metric_data then @stats_engine
26
- # type code here
27
- end
28
- end
29
-
30
- def transmit_data
31
- ::TingYun::Agent.logger.debug('Sending data to Ting Yun Service')
32
-
33
- @service.session do # use http keep-alive
34
- harvest_and_send_errors
35
- harvest_and_send_timeslice_data
36
- end
37
- end
38
-
39
- def harvest_and_send_timeslice_data
40
- harvest_and_send_from_container(@stats_engine, :metric_data)
41
- end
42
-
43
- def harvest_and_send_errors
44
- harvest_and_send_from_container(@error_collector.error_trace_array, :error_data)
45
- end
46
-
47
- # Harvests data from the given container, sends it to the named endpoint
48
- # on the service, and automatically merges back in upon a recoverable
49
- # failure.
50
- #
51
- # The given container should respond to:
52
- #
53
- # #harvest!
54
- # returns an enumerable collection of data items to be sent to the
55
- # collector.
56
- #
57
- # #reset!
58
- # drop any stored data and reset to a clean state.
59
- #
60
- # #merge!(items)
61
- # merge the given items back into the internal buffer of the
62
- # container, so that they may be harvested again later.
63
- #
64
- def harvest_and_send_from_container(container,endpoint)
65
- items = harvest_from_container(container, endpoint)
66
- if !items.empty? && TingYun::Agent.config[:'nbs.agent_enabled']
67
- send_data_to_endpoint(endpoint, items, container)
68
- end
69
- end
70
-
71
- def harvest_from_container(container, endpoint)
72
- items =[]
73
- begin
74
- items = container.harvest!
75
- rescue => e
76
- TingYun::Agent.logger.error("Failed to harvest #{endpoint} data, resetting. Error: ", e)
77
- container.reset!
78
- end
79
- items
80
- end
81
-
82
- def send_data_to_endpoint(endpoint, items, container)
83
- TingYun::Agent.logger.debug("Sending #{items.size} items to #{endpoint}")
84
- begin
85
- @service.send(endpoint, items)
86
- rescue => e
87
- TingYun::Agent.logger.info("Unable to send #{endpoint} data, will try again later. Error: ", e)
88
- end
89
-
90
- end
91
-
92
- end
93
- end
94
- end