logstash-codec-fluent 3.1.4-java → 3.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +13 -0
- data/LICENSE +199 -10
- data/README.md +1 -1
- data/docs/index.asciidoc +43 -3
- data/lib/logstash/codecs/fluent.rb +73 -32
- data/lib/logstash/codecs/fluent/event_time.rb +28 -0
- data/logstash-codec-fluent.gemspec +4 -2
- data/spec/codecs/fluent_spec.rb +149 -25
- metadata +39 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: e17d4af78cd9df1b4534f747813c106d9c1c4e3072a2f74989bfd78413e3173c
|
4
|
+
data.tar.gz: 4c77861536c3a5ea3c4e8eef9d97bdc0c986a42991261b9143a80bfa7ede0254
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8e876b1ee27ca9f647baff747432261a10a41d1217bc228f458d7c45641a93d70a6765eb312a1e141e05f6413a8866f4dee731bf215d7c5f8466583e7e2f7888
|
7
|
+
data.tar.gz: ffcfe5a551b868a02eb53ebefece63e97bd57c70f31a1b925d4a8e80093c92186fbfe1eeee061d1def481930f244b97f3061cc750a8880fb807f804c164982e1
|
data/CHANGELOG.md
CHANGED
@@ -1,3 +1,16 @@
|
|
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
|
+
|
5
|
+
## 3.3.0
|
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)
|
7
|
+
|
8
|
+
## 3.2.0
|
9
|
+
- Encode tags as fluent forward protocol tags. Ref: https://github.com/logstash-plugins/logstash-codec-fluent/pull/21
|
10
|
+
|
11
|
+
## 3.1.5
|
12
|
+
- Update gemspec summary
|
13
|
+
|
1
14
|
## 3.1.4
|
2
15
|
- Constrain msgpack dependency to ~> 1.1 due to old versions not containing some format and type definitions
|
3
16
|
## 3.1.3
|
data/LICENSE
CHANGED
@@ -1,13 +1,202 @@
|
|
1
|
-
Copyright (c) 2012–2016 Elasticsearch <http://www.elastic.co>
|
2
1
|
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
Apache License
|
3
|
+
Version 2.0, January 2004
|
4
|
+
http://www.apache.org/licenses/
|
6
5
|
|
7
|
-
|
6
|
+
TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
|
8
7
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
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.
|
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
|
-
|
42
|
-
|
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
|
+
|
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,16 +1,21 @@
|
|
1
1
|
# encoding: utf-8
|
2
2
|
require "logstash/codecs/base"
|
3
|
-
require "logstash/
|
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:
|
10
13
|
# [source,ruby]
|
11
14
|
# input {
|
12
15
|
# tcp {
|
13
|
-
# codec => fluent
|
16
|
+
# codec => fluent {
|
17
|
+
# nanosecond_precision => true
|
18
|
+
# }
|
14
19
|
# port => 4000
|
15
20
|
# }
|
16
21
|
# }
|
@@ -22,15 +27,33 @@ require "logstash/util"
|
|
22
27
|
#
|
23
28
|
# Notes:
|
24
29
|
#
|
25
|
-
# *
|
26
|
-
# subsecond precision on events processed by this codec.
|
30
|
+
# * to handle EventTime msgpack extension, you must specify nanosecond_precision parameter as true.
|
27
31
|
#
|
28
32
|
class LogStash::Codecs::Fluent < LogStash::Codecs::Base
|
33
|
+
require "logstash/codecs/fluent/event_time"
|
34
|
+
|
35
|
+
extend LogStash::PluginMixins::ValidatorSupport::FieldReferenceValidationAdapter
|
36
|
+
|
37
|
+
include LogStash::PluginMixins::EventSupport::EventFactoryAdapter
|
38
|
+
|
29
39
|
config_name "fluent"
|
30
40
|
|
41
|
+
config :nanosecond_precision, :validate => :boolean, :default => false
|
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
|
+
|
31
49
|
def register
|
32
50
|
require "msgpack"
|
33
|
-
@
|
51
|
+
@factory = MessagePack::Factory.new
|
52
|
+
if @nanosecond_precision
|
53
|
+
@factory.register_type(EventTime::TYPE, EventTime)
|
54
|
+
end
|
55
|
+
@packer = @factory.packer
|
56
|
+
@decoder = @factory.unpacker
|
34
57
|
end
|
35
58
|
|
36
59
|
def decode(data, &block)
|
@@ -40,19 +63,47 @@ class LogStash::Codecs::Fluent < LogStash::Codecs::Base
|
|
40
63
|
end # def decode
|
41
64
|
|
42
65
|
def encode(event)
|
43
|
-
tag
|
44
|
-
|
66
|
+
# Ensure tag to "tag1.tag2.tag3" style string.
|
67
|
+
# Fluentd cannot handle Array class value in forward protocol's tag.
|
68
|
+
tag = forwardable_tag(event)
|
69
|
+
epochtime = if @nanosecond_precision
|
70
|
+
EventTime.new(event.timestamp.to_i, event.timestamp.usec * 1000)
|
71
|
+
else
|
72
|
+
event.timestamp.to_i
|
73
|
+
end
|
45
74
|
|
46
75
|
# use normalize to make sure returned Hash is pure Ruby for
|
47
76
|
# MessagePack#pack which relies on pure Ruby object recognition
|
48
77
|
data = LogStash::Util.normalize(event.to_hash)
|
49
78
|
# timestamp is serialized as a iso8601 string
|
50
79
|
# merge to avoid modifying data which could have side effects if multiple outputs
|
51
|
-
@
|
80
|
+
@packer.clear
|
81
|
+
@on_event.call(event, @packer.pack([tag, epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)]))
|
52
82
|
end # def encode
|
53
83
|
|
84
|
+
def forwardable_tag(event)
|
85
|
+
tag = event.get("tags") || "log"
|
86
|
+
case tag
|
87
|
+
when Array
|
88
|
+
tag.join('.')
|
89
|
+
when String
|
90
|
+
tag
|
91
|
+
else
|
92
|
+
tag.to_s
|
93
|
+
end
|
94
|
+
end
|
95
|
+
|
54
96
|
private
|
55
97
|
|
98
|
+
def decode_fluent_time(fluent_time)
|
99
|
+
case fluent_time
|
100
|
+
when Integer
|
101
|
+
fluent_time
|
102
|
+
when EventTime
|
103
|
+
Time.at(fluent_time.sec, fluent_time.nsec / 1000.0)
|
104
|
+
end
|
105
|
+
end
|
106
|
+
|
56
107
|
def decode_event(data, &block)
|
57
108
|
tag = data[0]
|
58
109
|
entries = data[1]
|
@@ -66,42 +117,32 @@ class LogStash::Codecs::Fluent < LogStash::Codecs::Base
|
|
66
117
|
raise(LogStash::Error, "PackedForward with compression is not supported")
|
67
118
|
end
|
68
119
|
|
69
|
-
entries_decoder =
|
120
|
+
entries_decoder = @decoder
|
70
121
|
entries_decoder.feed_each(entries) do |entry|
|
71
|
-
|
72
|
-
map = entry[1]
|
73
|
-
event = LogStash::Event.new(map.merge(
|
74
|
-
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
|
75
|
-
"tags" => [ tag ]
|
76
|
-
))
|
77
|
-
yield event
|
122
|
+
yield generate_event(entry[1], entry[0], tag)
|
78
123
|
end
|
79
124
|
when Array
|
80
125
|
# Forward
|
81
126
|
entries.each do |entry|
|
82
|
-
|
83
|
-
map = entry[1]
|
84
|
-
event = LogStash::Event.new(map.merge(
|
85
|
-
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
|
86
|
-
"tags" => [ tag ]
|
87
|
-
))
|
88
|
-
yield event
|
127
|
+
yield generate_event(entry[1], entry[0], tag)
|
89
128
|
end
|
90
|
-
when
|
129
|
+
when Integer, EventTime
|
91
130
|
# Message
|
92
|
-
|
93
|
-
map = data[2]
|
94
|
-
event = LogStash::Event.new(map.merge(
|
95
|
-
LogStash::Event::TIMESTAMP => LogStash::Timestamp.at(epochtime),
|
96
|
-
"tags" => [ tag ]
|
97
|
-
))
|
98
|
-
yield event
|
131
|
+
yield generate_event(data[2], entries, tag)
|
99
132
|
else
|
100
133
|
raise(LogStash::Error, "Unknown event type")
|
101
134
|
end
|
102
135
|
rescue StandardError => e
|
103
136
|
@logger.error("Fluent parse error, original data now in message field", :error => e, :data => data)
|
104
|
-
yield
|
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
|
105
146
|
end
|
106
147
|
|
107
148
|
end # class LogStash::Codecs::Fluent
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module LogStash; module Codecs; class Fluent;
|
2
|
+
class EventTime
|
3
|
+
attr_reader :sec, :nsec
|
4
|
+
|
5
|
+
TYPE = 0
|
6
|
+
|
7
|
+
def initialize(sec, nsec = 0)
|
8
|
+
@sec = sec
|
9
|
+
@nsec = nsec
|
10
|
+
end
|
11
|
+
|
12
|
+
def to_msgpack(io = nil)
|
13
|
+
@sec.to_msgpack(io)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_msgpack_ext
|
17
|
+
[@sec, @nsec].pack('NN')
|
18
|
+
end
|
19
|
+
|
20
|
+
def self.from_msgpack_ext(data)
|
21
|
+
new(*data.unpack('NN'))
|
22
|
+
end
|
23
|
+
|
24
|
+
def to_json(*args)
|
25
|
+
@sec
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end; end; end
|
@@ -1,9 +1,9 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
|
3
3
|
s.name = 'logstash-codec-fluent'
|
4
|
-
s.version = '3.
|
4
|
+
s.version = '3.4.0'
|
5
5
|
s.licenses = ['Apache License (2.0)']
|
6
|
-
s.summary = "
|
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"
|
8
8
|
s.authors = ["Elastic"]
|
9
9
|
s.email = 'info@elastic.co'
|
@@ -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
|
|
data/spec/codecs/fluent_spec.rb
CHANGED
@@ -2,11 +2,31 @@
|
|
2
2
|
require_relative "../spec_helper"
|
3
3
|
require "logstash/plugin"
|
4
4
|
require "logstash/event"
|
5
|
+
require "msgpack"
|
5
6
|
|
6
7
|
describe LogStash::Codecs::Fluent do
|
8
|
+
before do
|
9
|
+
@factory = MessagePack::Factory.new
|
10
|
+
@factory.register_type(LogStash::Codecs::Fluent::EventTime::TYPE,
|
11
|
+
LogStash::Codecs::Fluent::EventTime)
|
12
|
+
@packer = @factory.packer
|
13
|
+
@unpacker = @factory.unpacker
|
14
|
+
end
|
15
|
+
|
16
|
+
subject { LogStash::Codecs::Fluent.new(config) }
|
17
|
+
|
18
|
+
let(:config) { Hash.new }
|
7
19
|
|
8
20
|
let(:properties) { {:name => "foo" } }
|
9
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
|
10
30
|
|
11
31
|
it "should register without errors" do
|
12
32
|
plugin = LogStash::Plugin.lookup("codec", "fluent").new
|
@@ -17,9 +37,26 @@ describe LogStash::Codecs::Fluent do
|
|
17
37
|
|
18
38
|
it "should encode as message pack format" do
|
19
39
|
subject.on_event do |event, data|
|
20
|
-
|
21
|
-
|
22
|
-
|
40
|
+
@unpacker.feed_each(data) do |fields|
|
41
|
+
expect(fields[0]).to eq("log")
|
42
|
+
expect(fields[2]["name"]).to eq("foo")
|
43
|
+
end
|
44
|
+
end
|
45
|
+
subject.encode(event)
|
46
|
+
end
|
47
|
+
|
48
|
+
end
|
49
|
+
|
50
|
+
describe "event encoding with EventTime" do
|
51
|
+
|
52
|
+
let(:config) { super().merge "nanosecond_precision" => true }
|
53
|
+
|
54
|
+
it "should encode as message pack format" do
|
55
|
+
subject.on_event do |event, data|
|
56
|
+
@unpacker.feed_each(data) do |fields|
|
57
|
+
expect(fields[0]).to eq("log")
|
58
|
+
expect(fields[2]["name"]).to eq("foo")
|
59
|
+
end
|
23
60
|
end
|
24
61
|
subject.encode(event)
|
25
62
|
end
|
@@ -28,16 +65,112 @@ describe LogStash::Codecs::Fluent do
|
|
28
65
|
|
29
66
|
describe "event decoding" do
|
30
67
|
|
31
|
-
let(:tag) { "mytag" }
|
32
|
-
let(:epochtime) { event.timestamp.to_i }
|
33
|
-
let(:data) { LogStash::Util.normalize(event.to_hash) }
|
34
68
|
let(:message) do
|
35
|
-
|
69
|
+
@packer.pack([tag, epochtime, data.merge(LogStash::Event::TIMESTAMP => timestamp.to_iso8601)])
|
36
70
|
end
|
37
71
|
|
38
72
|
it "should decode without errors" do
|
73
|
+
decoded = false
|
39
74
|
subject.decode(message) do |event|
|
40
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 ]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
describe "event decoding with EventTime" do
|
90
|
+
|
91
|
+
let(:epochtime) { LogStash::Codecs::Fluent::EventTime.new(timestamp.to_i, (timestamp.usec * 1000) + 123) }
|
92
|
+
|
93
|
+
subject { LogStash::Plugin.lookup("codec", "fluent").new({"nanosecond_precision" => true}) }
|
94
|
+
|
95
|
+
it "should decode without errors" do
|
96
|
+
decoded = false
|
97
|
+
subject.decode(message) do |event|
|
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)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
|
143
|
+
end
|
144
|
+
|
145
|
+
describe "forward protocol tag" do
|
146
|
+
|
147
|
+
describe "when passing Array value" do
|
148
|
+
let(:properties) { {:tags => ["test", "logstash"], :name => "foo" } }
|
149
|
+
|
150
|
+
it "should be joined with '.'" do
|
151
|
+
subject.forwardable_tag(event) do |tag|
|
152
|
+
expect(tag).to eq("test.logstash")
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
156
|
+
|
157
|
+
describe "when passing String value" do
|
158
|
+
let(:properties) { {:tags => "test.logstash", :name => "foo" } }
|
159
|
+
|
160
|
+
it "should be pass-through" do
|
161
|
+
subject.forwardable_tag(event) do |tag|
|
162
|
+
expect(tag).to eq("test.logstash")
|
163
|
+
end
|
164
|
+
end
|
165
|
+
end
|
166
|
+
|
167
|
+
describe "when passing other value" do
|
168
|
+
let(:properties) { {:tags => :symbol, :name => "foo" } }
|
169
|
+
|
170
|
+
it "should be called to_s" do
|
171
|
+
subject.forwardable_tag(event) do |tag|
|
172
|
+
expect(tag).to eq("symbol")
|
173
|
+
end
|
41
174
|
end
|
42
175
|
end
|
43
176
|
|
@@ -45,17 +178,15 @@ describe LogStash::Codecs::Fluent do
|
|
45
178
|
|
46
179
|
describe "event decoding (buckets of events)" do
|
47
180
|
|
48
|
-
let(:
|
49
|
-
let(:epochtime) { event.timestamp.to_i }
|
50
|
-
let(:data) { LogStash::Util.normalize(event.to_hash) }
|
181
|
+
let(:data) { LogStash::Util.normalize(event.to_hash) }
|
51
182
|
let(:message) do
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
183
|
+
@packer.pack([tag,
|
184
|
+
[
|
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)]
|
188
|
+
]
|
189
|
+
])
|
59
190
|
end
|
60
191
|
|
61
192
|
it "should decode without errors" do
|
@@ -73,14 +204,7 @@ describe LogStash::Codecs::Fluent do
|
|
73
204
|
|
74
205
|
describe "event decoding (broken package)" do
|
75
206
|
|
76
|
-
let(:
|
77
|
-
let(:epochtime) { event.timestamp.to_s }
|
78
|
-
let(:data) { LogStash::Util.normalize(event.to_hash) }
|
79
|
-
let(:message) do
|
80
|
-
MessagePack.pack([tag,
|
81
|
-
epochtime, data.merge(LogStash::Event::TIMESTAMP => event.timestamp.to_iso8601)
|
82
|
-
])
|
83
|
-
end
|
207
|
+
let(:epochtime) { timestamp.to_s }
|
84
208
|
|
85
209
|
it "should decode with errors" do
|
86
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.
|
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:
|
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,14 +79,16 @@ 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
|
- - ">="
|
59
87
|
- !ruby/object:Gem::Version
|
60
88
|
version: 1.0.0
|
61
|
-
description: This gem is a Logstash plugin required to be installed on top of the
|
89
|
+
description: This gem is a Logstash plugin required to be installed on top of the
|
90
|
+
Logstash core pipeline using $LS_HOME/bin/logstash-plugin install gemname. This
|
91
|
+
gem is not a stand-alone program
|
62
92
|
email: info@elastic.co
|
63
93
|
executables: []
|
64
94
|
extensions: []
|
@@ -72,6 +102,7 @@ files:
|
|
72
102
|
- README.md
|
73
103
|
- docs/index.asciidoc
|
74
104
|
- lib/logstash/codecs/fluent.rb
|
105
|
+
- lib/logstash/codecs/fluent/event_time.rb
|
75
106
|
- logstash-codec-fluent.gemspec
|
76
107
|
- spec/codecs/fluent_spec.rb
|
77
108
|
- spec/spec_helper.rb
|
@@ -96,11 +127,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
127
|
- !ruby/object:Gem::Version
|
97
128
|
version: '0'
|
98
129
|
requirements: []
|
99
|
-
|
100
|
-
rubygems_version: 2.4.8
|
130
|
+
rubygems_version: 3.0.6
|
101
131
|
signing_key:
|
102
132
|
specification_version: 4
|
103
|
-
summary:
|
133
|
+
summary: Reads the `fluentd` `msgpack` schema
|
104
134
|
test_files:
|
105
135
|
- spec/codecs/fluent_spec.rb
|
106
136
|
- spec/spec_helper.rb
|