logstash-codec-fluent 3.3.0-java → 3.4.0-java

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: 03c1ce6a081dedf60755a7a37842e814dd3a1ffc3af4d433a00cdaba91f9bc69
4
- data.tar.gz: bb1c16c6a60754f41fb7285a5b9fe422dbf4c1d85bfd2e5040793cffd810ec5c
3
+ metadata.gz: e17d4af78cd9df1b4534f747813c106d9c1c4e3072a2f74989bfd78413e3173c
4
+ data.tar.gz: 4c77861536c3a5ea3c4e8eef9d97bdc0c986a42991261b9143a80bfa7ede0254
5
5
  SHA512:
6
- metadata.gz: a2bf6928d517ebeca49942829d246965f14d1efaf08628e5b1767e5059f33df17e64f56338db35a5033b163fd87820388fd7d958a98179f80f3676af67baad29
7
- data.tar.gz: 820ae450a849d4aaa24eb5cd0814ed066bfc1f7abb98c24428f676c87beb10e745c7d5c9cb96d8549bb7c9a8749e02955e4f00bf88340127cd0680df90967401
6
+ metadata.gz: 8e876b1ee27ca9f647baff747432261a10a41d1217bc228f458d7c45641a93d70a6765eb312a1e141e05f6413a8866f4dee731bf215d7c5f8466583e7e2f7888
7
+ data.tar.gz: ffcfe5a551b868a02eb53ebefece63e97bd57c70f31a1b925d4a8e80093c92186fbfe1eeee061d1def481930f244b97f3061cc750a8880fb807f804c164982e1
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## 3.4.0
2
+ - Feat: added target configuration + event-factory support [#27](https://github.com/logstash-plugins/logstash-codec-fluent/pull/27)
3
+ - Fix: decoding of time's nano-second precision
4
+
1
5
  ## 3.3.0
2
6
  - Handle EventTime msgpack extension to handle nanosecond precision time and add its parameter [#18](https://github.com/logstash-plugins/logstash-codec-fluent/pull/18)
3
7
 
data/LICENSE CHANGED
@@ -1,13 +1,202 @@
1
- Copyright (c) 2012-2018 Elasticsearch <http://www.elastic.co>
2
1
 
3
- Licensed under the Apache License, Version 2.0 (the "License");
4
- you may not use this file except in compliance with the License.
5
- You may obtain a copy of the License at
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
6
5
 
7
- http://www.apache.org/licenses/LICENSE-2.0
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
8
7
 
9
- Unless required by applicable law or agreed to in writing, software
10
- distributed under the License is distributed on an "AS IS" BASIS,
11
- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
- See the License for the specific language governing permissions and
13
- limitations under the License.
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 Elastic and contributors
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Logstash Plugin
2
2
 
3
- [![Travis Build Status](https://travis-ci.org/logstash-plugins/logstash-codec-fluent.svg)](https://travis-ci.org/logstash-plugins/logstash-codec-fluent)
3
+ [![Travis Build Status](https://travis-ci.com/logstash-plugins/logstash-codec-fluent.svg)](https://travis-ci.com/logstash-plugins/logstash-codec-fluent)
4
4
 
5
5
  This is a plugin for [Logstash](https://github.com/elastic/logstash).
6
6
 
data/docs/index.asciidoc CHANGED
@@ -36,8 +36,48 @@ And from your ruby code in your own application:
36
36
  logger = Fluent::Logger::FluentLogger.new(nil, :host => "example.log", :port => 4000)
37
37
  logger.post("some_tag", { "your" => "data", "here" => "yay!" })
38
38
 
39
- Notes:
40
39
 
41
- * the fluent uses a second-precision time for events, so you will never see
42
- subsecond precision on events processed by this codec.
40
+ NOTE: Fluent uses second-precision for events, so you will not see sub-second precision
41
+ on events processed by this codec.
42
+
43
+
44
+ [id="plugins-{type}s-{plugin}-options"]
45
+ ==== Fluent Codec configuration options
46
+
47
+ [cols="<,<,<",options="header",]
48
+ |=======================================================================
49
+ |Setting |Input type|Required
50
+ | <<plugins-{type}s-{plugin}-nanosecond_precision>> |<<boolean,boolean>>|No
51
+ | <<plugins-{type}s-{plugin}-target>> |<<string,string>>|No
52
+ |=======================================================================
53
+
54
+ &nbsp;
55
+
56
+ [id="plugins-{type}s-{plugin}-nanosecond_precision"]
57
+ ===== `nanosecond_precision`
58
+
59
+ * Value type is <<boolean,boolean>>
60
+ * Default value is `false`
61
+
62
+ Enables sub-second level precision while encoding events.
63
+
64
+ [id="plugins-{type}s-{plugin}-target"]
65
+ ===== `target`
66
+
67
+ * Value type is <<string,string>>
68
+ * There is no default value for this setting.
69
+
70
+ Define the target field for placing the decoded values. If this setting is not
71
+ set, data will be stored at the root (top level) of the event.
72
+
73
+ For example, if you want data to be put under the `logs` field:
74
+ [source,ruby]
75
+ input {
76
+ tcp {
77
+ codec => fluent {
78
+ target => "[logs]"
79
+ }
80
+ port => 4000
81
+ }
82
+ }
43
83
 
@@ -1,9 +1,12 @@
1
1
  # encoding: utf-8
2
2
  require "logstash/codecs/base"
3
- require "logstash/util/charset"
3
+ require "logstash/event"
4
4
  require "logstash/timestamp"
5
5
  require "logstash/util"
6
6
 
7
+ require 'logstash/plugin_mixins/event_support/event_factory_adapter'
8
+ require 'logstash/plugin_mixins/validator_support/field_reference_validation_adapter'
9
+
7
10
  # This codec handles fluentd's msgpack schema.
8
11
  #
9
12
  # For example, you can receive logs from `fluent-logger-ruby` with:
@@ -29,10 +32,20 @@ require "logstash/util"
29
32
  class LogStash::Codecs::Fluent < LogStash::Codecs::Base
30
33
  require "logstash/codecs/fluent/event_time"
31
34
 
35
+ extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
36
+
37
+ include LogStash::PluginMixins::EventSupport::EventFactoryAdapter
38
+
32
39
  config_name "fluent"
33
40
 
34
41
  config :nanosecond_precision, :validate => :boolean, :default => false
35
42
 
43
+ # Defines a target field for placing decoded fields.
44
+ # If this setting is omitted, data gets stored at the root (top level) of the event.
45
+ #
46
+ # NOTE: the target is only relevant while decoding data into a new event.
47
+ config :target, :validate => :field_reference
48
+
36
49
  def register
37
50
  require "msgpack"
38
51
  @factory = MessagePack::Factory.new
@@ -84,10 +97,10 @@ class LogStash::Codecs::Fluent < LogStash::Codecs::Base
84
97
 
85
98
  def decode_fluent_time(fluent_time)
86
99
  case fluent_time
87
- when Fixnum
100
+ when Integer
88
101
  fluent_time
89
102
  when EventTime
90
- Time.at(fluent_time.sec, fluent_time.nsec)
103
+ Time.at(fluent_time.sec, fluent_time.nsec / 1000.0)
91
104
  end
92
105
  end
93
106
 
@@ -106,40 +119,30 @@ class LogStash::Codecs::Fluent < LogStash::Codecs::Base
106
119
 
107
120
  entries_decoder = @decoder
108
121
  entries_decoder.feed_each(entries) do |entry|
109
- epochtime = decode_fluent_time(entry[0])
110
- map = entry[1]
111
- event = LogStash::Event.new(map.merge(
112
- LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
113
- "tags" => [ tag ]
114
- ))
115
- yield event
122
+ yield generate_event(entry[1], entry[0], tag)
116
123
  end
117
124
  when Array
118
125
  # Forward
119
126
  entries.each do |entry|
120
- epochtime = decode_fluent_time(entry[0])
121
- map = entry[1]
122
- event = LogStash::Event.new(map.merge(
123
- LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
124
- "tags" => [ tag ]
125
- ))
126
- yield event
127
+ yield generate_event(entry[1], entry[0], tag)
127
128
  end
128
- when Fixnum, EventTime
129
+ when Integer, EventTime
129
130
  # Message
130
- epochtime = decode_fluent_time(entries)
131
- map = data[2]
132
- event = LogStash::Event.new(map.merge(
133
- LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
134
- "tags" => [ tag ]
135
- ))
136
- yield event
131
+ yield generate_event(data[2], entries, tag)
137
132
  else
138
133
  raise(LogStash::Error, "Unknown event type")
139
134
  end
140
135
  rescue StandardError => e
141
136
  @logger.error("Fluent parse error, original data now in message field", :error => e, :data => data)
142
- yield LogStash::Event.new("message" => data, "tags" => [ "_fluentparsefailure" ])
137
+ yield event_factory.new_event("message" => data, "tags" => [ "_fluentparsefailure" ])
138
+ end
139
+
140
+ def generate_event(map, fluent_time, tag)
141
+ epoch_time = decode_fluent_time(fluent_time)
142
+ event = targeted_event_factory.new_event(map)
143
+ event.set(LogStash::Event::TIMESTAMP, LogStash::Timestamp.at(epoch_time))
144
+ event.tag(tag)
145
+ event
143
146
  end
144
147
 
145
148
  end # class LogStash::Codecs::Fluent
@@ -1,7 +1,7 @@
1
1
  Gem::Specification.new do |s|
2
2
 
3
3
  s.name = 'logstash-codec-fluent'
4
- s.version = '3.3.0'
4
+ s.version = '3.4.0'
5
5
  s.licenses = ['Apache License (2.0)']
6
6
  s.summary = "Reads the `fluentd` `msgpack` schema"
7
7
  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"
@@ -21,6 +21,8 @@ Gem::Specification.new do |s|
21
21
 
22
22
  # Gem dependencies
23
23
  s.add_runtime_dependency "logstash-core-plugin-api", ">= 1.60", "<= 2.99"
24
+ s.add_runtime_dependency 'logstash-mixin-event_support', '~> 1.0'
25
+ s.add_runtime_dependency 'logstash-mixin-validator_support', '~> 1.0'
24
26
 
25
27
  s.platform = 'java'
26
28
 
@@ -13,8 +13,20 @@ describe LogStash::Codecs::Fluent do
13
13
  @unpacker = @factory.unpacker
14
14
  end
15
15
 
16
+ subject { LogStash::Codecs::Fluent.new(config) }
17
+
18
+ let(:config) { Hash.new }
19
+
16
20
  let(:properties) { {:name => "foo" } }
17
21
  let(:event) { LogStash::Event.new(properties) }
22
+ let(:timestamp) { event.timestamp }
23
+ let(:epochtime) { timestamp.to_i }
24
+ let(:tag) { "mytag" }
25
+ let(:data) { { 'name' => 'foo', 'number' => 42 } }
26
+
27
+ let(:message) do
28
+ @packer.pack([tag, epochtime, data])
29
+ end
18
30
 
19
31
  it "should register without errors" do
20
32
  plugin = LogStash::Plugin.lookup("codec", "fluent").new
@@ -36,7 +48,8 @@ describe LogStash::Codecs::Fluent do
36
48
  end
37
49
 
38
50
  describe "event encoding with EventTime" do
39
- subject { LogStash::Plugin.lookup("codec", "fluent").new({"nanosecond_precision" => true}) }
51
+
52
+ let(:config) { super().merge "nanosecond_precision" => true }
40
53
 
41
54
  it "should encode as message pack format" do
42
55
  subject.on_event do |event, data|
@@ -52,16 +65,22 @@ describe LogStash::Codecs::Fluent do
52
65
 
53
66
  describe "event decoding" do
54
67
 
55
- let(:tag) { "mytag" }
56
- let(:epochtime) { event.timestamp.to_i }
57
- let(:data) { LogStash::Util.normalize(event.to_hash) }
58
68
  let(:message) do
59
- @packer.pack([tag, epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)])
69
+ @packer.pack([tag, epochtime, data.merge(LogStash::Event::TIMESTAMP => timestamp.to_iso8601)])
60
70
  end
61
71
 
62
72
  it "should decode without errors" do
73
+ decoded = false
63
74
  subject.decode(message) do |event|
64
75
  expect(event.get("name")).to eq("foo")
76
+ decoded = true
77
+ end
78
+ expect(decoded).to be true
79
+ end
80
+
81
+ it "should tag event" do
82
+ subject.decode(message) do |event|
83
+ expect(event.get("tags")).to eql [ tag ]
65
84
  end
66
85
  end
67
86
 
@@ -69,31 +88,65 @@ describe LogStash::Codecs::Fluent do
69
88
 
70
89
  describe "event decoding with EventTime" do
71
90
 
72
- let(:tag) { "mytag" }
73
- let(:epochtime) { LogStash::Codecs::Fluent::EventTime.new(event.timestamp.to_i,
74
- event.timestamp.usec * 1000) }
75
- let(:data) { LogStash::Util.normalize(event.to_hash) }
76
- let(:message) do
77
- @packer.pack([tag, epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)])
78
- end
91
+ let(:epochtime) { LogStash::Codecs::Fluent::EventTime.new(timestamp.to_i, (timestamp.usec * 1000) + 123) }
92
+
79
93
  subject { LogStash::Plugin.lookup("codec", "fluent").new({"nanosecond_precision" => true}) }
80
94
 
81
95
  it "should decode without errors" do
96
+ decoded = false
82
97
  subject.decode(message) do |event|
83
98
  expect(event.get("name")).to eq("foo")
99
+ decoded = true
100
+ end
101
+ expect(decoded).to be true
102
+ end
103
+
104
+ it "decodes timestamp with nanos" do
105
+ subject.decode(message) do |event|
106
+ expect(event.timestamp.to_i).to eql epochtime.sec
107
+ expect(event.timestamp.usec * 1000 + 123).to eql epochtime.nsec
108
+ end
109
+ end
110
+
111
+ end
112
+
113
+ describe "event decoding with target" do
114
+
115
+ let(:tag) { "a_tag" }
116
+ let(:epochtime) { 123 }
117
+ let(:data) { LogStash::Util.normalize('name' => 'foo') }
118
+
119
+ let(:config) { super().merge "target" => '[bar]' }
120
+
121
+ it "should decode without errors" do
122
+ decoded = false
123
+ subject.decode(message) do |event|
124
+ expect(event.include?("name")).to be false
125
+ expect(event.get("bar")).to eql('name' => "foo")
126
+ decoded = true
127
+ end
128
+ expect(decoded).to be true
129
+ end
130
+
131
+ it "should tag event" do
132
+ subject.decode(message) do |event|
133
+ expect(event.get("tags")).to eql [ 'a_tag' ]
134
+ end
135
+ end
136
+
137
+ it "should set timestamp" do
138
+ subject.decode(message) do |event|
139
+ expect(event.timestamp.to_i).to eql(epochtime)
84
140
  end
85
141
  end
86
142
 
87
143
  end
88
144
 
89
145
  describe "forward protocol tag" do
90
- let(:event) { LogStash::Event.new(properties) }
91
- subject { LogStash::Plugin.lookup("codec", "fluent").new }
92
146
 
93
147
  describe "when passing Array value" do
94
148
  let(:properties) { {:tags => ["test", "logstash"], :name => "foo" } }
95
149
 
96
-
97
150
  it "should be joined with '.'" do
98
151
  subject.forwardable_tag(event) do |tag|
99
152
  expect(tag).to eq("test.logstash")
@@ -104,7 +157,6 @@ describe LogStash::Codecs::Fluent do
104
157
  describe "when passing String value" do
105
158
  let(:properties) { {:tags => "test.logstash", :name => "foo" } }
106
159
 
107
-
108
160
  it "should be pass-through" do
109
161
  subject.forwardable_tag(event) do |tag|
110
162
  expect(tag).to eq("test.logstash")
@@ -126,15 +178,13 @@ describe LogStash::Codecs::Fluent do
126
178
 
127
179
  describe "event decoding (buckets of events)" do
128
180
 
129
- let(:tag) { "mytag" }
130
- let(:epochtime) { event.timestamp.to_i }
131
- let(:data) { LogStash::Util.normalize(event.to_hash) }
181
+ let(:data) { LogStash::Util.normalize(event.to_hash) }
132
182
  let(:message) do
133
183
  @packer.pack([tag,
134
184
  [
135
- [epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)],
136
- [epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)],
137
- [epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)]
185
+ [epochtime, data.merge(LogStash::Event::TIMESTAMP => timestamp.to_iso8601)],
186
+ [epochtime, data.merge(LogStash::Event::TIMESTAMP => timestamp.to_iso8601)],
187
+ [epochtime, data.merge(LogStash::Event::TIMESTAMP => timestamp.to_iso8601)]
138
188
  ]
139
189
  ])
140
190
  end
@@ -154,14 +204,7 @@ describe LogStash::Codecs::Fluent do
154
204
 
155
205
  describe "event decoding (broken package)" do
156
206
 
157
- let(:tag) { "mytag" }
158
- let(:epochtime) { event.timestamp.to_s }
159
- let(:data) { LogStash::Util.normalize(event.to_hash) }
160
- let(:message) do
161
- MessagePack.pack([tag,
162
- epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)
163
- ])
164
- end
207
+ let(:epochtime) { timestamp.to_s }
165
208
 
166
209
  it "should decode with errors" do
167
210
  subject.decode(message) do |event|
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-codec-fluent
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.3.0
4
+ version: 3.4.0
5
5
  platform: java
6
6
  authors:
7
7
  - Elastic
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-11-08 00:00:00.000000000 Z
11
+ date: 2021-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  requirement: !ruby/object:Gem::Requirement
@@ -20,8 +20,8 @@ dependencies:
20
20
  - !ruby/object:Gem::Version
21
21
  version: '2.99'
22
22
  name: logstash-core-plugin-api
23
- prerelease: false
24
23
  type: :runtime
24
+ prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - ">="
@@ -30,6 +30,34 @@ dependencies:
30
30
  - - "<="
31
31
  - !ruby/object:Gem::Version
32
32
  version: '2.99'
33
+ - !ruby/object:Gem::Dependency
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - "~>"
37
+ - !ruby/object:Gem::Version
38
+ version: '1.0'
39
+ name: logstash-mixin-event_support
40
+ type: :runtime
41
+ prerelease: false
42
+ version_requirements: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - "~>"
45
+ - !ruby/object:Gem::Version
46
+ version: '1.0'
47
+ - !ruby/object:Gem::Dependency
48
+ requirement: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - "~>"
51
+ - !ruby/object:Gem::Version
52
+ version: '1.0'
53
+ name: logstash-mixin-validator_support
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - "~>"
59
+ - !ruby/object:Gem::Version
60
+ version: '1.0'
33
61
  - !ruby/object:Gem::Dependency
34
62
  requirement: !ruby/object:Gem::Requirement
35
63
  requirements:
@@ -37,8 +65,8 @@ dependencies:
37
65
  - !ruby/object:Gem::Version
38
66
  version: '1.1'
39
67
  name: msgpack
40
- prerelease: false
41
68
  type: :runtime
69
+ prerelease: false
42
70
  version_requirements: !ruby/object:Gem::Requirement
43
71
  requirements:
44
72
  - - "~>"
@@ -51,8 +79,8 @@ dependencies:
51
79
  - !ruby/object:Gem::Version
52
80
  version: 1.0.0
53
81
  name: logstash-devutils
54
- prerelease: false
55
82
  type: :development
83
+ prerelease: false
56
84
  version_requirements: !ruby/object:Gem::Requirement
57
85
  requirements:
58
86
  - - ">="
@@ -99,8 +127,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
99
127
  - !ruby/object:Gem::Version
100
128
  version: '0'
101
129
  requirements: []
102
- rubyforge_project:
103
- rubygems_version: 2.6.13
130
+ rubygems_version: 3.0.6
104
131
  signing_key:
105
132
  specification_version: 4
106
133
  summary: Reads the `fluentd` `msgpack` schema