logstash-output-scalyr 0.1.14.beta → 0.1.15.beta

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
  SHA256:
3
- metadata.gz: 1af6e37035c37c270036487e9b939f40e8454d39ddea9983a737f409957e0747
4
- data.tar.gz: 95438909311aa595d2d4e771424765f3705cdc649225ca81c053e3b9c129b183
3
+ metadata.gz: b2e4aabe9bf971e1e0638899d713f5f16d7123e9be6f1dd98b82ab7ccfadb63f
4
+ data.tar.gz: 59ed216e6811e485f48ebed2a8fb3875f31c64cdf0f3a3b6e0a6112b2d8e11b6
5
5
  SHA512:
6
- metadata.gz: d2a9f542cfaaf8bb9e84ebf976694c548e153e1e170417309644b9206bf4df2ba8844447cbb2b0afd4ba8d03922688f6348a6fb77a6c8489a3f2a49bb873fed9
7
- data.tar.gz: 514fab3aa32f39e1ebe6e4bf164a9b9f648b82e7aa861d9cbc2edd6d44d9c6b4d9d3ea9b7c281ae26bf719e4373bde6059f220033dc660821a369b6186180798
6
+ metadata.gz: 45f6f63a99a7d232ea7cedaaa15ba5a64893d26788701ccfd6140367035771748cf4829a7a856642b704a20524a3d41710c9d9f23cc1daf3fea5b0b50394a626
7
+ data.tar.gz: 9a24eb6f935f9accd942b6091c33d9c3aca3601e7b833f07516c17a07e8e47660715f3e024748605ae57c40c38f3fc2f507151fa5708f6ab99280d3021c93e07
data/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # Beta
2
2
 
3
+ ## 0.1.15.beta
4
+ - Only call ``send_status`` method at the end of ``multi_receive()`` if there is at least one
5
+ record in the batch when ``report_status_for_empty_batches`` config option is set to ``false``.
6
+ - Update ``register()`` method to use a separate short-lived client session for sending initial
7
+ client status.
8
+
3
9
  ## 0.1.14.beta
4
10
  - Add configurable max retries for requests when running into errors.
5
11
  - Add ability to send messages to the dead letter queue if we exhaust all retries and if it is configured.
@@ -109,6 +109,11 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
109
109
  # minutes.
110
110
  config :status_report_interval, :validate => :number, :default => 300
111
111
 
112
+ # True to also call send_status when multi_receive() is called with no events.
113
+ # In some situations (e.g. when logstash is configured with multiple scalyr
114
+ # plugins conditionally where most are idle) you may want to set this to false
115
+ config :report_status_for_empty_batches, :validate => :boolean, :default => true
116
+
112
117
  # Set to true to also log status messages with various metrics to stdout in addition to sending
113
118
  # this data to Scalyr
114
119
  config :log_status_messages_to_stdout, :validate => :boolean, :default => false
@@ -251,7 +256,18 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
251
256
  @logger.info(sprintf("Started Scalyr output plugin (%s)." % [PLUGIN_VERSION]), :class => self.class.name)
252
257
 
253
258
  # Finally, send a status line to Scalyr
254
- send_status
259
+ # We use a special separate short lived client session for sending the initial client status.
260
+ # This is done to avoid the overhead in case single logstash instance has many scalyr output
261
+ # plugins configured with conditionals and majority of them are inactive (aka receive no data).
262
+ # This way we don't need to keep idle long running connection open.
263
+ initial_send_status_client_session = Scalyr::Common::Client::ClientSession.new(
264
+ @logger, @add_events_uri,
265
+ @compression_type, @compression_level, @ssl_verify_peer, @ssl_ca_bundle_path, @append_builtin_cert,
266
+ @record_stats_for_status, @flush_quantile_estimates_on_status_send,
267
+ @http_connect_timeout, @http_socket_timeout, @http_request_timeout, @http_pool_max, @http_pool_max_per_route
268
+ )
269
+ send_status(initial_send_status_client_session)
270
+ initial_send_status_client_session.close
255
271
 
256
272
  end # def register
257
273
 
@@ -394,7 +410,10 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
394
410
  end
395
411
  end
396
412
 
397
- send_status
413
+ if @report_status_for_empty_batches or records_count > 0
414
+ send_status
415
+ end
416
+
398
417
  return result
399
418
 
400
419
  rescue => e
@@ -778,7 +797,8 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
778
797
  # Finally, note that there could be multiple instances of this plugin (one per worker), in which case each worker
779
798
  # thread sends their own status updates. This is intentional so that we know how much data each worker thread is
780
799
  # uploading to Scalyr over time.
781
- def send_status
800
+ def send_status(client_session = nil)
801
+ client_session = @client_session if client_session.nil?
782
802
 
783
803
  status_event = {
784
804
  :ts => (Time.now.to_f * (10**9)).round,
@@ -797,7 +817,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
797
817
  # echee TODO: get instance stats from session and create a status log line
798
818
  msg = 'plugin_status: '
799
819
  cnt = 0
800
- @client_session.get_stats.each do |k, v|
820
+ client_session.get_stats.each do |k, v|
801
821
  val = v.instance_of?(Float) ? sprintf("%.4f", v) : v
802
822
  val = val.nil? ? 0 : val
803
823
  msg << ' ' if cnt > 0
@@ -817,7 +837,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
817
837
  end
818
838
  multi_event_request = create_multi_event_request([status_event], nil, nil, nil)
819
839
  begin
820
- @client_session.post_add_events(multi_event_request[:body], true, 0)
840
+ client_session.post_add_events(multi_event_request[:body], true, 0)
821
841
  rescue => e
822
842
  if e.body
823
843
  @logger.warn(
@@ -267,6 +267,7 @@ class ClientSession
267
267
 
268
268
 
269
269
  def close
270
+ @client.close if @client
270
271
  end # def close
271
272
 
272
273
 
@@ -1,2 +1,2 @@
1
1
  # encoding: utf-8
2
- PLUGIN_VERSION = "v0.1.14.beta"
2
+ PLUGIN_VERSION = "v0.1.15.beta"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-scalyr'
3
- s.version = '0.1.14.beta'
3
+ s.version = '0.1.15.beta'
4
4
  s.licenses = ['Apache-2.0']
5
5
  s.summary = "Scalyr output plugin for Logstash"
6
6
  s.description = "Sends log data collected by Logstash to Scalyr (https://www.scalyr.com)"
@@ -69,7 +69,7 @@ describe LogStash::Outputs::Scalyr do
69
69
  end
70
70
 
71
71
  it "it doesnt include flatten metrics if flattening is disabled" do
72
- plugin1 = LogStash::Outputs::Scalyr.new({
72
+ plugin1 = LogStash::Outputs::Scalyr.new({
73
73
  'api_write_token' => '1234',
74
74
  'serverhost_field' => 'source_host',
75
75
  'log_constants' => ['tags'],
@@ -122,7 +122,7 @@ describe LogStash::Outputs::Scalyr do
122
122
  expect(status_event[:attrs]["message"]).to eq("plugin_status: total_requests_sent=20 total_requests_failed=10 total_request_bytes_sent=100 total_compressed_request_bytes_sent=50 total_response_bytes_received=100 total_request_latency_secs=100 total_serialization_duration_secs=100.5000 total_compression_duration_secs=10.2000 compression_type=deflate compression_level=9 total_multi_receive_secs=0 multi_receive_duration_p50=10 multi_receive_duration_p90=18 multi_receive_duration_p99=19 multi_receive_event_count_p50=0 multi_receive_event_count_p90=0 multi_receive_event_count_p99=0 event_attributes_count_p50=0 event_attributes_count_p90=0 event_attributes_count_p99=0 batches_per_multi_receive_p50=0 batches_per_multi_receive_p90=0 batches_per_multi_receive_p99=0 flatten_values_duration_secs_p50=0 flatten_values_duration_secs_p90=0 flatten_values_duration_secs_p99=0")
123
123
  end
124
124
 
125
- it "send_stats is called when events list is empty, but otherwise noop" do
125
+ it "send_stats is called when events list is empty, but otherwise is noop" do
126
126
  quantile_estimator = Quantile::Estimator.new
127
127
  plugin.instance_variable_set(:@plugin_metrics, {
128
128
  :multi_receive_duration_secs => Quantile::Estimator.new,
@@ -137,6 +137,30 @@ describe LogStash::Outputs::Scalyr do
137
137
  plugin.multi_receive([])
138
138
  end
139
139
 
140
+ it "send_stats is not called when events list is empty and report_status_for_empty_batches is false" do
141
+ plugin2 = LogStash::Outputs::Scalyr.new({
142
+ 'api_write_token' => '1234',
143
+ 'serverhost_field' => 'source_host',
144
+ 'log_constants' => ['tags'],
145
+ 'flatten_nested_values' => false,
146
+ 'report_status_for_empty_batches' => false,
147
+ })
148
+
149
+ mock_client_session = MockClientSession.new
150
+ quantile_estimator = Quantile::Estimator.new
151
+ plugin2.instance_variable_set(:@plugin_metrics, {
152
+ :multi_receive_duration_secs => Quantile::Estimator.new,
153
+ :multi_receive_event_count => Quantile::Estimator.new,
154
+ :event_attributes_count => Quantile::Estimator.new,
155
+ :flatten_values_duration_secs => Quantile::Estimator.new
156
+ })
157
+ plugin2.instance_variable_set(:@client_session, mock_client_session)
158
+ expect(plugin2).not_to receive(:send_status)
159
+ expect(quantile_estimator).not_to receive(:observe)
160
+ expect(mock_client_session).not_to receive(:post_add_events)
161
+ plugin2.multi_receive([])
162
+ end
163
+
140
164
  # Kind of a weak test but I don't see a decent way to write a stronger one without a live client session
141
165
  it "send_status only sends posts with is_status = true" do
142
166
  # 1. Initial send
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
  'exec' "jruby" '-x' "$0" "$@"
3
- #!/Users/yans/.rvm/rubies/jruby-9.2.9.0/bin/jruby
3
+ #!/Users/tomaz/.rvm/rubies/jruby-9.2.9.0/bin/jruby
4
4
  #
5
5
  # This file was generated by RubyGems.
6
6
  #
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
  'exec' "jruby" '-x' "$0" "$@"
3
- #!/Users/yans/.rvm/rubies/jruby-9.2.9.0/bin/jruby
3
+ #!/Users/tomaz/.rvm/rubies/jruby-9.2.9.0/bin/jruby
4
4
  #
5
5
  # This file was generated by RubyGems.
6
6
  #
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-scalyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.14.beta
4
+ version: 0.1.15.beta
5
5
  platform: ruby
6
6
  authors:
7
7
  - Edward Chee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-22 00:00:00.000000000 Z
11
+ date: 2021-06-23 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement