fluent-format 0.2.1 → 0.2.2
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 +4 -4
- data/CHANGELOG.md +6 -0
- data/README.md +2 -2
- data/example/out_example.rb +15 -0
- data/example/param_error.conf +4 -0
- data/example/{unknown_plugin.conf → plugin_error.conf} +0 -0
- data/lib/fluent/format.rb +1 -1
- data/lib/fluent/format/check.rb +6 -4
- data/lib/fluent/format/cli.rb +2 -2
- data/lib/fluent/format/format.rb +34 -21
- data/lib/fluent/format/version.rb +1 -1
- data/spec/fluent/format/check_spec.rb +7 -1
- data/spec/fluent/format/cli_spec.rb +29 -2
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 495a2bd0d34f9a30ff0ac8be3700d5e361cf6150
|
|
4
|
+
data.tar.gz: 01554a964c734cedf4f7c2cfb0e915e3c608a158
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 2e5e950a92c5fb60dd20e86cebe99946c0b6410f1e7c20a55100a54fa0ac6923237b67bccd155d6859e48e59d0a5f9e5f2ef350da16325f2fa28bb3d467e27e1
|
|
7
|
+
data.tar.gz: 36673c63cfd92f6e12c3aebc294b64132e37bed1c59780266066ea529ff29f827e75e7c2e122a7e5be3e828c997a9f8a6fef16cc6119d51ad1e7e58d1f35488a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
# fluent-format
|
|
1
|
+
# fluent-format [](http://travis-ci.org/sonots/fluent-format)
|
|
2
2
|
|
|
3
3
|
A command line utility to format fluentd configuration beautifully
|
|
4
4
|
|
|
@@ -34,7 +34,7 @@ require 'fluent-format'
|
|
|
34
34
|
|
|
35
35
|
File.open(path) {|config|
|
|
36
36
|
puts Fluent::Format.format(config) # formatted string
|
|
37
|
-
|
|
37
|
+
Fluent::Format.check(config, plugin_dir) #=> Fluent::ConfigParseError or Fluent::ConfigError if failed
|
|
38
38
|
}
|
|
39
39
|
```
|
|
40
40
|
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
class Fluent::ExampleOutput < Fluent::Output
|
|
2
|
+
Fluent::Plugin.register_output('example', self)
|
|
3
|
+
|
|
4
|
+
config_param :param, :string, :default => nil
|
|
5
|
+
|
|
6
|
+
def configure(conf)
|
|
7
|
+
super
|
|
8
|
+
|
|
9
|
+
raise Fluent::ConfigError, "bad param" if @param == "bad"
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def emit(tag, es, chain)
|
|
13
|
+
chain.next
|
|
14
|
+
end
|
|
15
|
+
end
|
|
File without changes
|
data/lib/fluent/format.rb
CHANGED
data/lib/fluent/format/check.rb
CHANGED
|
@@ -30,12 +30,14 @@ module Fluent
|
|
|
30
30
|
# @raise Fluent::ConfigError if plugin raises config error
|
|
31
31
|
# @return true if success
|
|
32
32
|
def run
|
|
33
|
-
Fluent::Supervisor.new(@opts).
|
|
33
|
+
Fluent::Supervisor.new(@opts).extended_dry_run
|
|
34
34
|
end
|
|
35
35
|
end
|
|
36
36
|
end
|
|
37
37
|
end
|
|
38
38
|
|
|
39
|
+
# lib/fluent/supervisor.rb
|
|
40
|
+
# Open the existing class and define new methods
|
|
39
41
|
module Fluent
|
|
40
42
|
class Supervisor
|
|
41
43
|
# Extended to accept IO object
|
|
@@ -43,8 +45,8 @@ module Fluent
|
|
|
43
45
|
# @raise Fluent::ConfigParseError if conf has syntax errors
|
|
44
46
|
# @raise Fluent::ConfigError if plugin raises config error
|
|
45
47
|
# @return true if success
|
|
46
|
-
def
|
|
47
|
-
|
|
48
|
+
def extended_dry_run
|
|
49
|
+
extended_read_config
|
|
48
50
|
change_privilege
|
|
49
51
|
init_engine
|
|
50
52
|
install_main_process_signal_handlers
|
|
@@ -53,7 +55,7 @@ module Fluent
|
|
|
53
55
|
end
|
|
54
56
|
|
|
55
57
|
# Extended to accept IO object
|
|
56
|
-
def
|
|
58
|
+
def extended_read_config
|
|
57
59
|
if @config_path.respond_to?(:read) # IO object
|
|
58
60
|
@config_data = @config_path.read
|
|
59
61
|
else
|
data/lib/fluent/format/cli.rb
CHANGED
|
@@ -11,7 +11,7 @@ module Fluent
|
|
|
11
11
|
config = @options[:config]
|
|
12
12
|
taputs Fluent::Format.format(config)
|
|
13
13
|
rescue => e
|
|
14
|
-
$
|
|
14
|
+
$stderr.puts "#{e.class} #{e.message} #{e.backtrace.first}"
|
|
15
15
|
exit 1
|
|
16
16
|
end
|
|
17
17
|
|
|
@@ -23,7 +23,7 @@ module Fluent
|
|
|
23
23
|
plugin = @options[:plugin]
|
|
24
24
|
Fluent::Format.check(config, plugin)
|
|
25
25
|
rescue => e
|
|
26
|
-
$
|
|
26
|
+
$stderr.puts "#{e.class} #{e.message} #{e.backtrace.first}"
|
|
27
27
|
exit 1
|
|
28
28
|
end
|
|
29
29
|
|
data/lib/fluent/format/format.rb
CHANGED
|
@@ -13,32 +13,14 @@ module Fluent
|
|
|
13
13
|
# @raise Fluent::ConfigParseError if conf has syntax errors
|
|
14
14
|
# @return [String] the formatted config
|
|
15
15
|
def run
|
|
16
|
-
config =
|
|
17
|
-
|
|
16
|
+
config = Fluent::ExtConfig.read(@config_dev)
|
|
17
|
+
indent(config)
|
|
18
18
|
end
|
|
19
19
|
|
|
20
20
|
private
|
|
21
21
|
|
|
22
|
-
# partial copy from lib/fluent/config.rb
|
|
23
|
-
def read_config(dev)
|
|
24
|
-
if dev.respond_to?(:read) # IO object
|
|
25
|
-
parse_config(dev, '-', '-')
|
|
26
|
-
else
|
|
27
|
-
File.open(dev) {|io| parse_config(io, File.basename(dev), File.dirname(dev)) }
|
|
28
|
-
end
|
|
29
|
-
end
|
|
30
|
-
|
|
31
|
-
# partial copy from lib/fluent/config.rb
|
|
32
|
-
def parse_config(io, fname, basepath=Dir.pwd)
|
|
33
|
-
if fname =~ /\.rb$/
|
|
34
|
-
Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
|
|
35
|
-
else
|
|
36
|
-
Fluent::Config.parse(io, fname, basepath)
|
|
37
|
-
end
|
|
38
|
-
end
|
|
39
|
-
|
|
40
22
|
# hmm, ugly workaround
|
|
41
|
-
def
|
|
23
|
+
def indent(conf)
|
|
42
24
|
lines = conf.to_s.split("\n")[1..-2] # remove <ROOT> and </ROOT>
|
|
43
25
|
lines = lines.map {|line| line[2..-1] } # remove heading 2 white spaces
|
|
44
26
|
lines.join("\n")
|
|
@@ -46,3 +28,34 @@ module Fluent
|
|
|
46
28
|
end
|
|
47
29
|
end
|
|
48
30
|
end
|
|
31
|
+
|
|
32
|
+
# lib/fluent/config.rb
|
|
33
|
+
module Fluent
|
|
34
|
+
module ExtConfig
|
|
35
|
+
# Extended to accept IO object
|
|
36
|
+
#
|
|
37
|
+
# @raise Fluent::ConfigParseError if conf has syntax errors
|
|
38
|
+
# @raise Fluent::ConfigError if plugin raises config error
|
|
39
|
+
# @return [String] parsed config string
|
|
40
|
+
def self.read(dev)
|
|
41
|
+
if dev.respond_to?(:read) # IO object
|
|
42
|
+
parse(dev, '-', '-')
|
|
43
|
+
else
|
|
44
|
+
File.open(dev) {|io| parse(io, File.basename(dev), File.dirname(dev)) }
|
|
45
|
+
end
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Extended to accept config dsl
|
|
49
|
+
#
|
|
50
|
+
# @raise Fluent::ConfigParseError if conf has syntax errors
|
|
51
|
+
# @raise Fluent::ConfigError if plugin raises config error
|
|
52
|
+
# @return [String] parsed config string
|
|
53
|
+
def self.parse(io, fname, basepath=Dir.pwd)
|
|
54
|
+
if fname =~ /\.rb$/
|
|
55
|
+
Fluent::Config::DSL::Parser.parse(io, File.join(basepath, fname))
|
|
56
|
+
else
|
|
57
|
+
Fluent::Config.parse(io, fname, basepath)
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
end
|
|
61
|
+
end
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
require 'spec_helper'
|
|
2
2
|
|
|
3
3
|
describe Fluent::Format::Check do
|
|
4
|
-
let(:
|
|
4
|
+
let(:plugin_dir) { File.expand_path('../../../example', File.dirname(__FILE__)) }
|
|
5
|
+
let(:subject) { Fluent::Format.check(config, plugin_dir) }
|
|
5
6
|
|
|
6
7
|
context "valid" do
|
|
7
8
|
let(:config) { StringIO.new(%[<match>\ntype stdout\n</match>]) }
|
|
@@ -17,5 +18,10 @@ describe Fluent::Format::Check do
|
|
|
17
18
|
let(:config) { StringIO.new(%[<match>\ntype foobar\n</match>]) }
|
|
18
19
|
it { expect { subject }.to raise_error(Fluent::ConfigError) }
|
|
19
20
|
end
|
|
21
|
+
|
|
22
|
+
context "param error" do
|
|
23
|
+
let(:config) { StringIO.new(%[<match>\ntype example\nparam bad\n</match>]) }
|
|
24
|
+
it { expect { subject }.to raise_error(Fluent::ConfigError) }
|
|
25
|
+
end
|
|
20
26
|
end
|
|
21
27
|
|
|
@@ -4,16 +4,29 @@ require 'fluent/format/cli'
|
|
|
4
4
|
describe Fluent::Format::CLI do
|
|
5
5
|
let(:cli) { Fluent::Format::CLI.new }
|
|
6
6
|
|
|
7
|
+
def capture_stderr
|
|
8
|
+
$stderr = StringIO.new
|
|
9
|
+
begin
|
|
10
|
+
yield
|
|
11
|
+
rescue SystemExit
|
|
12
|
+
end
|
|
13
|
+
return $stderr.string
|
|
14
|
+
ensure
|
|
15
|
+
$stderr = STDERR
|
|
16
|
+
end
|
|
17
|
+
|
|
7
18
|
context "#format" do
|
|
8
19
|
let(:subject) { cli.invoke(:format, [], opts) }
|
|
9
20
|
|
|
10
21
|
context "success" do
|
|
11
22
|
let(:opts) { {config: "fluent.conf"} }
|
|
23
|
+
it { capture_stderr { subject }.should == "" }
|
|
12
24
|
it { expect { subject }.not_to raise_error }
|
|
13
25
|
end
|
|
14
26
|
|
|
15
27
|
context "failure" do
|
|
16
28
|
let(:opts) { {config: "unknown.conf"} }
|
|
29
|
+
it { capture_stderr { subject }.should include "No such file or directory" }
|
|
17
30
|
it { expect { subject }.to raise_error(SystemExit) }
|
|
18
31
|
end
|
|
19
32
|
end
|
|
@@ -23,11 +36,25 @@ describe Fluent::Format::CLI do
|
|
|
23
36
|
|
|
24
37
|
context "success" do
|
|
25
38
|
let(:opts) { {config: "fluent.conf"} }
|
|
39
|
+
it { capture_stderr { subject }.should == "" }
|
|
26
40
|
it { expect { subject }.not_to raise_error }
|
|
27
41
|
end
|
|
28
42
|
|
|
29
|
-
context "
|
|
30
|
-
let(:opts) { {config: "
|
|
43
|
+
context "syntax error" do
|
|
44
|
+
let(:opts) { {config: "example/syntax_error.conf"} }
|
|
45
|
+
it { capture_stderr { subject }.should include("parse error") }
|
|
46
|
+
it { expect { subject }.to raise_error(SystemExit) }
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
context "plugin error" do
|
|
50
|
+
let(:opts) { {config: "example/plugin_error.conf"} }
|
|
51
|
+
it { capture_stderr { subject }.should include("Unknown input plugin") }
|
|
52
|
+
it { expect { subject }.to raise_error(SystemExit) }
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
context "param error" do
|
|
56
|
+
let(:opts) { {config: "example/param_error.conf", plugin: "example"} }
|
|
57
|
+
it { capture_stderr { subject }.should include("out_example.rb") }
|
|
31
58
|
it { expect { subject }.to raise_error(SystemExit) }
|
|
32
59
|
end
|
|
33
60
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fluent-format
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Naotoshi Seo
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2014-02-
|
|
11
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: thor
|
|
@@ -111,8 +111,10 @@ files:
|
|
|
111
111
|
- README.md
|
|
112
112
|
- Rakefile
|
|
113
113
|
- bin/fluent-format
|
|
114
|
+
- example/out_example.rb
|
|
115
|
+
- example/param_error.conf
|
|
116
|
+
- example/plugin_error.conf
|
|
114
117
|
- example/syntax_error.conf
|
|
115
|
-
- example/unknown_plugin.conf
|
|
116
118
|
- fluent-format.gemspec
|
|
117
119
|
- fluent.conf
|
|
118
120
|
- lib/fluent-format.rb
|