logstash-output-loggly 4.0.0 → 5.0.0

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: 1e15e34b7a8077fdb9c36ebd61ddad7d3e89adf138381cb339849f7dfe55b2ea
4
- data.tar.gz: 509a2c487b8faf7821e8e83b32db90096dc46c23af35bfc7757dc8a698643901
3
+ metadata.gz: c5ef3911c30709e44be9b65e5be43f192b716bc00b40c9d373fcc78677f7b060
4
+ data.tar.gz: 1be2aa1769cf66c2bf19d431738a6995217b8ee9007533a1848647c0b358b2dd
5
5
  SHA512:
6
- metadata.gz: aef1bc454004b3978558d783ae2fc2194f715405cc3e60bc9f06b635fe722eab60a6b9b088c8c0a61fd0ac92cc4c609510e2c17198d9980db006505b66905050
7
- data.tar.gz: 36dd4857187cefd3bca6fed7c65badd69b3a0adb8b0f220af085758b99f4d23a82a6a598bab479dee55d3b2179bb74d065e2af0ab5f51e8984e6038f83f2fe91
6
+ metadata.gz: 85b87a48f7c044a25fb8739c21761ced70f6d131614890fb39a7ae7edd03be025e0f0cc0bbc4b4ab16ca19d398ff389c95f9aea759d31e63cb294ded666e659f
7
+ data.tar.gz: 6bfa8d3d9ef0dbbceb2332b30b13fc794dc75935ff31c45ba7494ad4de243db5f433642b78538dccbaf30593f476702307d01913788e5c684a6e56d0734b1c41
data/CHANGELOG.md CHANGED
@@ -1,3 +1,17 @@
1
+ ## 5.0.0
2
+ - This version introduces "breaking" changes for users who never copied/renamed
3
+ their `@timestamp` field to `timestamp`: their events will suddenly appear
4
+ in Loggly with a `timestamp` based on Logstash's value of `@timestamp`.
5
+ This would especially be noticed at times where processing is behind, and
6
+ events need to be "backfilled".
7
+ - The plugin now sets field `timestamp` so that Loggly will recognize the
8
+ correct timestamp.
9
+ - The event's timestamps will however not be touched at all if `timestamp`
10
+ is already set on the event or if `@timestamp` is missing.
11
+ - This version introduces attribute `convert_timestamp` (defaults to true), which
12
+ triggers the timestamp mingling.
13
+ - Now log a debug message with all of the plugin's configuration upon initialization.
14
+
1
15
  ## 4.0.0
2
16
  - The plugin now uses the Loggly bulk API.
3
17
  - If you need to modify event batch sizes and max delay between flushes,
data/docs/index.asciidoc CHANGED
@@ -38,6 +38,7 @@ This plugin supports the following configuration options plus the <<plugins-{typ
38
38
  |=======================================================================
39
39
  |Setting |Input type|Required
40
40
  | <<plugins-{type}s-{plugin}-can_retry>> |<<boolean,boolean>>|No
41
+ | <<plugins-{type}s-{plugin}-convert_timestamp>> |<<boolean,boolean>>|No
41
42
  | <<plugins-{type}s-{plugin}-host>> |<<string,string>>|No
42
43
  | <<plugins-{type}s-{plugin}-key>> |<<string,string>>|Yes
43
44
  | <<plugins-{type}s-{plugin}-max_event_size>> |<<bytes,bytes>>|Yes
@@ -57,7 +58,7 @@ output plugins.
57
58
  &nbsp;
58
59
 
59
60
  [id="plugins-{type}s-{plugin}-can_retry"]
60
- ===== `can_retry`
61
+ ===== `can_retry`
61
62
 
62
63
  * Value type is <<boolean,boolean>>
63
64
  * Default value is `true`
@@ -65,6 +66,21 @@ output plugins.
65
66
  Can Retry.
66
67
  Setting this value true helps user to send multiple retry attempts if the first request fails
67
68
 
69
+ [id="plugins-{type}s-{plugin}-convert_timestamp"]
70
+ ===== `convert_timestamp`
71
+
72
+ * Value type is <<boolean,boolean>>
73
+ * Default value is `true`
74
+
75
+ The plugin renames Logstash's '@timestamp' field to 'timestamp' before sending,
76
+ so that Loggly recognizes it automatically.
77
+
78
+ This will do nothing if your event doesn't have a '@timestamp' field or if
79
+ your event already has a 'timestamp' field.
80
+
81
+ Note that the actual Logstash event is not modified by the output. This modification
82
+ only happens on a copy of the event, prior to sending.
83
+
68
84
  [id="plugins-{type}s-{plugin}-host"]
69
85
  ===== `host`
70
86
 
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/outputs/base"
3
3
  require "logstash/namespace"
4
+ require "json"
4
5
  require "timeout"
5
6
  require "uri"
6
7
  # TODO(sissel): Move to something that performs better than net/http
@@ -30,6 +31,16 @@ class LogStash::Outputs::Loggly < LogStash::Outputs::Base
30
31
 
31
32
  config_name "loggly"
32
33
 
34
+ # Rename Logstash's '@timestamp' field to 'timestamp' before sending,
35
+ # so that Loggly recognizes it automatically.
36
+ #
37
+ # This will do nothing if your event doesn't have a '@timestamp' field or if
38
+ # your event already has a 'timestamp' field.
39
+ #
40
+ # Note that the actual Logstash event is not modified by the output. This
41
+ # modification only happens on a copy of the event, prior to sending.
42
+ config :convert_timestamp, :validate => :boolean, :default => true
43
+
33
44
  # The hostname to send logs to. This should target the loggly http input
34
45
  # server which is usually "logs-01.loggly.com" (Gen2 account).
35
46
  # See Loggly HTTP endpoint documentation at
@@ -105,6 +116,7 @@ class LogStash::Outputs::Loggly < LogStash::Outputs::Base
105
116
 
106
117
  public
107
118
  def register
119
+ @logger.debug "Initializing Loggly Output", @config
108
120
  end
109
121
 
110
122
  public
@@ -133,7 +145,12 @@ class LogStash::Outputs::Loggly < LogStash::Outputs::Base
133
145
  # we should ship logs with the default tag value.
134
146
  tag = DEFAULT_LOGGLY_TAG if /%{\w+}/.match(tag)
135
147
 
136
- meta_event = { key: key, tag: tag, event: event }
148
+ event_hash = event.to_hash # Don't want to modify the event in an output
149
+ if @convert_timestamp && event_hash['@timestamp'] && !event_hash['timestamp']
150
+ event_hash['timestamp'] = event_hash.delete('@timestamp')
151
+ end
152
+
153
+ meta_event = { key: key, tag: tag, event: event_hash }
137
154
  end # prepare_meta
138
155
 
139
156
  public
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'logstash-output-loggly'
3
- s.version = '4.0.0'
3
+ s.version = '5.0.0'
4
4
  s.licenses = ['Apache License (2.0)']
5
5
  s.summary = "Ships logs to Loggly"
6
6
  s.description = "This gem is a Logstash plugin required to be installed on top of the Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This gem is not a stand-alone program"
@@ -23,5 +23,6 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.add_development_dependency 'logstash-devutils'
25
25
  s.add_development_dependency 'logstash-codec-plain'
26
+ s.add_development_dependency 'rake', '~> 12.2.1' # for JRuby 1.7, Ruby 1.9
26
27
  end
27
28
 
@@ -7,7 +7,7 @@ def logger_for(plugin)
7
7
  end
8
8
 
9
9
  describe 'outputs/loggly' do
10
- let(:config) { { 'key' => 'abcdef123456' } }
10
+ let(:config) { { 'key' => 'abcdef123456', 'convert_timestamp' => false } }
11
11
 
12
12
  let(:output) do
13
13
  LogStash::Outputs::Loggly.new(config).tap do |output|
@@ -41,7 +41,7 @@ describe 'outputs/loggly' do
41
41
 
42
42
  context 'when sending events' do
43
43
  it 'should set the default tag to logstash' do
44
- expect(output).to receive(:send_batch).with([{event: event, key: 'abcdef123456', tag: 'logstash'}])
44
+ expect(output).to receive(:send_batch).with([{event: event.to_hash, key: 'abcdef123456', tag: 'logstash'}])
45
45
  output.receive(event)
46
46
  end
47
47
 
@@ -50,19 +50,19 @@ describe 'outputs/loggly' do
50
50
  event.set('token', 'xxxxxxx1234567')
51
51
  config['key'] = '%{token}'
52
52
 
53
- expect(output).to receive(:send_batch).with([{event: event, key: 'xxxxxxx1234567', tag: 'logstash'}])
53
+ expect(output).to receive(:send_batch).with([{event: event.to_hash, key: 'xxxxxxx1234567', tag: 'logstash'}])
54
54
  output.receive(event)
55
55
  end
56
56
 
57
57
  it 'should support field interpolation for tag' do
58
58
  config['tag'] = '%{source}'
59
- expect(output).to receive(:send_batch).with([{event: event, key: 'abcdef123456', tag: 'someapp'}])
59
+ expect(output).to receive(:send_batch).with([{event: event.to_hash, key: 'abcdef123456', tag: 'someapp'}])
60
60
  output.receive(event)
61
61
  end
62
62
 
63
63
  it 'should default tag to logstash if interpolated field for tag does not exist' do
64
64
  config['tag'] = '%{foobar}'
65
- expect(output).to receive(:send_batch).with([{event: event, key: 'abcdef123456', tag: 'logstash'}])
65
+ expect(output).to receive(:send_batch).with([{event: event.to_hash, key: 'abcdef123456', tag: 'logstash'}])
66
66
  output.receive(event)
67
67
  end
68
68
 
@@ -72,7 +72,7 @@ describe 'outputs/loggly' do
72
72
  event2 = event.clone
73
73
  event2.remove('custom_key')
74
74
 
75
- expect(output).to receive(:send_batch).once.with([{event: event, key: 'a_key', tag: 'logstash'}, nil])
75
+ expect(output).to receive(:send_batch).once.with([{event: event.to_hash, key: 'a_key', tag: 'logstash'}, nil])
76
76
  logger = logger_for(output)
77
77
  expect(logger).to receive(:warn).with(/No key provided/)
78
78
  expect(logger).to receive(:debug).with(/Dropped message/, kind_of(Hash))
@@ -109,6 +109,48 @@ describe 'outputs/loggly' do
109
109
  output.multi_receive([event1, event2, event3, event4])
110
110
  end
111
111
  end
112
+
113
+ context 'timestamp mingling' do
114
+ context 'when convert_timestamp is false' do
115
+ let(:config) { super.merge('convert_timestamp' => false) }
116
+
117
+ it 'should not create a timestamp field nor delete @timestamp' do
118
+ expected_time = event.get('@timestamp')
119
+ meta_event = output.send :prepare_meta, event
120
+
121
+ expect(meta_event[:event]['@timestamp']).to eq(expected_time)
122
+ expect(meta_event[:event]['timestamp']).to be_nil
123
+ end
124
+ end
125
+
126
+ context 'when convert_timestamp is true' do
127
+ let(:config) { super.merge('convert_timestamp' => true) }
128
+
129
+ it 'should rename @timestamp to timestamp in the normal case' do
130
+ expected_time = event.get('@timestamp')
131
+ meta_event = output.send :prepare_meta, event
132
+
133
+ expect(meta_event[:event]['timestamp']).to eq(expected_time)
134
+ expect(meta_event[:event]['@timestamp']).to be_nil
135
+ end
136
+
137
+ it 'should not overwrite an existing timestamp field' do
138
+ event.set('timestamp', "no tocar")
139
+ meta_event = output.send :prepare_meta, event
140
+
141
+ expect(meta_event[:event]['timestamp']).to eq('no tocar')
142
+ expect(meta_event[:event]['@timestamp']).to eq(event.get('@timestamp'))
143
+ end
144
+
145
+ it 'should not attempt to set timestamp if the event has no @timestamp' do
146
+ event.remove('@timestamp')
147
+ meta_event = output.send :prepare_meta, event
148
+
149
+ expect(meta_event[:event]['timestamp']).to be_nil
150
+ expect(meta_event[:event]['@timestamp']).to be_nil
151
+ end
152
+ end
153
+ end
112
154
  end
113
155
 
114
156
  context 'splitting batches of events' do
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-output-loggly
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.0.0
4
+ version: 5.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-15 00:00:00.000000000 Z
11
+ date: 2018-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -58,6 +58,20 @@ dependencies:
58
58
  - - ">="
59
59
  - !ruby/object:Gem::Version
60
60
  version: '0'
61
+ - !ruby/object:Gem::Dependency
62
+ requirement: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 12.2.1
67
+ name: rake
68
+ prerelease: false
69
+ type: :development
70
+ version_requirements: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - "~>"
73
+ - !ruby/object:Gem::Version
74
+ version: 12.2.1
61
75
  description: This gem is a Logstash plugin required to be installed on top of the
62
76
  Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
63
77
  gem is not a stand-alone program