fluent-plugin-named_pipe 0.1.2 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8d07b39b6f3847cf4c06b65005af568aa30c174b
4
- data.tar.gz: 9d76bb33a6cc162c16112f560a2b2ff463618dae
3
+ metadata.gz: a5034743f0d689be092bb85e3b3dad91e7883147
4
+ data.tar.gz: b6c1a96e9972546bbb14fe34101ebde66283461a
5
5
  SHA512:
6
- metadata.gz: 80e1bccd49cff7284b76d919f604c1ed57ab80e6ecf7a8fe71235da91f604b4f1bbd2616f52fc62389c991af0f1006cd0f77780c4c1177239d9fac950cf4e1dd
7
- data.tar.gz: 292d56dc7656074c5d3c4fa8f95ab860c2c94a56b347ec6e63be74b8a19171c1c00358abff242616e0f1add7cac6127e0d1513a22c4899b1be4d8319c7868bd0
6
+ metadata.gz: 7611d8aa5a27a979c884c520887452672c71d0f827225c352e7b9154dec2b94e1ff7823b3d3e239da952f97c74b4d7cdcd5910de55e4e90f4fcb276b57211535
7
+ data.tar.gz: dc6cb4142953e05a205f39b5f8b1b428010e736b5a998fb0fae61eef8e68c3512ff30056252bd57cb82e8e2ab56fb87c970ddf4c1f0c41968b97f7b86d180a64
@@ -1,6 +1,10 @@
1
1
  rvm:
2
- - 1.9.3
3
- - 2.0.0
4
2
  - 2.1.*
3
+ - 2.2.*
4
+ - 2.3.*
5
5
  gemfile:
6
6
  - Gemfile
7
+ - Gemfile.v0.10
8
+ - Gemfile.v0.12
9
+ before_install:
10
+ - gem update bundler
@@ -1,3 +1,15 @@
1
+ ## 0.2.0 (2017/12/02)
2
+
3
+ Changes:
4
+
5
+ * Drop Windows Support
6
+
7
+ Enhancenments:
8
+
9
+ * Create lib/fluent/plugin/fifo.rb as own fifo library because `ruby-fifo` gem looks like not maintained (thanks to m-mizutani)
10
+ * Use `IO.sysread instead` of `File.read` to avoid read blocking
11
+ * Add error handling for EOF
12
+
1
13
  ## 0.1.2 (2015/08/04)
2
14
 
3
15
  Fixes:
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+ gem 'fluentd', '~> 0.10.0'
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+ gem 'fluentd', '~> 0.12.0'
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = "fluent-plugin-named_pipe"
6
- s.version = "0.1.2"
6
+ s.version = "0.2.0"
7
7
  s.authors = ["Naotoshi Seo"]
8
8
  s.email = ["sonots@gmail.com"]
9
9
  s.homepage = "https://github.com/sonots/fluent-plugin-named_pipe"
@@ -17,12 +17,9 @@ Gem::Specification.new do |s|
17
17
  s.require_paths = ["lib"]
18
18
 
19
19
  s.add_runtime_dependency "fluentd", ">= 0.10.58"
20
- s.add_runtime_dependency "ruby-fifo", "0.0.1"
21
- if RUBY_PLATFORM =~ /mswin|mingw/i
22
- s.add_runtime_dependency "win32-pipe"
23
- else
24
- s.add_runtime_dependency "mkfifo"
25
- end
20
+ # File.mkfifo is available from ruby >= 2.3.0, though
21
+ s.add_runtime_dependency "mkfifo"
22
+
26
23
  s.add_development_dependency "rake"
27
24
  s.add_development_dependency "test-unit"
28
25
  s.add_development_dependency "pry"
@@ -1,3 +1,6 @@
1
+ require 'fluent/input'
2
+ require_relative 'named_pipe/fifo'
3
+
1
4
  module Fluent
2
5
  class NamedPipeInput < Input
3
6
  Fluent::Plugin.register_input('named_pipe', self)
@@ -10,16 +13,16 @@ module Fluent
10
13
  define_method(:log) { $log }
11
14
  end
12
15
 
13
- def initialize
14
- require 'fifo'
15
- super
16
+ # Define `router` method of v0.12 to support v0.10 or earlier
17
+ unless method_defined?(:router)
18
+ define_method("router") { Fluent::Engine }
16
19
  end
17
20
 
18
21
  def configure(conf)
19
22
  super
20
23
 
21
24
  begin
22
- pipe = Fifo.new(@path, :r, :nowait)
25
+ pipe = PluginNamedPipe::Fifo.new(@path, :r)
23
26
  pipe.close # just to try open
24
27
  rescue => e
25
28
  raise ConfigError, "#{e.class}: #{e.message}"
@@ -42,16 +45,19 @@ module Fluent
42
45
  end
43
46
 
44
47
  def run
45
- @pipe = Fifo.new(@path, :r, :wait)
48
+ @pipe = PluginNamedPipe::Fifo.new(@path, :r)
46
49
 
47
50
  while @running
48
51
  begin
49
52
  line = @pipe.readline # blocking
50
- time, record = @parser.parse(line)
51
- if time and record
52
- Engine.emit(@tag, time, record)
53
- else
54
- log.warn "Pattern not match: #{line.inspect}"
53
+ next if line.nil?
54
+
55
+ @parser.parse(line) do |time, record|
56
+ if time and record
57
+ router.emit(@tag, time, record)
58
+ else
59
+ log.warn "Pattern not match: #{line.inspect}"
60
+ end
55
61
  end
56
62
  rescue => e
57
63
  log.error "in_named_pipe: unexpected error", :error_class => e.class, :error => e.to_s
@@ -0,0 +1,54 @@
1
+ require 'forwardable'
2
+ require 'mkfifo'
3
+
4
+ module Fluent
5
+ module PluginNamedPipe
6
+ class Fifo
7
+ extend Forwardable
8
+
9
+ READ_TIMEOUT = 1
10
+
11
+ def initialize(file_path, mode = :r)
12
+ if !File.exist?(file_path)
13
+ File.mkfifo(file_path)
14
+ File.chmod(0666, file_path)
15
+ end
16
+
17
+ @file_path = file_path
18
+ @mode = mode
19
+ self.open
20
+
21
+ @buf = ''
22
+ end
23
+
24
+ def_delegators :@pipe, :read, :write, :close, :flush
25
+
26
+ def open
27
+ m = {:r => 'r+', :w => 'w+'}[@mode]
28
+ @pipe = File.open(@file_path, m)
29
+ end
30
+
31
+ def readline
32
+ res = IO.select([@pipe], [], [], READ_TIMEOUT)
33
+ return nil if res.nil?
34
+
35
+ while nil == (idx = @buf.index("\n")) do
36
+ tmp = ''
37
+ begin
38
+ s = @pipe.sysread(0xffff, tmp)
39
+ @buf << s
40
+ rescue EOFError
41
+ # reopen
42
+ @pipe.close
43
+ @pipe.open
44
+ end
45
+ end
46
+
47
+ line = @buf[0, idx + 1]
48
+ @buf = @buf[idx + 1, @buf.length - line.length]
49
+ return line
50
+ end
51
+
52
+ end
53
+ end
54
+ end
@@ -1,3 +1,5 @@
1
+ require_relative 'named_pipe/fifo'
2
+
1
3
  module Fluent
2
4
  class NamedPipeOutput < Output
3
5
  Plugin.register_output('named_pipe', self)
@@ -9,16 +11,11 @@ module Fluent
9
11
  define_method(:log) { $log }
10
12
  end
11
13
 
12
- def initialize
13
- require 'fifo'
14
- super
15
- end
16
-
17
14
  def configure(conf)
18
15
  super
19
16
 
20
17
  begin
21
- @pipe = Fifo.new(@path, :w, :nowait)
18
+ @pipe = PluginNamedPipe::Fifo.new(@path, :w)
22
19
  rescue => e
23
20
  raise ConfigError, "#{e.class}: #{e.message}"
24
21
  end
@@ -34,6 +31,7 @@ module Fluent
34
31
  def emit(tag, es, chain)
35
32
  es.each do |time, record|
36
33
  @pipe.write @formatter.format(tag, time, record)
34
+ @pipe.flush
37
35
  end
38
36
 
39
37
  chain.next
@@ -43,8 +43,9 @@ class NamedPipeInputTest < Test::Unit::TestCase
43
43
  test 'read and emit' do
44
44
  d = create_driver(CONFIG)
45
45
  d.run {
46
- pipe = Fifo.new(TEST_PATH, :w, :nowait)
46
+ pipe = ::Fluent::PluginNamedPipe::Fifo.new(TEST_PATH, :w)
47
47
  pipe.write "foo:bar\n"
48
+ pipe.flush
48
49
  }
49
50
 
50
51
  emits = d.emits
@@ -53,6 +54,30 @@ class NamedPipeInputTest < Test::Unit::TestCase
53
54
  assert_equal({"foo"=>"bar\n"}, record)
54
55
  end
55
56
  end
57
+
58
+
59
+ test 'fragmented emit' do
60
+ d = create_driver(CONFIG)
61
+ d.run {
62
+ pipe = ::Fluent::PluginNamedPipe::Fifo.new(TEST_PATH, :w)
63
+ pipe.write "fo"
64
+ pipe.flush
65
+ sleep 0.2
66
+ pipe.write "o:ba"
67
+ pipe.flush
68
+ sleep 0.2
69
+ pipe.write "r\n"
70
+ pipe.flush
71
+ }
72
+
73
+ emits = d.emits
74
+ emits.each do |tag, time, record|
75
+ assert_equal("named_pipe", tag)
76
+ assert_equal({"foo"=>"bar\n"}, record)
77
+ end
78
+ end
79
+
80
+
56
81
  end
57
82
  end
58
83
 
@@ -1,7 +1,6 @@
1
1
  require_relative 'helper'
2
2
  require 'fluent/test'
3
3
  require 'fluent/plugin/out_named_pipe'
4
- require 'fifo'
5
4
 
6
5
  Fluent::Test.setup
7
6
 
@@ -48,7 +47,7 @@ class NamedPipeOutputTest < Test::Unit::TestCase
48
47
  test 'reader is waiting' do
49
48
  readline = nil
50
49
  thread = Thread.new {
51
- pipe = Fifo.new(TEST_PATH, :r, :wait)
50
+ pipe = ::Fluent::PluginNamedPipe::Fifo.new(TEST_PATH, :r)
52
51
  readline = pipe.readline
53
52
  }
54
53
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fluent-plugin-named_pipe
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Naotoshi Seo
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-28 00:00:00.000000000 Z
11
+ date: 2017-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: fluentd
@@ -24,20 +24,6 @@ dependencies:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
26
  version: 0.10.58
27
- - !ruby/object:Gem::Dependency
28
- name: ruby-fifo
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - '='
32
- - !ruby/object:Gem::Version
33
- version: 0.0.1
34
- type: :runtime
35
- prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - '='
39
- - !ruby/object:Gem::Version
40
- version: 0.0.1
41
27
  - !ruby/object:Gem::Dependency
42
28
  name: mkfifo
43
29
  requirement: !ruby/object:Gem::Requirement
@@ -119,11 +105,14 @@ files:
119
105
  - ".travis.yml"
120
106
  - CHANGELOG.md
121
107
  - Gemfile
108
+ - Gemfile.v0.10
109
+ - Gemfile.v0.12
122
110
  - LICENSE
123
111
  - README.md
124
112
  - Rakefile
125
113
  - fluent-plugin-named_pipe.gemspec
126
114
  - lib/fluent/plugin/in_named_pipe.rb
115
+ - lib/fluent/plugin/named_pipe/fifo.rb
127
116
  - lib/fluent/plugin/out_named_pipe.rb
128
117
  - test/helper.rb
129
118
  - test/test_in_named_pipe.rb
@@ -148,7 +137,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
148
137
  version: '0'
149
138
  requirements: []
150
139
  rubyforge_project:
151
- rubygems_version: 2.4.5
140
+ rubygems_version: 2.5.2
152
141
  signing_key:
153
142
  specification_version: 4
154
143
  summary: Named pipe input/output plugin for Fluentd