fluent-plugin-systemd 1.0.0.rc3 → 1.0.4

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: d36c2726704e80195922ab5a2e7cb0f89825f27e
4
- data.tar.gz: 93d387a176097b858761bbeb5a0f01682ed30b0b
2
+ SHA256:
3
+ metadata.gz: 194ee210390aeeb11282e5d7691bb4694d1978fd760abc8eb1ef078864ecc362
4
+ data.tar.gz: 8ccbbcff3e50c691a36f6fdaf66122882af8daa0201ff137218aa28018e31f84
5
5
  SHA512:
6
- metadata.gz: 495c1d1fe28618d1e131a1c540c0143bb4935e80f5f86393bd5504a38fbb04c353bb859e59f6c19773e69d54165094f4a8db2f9d0be20d49565fb83ee836d06c
7
- data.tar.gz: de2ac2e4860d441bbd8bc9e3bdaae98cc97aa456b83fc051b7706c8885ef6e56c90b8f0b3905e46156592d346728d6fd89493a02577ec467f011495b082bcb1c
6
+ metadata.gz: 39823bce21570d0b8721e7427589a6b85f811f70d79e9a61b959e6408fff607d73786e1e2d431f912d79892fcf41c892cb4dd6d67ba2a26f9b923f747d2beb05
7
+ data.tar.gz: 12355bccdcec5a37420a50f81e295c3778b233ecba77748bf88fcbe4c9d042d519550a26f9143ad98401ff541c1810bceefe0b5ee41f9e196f2c42323e1662d6
data/README.md CHANGED
@@ -1,19 +1,16 @@
1
1
  # systemd plugin for [Fluentd](http://github.com/fluent/fluentd)
2
2
 
3
- [![Build Status](https://travis-ci.org/reevoo/fluent-plugin-systemd.svg?branch=master)](https://travis-ci.org/reevoo/fluent-plugin-systemd) [![Code Climate GPA](https://codeclimate.com/github/reevoo/fluent-plugin-systemd/badges/gpa.svg)](https://codeclimate.com/github/reevoo/fluent-plugin-systemd) [![Gem Version](https://badge.fury.io/rb/fluent-plugin-systemd.svg)](https://rubygems.org/gems/fluent-plugin-systemd)
3
+ [![Build Status](https://github.com/fluent-plugin-systemd/fluent-plugin-systemd/actions/workflows/ci.yml/badge.svg)](https://github.com/fluent-plugin-systemd/fluent-plugin-systemd/actions/workflows/ci.yml) [![Maintainability](https://api.codeclimate.com/v1/badges/5c773a4c1c6a6964fa4b/maintainability)](https://codeclimate.com/github/fluent-plugin-systemd/fluent-plugin-systemd/maintainability) [![Gem Version](https://badge.fury.io/rb/fluent-plugin-systemd.svg)](https://rubygems.org/gems/fluent-plugin-systemd)
4
4
 
5
5
  ## Overview
6
6
 
7
- **systemd** input plugin reads logs from the systemd journal
8
- **systemd** filter plugin allows for basic manipulation of systemd journal entries
7
+ * **systemd** input plugin to read logs from the systemd journal
8
+ * **systemd** filter plugin for basic manipulation of systemd journal entries
9
9
 
10
10
  ## Support
11
11
 
12
- [![Fluentd Slack](http://slack.fluentd.org/badge.svg)](http://slack.fluentd.org/)
13
-
14
12
  Join the #plugin-systemd channel on the [Fluentd Slack](http://slack.fluentd.org/)
15
13
 
16
-
17
14
  ## Requirements
18
15
 
19
16
  |fluent-plugin-systemd|fluentd|td-agent|ruby|
@@ -21,51 +18,58 @@ Join the #plugin-systemd channel on the [Fluentd Slack](http://slack.fluentd.org
21
18
  | > 0.1.0 | >= 0.14.11, < 2 | 3 | >= 2.1 |
22
19
  | 0.0.x | ~> 0.12.0 | 2 | >= 1.9 |
23
20
 
24
- * The 0.x.x series is developed from this branch (master)
25
- * The 0.0.x series (compatible with fluentd v0.12, and td-agent 2) is developed on the [0.0.x branch](https://github.com/reevoo/fluent-plugin-systemd/tree/0.0.x)
26
- * The next version is currently under development on the [1.0.0 branch](https://github.com/reevoo/fluent-plugin-systemd/tree/1.0.0) it's progress is tracked [here](https://github.com/reevoo/fluent-plugin-systemd/issues/53)
21
+ * The 1.x.x series is developed from this branch (master)
22
+ * The 0.0.x series (compatible with fluentd v0.12, and td-agent 2) is maintained on the [0.0.x branch](https://github.com/reevoo/fluent-plugin-systemd/tree/0.0.x)
27
23
 
28
24
  ## Installation
29
25
 
30
26
  Simply use RubyGems:
31
27
 
32
- gem install fluent-plugin-systemd -v 0.3.1
28
+ gem install fluent-plugin-systemd -v 1.0.3
33
29
 
34
30
  or
35
31
 
36
- td-agent-gem install fluent-plugin-systemd -v 0.3.1
32
+ td-agent-gem install fluent-plugin-systemd -v 1.0.3
33
+
34
+ ## Upgrading
35
+
36
+ If you are upgrading to version 1.0 from a previous version of this plugin take a look at the [upgrade documentation](docs/upgrading.md). A number of deprecated config options were removed so you might need to update your configuration.
37
37
 
38
38
  ## Input Plugin Configuration
39
39
 
40
40
  <source>
41
41
  @type systemd
42
- tag kube-proxy
42
+ tag kubelet
43
43
  path /var/log/journal
44
- matches [{ "_SYSTEMD_UNIT": "kube-proxy.service" }]
44
+ matches [{ "_SYSTEMD_UNIT": "kubelet.service" }]
45
45
  read_from_head true
46
+
46
47
  <storage>
47
48
  @type local
48
- persistent false
49
- path kube-proxy.pos
49
+ path /var/log/fluentd-journald-kubelet-cursor.json
50
50
  </storage>
51
+
51
52
  <entry>
52
- field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
53
53
  fields_strip_underscores true
54
54
  fields_lowercase true
55
55
  </entry>
56
56
  </source>
57
57
 
58
- <match kube-proxy>
58
+ <match kubelet>
59
59
  @type stdout
60
60
  </match>
61
61
 
62
+ <system>
63
+ root_dir /var/log/fluentd
64
+ </system>
65
+
62
66
  **`path`**
63
67
 
64
68
  Path to the systemd journal, defaults to `/var/log/journal`
65
69
 
66
70
  **`filters`**
67
71
 
68
- _This parameter name is deprecated and should be renamed to `matches`_
72
+ _This parameter name is depreciated and should be renamed to `matches`_
69
73
 
70
74
  **`matches`**
71
75
 
@@ -73,40 +77,21 @@ Expects an array of hashes defining desired matches to filter the log
73
77
  messages with. When this property is not specified, this plugin will default to
74
78
  reading all logs from the journal.
75
79
 
76
- See [matching details](docs/Matching-Details.md) for a more exhaustive
80
+ See [matching details](docs/matching.md) for a more exhaustive
77
81
  description of this property and how to use it.
78
82
 
79
- **`pos_file`**
80
-
81
- _This parameter is deprecated and will be removed in favour of storage in v1.0._
82
-
83
-
84
- Path to pos file, stores the journald cursor. File is created if does not exist.
85
-
86
83
  **`storage`**
87
84
 
88
- Configuration for a [storage plugin](http://docs.fluentd.org/v0.14/articles/storage-plugin-overview) used to store the journald cursor.
89
-
90
- _Upgrading from `pos_file`_
91
-
92
- If `pos_file` is specified in addition to a storage plugin with persistent set to true, the cursor will be
93
- copied from the `pos_file` on startup, and the old `pos_file` removed.
85
+ Configuration for a [storage plugin](https://docs.fluentd.org/storage) used to store the journald cursor.
94
86
 
95
87
  **`read_from_head`**
96
88
 
97
89
  If true reads all available journal from head, otherwise starts reading from tail,
98
- ignored if pos file exists (and is valid). Defaults to false.
99
-
100
- **`strip_underscores`**
101
-
102
- _This parameter is deprecated and will be removed in favour of entry in v1.0._
103
-
104
- If true strips underscores from the beginning of systemd field names.
105
- May be useful if outputting to kibana, as underscore prefixed fields are unindexed there.
90
+ ignored if cursor exists in storage (and is valid). Defaults to false.
106
91
 
107
92
  **`entry`**
108
93
 
109
- Optional configuration for an embeded systemd entry filter. See the [Filter Plugin Configuration](#filter-plugin-configuration) for config reference.
94
+ Optional configuration for an embedded systemd entry filter. See the [Filter Plugin Configuration](#filter-plugin-configuration) for config reference.
110
95
 
111
96
  **`tag`**
112
97
 
@@ -114,19 +99,20 @@ _Required_
114
99
 
115
100
  A tag that will be added to events generated by this input.
116
101
 
117
- ### Example
118
-
119
- For an example of a full working setup including the plugin, [take a look at](https://github.com/assemblyline/fluentd)
120
102
 
121
103
  ## Filter Plugin Configuration
122
104
 
123
- <filter kube-proxy>
124
- @type systemd_entry
125
- field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
126
- field_map_strict false
127
- fields_lowercase true
128
- fields_strip_underscores true
129
- </filter>
105
+ ```
106
+ <filter kube-proxy>
107
+ @type systemd_entry
108
+ field_map {"MESSAGE": "log", "_PID": ["process", "pid"], "_CMDLINE": "process", "_COMM": "cmd"}
109
+ field_map_strict false
110
+ fields_lowercase true
111
+ fields_strip_underscores true
112
+ </filter>
113
+ ```
114
+
115
+ _Note that the following configurations can be embedded in a systemd source block, within an entry block, you only need to use a filter directly for more complicated workflows._
130
116
 
131
117
  **`field_map`**
132
118
 
@@ -151,7 +137,7 @@ If true, lowercase all non-mapped fields. Defaults to false.
151
137
 
152
138
  If true, strip leading underscores from all non-mapped fields. Defaults to false.
153
139
 
154
- ### Example
140
+ ### Filter Example
155
141
 
156
142
  Given a systemd journal source entry:
157
143
  ```
@@ -178,26 +164,73 @@ The resulting entry using the above sample configuration:
178
164
 
179
165
  ## Common Issues
180
166
 
181
- > ### When I look at fluentd logs, everything looks fine but no journal logs are read
167
+ > ### When I look at fluentd logs, everything looks fine but no journal logs are read ?
182
168
 
183
- This is commonly caused when the user running fluentd does not have enough permisions
169
+ This is commonly caused when the user running fluentd does not have the correct permissions
184
170
  to read the systemd journal.
185
171
 
186
- Acording to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html):
172
+ According to the [systemd documentation](https://www.freedesktop.org/software/systemd/man/systemd-journald.service.html):
187
173
  > Journal files are, by default, owned and readable by the "systemd-journal" system group but are not writable. Adding a user to this group thus enables her/him to read the journal files.
188
174
 
175
+ > ### How can I deal with multi-line logs ?
176
+
177
+ Ideally you want to ensure that your logs are saved to the systemd journal as a single entry regardless of how many lines they span.
178
+
179
+ It is possible for applications to naively support this (but only if they have tight integration with systemd it seems) see: https://github.com/systemd/systemd/issues/5188.
180
+
181
+ Typically you would not be able to this, so another way is to configure your logger to replace newline characters with something else. See this blog post for an example configuring a Java logging library to do this https://fabianlee.org/2018/03/09/java-collapsing-multiline-stack-traces-into-a-single-log-event-using-spring-backed-by-logback-or-log4j2/
182
+
183
+ Another strategy would be to use a plugin like [fluent-plugin-concat](https://github.com/fluent-plugins-nursery/fluent-plugin-concat) to combine multi line logs into a single event, this is more tricky though because you need to be able to identify the first and last lines of a multi line message with a regex.
184
+
185
+ > ### How can I use this plugin inside of a docker container ?
186
+
187
+ * Install the [systemd dependencies](#dependencies) if required
188
+ * You can use an [offical fluentd docker](https://github.com/fluent/fluentd-docker-image) image as a base, (choose the debian based version, as alpine linux doesn't support systemd).
189
+ * Bind mount `/var/log/journal` into your container.
190
+
191
+ > ### I am seeing lots of logs being generated very rapidly!
192
+
193
+ This commonly occurs when a loop is created when fluentd is logging to STDOUT, and the collected logs are then written to the systemd journal. This could happen if you run fluentd as a systemd serivce, or as a docker container with the systemd log driver.
194
+
195
+ Workarounds include:
196
+
197
+ * Use another fluentd output
198
+ * Don't read every message from the journal, set some `matches` so you only read the messages you are interested in.
199
+ * Disable the systemd log driver when you launch your fluentd docker container, e.g. by passing `--log-driver json-file`
200
+
201
+ ### Example
202
+
203
+ For an example of a full working setup including the plugin, take a look at [the fluentd kubernetes daemonset](https://github.com/fluent/fluentd-kubernetes-daemonset)
189
204
 
190
205
  ## Dependencies
191
206
 
192
207
  This plugin depends on libsystemd
193
208
 
209
+ On Debian or Ubuntu you might need to install the libsystemd0 package:
210
+
211
+ ```
212
+ apt-get install libsystemd0
213
+ ```
214
+
215
+ On CentOS or RHEL you might need to install the systemd package:
216
+
217
+ ```
218
+ yum install -y systemd
219
+ ```
220
+
221
+ If you want to do this in a CentOS docker image you might first need to remove the `fakesystemd` package.
222
+
223
+ ```
224
+ yum remove -y fakesystemd
225
+ ```
226
+
194
227
  ## Running the tests
195
228
 
196
229
  To run the tests with docker on several distros simply run `rake`
197
230
 
198
231
  For systems with systemd installed you can run the tests against your installed libsystemd with `rake test`
199
232
 
200
- ## Licence
233
+ ## License
201
234
 
202
235
  [Apache-2.0](LICENCE)
203
236
 
@@ -217,14 +250,16 @@ We have adopted the [Contributor Covenant](CODE_OF_CONDUCT.md) and thus expect a
217
250
 
218
251
  Many thanks to our fantastic contributors
219
252
 
220
- * [Hiroshi Hatake](https://github.com/cosmo0920)
221
253
  * [Erik Maciejewski](https://github.com/emacski)
222
- * [Masahiro Nakagawa](https://github.com/repeatedly)
223
- * [Richard Megginson](https://github.com/richm)
224
- * [Mike Kaplinskiy](https://github.com/mikekap)
225
- * [neko-neko](https://github.com/neko-neko)
226
- * [Sadayuki Furuhashi](https://github.com/frsyuki)
254
+ * [Ernie Hershey](https://github.com/ehershey)
255
+ * [Hiroshi Hatake](https://github.com/cosmo0920)
227
256
  * [Jesus Rafael Carrillo](https://github.com/jescarri)
257
+ * [Joel Gerber](https://github.com/Jitsusama)
228
258
  * [John Thomas Wile II](https://github.com/jtwile2)
229
259
  * [Kazuhiro Suzuki](https://github.com/ksauzz)
230
- * [Joel Gerber](https://github.com/Jitsusama)
260
+ * [Marius Grigoriu](https://github.com/mariusgrigoriu)
261
+ * [Masahiro Nakagawa](https://github.com/repeatedly)
262
+ * [Mike Kaplinskiy](https://github.com/mikekap)
263
+ * [Richard Megginson](https://github.com/richm)
264
+ * [Sadayuki Furuhashi](https://github.com/frsyuki)
265
+ * [Seiichi Nishikata](https://github.com/neko-neko)
@@ -57,18 +57,21 @@ module Fluent
57
57
 
58
58
  def start
59
59
  super
60
+ @running = true
60
61
  timer_execute(:in_systemd_emit_worker, 1, &method(:run))
61
62
  end
62
63
 
64
+ def shutdown
65
+ @running = false
66
+ super
67
+ end
68
+
63
69
  private
64
70
 
65
71
  def init_journal
66
72
  # TODO: ruby 2.3
67
73
  @journal.close if @journal # rubocop:disable Style/SafeNavigation
68
74
  @journal = Systemd::Journal.new(path: @path)
69
- # make sure initial call to wait doesn't return :invalidate
70
- # see https://github.com/ledbettj/systemd-journal/issues/70
71
- @journal.wait(0)
72
75
  @journal.filter(*(@matches || @filters))
73
76
  seek
74
77
  true
@@ -95,6 +98,7 @@ module Fluent
95
98
  def seek_to(pos)
96
99
  @journal.seek(pos)
97
100
  return if pos == :head
101
+
98
102
  if pos == :tail
99
103
  @journal.move(-2)
100
104
  else
@@ -108,6 +112,7 @@ module Fluent
108
112
 
109
113
  def run
110
114
  return unless @journal || init_journal
115
+
111
116
  init_journal if @journal.wait(0) == :invalidate
112
117
  watch do |entry|
113
118
  emit(entry)
@@ -119,6 +124,7 @@ module Fluent
119
124
  rescue Fluent::Plugin::Buffer::BufferOverflowError => e
120
125
  retries ||= 0
121
126
  raise e if retries > 10
127
+
122
128
  retries += 1
123
129
  sleep 1.5**retries + rand(0..3)
124
130
  retry
@@ -131,7 +137,9 @@ module Fluent
131
137
  end
132
138
 
133
139
  def watch(&block)
134
- yield_current_entry(&block) while @journal.move_next
140
+ yield_current_entry(&block) while @running && @journal.move_next
141
+ rescue Systemd::JournalError => e
142
+ log.warn("Error moving to next Journal entry: #{e.class}: #{e.message}")
135
143
  end
136
144
 
137
145
  def yield_current_entry
@@ -67,6 +67,7 @@ module Fluent
67
67
  # Expose config state as read-only instance properties of the mutator.
68
68
  def method_missing(sym, *args)
69
69
  return @opts[sym] if @opts.members.include?(sym)
70
+
70
71
  super
71
72
  end
72
73
 
@@ -80,6 +81,7 @@ module Fluent
80
81
  def run(entry)
81
82
  return entry.to_h if @no_transform
82
83
  return map_fields(entry) if @opts.field_map_strict
84
+
83
85
  format_fields(entry, map_fields(entry))
84
86
  end
85
87
 
@@ -90,6 +92,7 @@ module Fluent
90
92
  @map.each_with_object({}) do |(cstm, sysds), mapped|
91
93
  vals = sysds.collect { |fld| entry[fld] }.compact
92
94
  next if vals.empty? # systemd field does not exist in source entry
95
+
93
96
  mapped[cstm] = join_if_needed(vals)
94
97
  end
95
98
  end
@@ -103,6 +106,7 @@ module Fluent
103
106
  entry.each_with_object(mapped || {}) do |(fld, val), formatted_entry|
104
107
  # don't mess with explicitly mapped fields
105
108
  next if @map_src_fields.include?(fld)
109
+
106
110
  fld = format_field_name(fld)
107
111
  # account for mapping (appending) to an existing systemd field
108
112
  formatted_entry[fld] = join_if_needed([val, mapped[fld]])
@@ -111,6 +115,7 @@ module Fluent
111
115
 
112
116
  def warnings
113
117
  return [] unless field_map_strict && field_map.empty?
118
+
114
119
  '`field_map_strict` set to true with empty `field_map`, expect no fields'
115
120
  end
116
121
 
@@ -119,6 +124,7 @@ module Fluent
119
124
  def join_if_needed(values)
120
125
  values.compact!
121
126
  return values.first if values.length == 1
127
+
122
128
  values.join(' ')
123
129
  end
124
130
 
@@ -146,7 +152,7 @@ module Fluent
146
152
  end
147
153
  end
148
154
 
149
- def validate_all_strings(arr, message, allow_nesting = false)
155
+ def validate_all_strings(arr, message, allow_nesting = false) # rubocop:disable Style/OptionalBooleanParameter
150
156
  valid = arr.all? do |value|
151
157
  value.is_a?(String) || allow_nesting && value.is_a?(Array) && value.all? { |key| key.is_a?(String) }
152
158
  end
metadata CHANGED
@@ -1,27 +1,27 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-systemd
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.rc3
4
+ version: 1.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ed Robinson
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-05-03 00:00:00.000000000 Z
11
+ date: 2021-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.10'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ">"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.10'
27
27
  - !ruby/object:Gem::Dependency
@@ -44,28 +44,28 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '2.5'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '2.5'
54
+ version: '3.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: rubocop
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - "~>"
59
+ - - '='
60
60
  - !ruby/object:Gem::Version
61
- version: 0.53.0
61
+ version: 1.13.0
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - "~>"
66
+ - - '='
67
67
  - !ruby/object:Gem::Version
68
- version: 0.53.0
68
+ version: 1.13.0
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: fluentd
71
71
  requirement: !ruby/object:Gem::Requirement
@@ -92,14 +92,14 @@ dependencies:
92
92
  requirements:
93
93
  - - "~>"
94
94
  - !ruby/object:Gem::Version
95
- version: '1.3'
95
+ version: 1.4.2
96
96
  type: :runtime
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
100
  - - "~>"
101
101
  - !ruby/object:Gem::Version
102
- version: '1.3'
102
+ version: 1.4.2
103
103
  description: This is a fluentd input plugin. It reads logs from the systemd journal.
104
104
  email:
105
105
  - edward-robinson@cookpad.com
@@ -116,7 +116,7 @@ homepage: https://github.com/reevoo/fluent-plugin-systemd
116
116
  licenses:
117
117
  - Apache-2.0
118
118
  metadata: {}
119
- post_install_message:
119
+ post_install_message:
120
120
  rdoc_options: []
121
121
  require_paths:
122
122
  - lib
@@ -127,13 +127,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  required_rubygems_version: !ruby/object:Gem::Requirement
129
129
  requirements:
130
- - - ">"
130
+ - - ">="
131
131
  - !ruby/object:Gem::Version
132
- version: 1.3.1
132
+ version: '0'
133
133
  requirements: []
134
- rubyforge_project:
135
- rubygems_version: 2.6.13
136
- signing_key:
134
+ rubygems_version: 3.2.15
135
+ signing_key:
137
136
  specification_version: 4
138
137
  summary: Input plugin to read from systemd journal.
139
138
  test_files: []