logstash-output-scalyr 0.1.23.beta → 0.2.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (86) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +19 -0
  3. data/Gemfile +1 -0
  4. data/README.md +109 -3
  5. data/lib/logstash/outputs/scalyr.rb +121 -33
  6. data/lib/scalyr/common/client.rb +2 -1
  7. data/lib/scalyr/common/util.rb +28 -1
  8. data/lib/scalyr/constants.rb +4 -1
  9. data/logstash-output-scalyr.gemspec +3 -2
  10. data/spec/benchmarks/bignum_fixing.rb +2 -5
  11. data/spec/benchmarks/flattening_and_serialization.rb +2 -27
  12. data/spec/benchmarks/json_serialization.rb +85 -0
  13. data/spec/benchmarks/set_session_level_serverhost_on_events.rb +109 -0
  14. data/spec/benchmarks/util.rb +24 -0
  15. data/spec/logstash/outputs/scalyr_integration_spec.rb +7 -7
  16. data/spec/logstash/outputs/scalyr_spec.rb +488 -11
  17. data/vendor/bundle/jruby/2.5.0/cache/jrjackson-0.4.14-java.gem +0 -0
  18. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/Gemfile +0 -0
  19. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/Mavenfile +1 -7
  20. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/README.md +0 -0
  21. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/Rakefile +8 -2
  22. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/alt_bench.rb +0 -0
  23. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/changelog.md +25 -2
  24. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/jrjackson.gemspec +2 -1
  25. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/lib/com/fasterxml/jackson/core/jackson-annotations/2.9.10/jackson-annotations-2.9.10.jar +0 -0
  26. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/lib/com/fasterxml/jackson/core/jackson-core/2.9.10/jackson-core-2.9.10.jar +0 -0
  27. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/lib/com/fasterxml/jackson/core/jackson-databind/2.9.10.8/jackson-databind-2.9.10.8.jar +0 -0
  28. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.14-java/lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.9.10/jackson-module-afterburner-2.9.10.jar +0 -0
  29. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/lib/jrjackson/build_info.rb +9 -5
  30. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java/lib/jrjackson/jars/jrjackson-1.2.26.jar → jrjackson-0.4.14-java/lib/jrjackson/jars/jrjackson-1.2.32.jar} +0 -0
  31. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/lib/jrjackson/jrjackson.rb +0 -0
  32. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/lib/jrjackson.rb +0 -0
  33. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/lib/jrjackson_jars.rb +8 -8
  34. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/lib/require_relative_patch.rb +0 -0
  35. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/pom.xml +8 -25
  36. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/profiling/profiled.rb +0 -0
  37. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/run_all_individual_bench.sh +0 -0
  38. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/run_jruby_individual_bench.sh +0 -0
  39. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/run_mri_individual_bench.sh +0 -0
  40. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/IParseHandler.java +0 -0
  41. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JavaBigDecimalValueConverter.java +0 -0
  42. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JavaBigIntValueConverter.java +0 -0
  43. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JavaConverter.java +0 -0
  44. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JavaFloatValueConverter.java +0 -0
  45. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JavaHandler.java +0 -0
  46. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JavaLongValueConverter.java +0 -0
  47. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JjParse.java +0 -0
  48. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonBase.java +0 -0
  49. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonJava.java +0 -0
  50. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonRaw.java +0 -0
  51. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonRuby.java +0 -0
  52. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonSaj.java +0 -0
  53. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonSch.java +0 -0
  54. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrJacksonService.java +0 -0
  55. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/JrParse.java +0 -0
  56. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/ParseError.java +0 -0
  57. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyAnySerializer.java +4 -4
  58. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyBigDecimalValueConverter.java +0 -0
  59. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyBigIntValueConverter.java +0 -0
  60. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyConverter.java +0 -0
  61. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyDateFormat.java +0 -0
  62. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyFloatValueConverter.java +0 -0
  63. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyHandler.java +0 -0
  64. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyIntValueConverter.java +0 -0
  65. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyJacksonModule.java +18 -6
  66. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyKeyConverter.java +0 -0
  67. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyNameConverter.java +0 -0
  68. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyObjectDeserializer.java +0 -0
  69. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyStringConverter.java +0 -0
  70. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyStringKeyConverter.java +0 -0
  71. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyStringNameConverter.java +0 -0
  72. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubySymbolKeyConverter.java +0 -0
  73. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubySymbolNameConverter.java +0 -0
  74. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/RubyUtils.java +0 -0
  75. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/SajParse.java +0 -0
  76. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/SchParse.java +0 -0
  77. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/main/java/com/jrjackson/StreamParse.java +0 -0
  78. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/src/test/java/com/jrjackson/RubyAnySerializerTest.java +0 -0
  79. data/vendor/bundle/jruby/2.5.0/gems/{jrjackson-0.4.8-java → jrjackson-0.4.14-java}/test/jrjackson_test.rb +15 -0
  80. data/vendor/bundle/jruby/2.5.0/specifications/{jrjackson-0.4.8-java.gemspec → jrjackson-0.4.14-java.gemspec} +7 -7
  81. metadata +100 -66
  82. data/vendor/bundle/jruby/2.5.0/cache/jrjackson-0.4.8-java.gem +0 -0
  83. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/lib/com/fasterxml/jackson/core/jackson-annotations/2.9.7/jackson-annotations-2.9.7.jar +0 -0
  84. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/lib/com/fasterxml/jackson/core/jackson-core/2.9.7/jackson-core-2.9.7.jar +0 -0
  85. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/lib/com/fasterxml/jackson/core/jackson-databind/2.9.7/jackson-databind-2.9.7.jar +0 -0
  86. data/vendor/bundle/jruby/2.5.0/gems/jrjackson-0.4.8-java/lib/com/fasterxml/jackson/module/jackson-module-afterburner/2.9.7/jackson-module-afterburner-2.9.7.jar +0 -0
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8e2757da74eb03ea09a88597ed713db01bc050e17c31c771558bdb16a80ca40e
4
- data.tar.gz: 1bc8519d1b30aea135d66b8b9ecfb632f688fd62abd58cd3b91cc92c4ad8957f
3
+ metadata.gz: d2f63d5c51030c7bbb033edc0d7f8b8d3affff48f94f0bb2134fdfb75af36a76
4
+ data.tar.gz: 5787605f828a4a4f7d992003ed8a27e1f67439c49fab37d91c5077aa08d50428
5
5
  SHA512:
6
- metadata.gz: 327a3e2ba020f3166b0c435700bdfedf4f96598a352f1f66f45fe9e671a053ee684aa812d686a4d58b5dd9f319e8b0f87e2ea8290d876e504b8416a8010795ed
7
- data.tar.gz: 1ba44520daddda5c17da810221063ce815af082645ae3fd12e76b031247ff8a13cb3e7dab4fbf69e84e5a876605290702785cc17639de69435f0b780a74691f9
6
+ metadata.gz: ba560b44dd9ad73f56b2f105007a37bedd5b7821f7776c8d58c44ec7bb0fa544e80bd287756f8bb6ca76d53eedd3a1f36131cc60f2e7cf26ef9937af21c0a5a9
7
+ data.tar.gz: 4c8e3d4528ab613bd506e8b87e014ddfbd9725a088171396d483826348e8e7467ca75b1164dadb082b3d0732b37bfe4d4d1985b86cfb4ca389f592294055d2a3
data/CHANGELOG.md CHANGED
@@ -1,5 +1,24 @@
1
1
  # Beta
2
2
 
3
+ ## 0.2.0.beta
4
+
5
+ - Fix a bug and correctly handle ``serverHost`` event level attribute. Now if an event contains
6
+ ``serverHost`` attribute, this attribute will be correctly set on the event level and available for
7
+ "Sources" filtering in the UI.
8
+ - Plugin doesn't set ``serverHost`` attribute with a fixed value of ``Logstash`` on each event
9
+ level anymore. If you still want this behavior, you can achieve that with logstash mutate filter.
10
+ - Session level ``serverHost`` value now defaults to logstash aggregator node hostname
11
+ (``use_hostname_for_serverhost`` config option now defaults to true).
12
+ - ``host`` attribute is not removed by default from all the events. By default, logstash adds
13
+ ``host`` attribute which contains logstash aggregator host to each event. This is now redundant
14
+ and unncessary with the fixed and improved serverHost behavior (host and serverHost would contain
15
+ the same value by default). If you want to change this behavior and and still include ``host``
16
+ attribute on each event you can do that by setting ``remove_host_attribute_from_events`` config
17
+ option to false.
18
+
19
+ ## 0.1.26.beta
20
+ - Add support for new ``json_library`` config option. Valid values are ``stdlib`` (default) are ``jrjackson``. The later may offer 2-4x faster JSON serialization.
21
+
3
22
  ## 0.1.23.beta
4
23
  - Add testing support for disabling estimation of serialized event size for each event in the batch.
5
24
 
data/Gemfile CHANGED
@@ -18,3 +18,4 @@ gem 'pry'
18
18
  gem 'pry-nav'
19
19
  gem 'quantile', '~> 0.2.1'
20
20
  gem 'manticore', '~> 0.7.1', platform: :jruby
21
+ gem 'jrjackson', '~> 0.4.14', platform: :jruby
data/README.md CHANGED
@@ -1,4 +1,3 @@
1
-
2
1
  [![CircleCI](https://circleci.com/gh/scalyr/logstash-output-scalyr.svg?style=svg)](https://circleci.com/gh/scalyr/logstash-output-scalyr)
3
2
 
4
3
  # [Scalyr output plugin for Logstash (Beta release)]
@@ -10,7 +9,7 @@ You can view documentation for this plugin [on the Scalyr website](https://app.s
10
9
  # Quick start
11
10
 
12
11
  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.22.beta.gem` or follow the latest official instructions on working with plugins from Logstash.
12
+ 2. Install the gem into a Logstash installation, run `/usr/share/logstash/bin/logstash-plugin install logstash-output-scalyr-0.2.0.beta.gem` or follow the latest official instructions on working with plugins from Logstash.
14
13
  3. Configure the output plugin (e.g. add it to a pipeline .conf)
15
14
  4. Restart Logstash
16
15
 
@@ -40,6 +39,51 @@ output {
40
39
 
41
40
  In the above example, the Logstash pipeline defines a file input that reads from `/var/log/messages`. Log events from this source have the `host` and `path` fields. The pipeline then outputs to the scalyr plugin, which in this example is configured to remap `host`->`serverHost` and `path`->`logfile`, thus facilitating filtering in the Scalyr UI.
42
41
 
42
+ ## Notes on serverHost attribute handling
43
+
44
+ > Some of this functionality has been fixed and changed in the v0.2.0beta release. In previous
45
+ versions, plugin added ``serverHost`` attribute with a value of ``Logstash`` to each event and
46
+ this attribute was not handled correctly - it was treated as a regular event level attribute
47
+ and not a special attribute which can be used for Source functionality and filtering.
48
+
49
+ By default this plugin will set ``serverHost`` for all the events in a batch to match hostname of
50
+ the logstash node where the output plugin is running.
51
+
52
+ You can change that either by setting ``serverHost`` attribute in the ``server_attributes`` config
53
+ option hash or by setting ``serverHost`` attribute on the event level via logstash record attribute.
54
+
55
+ In both scenarios, you will be able to utilize this value for "Sources" functionality and filterin
56
+ in the Scalyr UI.
57
+
58
+ For example:
59
+
60
+ 1. Define static value for all the events handled by specific plugin instance
61
+
62
+ ```
63
+ output {
64
+ scalyr {
65
+ api_write_token => 'SCALYR_API_KEY'
66
+ server_attributes => {'serverHost' => 'my-host-1'}
67
+ }
68
+ }
69
+ ```
70
+
71
+ 2. Define static value on the event level which is set via logstash filter
72
+
73
+ ```
74
+ mutate {
75
+ add_field => { "serverHost" => "my hostname" }
76
+ }
77
+ ```
78
+
79
+ 3. Define dynamic value on the event level which is set via logstash filter
80
+
81
+ ```
82
+ mutate {
83
+ add_field => { "serverHost" => "%{[host][name]}" }
84
+ }
85
+ ```
86
+
43
87
  ## Options
44
88
 
45
89
  - The Scalyr API write token, these are available at https://www.scalyr.com/keys. This is the only compulsory configuration field required for proper upload
@@ -72,7 +116,7 @@ In the above example, the Logstash pipeline defines a file input that reads from
72
116
  - Related to the server_attributes dictionary above, if you do not define the 'serverHost' key in server_attributes,
73
117
  the plugin will automatically set it, using the aggregator hostname as value, if this value is true.
74
118
 
75
- `config :use_hostname_for_serverhost, :validate => :boolean, :default => false`
119
+ `config :use_hostname_for_serverhost, :validate => :boolean, :default => true`
76
120
 
77
121
  ---
78
122
 
@@ -395,3 +439,65 @@ bundle exec rake publish_gem
395
439
 
396
440
  `RUBY_USER` and `RUBY_PASSWORD` should be replaced with the username and password to the RubyGems.org account you wish to release to,
397
441
  these credentials should be found in Keeper.
442
+
443
+ # Testing Plugin Changes
444
+
445
+ This section describes how to test the plugin and changes using docker compose setup from
446
+ lostash-config-tester repo available at https://github.com/Kami/logstash-config-tester.
447
+
448
+ This repo has been forked and already contains some changes which make testing the plugin
449
+ easier.
450
+
451
+ The logstash configuration in that repo is set up to receive records encoded as JSON via
452
+ standard input, decode the JSON into the event object and print it to stdout + send it
453
+ to the Scalyr output.
454
+
455
+ ```bash
456
+ # 0. Clone the tester repo
457
+ git clone https://github.com/Kami/logstash-config-tester ~/
458
+
459
+ # 1. Build the plugin
460
+ gem build logstash-output-scalyr.gemspec
461
+
462
+ # 2. Copy it to the config test repo
463
+ cp logstash-output-scalyr-0.2.0.beta.gem ~/logstash-config-test/logstash-output-scalyr.gem
464
+
465
+ # 3. Build docker image with the latest dev version of the plugin (may take a while)
466
+ docker-compose build
467
+
468
+ # 4. Configure API key in docker-compose.yml and make any changes to plugin config in
469
+ # pipeline/scalyr_output.conf.j2, if necessary
470
+ vim docker-compose.yml
471
+
472
+ vim pipeline/scalyr_output.conf.j2
473
+
474
+ # 4. Run logstash with the stdin input and stdout + scalyr output
475
+ docker-compose run logstash
476
+ ```
477
+
478
+ A couple of things to keep in mind:
479
+
480
+ 1. Logstash log level is set to debug which is quite verbose, but it makes troubleshooting and
481
+ testing easier.
482
+ 2. Plugin accepts records (events) as JSON via standard input. This means to inject the mock
483
+ event you can simply copy the JSON event representation string to stdin and press enter. If you
484
+ want to submit multiples events to be handled as a single batch, paste each event one at a time
485
+ and press enter at the end. Logstash pipeline has been configured to wait up to 5 seconds before
486
+ handling the batch which should give you enough time to test batches with multiple events (this
487
+ setting can be adjusted in ``config/logstash.yml`` - ``pipeline.batch.delay``, if needed)
488
+
489
+ Example values you can enter into stdin:
490
+
491
+ 1. Single event batch
492
+
493
+ ```javascript
494
+ {"foo": "bar", "message": "test logstash"}
495
+ ```
496
+
497
+ 2. Batch with 3 events
498
+
499
+ ```javascript
500
+ {"serverHost": "host-1", "bar": "baz", "message": "test logstash 1"}
501
+ {"serverHost": "host-2", "bar": "baz", "message": "test logstash 2"}
502
+ {"bar": "baz", "message": "test logstash 3"}
503
+ ```
@@ -13,6 +13,7 @@ require 'rbzip2'
13
13
  require 'zlib'
14
14
  require 'stringio'
15
15
  require 'quantile'
16
+ require 'jrjackson'
16
17
 
17
18
  require 'scalyr/common/client'
18
19
  require "scalyr/common/util"
@@ -42,7 +43,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
42
43
 
43
44
  # Related to the server_attributes dictionary above, if you do not define the 'serverHost' key in server_attributes,
44
45
  # the plugin will automatically set it, using the aggregator hostname as value, if this value is true.
45
- config :use_hostname_for_serverhost, :validate => :boolean, :default => false
46
+ config :use_hostname_for_serverhost, :validate => :boolean, :default => true
46
47
 
47
48
  # Field that represents the origin of the log event.
48
49
  # (Warning: events with an existing 'serverHost' field, it will be overwritten)
@@ -65,6 +66,23 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
65
66
  # value with have fields moved.
66
67
  config :log_constants, :validate => :array, :default => nil
67
68
 
69
+ # When this option is true and session level server host is defined (either via
70
+ # server_attributes config option or via node hostname) and some events in a batch contain
71
+ # "serverHost" attributes, other nodes in a batch which don't contain it will have serverHost
72
+ # set to the session level value.
73
+ # This is needed because session level attribute has priority over event level which means
74
+ # that in case we specify serverHost on some events, other events won't have any value set
75
+ # for serverHost.
76
+ # Since this option adds some overhead and requires additional processing time, it's
77
+ # disabled by default.
78
+ config :set_session_level_serverhost_on_events, validate: :boolean, default: false
79
+
80
+ # By default, logstash will add "host" attribute which includes logstash aggregator server
81
+ # host to each event. This is not really needed and desired anymore with the fixed and improved
82
+ # serverHost attribute handling (serverHost now contains logstash aggregator hostname by
83
+ # default).
84
+ config :remove_host_attribute_from_events, validate: :boolean, default: true
85
+
68
86
  # If true, nested values will be flattened (which changes keys to delimiter-separated concatenation of all
69
87
  # nested keys).
70
88
  config :flatten_nested_values, :validate => :boolean, :default => false
@@ -151,6 +169,10 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
151
169
  # Scalyr single request limit won't be reached.
152
170
  config :estimate_each_event_size, :validate => :boolean, :default => true
153
171
 
172
+ # Library to use for JSON serialization. Valid values are "stdlib" and "jrjackson". The later may offer 2-4 performance
173
+ # improvements on serialization.
174
+ config :json_library, :validate => :string, :default => "stdlib"
175
+
154
176
  # Manticore related options
155
177
  config :http_connect_timeout, :validate => :number, :default => 10
156
178
  config :http_socket_timeout, :validate => :number, :default => 10
@@ -190,6 +212,24 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
190
212
  @logger.warn "Maximum request buffer > 6 MB. This may result in requests being rejected by Scalyr."
191
213
  end
192
214
 
215
+ if not @estimate_each_event_size
216
+ @logger.warn("estimate_each_event_size config option is false, this means very large batches may be rejected or partially processed by the server")
217
+ end
218
+
219
+ if @json_library != "stdlib" and @json_library != "jrjackson"
220
+ raise LogStash::ConfigurationError, "json_library config option needs to be either stdlib or jrjackson"
221
+ end
222
+
223
+ if @json_library == "stdlib"
224
+ define_singleton_method "json_encode" do |data|
225
+ data.to_json
226
+ end
227
+ elsif @json_library == "jrjackson"
228
+ define_singleton_method "json_encode" do |data|
229
+ JrJackson::Json.dump(data)
230
+ end
231
+ end
232
+
193
233
  @dlq_writer = dlq_enabled? ? execution_context.dlq_writer : nil
194
234
 
195
235
  @message_encoding = nil
@@ -218,12 +258,13 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
218
258
  @server_attributes = new_attributes
219
259
  end
220
260
 
221
- # See if we should use the hostname as the server_attributes.serverHost
222
- if @use_hostname_for_serverhost
223
- if @server_attributes.nil?
261
+ # See if we should use the hostname as the server_attributes.serverHost (aka if fixed serverHost is not
262
+ # defined as part of server_attributes config option)
263
+ if @server_attributes.nil?
224
264
  @server_attributes = {}
225
- end
265
+ end
226
266
 
267
+ if @use_hostname_for_serverhost
227
268
  # only set serverHost if it doesn't currently exist in server_attributes
228
269
  # Note: Use strings rather than symbols for the key, because keys coming
229
270
  # from the config file will be strings
@@ -235,6 +276,15 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
235
276
  # Add monitor server attribute to identify this as coming from a plugin
236
277
  @server_attributes['monitor'] = 'pluginLogstash'
237
278
 
279
+ # We create a fixed copy without host here so we can reference this later if needed to avoid
280
+ # some of the copy + manipulate overhead per batch
281
+ @server_attributes_without_serverhost = @server_attributes.clone
282
+ if @server_attributes_without_serverhost.key? "serverHost"
283
+ @server_attributes_without_serverhost.delete "serverHost"
284
+ end
285
+
286
+ @session_server_host = @server_attributes["serverHost"]
287
+
238
288
  @scalyr_server << '/' unless @scalyr_server.end_with?('/')
239
289
 
240
290
  @add_events_uri = URI(@scalyr_server) + "addEvents"
@@ -267,7 +317,8 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
267
317
  @http_connect_timeout, @http_socket_timeout, @http_request_timeout, @http_pool_max, @http_pool_max_per_route
268
318
  )
269
319
 
270
- @logger.info(sprintf("Started Scalyr output plugin (%s)." % [PLUGIN_VERSION]), :class => self.class.name)
320
+ @logger.info(sprintf("Started Scalyr LogStash output plugin %s (compression_type=%s,compression_level=%s,json_library=%s)." %
321
+ [PLUGIN_VERSION, @compression_type, @compression_type, @json_library]), :class => self.class.name)
271
322
 
272
323
  # Finally, send a status line to Scalyr
273
324
  # We use a special separate short lived client session for sending the initial client status.
@@ -482,7 +533,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
482
533
  @dlq_writer.write(l_event, "#{exc_data[:message]}")
483
534
  }
484
535
  else
485
- @logger.warn("Deal letter queue not configured, dropping #{multi_event_request[:logstash_events].length} events after #{exc_retries} tries.", :sample_events => sample_events)
536
+ @logger.warn("Dead letter queue not configured, dropping #{multi_event_request[:logstash_events].length} events after #{exc_retries} tries.", :sample_events => sample_events)
486
537
  end
487
538
  end
488
539
 
@@ -526,6 +577,8 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
526
577
  logs_ids = Hash.new
527
578
  next_log_id = 1
528
579
 
580
+ batch_has_event_level_server_host = false
581
+
529
582
  logstash_events.each {|l_event|
530
583
 
531
584
  record = l_event.to_hash
@@ -581,6 +634,11 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
581
634
  # Rename user-specified logfile field -> 'logfile'
582
635
  rename.call(@logfile_field, 'logfile')
583
636
 
637
+ # Remove "host" attribute
638
+ if @remove_host_attribute_from_events and record.key? "host"
639
+ record.delete("host")
640
+ end
641
+
584
642
  # Set a default parser is none is present in the event
585
643
  if record['parser'].to_s.empty?
586
644
  record['parser'] = "logstashParser"
@@ -591,26 +649,31 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
591
649
  record['logfile'] = "/logstash/#{serverHost}"
592
650
  end
593
651
 
594
- # Set a default if no serverHost value is present.
595
- if serverHost.nil?
596
- record['serverHost'] = "Logstash"
652
+ # Rename serverHost (if exists) to __origServerHost so sources filtering works correctly
653
+ # It's important that this happens at the very end of the event processing in this function.
654
+ record_has_server_host_attribute = record.key? 'serverHost'
655
+ batch_has_event_level_server_host |= record_has_server_host_attribute
656
+
657
+ if record_has_server_host_attribute
658
+ record[EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME] = record['serverHost']
659
+ record.delete('serverHost')
597
660
  end
598
661
 
662
+ # To reduce duplication of common event-level attributes, we "fold" them into top-level "logs" attribute
663
+ # and reference log entry inside the event
599
664
  log_identifier = nil
600
665
  add_log = false
601
666
  if serverHost
602
667
  log_identifier = serverHost + record['logfile']
603
668
  end
669
+
604
670
  if log_identifier and not logs.key? log_identifier
605
671
  add_log = true
606
672
  logs[log_identifier] = {
607
673
  'id' => next_log_id,
608
674
  'attrs' => Hash.new
609
675
  }
610
- if not record['serverHost'].to_s.empty?
611
- logs[log_identifier]['attrs']['serverHost'] = record['serverHost']
612
- record.delete('serverHost')
613
- end
676
+
614
677
  if not record['logfile'].to_s.empty?
615
678
  logs[log_identifier]['attrs']['logfile'] = record['logfile']
616
679
  record.delete('logfile')
@@ -623,10 +686,21 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
623
686
  end
624
687
  }
625
688
  end
689
+
626
690
  logs_ids[log_identifier] = next_log_id
627
691
  next_log_id += 1
628
692
  end
629
693
 
694
+ # If we already contain "logs" entry for this record, we remove duplicated serverHost from
695
+ # the event attributes since it's already part of the log level attributes which are
696
+ # referenced by the event.
697
+ if log_identifier and logs.key? log_identifier
698
+ if not record[EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME].to_s.empty?
699
+ logs[log_identifier]['attrs'][EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME] = record[EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME]
700
+ record.delete(EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME)
701
+ end
702
+ end
703
+
630
704
  # Delete unwanted fields from record
631
705
  record.delete('@version')
632
706
  record.delete('@timestamp')
@@ -672,7 +746,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
672
746
  :attrs => record
673
747
  }
674
748
 
675
- # optionally set thread
749
+ # optionally set thread and referenced log file
676
750
  if serverHost
677
751
  scalyr_event[:thread] = thread_id.to_s
678
752
  scalyr_event[:log] = logs_ids[log_identifier]
@@ -681,10 +755,10 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
681
755
  if @estimate_each_event_size
682
756
  # get json string of event to keep track of how many bytes we are sending
683
757
  begin
684
- event_json = scalyr_event.to_json
758
+ event_json = self.json_encode(scalyr_event)
685
759
  log_json = nil
686
760
  if add_log
687
- log_json = logs[log_identifier].to_json
761
+ log_json = self.json_encode(logs[log_identifier])
688
762
  end
689
763
  rescue JSON::GeneratorError, Encoding::UndefinedConversionError => e
690
764
  @logger.warn "#{e.class}: #{e.message}"
@@ -700,7 +774,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
700
774
  "UTF-8", :invalid => :replace, :undef => :replace, :replace => "<?>"
701
775
  ).force_encoding('UTF-8')
702
776
  end
703
- event_json = scalyr_event.to_json
777
+ event_json = self.json_encode(scalyr_event)
704
778
  rescue Java::JavaLang::ClassCastException => e
705
779
  # Most likely we ran into the issue described here: https://github.com/flori/json/issues/336
706
780
  # Because of the version of jruby logstash works with we don't have the option to just update this away,
@@ -711,10 +785,10 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
711
785
  @multi_receive_statistics[:total_java_class_cast_errors] += 1
712
786
  end
713
787
  Scalyr::Common::Util.convert_bignums(scalyr_event)
714
- event_json = scalyr_event.to_json
788
+ event_json = self.json_encode(scalyr_event)
715
789
  log_json = nil
716
790
  if add_log
717
- log_json = logs[log_identifier].to_json
791
+ log_json = self.json_encode(logs[log_identifier])
718
792
  end
719
793
  end
720
794
 
@@ -733,7 +807,8 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
733
807
  append_event = false
734
808
  end
735
809
 
736
- multi_event_request = self.create_multi_event_request(scalyr_events, l_events, current_threads, logs)
810
+ Scalyr::Common::Util.set_session_level_serverhost_on_events(@session_server_host, scalyr_events, logs, batch_has_event_level_server_host)
811
+ multi_event_request = self.create_multi_event_request(scalyr_events, l_events, current_threads, logs, batch_has_event_level_server_host)
737
812
  multi_event_request_array << multi_event_request
738
813
 
739
814
  total_bytes = 0
@@ -742,10 +817,12 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
742
817
  logs_ids = Hash.new
743
818
  scalyr_events = Array.new
744
819
  l_events = Array.new
820
+ batch_has_event_level_server_host = false
745
821
  end
746
822
  else
747
823
  # If size estimation is disabled we simply append the event and handle splitting later on (if needed)
748
824
  append_event = true
825
+ add_bytes = 0
749
826
  end
750
827
 
751
828
  # if we haven't consumed the current event already
@@ -758,13 +835,16 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
758
835
 
759
836
  }
760
837
 
761
- # create a final request with any left over events
762
- multi_event_request = self.create_multi_event_request(scalyr_events, l_events, current_threads, logs)
763
- multi_event_request_array << multi_event_request
838
+ # create a final request with any left over events (and make sure there is at least one event)
839
+ if scalyr_events.size >= 1
840
+ Scalyr::Common::Util.set_session_level_serverhost_on_events(@session_server_host, scalyr_events, logs, batch_has_event_level_server_host)
841
+ multi_event_request = self.create_multi_event_request(scalyr_events, l_events, current_threads, logs, batch_has_event_level_server_host)
842
+ multi_event_request_array << multi_event_request
843
+ end
844
+
764
845
  multi_event_request_array
765
846
  end
766
847
 
767
-
768
848
  # Helper method that adds a client_timestamp to a batch addEvents request body
769
849
  def add_client_timestamp_to_body(body)
770
850
  current_time_millis = DateTime.now.strftime('%Q').to_i
@@ -777,7 +857,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
777
857
  # A request comprises multiple Scalyr Events. This function creates a request hash for
778
858
  # final upload to Scalyr (from an array of events, and an optional hash of current threads)
779
859
  # Note: The request body field will be json-encoded.
780
- def create_multi_event_request(scalyr_events, logstash_events, current_threads, current_logs)
860
+ def create_multi_event_request(scalyr_events, logstash_events, current_threads, current_logs, batch_has_event_level_server_host = false)
781
861
 
782
862
  body = {
783
863
  :session => @session_id + Thread.current.object_id.to_s,
@@ -806,26 +886,33 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
806
886
  end
807
887
 
808
888
  # add serverAttributes
809
- body[:sessionInfo] = @server_attributes if @server_attributes
889
+ # If serverHost is defined on any of the events, we don't send it via sessionInfo since
890
+ # sesionInfo has the higest priority and would always overwritte the event level one
891
+ if batch_has_event_level_server_host
892
+ body[:sessionInfo] = @server_attributes_without_serverhost if @server_attributes_without_serverhost
893
+ else
894
+ body[:sessionInfo] = @server_attributes if @server_attributes
895
+ end
810
896
 
811
897
  # We time serialization to get some insight on how long it takes to serialize the request body
812
898
  start_time = Time.now.to_f
813
899
  begin
814
- serialized_body = body.to_json
900
+ serialized_body = self.json_encode(body)
815
901
  rescue Java::JavaLang::ClassCastException => e
816
902
  @logger.warn("Error serializing events to JSON, likely due to the presence of Bignum values. Converting Bignum values to strings.")
817
903
  @stats_lock.synchronize do
818
904
  @multi_receive_statistics[:total_java_class_cast_errors] += 1
819
905
  end
820
906
  Scalyr::Common::Util.convert_bignums(body)
821
- serialized_body = body.to_json
907
+ serialized_body = self.json_encode(body)
822
908
  end
823
909
  end_time = Time.now.to_f
824
910
  serialization_duration = end_time - start_time
825
911
 
826
912
  serialized_request_size = serialized_body.bytesize
827
913
 
828
- if serialized_request_size >= @max_request_buffer
914
+ # We give it "buffer" since the splitting code allows for some slack and doesn't take into account top-level non-event attributes
915
+ if not @estimate_each_event_size and serialized_request_size >= @max_request_buffer + 5000
829
916
  # TODO: If we end up here is estimate config opsion is false, split the request here into multiple ones
830
917
  @logger.warn("Serialized request size (#{serialized_request_size}) is larger than max_request_buffer (#{max_request_buffer})!")
831
918
  end
@@ -898,8 +985,9 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
898
985
  }
899
986
  @send_stats.synchronize do
900
987
  if !@last_status_transmit_time
901
- status_event[:attrs]['message'] = sprintf("Started Scalyr LogStash output plugin (%s)." % [PLUGIN_VERSION])
902
- status_event[:attrs]['serverHost'] = @node_hostname
988
+ status_event[:attrs]['message'] = sprintf("Started Scalyr LogStash output plugin %s (compression_type=%s,compression_level=%s,json_library=%s)." %
989
+ [PLUGIN_VERSION, @compression_type, @compression_type, @json_library])
990
+ status_event[:attrs][EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME] = @node_hostname
903
991
  else
904
992
  cur_time = Time.now()
905
993
  return if (cur_time.to_i - @last_status_transmit_time.to_i) < @status_report_interval
@@ -921,7 +1009,7 @@ class LogStash::Outputs::Scalyr < LogStash::Outputs::Base
921
1009
  cnt += 1
922
1010
  end
923
1011
  status_event[:attrs]['message'] = msg
924
- status_event[:attrs]['serverHost'] = @node_hostname
1012
+ status_event[:attrs][EVENT_LEVEL_SERVER_HOST_ATTRIBUTE_NAME] = @node_hostname
925
1013
  status_event[:attrs]['parser'] = @status_parser
926
1014
  end
927
1015
  multi_event_request = create_multi_event_request([status_event], nil, nil, nil)