logstash-output-scalyr 0.1.16.beta → 0.1.17.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: 16e88c3869fdb18e4132726af302e37c8bac2c10038ca3a078f85cebe67c4940
4
- data.tar.gz: a42194413ec2969e31bbe44e72df7cf71d09911b61adae9db16b6041a97bc1b4
3
+ metadata.gz: 96fd1b3adba21150a05f43d1e8d6510711197da866d3cd6ec8b57bae14e53391
4
+ data.tar.gz: 221aac42711955c49c878c324e2570ebb55050cad13f2d4911b99c4b3f1eb5a1
5
5
  SHA512:
6
- metadata.gz: 66d4261da66deaa8f5227b0ecfcdfce51f170c561902397c6020d3baa8694bd7c92291b0faa84178e4dda180c71892ab4a30ba425dc1133f5f7b349c1b7e44fa
7
- data.tar.gz: 6689e3c9fd5fa2a571ca8076a4ae24b5eb1bf5da9216030b8c759a0baff17f4577a478f3c3efced4ddb22ecf273ec675f8831733aded928fd2c92c7ce91d1983
6
+ metadata.gz: c8a678e7caf8778dbe9b44e8d8e48c809b016ac6b89424c4c29c29b63578fea61f236ae80a528dab7707c8ee534cfab0f20a252d688f44df53faccdd1ce907b0
7
+ data.tar.gz: c263ae0ecffacb454f98f112d384c544cfd68fb0e0e6a0d7339a6b84add2c94b4bb99afd20a815b587f5722e0125d80fc25f9285574187c9f2a0ff2af7f219ec
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Beta
2
2
 
3
+ ## 0.1.17.beta
4
+ - Catch errors relating to Bignum conversions present in the ``json`` library and manually convert to string as
5
+ a workaround.
6
+
3
7
  ## 0.1.16.beta
4
8
  - Fix race condition in ``register()`` method.
5
9
 
data/README.md CHANGED
@@ -10,7 +10,7 @@ You can view documentation for this plugin [on the Scalyr website](https://app.s
10
10
  # Quick start
11
11
 
12
12
  1. Build the gem, run `gem build logstash-output-scalyr.gemspec`
13
- 2. Install the gem into a Logstash installation, run `/usr/share/logstash/bin/logstash-plugin install logstash-output-scalyr-0.1.14.beta.gem` or follow the latest official instructions on working with plugins from Logstash.
13
+ 2. Install the gem into a Logstash installation, run `/usr/share/logstash/bin/logstash-plugin install logstash-output-scalyr-0.1.17.beta.gem` or follow the latest official instructions on working with plugins from Logstash.
14
14
  3. Configure the output plugin (e.g. add it to a pipeline .conf)
15
15
  4. Restart Logstash
16
16
 
@@ -240,7 +240,8 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
240
240
  # Plugin level (either per batch or event level metrics). Other request
241
241
  # level metrics are handled by the HTTP Client class.
242
242
  @multi_receive_statistics = {
243
- :total_multi_receive_secs => 0
243
+ :total_multi_receive_secs => 0,
244
+ :total_java_class_cast_errors => 0
244
245
  }
245
246
  @plugin_metrics = get_new_metrics
246
247
 
@@ -661,6 +662,21 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
661
662
  ).force_encoding('UTF-8')
662
663
  end
663
664
  event_json = scalyr_event.to_json
665
+ rescue Java::JavaLang::ClassCastException => e
666
+ # Most likely we ran into the issue described here: https://github.com/flori/json/issues/336
667
+ # Because of the version of jruby logstash works with we don't have the option to just update this away,
668
+ # so if we run into it we convert bignums into strings so we can get the data in at least.
669
+ # This is fixed in JRuby 9.2.7, which includes json 2.2.0
670
+ @logger.warn("Error serializing events to JSON, likely due to the presence of Bignum values. Converting Bignum values to strings.")
671
+ @stats_lock.synchronize do
672
+ @multi_receive_statistics[:total_java_class_cast_errors] += 1
673
+ end
674
+ Scalyr::Common::Util.convert_bignums(scalyr_event)
675
+ event_json = scalyr_event.to_json
676
+ log_json = nil
677
+ if add_log
678
+ log_json = logs[log_identifier].to_json
679
+ end
664
680
  end
665
681
 
666
682
  # generate new request if json size of events in the array exceed maximum request buffer size
@@ -749,7 +765,16 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
749
765
 
750
766
  # We time serialization to get some insight on how long it takes to serialize the request body
751
767
  start_time = Time.now.to_f
752
- serialized_body = body.to_json
768
+ begin
769
+ serialized_body = body.to_json
770
+ rescue Java::JavaLang::ClassCastException => e
771
+ @logger.warn("Error serializing events to JSON, likely due to the presence of Bignum values. Converting Bignum values to strings.")
772
+ @stats_lock.synchronize do
773
+ @multi_receive_statistics[:total_java_class_cast_errors] += 1
774
+ end
775
+ Scalyr::Common::Util.convert_bignums(body)
776
+ serialized_body = body.to_json
777
+ end
753
778
  end_time = Time.now.to_f
754
779
  serialization_duration = end_time - start_time
755
780
  {
@@ -52,5 +52,26 @@ def self.truncate(content, max)
52
52
  return content
53
53
  end
54
54
 
55
+ def self.convert_bignums(obj)
56
+ if obj.respond_to?(:has_key?) and obj.respond_to?(:each)
57
+ # input object is a hash
58
+ obj.each do |key, value|
59
+ obj[key] = convert_bignums(value)
60
+ end
61
+
62
+ elsif obj.respond_to?(:each)
63
+ # input object is an array or set
64
+ obj.each_with_index do |value, index|
65
+ obj[index] = convert_bignums(value)
66
+ end
67
+
68
+ elsif obj.is_a? Bignum
69
+ return obj.to_s
70
+
71
+ else
72
+ return obj
73
+ end
74
+ end
75
+
55
76
  end; end; end;
56
77
 
@@ -1,2 +1,2 @@
1
1
  # encoding: utf-8
2
- PLUGIN_VERSION = "v0.1.16.beta"
2
+ PLUGIN_VERSION = "v0.1.17.beta"
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-scalyr'
3
- s.version = '0.1.16.beta'
3
+ s.version = '0.1.17.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)"
@@ -0,0 +1,90 @@
1
+ require 'benchmark'
2
+ require 'quantile'
3
+
4
+ require_relative '../../lib/scalyr/common/util'
5
+
6
+ # Micro benchmark which measures how long it takes to find all the Bignums in a record and convert them to strings
7
+
8
+ ITERATIONS = 500
9
+
10
+ def rand_str(len)
11
+ return (0...len).map { (65 + rand(26)).chr }.join
12
+ end
13
+
14
+ def rand_bignum()
15
+ return 200004000020304050300 + rand(999999)
16
+ end
17
+
18
+ def generate_hash(widths)
19
+ result = {}
20
+ if widths.empty?
21
+ return rand_bignum()
22
+ else
23
+ widths[0].times do
24
+ result[rand_str(9)] = generate_hash(widths[1..widths.length])
25
+ end
26
+ return result
27
+ end
28
+ end
29
+
30
+ def generate_data_array_for_spec(spec)
31
+ data = []
32
+ ITERATIONS.times do
33
+ data << generate_hash(spec)
34
+ end
35
+
36
+ data
37
+ end
38
+
39
+ def run_benchmark_and_print_results(data, run_benchmark_func)
40
+ puts ""
41
+ puts "Using %s total keys in a hash" % [Scalyr::Common::Util.flatten(data[0]).count]
42
+ puts ""
43
+
44
+ result = []
45
+ ITERATIONS.times do |i|
46
+ result << Benchmark.measure { run_benchmark_func.(data[0]) }
47
+ end
48
+
49
+ sum = result.inject(nil) { |sum, t| sum.nil? ? sum = t : sum += t }
50
+ avg = sum / result.size
51
+
52
+ Benchmark.bm(7, "sum:", "avg:") do |b|
53
+ [sum, avg]
54
+ end
55
+ puts ""
56
+ end
57
+
58
+
59
+ puts "Using %s iterations" % [ITERATIONS]
60
+ puts ""
61
+
62
+ @value = Quantile::Estimator.new
63
+ @prng = Random.new
64
+
65
+ def convert_bignums(record)
66
+ Scalyr::Common::Util.convert_bignums(record)
67
+ end
68
+
69
+ puts "Util.convert_bignums()"
70
+ puts "==============================="
71
+
72
+ # Around ~200 keys in a hash
73
+ data = generate_data_array_for_spec([4, 4, 3, 4])
74
+ run_benchmark_and_print_results(data, method(:convert_bignums))
75
+
76
+ # Around ~200 keys in a hash (single level)
77
+ data = generate_data_array_for_spec([200])
78
+ run_benchmark_and_print_results(data, method(:convert_bignums))
79
+
80
+ # Around ~512 keys in a hash
81
+ data = generate_data_array_for_spec([8, 4, 4, 4])
82
+ run_benchmark_and_print_results(data, method(:convert_bignums))
83
+
84
+ # Around ~960 keys in a hash
85
+ data = generate_data_array_for_spec([12, 5, 4, 4])
86
+ run_benchmark_and_print_results(data, method(:convert_bignums))
87
+
88
+ # Around ~2700 keys in a hash
89
+ data = generate_data_array_for_spec([14, 8, 6, 4])
90
+ run_benchmark_and_print_results(data, method(:convert_bignums))
@@ -342,5 +342,23 @@ describe LogStash::Outputs::Scalyr do
342
342
  })
343
343
  end
344
344
  end
345
+
346
+ context "when receiving an event with Bignums" do
347
+ config = {
348
+ 'api_write_token' => '1234',
349
+ }
350
+ plugin = LogStash::Outputs::Scalyr.new(config)
351
+ it "doesn't throw an error" do
352
+ allow(plugin).to receive(:send_status).and_return(nil)
353
+ plugin.register
354
+ e = LogStash::Event.new
355
+ e.set('bignumber', 2000023030042002050202030320240)
356
+ allow(plugin.instance_variable_get(:@logger)).to receive(:error)
357
+ result = plugin.build_multi_event_request_array([e])
358
+ body = JSON.parse(result[0][:body])
359
+ expect(body['events'].size).to eq(1)
360
+ expect(plugin.instance_variable_get(:@logger)).to_not receive(:error)
361
+ end
362
+ end
345
363
  end
346
364
  end
@@ -1,6 +1,6 @@
1
1
  #!/bin/sh
2
2
  'exec' "jruby" '-x' "$0" "$@"
3
- #!/Users/tomaz/.rvm/rubies/jruby-9.2.9.0/bin/jruby
3
+ #!/Users/yans/.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/tomaz/.rvm/rubies/jruby-9.2.9.0/bin/jruby
3
+ #!/Users/yans/.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.16.beta
4
+ version: 0.1.17.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-23 00:00:00.000000000 Z
11
+ date: 2021-07-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -132,6 +132,7 @@ files:
132
132
  - lib/scalyr/common/util.rb
133
133
  - lib/scalyr/constants.rb
134
134
  - logstash-output-scalyr.gemspec
135
+ - spec/benchmarks/bignum_fixing.rb
135
136
  - spec/benchmarks/flattening_and_serialization.rb
136
137
  - spec/benchmarks/metrics_overhead.rb
137
138
  - spec/logstash/outputs/scalyr_integration_spec.rb
@@ -4062,6 +4063,7 @@ signing_key:
4062
4063
  specification_version: 4
4063
4064
  summary: Scalyr output plugin for Logstash
4064
4065
  test_files:
4066
+ - spec/benchmarks/bignum_fixing.rb
4065
4067
  - spec/benchmarks/flattening_and_serialization.rb
4066
4068
  - spec/benchmarks/metrics_overhead.rb
4067
4069
  - spec/logstash/outputs/scalyr_integration_spec.rb