fluent-plugin-scalyr 0.8.5 → 0.8.10

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
- SHA1:
3
- metadata.gz: 891497d6c594d6e115191cae7b8d9d48c428770d
4
- data.tar.gz: e1f90aac40a8ed67aaa103ec552924eddf09d54c
2
+ SHA256:
3
+ metadata.gz: 607dd0cf45280387ab9c19b460eab081f2111b1059f8036032e13c1c5c4fd901
4
+ data.tar.gz: 3d0fa711e084ce2f204dbf69c249363a88d73293a6874c8eb6a175ee920e5cc5
5
5
  SHA512:
6
- metadata.gz: c1be90d4ae35f8e434269493d19321e27108cf3a608d3874ad4a08d151f69706479f304688630669c8ad79b9785b628a0bf7f4764e955e7e0e7a4bdcc486684b
7
- data.tar.gz: 29ca4a9a59d7e1047fd675a6baaaa9a37c45379e48587e586c929db78ea6b1c9323055db7f9c33792765a36cf58a02329286e3cf7ed35ea1a515a0a437d15a01
6
+ metadata.gz: f6075b808c1126d4b4d8ba7ea30fb5d899facc78c38f4d0d95afc8c97f5eca8f28aefdf414b267dd45695ebe70feb2dd976be76babb8f8458d1240382077a3f0
7
+ data.tar.gz: deeafb8a4886f51ce635541756e33ba5c3a98b31e6c4ac6f0a5a37a9f8f8862e2a32d0be2026d90f6f7828157e43ac77261529364f1b2bf697b9a2948f7fd3e4
data/README.md CHANGED
@@ -1,5 +1,5 @@
1
1
  Scalyr output plugin for Fluentd
2
- =========================
2
+ ================================
3
3
 
4
4
  **Note:** Fluentd introduced breaking changes to their plugin API between
5
5
  version 0.12 and 0.14.
@@ -24,7 +24,7 @@ Fluentd may format log messages into json or some other format. If you want to
24
24
  format none
25
25
  ```
26
26
 
27
- The Scalyr output plugin assigns a unique Scalyr session id for each Fluentd <match> block. It is recommended that a single machine doesn't create too many simultaneous Scalyr sessions, so if possible you should try to have a single match for all logs you wish to send to Scalyr.
27
+ The Scalyr output plugin assigns a unique Scalyr session id for each Fluentd <match> block, or for each worker. It is recommended that a single machine doesn't create too many simultaneous Scalyr sessions, so if possible you should try to have a single match for all logs you wish to send to Scalyr.
28
28
 
29
29
  This can be done by specifying tags such as scalyr.apache, scalyr.maillog etc and matching on scalyr.\*
30
30
 
@@ -33,7 +33,7 @@ Fluentd tag names will be used for the logfile name in Scalyr.
33
33
  Scalyr Parsers and Custom Fields
34
34
  --------------------------------
35
35
 
36
- You may also need to specify a Scalyr parser for your log message or add custom fields to each log event. This can be done using Fluentd's filter mechanism, in particular the [record_transformer filter](http://docs.fluentd.org/articles/filter_record_transformer).
36
+ You may also need to specify a Scalyr parser for your log message or add custom fields to each log event. This can be done using Fluentd's filter mechanism, in particular the [record_transformer filter](https://docs.fluentd.org/filter/record_transformer).
37
37
 
38
38
  For example, if you want to use Scalyr's ```accessLog``` parser for all events with the ```scalyr.access``` tag you would add the following to your fluent.conf file:
39
39
 
@@ -66,7 +66,9 @@ The following configuration options are also supported:
66
66
 
67
67
  #scalyr specific options
68
68
  api_write_token YOUR_SCALYR_WRITE_TOKEN
69
- compression_type bz2
69
+ compression_type deflate
70
+ compression_level 6
71
+ use_hostname_for_serverhost true
70
72
  server_attributes {
71
73
  "serverHost": "front-1",
72
74
  "serverType": "frontend",
@@ -79,7 +81,7 @@ The following configuration options are also supported:
79
81
  ssl_verify_depth 5
80
82
  message_field message
81
83
 
82
- max_request_buffer 1048576
84
+ max_request_buffer 5500000
83
85
 
84
86
  force_message_encoding nil
85
87
  replace_invalid_utf8 false
@@ -91,14 +93,18 @@ The following configuration options are also supported:
91
93
  retry_max_interval 30s
92
94
  flush_interval 5s
93
95
  flush_thread_count 1
94
- chunk_limit_size 100k
96
+ chunk_limit_size 2.5m
95
97
  queue_limit_length 1024
96
98
  </buffer>
97
99
 
98
100
  </match>
99
101
  ```
100
102
 
101
- ####Scalyr specific options
103
+ For some additional examples of configuration for different setups, please refer to the
104
+ [examples/configs/](https://github.com/scalyr/scalyr-fluentd/tree/master/examples/configs/)
105
+ directory.
106
+
107
+ ### Scalyr specific options
102
108
 
103
109
  ***compression_type*** - compress Scalyr traffic to reduce network traffic. Options are `bz2` and `deflate`. See [here](https://www.scalyr.com/help/scalyr-agent#compressing) for more details. This feature is optional.
104
110
 
@@ -106,6 +112,8 @@ The following configuration options are also supported:
106
112
 
107
113
  ***server_attributes*** - a JSON hash containing custom server attributes you want to include with each log request. This value is optional and defaults to *nil*.
108
114
 
115
+ ***use_hostname_for_serverhost*** - if `true` then if `server_attributes` is nil or it does *not* include a field called `serverHost` then the plugin will add the `serverHost` field with the value set to the hostname that fluentd is running on. Defaults to `true`.
116
+
109
117
  ***scalyr_server*** - the Scalyr server to send API requests to. This value is optional and defaults to https://agent.scalyr.com/
110
118
 
111
119
  ***ssl_ca_bundle_path*** - a path on your server pointing to a valid certificate bundle. This value is optional and defaults to */etc/ssl/certs/ca-bundle.crt*.
@@ -126,13 +134,13 @@ The cURL project maintains CA certificate bundles automatically converted from m
126
134
 
127
135
  ***message_field*** - Scalyr expects all log events to have a 'message' field containing the contents of a log message. If your event has the log message stored in another field, you can specify the field name here, and the plugin will rename that field to 'message' before sending the data to Scalyr. **Note:** this will override any existing 'message' field if the log record contains both a 'message' field and the field specified by this config option.
128
136
 
129
- ***max_request_buffer*** - The maximum size in bytes of each request to send to Scalyr. Defaults to 1,048,576 (1MB). Fluentd chunks that generate JSON requests larger than the max_request_buffer will be split in to multiple separate requests. **Note:** If you set this value too large Scalyr may reject your requests.
137
+ ***max_request_buffer*** - The maximum size in bytes of each request to send to Scalyr. Defaults to 5,500,000 (5.5MB). Fluentd chunks that generate JSON requests larger than the max_request_buffer will be split in to multiple separate requests. **Note:** The maximum size the Scalyr servers accept for this value is 6MB and requests containing data larger than this will be rejected.
130
138
 
131
139
  ***force_message_encoding*** - Set a specific encoding for all your log messages (defaults to nil). If your log messages are not in UTF-8, this can cause problems when converting the message to JSON in order to send to the Scalyr server. You can avoid these problems by setting an encoding for your log messages so they can be correctly converted.
132
140
 
133
141
  ***replace_invalid_utf8*** - If this value is true and ***force_message_encoding*** is set to 'UTF-8' then all invalid UTF-8 sequences in log messages will be replaced with <?>. Defaults to false. This flag has no effect if ***force_message_encoding*** is not set to 'UTF-8'.
134
142
 
135
- ####Buffer options
143
+ ### Buffer options
136
144
 
137
145
  ***retry_max_times*** - the maximum number of times to retry a failed post request before giving up. Defaults to *40*.
138
146
 
@@ -144,7 +152,7 @@ The cURL project maintains CA certificate bundles automatically converted from m
144
152
 
145
153
  ***flush_thread_count*** - the number of threads to use to upload logs. This is currently fixed to 1 will cause fluentd to fail with a ConfigError if set to anything greater.
146
154
 
147
- ***chunk_limit_size*** - the maximum amount of log data to send to Scalyr in a single request. Defaults to *100KB*. **Note:** if you set this value too large, then Scalyr may reject your requests. Requests smaller than 1MB will typically be accepted by Scalyr, but note that the 1MB limit also includes the entire request body and all associated JSON keys and punctuation, which may be considerably larger than the raw log data.
155
+ ***chunk_limit_size*** - the maximum amount of log data to send to Scalyr in a single request. Defaults to *2.5MB*. **Note:** if you set this value too large, then Scalyr may reject your requests. Requests smaller than 6 MB will typically be accepted by Scalyr, but note that the 6 MB limit also includes the entire request body and all associated JSON keys and punctuation, which may be considerably larger than the raw log data. This value should be set lower than the `max_request_buffer` option.
148
156
 
149
157
  ***queue_limit_length*** - the maximum number of chunks to buffer before dropping new log requests. Defaults to *1024*. Combines with ***chunk_limit_size*** to give you the total amount of buffer to use in the event of request failures before dropping requests.
150
158
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.8.5
1
+ 0.8.10
@@ -9,7 +9,6 @@ Gem::Specification.new do |gem|
9
9
  gem.authors = ["Imron Alston"]
10
10
  gem.licenses = ["Apache-2.0"]
11
11
  gem.email = "imron@scalyr.com"
12
- gem.has_rdoc = false
13
12
  gem.platform = Gem::Platform::RUBY
14
13
  gem.files = Dir['AUTHORS', 'Gemfile', 'LICENSE', 'README.md', 'Rakefile', 'VERSION', 'fluent-plugin-scalyr.gemspec', 'fluent.conf.sample', 'lib/**/*', 'test/**/*']
15
14
  gem.test_files = Dir.glob("{test,spec,features}/**/*")
@@ -1,7 +1,7 @@
1
1
  <match scalyr.*>
2
2
  @type scalyr
3
3
  api_write_token YOUR_WRITE_LOGS_API_TOKEN
4
- compression_type bz2
4
+ compression_type deflate
5
5
 
6
6
  ##Scalyr specific options
7
7
  # server_attributes {
@@ -26,6 +26,7 @@ require 'rbzip2'
26
26
  require 'stringio'
27
27
  require 'zlib'
28
28
  require 'securerandom'
29
+ require 'socket'
29
30
  require 'thread'
30
31
 
31
32
  module Scalyr
@@ -36,23 +37,24 @@ module Scalyr
36
37
 
37
38
  config_param :api_write_token, :string
38
39
  config_param :server_attributes, :hash, :default => nil
40
+ config_param :use_hostname_for_serverhost, :bool, :default => true
39
41
  config_param :scalyr_server, :string, :default => "https://agent.scalyr.com/"
40
42
  config_param :ssl_ca_bundle_path, :string, :default => "/etc/ssl/certs/ca-bundle.crt"
41
43
  config_param :ssl_verify_peer, :bool, :default => true
42
44
  config_param :ssl_verify_depth, :integer, :default => 5
43
45
  config_param :message_field, :string, :default => "message"
44
- config_param :max_request_buffer, :integer, :default => 1024*1024
46
+ config_param :max_request_buffer, :integer, :default => 5500000
45
47
  config_param :force_message_encoding, :string, :default => nil
46
48
  config_param :replace_invalid_utf8, :bool, :default => false
47
49
  config_param :compression_type, :string, :default => nil #Valid options are bz2, deflate or None. Defaults to None.
48
- config_param :compression_level, :integer, :default => 9 #An int containing the compression level of compression to use, from 1-9. Defaults to 9 (max)
50
+ config_param :compression_level, :integer, :default => 6 #An int containing the compression level of compression to use, from 1-9. Defaults to 6
49
51
 
50
52
  config_section :buffer do
51
53
  config_set_default :retry_max_times, 40 #try a maximum of 40 times before discarding
52
54
  config_set_default :retry_max_interval, 30 #wait a maximum of 30 seconds per retry
53
55
  config_set_default :retry_wait, 5 #wait a minimum of 5 seconds per retry
54
56
  config_set_default :flush_interval, 5 #default flush interval of 5 seconds
55
- config_set_default :chunk_limit_size, 1024*100 #default chunk size of 100k
57
+ config_set_default :chunk_limit_size, 2500000 #default chunk size of 2.5mb
56
58
  config_set_default :queue_limit_length, 1024 #default queue size of 1024
57
59
  end
58
60
 
@@ -65,6 +67,10 @@ module Scalyr
65
67
  true
66
68
  end
67
69
 
70
+ def multi_workers_ready?
71
+ true
72
+ end
73
+
68
74
  def configure( conf )
69
75
 
70
76
  if conf.elements('buffer').empty?
@@ -75,12 +81,12 @@ module Scalyr
75
81
 
76
82
  super
77
83
 
78
- if @buffer.chunk_limit_size > 1024*1024
79
- $log.warn "Buffer chunk size is greater than 1Mb. This may result in requests being rejected by Scalyr"
84
+ if @buffer.chunk_limit_size > 6000000
85
+ $log.warn "Buffer chunk size is greater than 6Mb. This may result in requests being rejected by Scalyr"
80
86
  end
81
87
 
82
- if @max_request_buffer > (1024*1024*3)
83
- $log.warn "Maximum request buffer > 3Mb. This may result in requests being rejected by Scalyr"
88
+ if @max_request_buffer > 6000000
89
+ $log.warn "Maximum request buffer > 6Mb. This may result in requests being rejected by Scalyr"
84
90
  end
85
91
 
86
92
  @message_encoding = nil
@@ -109,6 +115,22 @@ module Scalyr
109
115
  @server_attributes = new_attributes
110
116
  end
111
117
 
118
+ # See if we should use the hostname as the server_attributes.serverHost
119
+ if @use_hostname_for_serverhost
120
+
121
+ # ensure server_attributes is not nil
122
+ if @server_attributes.nil?
123
+ @server_attributes = {}
124
+ end
125
+
126
+ # only set serverHost if it doesn't currently exist in server_attributes
127
+ # Note: Use strings rather than symbols for the key, because keys coming
128
+ # from the config file will be strings
129
+ if !@server_attributes.key? 'serverHost'
130
+ @server_attributes['serverHost'] = Socket.gethostname
131
+ end
132
+ end
133
+
112
134
  @scalyr_server << '/' unless @scalyr_server.end_with?('/')
113
135
 
114
136
  @add_events_uri = URI @scalyr_server + "addEvents"
@@ -121,15 +143,10 @@ module Scalyr
121
143
 
122
144
  def start
123
145
  super
124
- $log.info "Scalyr Fluentd Plugin ID - #{self.plugin_id()}"
125
146
  #Generate a session id. This will be called once for each <match> in fluent.conf that uses scalyr
126
147
  @session = SecureRandom.uuid
127
148
 
128
- @sync = Mutex.new
129
- #the following variables are all under the control of the above mutex
130
- @thread_ids = Hash.new #hash of tags -> id
131
- @next_id = 1 #incrementing thread id for the session
132
- @last_timestamp = 0 #timestamp of most recent event in nanoseconds since epoch
149
+ $log.info "Scalyr Fluentd Plugin ID id=#{self.plugin_id()} worker=#{fluentd_worker_id} session=#{@session}"
133
150
 
134
151
  end
135
152
 
@@ -140,8 +157,14 @@ module Scalyr
140
157
  time = Fluent::Engine.now
141
158
  end
142
159
 
160
+ # handle timestamps that are not EventTime types
143
161
  if time.is_a?( Integer )
144
162
  time = Fluent::EventTime.new( time )
163
+ elsif time.is_a?( Float )
164
+ components = time.divmod 1 #get integer and decimal components
165
+ sec = components[0].to_i
166
+ nsec = (components[1] * 10**9).to_i
167
+ time = Fluent::EventTime.new( sec, nsec )
145
168
  end
146
169
 
147
170
  if @message_field != "message"
@@ -154,7 +177,7 @@ module Scalyr
154
177
  end
155
178
  end
156
179
 
157
- if @message_encoding
180
+ if @message_encoding and record.key? "message" and record["message"]
158
181
  if @replace_invalid_utf8 and @message_encoding == Encoding::UTF_8
159
182
  record["message"] = record["message"].encode("UTF-8", :invalid => :replace, :undef => :replace, :replace => "<?>").force_encoding('UTF-8')
160
183
  else
@@ -310,22 +333,7 @@ module Scalyr
310
333
 
311
334
  timestamp = self.to_nanos( sec, nsec )
312
335
 
313
- thread_id = 0
314
-
315
- @sync.synchronize {
316
- #ensure timestamp is at least 1 nanosecond greater than the last one
317
- timestamp = [timestamp, @last_timestamp + 1].max
318
- @last_timestamp = timestamp
319
-
320
- #get thread id or add a new one if we haven't seen this tag before
321
- if @thread_ids.key? tag
322
- thread_id = @thread_ids[tag]
323
- else
324
- thread_id = @next_id
325
- @thread_ids[tag] = thread_id
326
- @next_id += 1
327
- end
328
- }
336
+ thread_id = tag
329
337
 
330
338
  #then update the map of threads for this chunk
331
339
  current_threads[tag] = thread_id
@@ -17,12 +17,15 @@
17
17
 
18
18
 
19
19
  require 'helper'
20
+ require 'socket'
20
21
 
21
22
  class ConfigTest < Scalyr::ScalyrOutTest
22
23
 
23
24
  def test_default_params
24
25
  d = create_driver
25
- assert_nil( d.instance.server_attributes, "Default server_attributes not nil" )
26
+ hostname = Socket.gethostname
27
+ assert_not_nil( d.instance.server_attributes, "Default server_attributes should not be nil" )
28
+ assert_equal( hostname, d.instance.server_attributes['serverHost'], "Default serverHost is not hostname" )
26
29
  assert( d.instance.ssl_verify_peer, "Default ssl_verify_peer should be true" )
27
30
 
28
31
  #check default buffer limits because they are set outside of the config_set_default
@@ -30,6 +33,17 @@ class ConfigTest < Scalyr::ScalyrOutTest
30
33
  assert_equal( 1024, d.instance.buffer.buffer_queue_limit, "Buffer queue limit should be 1024" )
31
34
  end
32
35
 
36
+ def test_custom_serverhost_not_overwritten
37
+ hostname = "customHost"
38
+ d = create_driver CONFIG + "server_attributes { \"serverHost\":\"#{hostname}\" }\nuse_hostname_for_serverhost true"
39
+ assert_equal( hostname, d.instance.server_attributes['serverHost'], "Custom serverHost should not be overwritten" )
40
+ end
41
+
42
+ def test_configure_use_hostname_for_serverhost
43
+ d = create_driver CONFIG + 'use_hostname_for_serverhost false'
44
+ assert_nil( d.instance.server_attributes, "Default server_attributes should be nil" )
45
+ end
46
+
33
47
  def test_configure_ssl_verify_peer
34
48
  d = create_driver CONFIG + 'ssl_verify_peer false'
35
49
  assert( !d.instance.ssl_verify_peer, "Config failed to set ssl_verify_peer" )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-scalyr
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.8.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Imron Alston
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-11-22 00:00:00.000000000 Z
11
+ date: 2020-07-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -168,14 +168,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
168
  - !ruby/object:Gem::Version
169
169
  version: '0'
170
170
  requirements: []
171
- rubyforge_project:
172
- rubygems_version: 2.5.2
171
+ rubygems_version: 3.0.6
173
172
  signing_key:
174
173
  specification_version: 4
175
174
  summary: Scalyr plugin for fluentd
176
175
  test_files:
177
- - test/test_events.rb
178
- - test/test_config.rb
179
- - test/helper.rb
180
176
  - test/test_handle_response.rb
181
177
  - test/test_ssl_verify.rb
178
+ - test/test_config.rb
179
+ - test/test_events.rb
180
+ - test/helper.rb