logstash-core 2.2.4.snapshot1

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.

Potentially problematic release.


This version of logstash-core might be problematic. Click here for more details.

Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/lib/logstash-core.rb +1 -0
  3. data/lib/logstash-core/logstash-core.rb +3 -0
  4. data/lib/logstash-core/version.rb +8 -0
  5. data/lib/logstash/agent.rb +391 -0
  6. data/lib/logstash/codecs/base.rb +50 -0
  7. data/lib/logstash/config/config_ast.rb +550 -0
  8. data/lib/logstash/config/cpu_core_strategy.rb +32 -0
  9. data/lib/logstash/config/defaults.rb +12 -0
  10. data/lib/logstash/config/file.rb +39 -0
  11. data/lib/logstash/config/grammar.rb +3503 -0
  12. data/lib/logstash/config/mixin.rb +518 -0
  13. data/lib/logstash/config/registry.rb +13 -0
  14. data/lib/logstash/environment.rb +98 -0
  15. data/lib/logstash/errors.rb +12 -0
  16. data/lib/logstash/filters/base.rb +205 -0
  17. data/lib/logstash/inputs/base.rb +116 -0
  18. data/lib/logstash/inputs/threadable.rb +18 -0
  19. data/lib/logstash/java_integration.rb +116 -0
  20. data/lib/logstash/json.rb +61 -0
  21. data/lib/logstash/logging.rb +91 -0
  22. data/lib/logstash/namespace.rb +13 -0
  23. data/lib/logstash/output_delegator.rb +172 -0
  24. data/lib/logstash/outputs/base.rb +91 -0
  25. data/lib/logstash/patches.rb +5 -0
  26. data/lib/logstash/patches/bugfix_jruby_2558.rb +51 -0
  27. data/lib/logstash/patches/cabin.rb +35 -0
  28. data/lib/logstash/patches/profile_require_calls.rb +47 -0
  29. data/lib/logstash/patches/rubygems.rb +38 -0
  30. data/lib/logstash/patches/stronger_openssl_defaults.rb +68 -0
  31. data/lib/logstash/pipeline.rb +499 -0
  32. data/lib/logstash/pipeline_reporter.rb +114 -0
  33. data/lib/logstash/plugin.rb +120 -0
  34. data/lib/logstash/program.rb +14 -0
  35. data/lib/logstash/runner.rb +124 -0
  36. data/lib/logstash/shutdown_watcher.rb +100 -0
  37. data/lib/logstash/util.rb +203 -0
  38. data/lib/logstash/util/buftok.rb +139 -0
  39. data/lib/logstash/util/charset.rb +35 -0
  40. data/lib/logstash/util/decorators.rb +52 -0
  41. data/lib/logstash/util/defaults_printer.rb +31 -0
  42. data/lib/logstash/util/filetools.rb +186 -0
  43. data/lib/logstash/util/java_version.rb +66 -0
  44. data/lib/logstash/util/password.rb +25 -0
  45. data/lib/logstash/util/plugin_version.rb +56 -0
  46. data/lib/logstash/util/prctl.rb +10 -0
  47. data/lib/logstash/util/retryable.rb +40 -0
  48. data/lib/logstash/util/socket_peer.rb +7 -0
  49. data/lib/logstash/util/unicode_trimmer.rb +81 -0
  50. data/lib/logstash/util/worker_threads_default_printer.rb +29 -0
  51. data/lib/logstash/util/wrapped_synchronous_queue.rb +41 -0
  52. data/lib/logstash/version.rb +14 -0
  53. data/locales/en.yml +204 -0
  54. data/logstash-core.gemspec +58 -0
  55. data/spec/conditionals_spec.rb +429 -0
  56. data/spec/logstash/agent_spec.rb +85 -0
  57. data/spec/logstash/config/config_ast_spec.rb +146 -0
  58. data/spec/logstash/config/cpu_core_strategy_spec.rb +123 -0
  59. data/spec/logstash/config/defaults_spec.rb +10 -0
  60. data/spec/logstash/config/mixin_spec.rb +158 -0
  61. data/spec/logstash/environment_spec.rb +56 -0
  62. data/spec/logstash/filters/base_spec.rb +251 -0
  63. data/spec/logstash/inputs/base_spec.rb +74 -0
  64. data/spec/logstash/java_integration_spec.rb +304 -0
  65. data/spec/logstash/json_spec.rb +96 -0
  66. data/spec/logstash/output_delegator_spec.rb +144 -0
  67. data/spec/logstash/outputs/base_spec.rb +40 -0
  68. data/spec/logstash/patches_spec.rb +90 -0
  69. data/spec/logstash/pipeline_reporter_spec.rb +85 -0
  70. data/spec/logstash/pipeline_spec.rb +455 -0
  71. data/spec/logstash/plugin_spec.rb +169 -0
  72. data/spec/logstash/runner_spec.rb +68 -0
  73. data/spec/logstash/shutdown_watcher_spec.rb +113 -0
  74. data/spec/logstash/util/buftok_spec.rb +31 -0
  75. data/spec/logstash/util/charset_spec.rb +74 -0
  76. data/spec/logstash/util/defaults_printer_spec.rb +50 -0
  77. data/spec/logstash/util/java_version_spec.rb +79 -0
  78. data/spec/logstash/util/plugin_version_spec.rb +64 -0
  79. data/spec/logstash/util/unicode_trimmer_spec.rb +55 -0
  80. data/spec/logstash/util/worker_threads_default_printer_spec.rb +45 -0
  81. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +28 -0
  82. data/spec/logstash/util_spec.rb +35 -0
  83. metadata +364 -0
@@ -0,0 +1,85 @@
1
+ # encoding: utf-8
2
+ require 'spec_helper'
3
+
4
+ describe LogStash::Agent do
5
+ subject { LogStash::Agent.new('') }
6
+ let(:dummy_config) { 'input {}' }
7
+
8
+ context "when loading the configuration" do
9
+ context "when local" do
10
+ before { expect(subject).to receive(:local_config).with(path) }
11
+
12
+ context "unix" do
13
+ let(:path) { './test.conf' }
14
+ it 'works with relative path' do
15
+ subject.load_config(path)
16
+ end
17
+ end
18
+
19
+ context "windows" do
20
+ let(:path) { '.\test.conf' }
21
+ it 'work with relative windows path' do
22
+ subject.load_config(path)
23
+ end
24
+ end
25
+ end
26
+
27
+ context "when remote" do
28
+ context 'supported scheme' do
29
+ let(:path) { "http://test.local/superconfig.conf" }
30
+
31
+ before { expect(Net::HTTP).to receive(:get) { dummy_config } }
32
+ it 'works with http' do
33
+ expect(subject.load_config(path)).to eq("#{dummy_config}\n")
34
+ end
35
+ end
36
+ end
37
+ end
38
+
39
+ context "--pluginpath" do
40
+ let(:single_path) { "/some/path" }
41
+ let(:multiple_paths) { ["/some/path1", "/some/path2"] }
42
+
43
+ it "should add single valid dir path to the environment" do
44
+ expect(File).to receive(:directory?).and_return(true)
45
+ expect(LogStash::Environment).to receive(:add_plugin_path).with(single_path)
46
+ subject.configure_plugin_paths(single_path)
47
+ end
48
+
49
+ it "should fail with single invalid dir path" do
50
+ expect(File).to receive(:directory?).and_return(false)
51
+ expect(LogStash::Environment).not_to receive(:add_plugin_path)
52
+ expect{subject.configure_plugin_paths(single_path)}.to raise_error(LogStash::ConfigurationError)
53
+ end
54
+
55
+ it "should add multiple valid dir path to the environment" do
56
+ expect(File).to receive(:directory?).exactly(multiple_paths.size).times.and_return(true)
57
+ multiple_paths.each{|path| expect(LogStash::Environment).to receive(:add_plugin_path).with(path)}
58
+ subject.configure_plugin_paths(multiple_paths)
59
+ end
60
+ end
61
+
62
+ describe "debug_config" do
63
+ let(:pipeline_string) { "input {} output {}" }
64
+ let(:pipeline) { double("pipeline") }
65
+
66
+ before(:each) do
67
+ allow(pipeline).to receive(:run)
68
+ end
69
+ it "should set 'debug_config' to false by default" do
70
+ expect(LogStash::Pipeline).to receive(:new).
71
+ with(anything,hash_including(:debug_config => false)).
72
+ and_return(pipeline)
73
+ args = ["--debug", "-e", pipeline_string]
74
+ subject.run(args)
75
+ end
76
+
77
+ it "should allow overriding debug_config" do
78
+ expect(LogStash::Pipeline).to receive(:new).
79
+ with(anything, hash_including(:debug_config => true))
80
+ .and_return(pipeline)
81
+ args = ["--debug", "--debug-config", "-e", pipeline_string]
82
+ subject.run(args)
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,146 @@
1
+ # encoding: utf-8
2
+ # config syntax tests
3
+ #
4
+ require "spec_helper"
5
+ require "logstash/config/grammar"
6
+ require "logstash/config/config_ast"
7
+
8
+ describe LogStashConfigParser do
9
+ context '#parse' do
10
+ context "valid configuration" do
11
+ it "should permit single-quoted attribute names" do
12
+ parser = LogStashConfigParser.new
13
+ config = parser.parse(%q(
14
+ input {
15
+ example {
16
+ 'foo' => 'bar'
17
+ test => { 'bar' => 'baz' }
18
+ }
19
+ }
20
+ ))
21
+
22
+ expect(config).not_to be_nil
23
+ end
24
+
25
+ it "should permit empty plugin sections" do
26
+ parser = LogStashConfigParser.new
27
+ config = parser.parse(%q(
28
+ filter {
29
+ }
30
+ ))
31
+
32
+ expect(config).not_to be_nil
33
+ end
34
+
35
+ it 'permits hash to contains array' do
36
+ parser = LogStashConfigParser.new
37
+ config = parser.parse(%q(
38
+ input{
39
+ example {
40
+ match => {
41
+ "message"=> ["pattern1", "pattern2", "pattern3"]
42
+ }
43
+ }
44
+ }))
45
+ expect(config).not_to be_nil
46
+ end
47
+ end
48
+ end
49
+
50
+ context "#compile" do
51
+ context "if with multiline conditionals" do
52
+ let(:config) { <<-CONFIG }
53
+ filter {
54
+ if [something]
55
+ or [anotherthing]
56
+ or [onemorething] {
57
+ }
58
+ }
59
+ CONFIG
60
+ subject { LogStashConfigParser.new }
61
+
62
+ it "should compile successfully" do
63
+ result = subject.parse(config)
64
+ expect(result).not_to(be_nil)
65
+ expect { eval(result.compile) }.not_to(raise_error)
66
+ end
67
+ end
68
+
69
+ context "elsif with multiline conditionals" do
70
+ let(:config) { <<-CONFIG }
71
+ filter {
72
+ if [notathing] {
73
+ } else if [something]
74
+ or [anotherthing]
75
+ or [onemorething] {
76
+ }
77
+ }
78
+ CONFIG
79
+ subject { LogStashConfigParser.new }
80
+
81
+ it "should compile successfully" do
82
+ result = subject.parse(config)
83
+ expect(result).not_to(be_nil)
84
+ expect { eval(result.compile) }.not_to(raise_error)
85
+ end
86
+ end
87
+
88
+
89
+ context "invalid configuration" do
90
+ it "rejects duplicate hash key" do
91
+ parser = LogStashConfigParser.new
92
+ config = parser.parse(%q(
93
+ input {
94
+ example {
95
+ match => {
96
+ "message"=> "pattern1"
97
+ "message"=> "pattern2"
98
+ "message"=> "pattern3"
99
+ }
100
+ }
101
+ }
102
+ ))
103
+
104
+ expect { config.compile }.to raise_error(LogStash::ConfigurationError, /Duplicate keys found in your configuration: \["message"\]/)
105
+ end
106
+
107
+ it "rejects duplicate keys in nested hash" do
108
+ parser = LogStashConfigParser.new
109
+ config = parser.parse(%q(
110
+ input {
111
+ example {
112
+ match => {
113
+ "message"=> "pattern1"
114
+ "more" => {
115
+ "cool" => true
116
+ "cool" => true
117
+ }
118
+ }
119
+ }
120
+ }
121
+ ))
122
+
123
+ expect { config.compile }.to raise_error(LogStash::ConfigurationError, /Duplicate keys found in your configuration: \["cool"\]/)
124
+ end
125
+
126
+ it "rejects a key with multiple double quotes" do
127
+ parser = LogStashConfigParser.new
128
+ config = parser.parse(%q(
129
+ input {
130
+ example {
131
+ match => {
132
+ "message"=> "pattern1"
133
+ ""more"" => {
134
+ "cool" => true
135
+ "cool" => true
136
+ }
137
+ }
138
+ }
139
+ }
140
+ ))
141
+
142
+ expect(config).to be_nil
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,123 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/config/cpu_core_strategy"
4
+
5
+ describe LogStash::Config::CpuCoreStrategy do
6
+
7
+ before do
8
+ allow(LogStash::Config::Defaults).to receive(:cpu_cores).and_return(cores)
9
+ end
10
+
11
+ context 'when the machine has 6 cores' do
12
+ let(:cores) { 6 }
13
+
14
+ it ".maximum should return 6" do
15
+ expect(described_class.maximum).to eq(6)
16
+ end
17
+
18
+ it ".fifty_percent should return 3" do
19
+ expect(described_class.fifty_percent).to eq(3)
20
+ end
21
+
22
+ it ".seventy_five_percent should return 4" do
23
+ expect(described_class.seventy_five_percent).to eq(4)
24
+ end
25
+
26
+ it ".twenty_five_percent should return 1" do
27
+ expect(described_class.twenty_five_percent).to eq(1)
28
+ end
29
+
30
+ it ".max_minus_one should return 5" do
31
+ expect(described_class.max_minus_one).to eq(5)
32
+ end
33
+
34
+ it ".max_minus_two should return 4" do
35
+ expect(described_class.max_minus_two).to eq(4)
36
+ end
37
+ end
38
+
39
+ context 'when the machine has 4 cores' do
40
+ let(:cores) { 4 }
41
+
42
+ it ".maximum should return 4" do
43
+ expect(described_class.maximum).to eq(4)
44
+ end
45
+
46
+ it ".fifty_percent should return 2" do
47
+ expect(described_class.fifty_percent).to eq(2)
48
+ end
49
+
50
+ it ".seventy_five_percent should return 3" do
51
+ expect(described_class.seventy_five_percent).to eq(3)
52
+ end
53
+
54
+ it ".twenty_five_percent should return 1" do
55
+ expect(described_class.twenty_five_percent).to eq(1)
56
+ end
57
+
58
+ it ".max_minus_one should return 3" do
59
+ expect(described_class.max_minus_one).to eq(3)
60
+ end
61
+
62
+ it ".max_minus_two should return 2" do
63
+ expect(described_class.max_minus_two).to eq(2)
64
+ end
65
+ end
66
+
67
+ context 'when the machine has 2 cores' do
68
+ let(:cores) { 2 }
69
+
70
+ it ".maximum should return 2" do
71
+ expect(described_class.maximum).to eq(2)
72
+ end
73
+
74
+ it ".fifty_percent should return 1" do
75
+ expect(described_class.fifty_percent).to eq(1)
76
+ end
77
+
78
+ it ".seventy_five_percent should return 1" do
79
+ expect(described_class.seventy_five_percent).to eq(1)
80
+ end
81
+
82
+ it ".twenty_five_percent should return 1" do
83
+ expect(described_class.twenty_five_percent).to eq(1)
84
+ end
85
+
86
+ it ".max_minus_one should return 1" do
87
+ expect(described_class.max_minus_one).to eq(1)
88
+ end
89
+
90
+ it ".max_minus_two should return 1" do
91
+ expect(described_class.max_minus_two).to eq(1)
92
+ end
93
+ end
94
+
95
+ context 'when the machine has 1 core' do
96
+ let(:cores) { 1 }
97
+
98
+ it ".maximum should return 1" do
99
+ expect(described_class.maximum).to eq(1)
100
+ end
101
+
102
+ it ".fifty_percent should return 1" do
103
+ expect(described_class.fifty_percent).to eq(1)
104
+ end
105
+
106
+ it ".seventy_five_percent should return 1" do
107
+ expect(described_class.seventy_five_percent).to eq(1)
108
+ end
109
+
110
+ it ".twenty_five_percent should return 1" do
111
+ expect(described_class.twenty_five_percent).to eq(1)
112
+ end
113
+
114
+ it ".max_minus_one should return 1" do
115
+ expect(described_class.max_minus_one).to eq(1)
116
+ end
117
+
118
+ it ".max_minus_two should return 1" do
119
+ expect(described_class.max_minus_two).to eq(1)
120
+ end
121
+ end
122
+
123
+ end
@@ -0,0 +1,10 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/config/defaults"
4
+
5
+ describe LogStash::Config::Defaults do
6
+ it ".cpu_cores should return a positive integer" do
7
+ expect(described_class.cpu_cores.nil?).to be false
8
+ expect(described_class.cpu_cores.zero?).to be false
9
+ end
10
+ end
@@ -0,0 +1,158 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/config/mixin"
4
+
5
+ describe LogStash::Config::Mixin do
6
+ context "when validating :bytes successfully" do
7
+ subject do
8
+ local_num_bytes = num_bytes # needs to be locally scoped :(
9
+ Class.new(LogStash::Filters::Base) do
10
+ include LogStash::Config::Mixin
11
+ config_name "test"
12
+ milestone 1
13
+ config :size_bytes, :validate => :bytes
14
+ config :size_default, :validate => :bytes, :default => "#{local_num_bytes}"
15
+ config :size_upcase, :validate => :bytes
16
+ config :size_downcase, :validate => :bytes
17
+ config :size_space, :validate => :bytes
18
+ end.new({
19
+ "size_bytes" => "#{local_num_bytes}",
20
+ "size_upcase" => "#{local_num_bytes}KiB".upcase,
21
+ "size_downcase" => "#{local_num_bytes}KiB".downcase,
22
+ "size_space" => "#{local_num_bytes} KiB"
23
+ })
24
+ end
25
+
26
+ let!(:num_bytes) { rand(1000) }
27
+ let!(:num_kbytes) { num_bytes * 1024 }
28
+
29
+ it "should validate :bytes successfully with no units" do
30
+ expect(subject.size_bytes).to eq(num_bytes)
31
+ end
32
+
33
+ it "should allow setting valid default" do
34
+ expect(subject.size_default).to eq(num_bytes)
35
+ end
36
+
37
+ it "should be case-insensitive when parsing units" do
38
+ expect(subject.size_upcase).to eq(num_kbytes)
39
+ expect(subject.size_downcase).to eq(num_kbytes)
40
+ end
41
+
42
+ it "should accept one space between num_bytes and unit suffix" do
43
+ expect(subject.size_space).to eq(num_kbytes)
44
+ end
45
+ end
46
+
47
+ context "when raising configuration errors while validating" do
48
+ it "should raise configuration error when provided with invalid units" do
49
+ expect {
50
+ Class.new(LogStash::Filters::Base) do
51
+ include LogStash::Config::Mixin
52
+ config_name "test"
53
+ milestone 1
54
+ config :size_file, :validate => :bytes
55
+ end.new({"size_file" => "10 yolobytes"})
56
+ }.to raise_error(LogStash::ConfigurationError)
57
+ end
58
+
59
+ it "should raise configuration error when provided with too many spaces" do
60
+ expect {
61
+ Class.new(LogStash::Filters::Base) do
62
+ include LogStash::Config::Mixin
63
+ config_name "test"
64
+ milestone 1
65
+ config :size_file, :validate => :bytes
66
+ end.new({"size_file" => "10 kib"})
67
+ }.to raise_error(LogStash::ConfigurationError)
68
+ end
69
+ end
70
+
71
+ context "when validating :password" do
72
+ let(:klass) do
73
+ Class.new(LogStash::Filters::Base) do
74
+ config_name "fake"
75
+ config :password, :validate => :password
76
+ end
77
+ end
78
+
79
+ let(:secret) { "fancy pants" }
80
+ subject { klass.new("password" => secret) }
81
+
82
+ it "should be a Password object" do
83
+ expect(subject.password).to(be_a(LogStash::Util::Password))
84
+ end
85
+
86
+ it "should make password values hidden" do
87
+ expect(subject.password.to_s).to(be == "<password>")
88
+ expect(subject.password.inspect).to(be == "<password>")
89
+ end
90
+
91
+ it "should show password values via #value" do
92
+ expect(subject.password.value).to(be == secret)
93
+ end
94
+
95
+ it "should correctly copy password types" do
96
+ clone = subject.class.new(subject.params)
97
+ expect(clone.password.value).to(be == secret)
98
+ end
99
+
100
+ it "should obfuscate original_params" do
101
+ expect(subject.original_params['password']).to(be_a(LogStash::Util::Password))
102
+ end
103
+ end
104
+
105
+ describe "obsolete settings" do
106
+ let(:plugin_class) do
107
+ Class.new(LogStash::Inputs::Base) do
108
+ include LogStash::Config::Mixin
109
+ config_name "example"
110
+ config :foo, :validate => :string, :obsolete => "This feature was removed."
111
+ end
112
+ end
113
+
114
+ context "when using an obsolete setting" do
115
+ it "should cause a configuration error" do
116
+ expect {
117
+ plugin_class.new("foo" => "hello")
118
+ }.to raise_error(LogStash::ConfigurationError)
119
+ end
120
+ end
121
+
122
+ context "when using an obsolete settings from the parent class" do
123
+ it "should cause a configuration error" do
124
+ expect {
125
+ plugin_class.new("debug" => true)
126
+ }.to raise_error(LogStash::ConfigurationError)
127
+ end
128
+ end
129
+
130
+ context "when not using an obsolete setting" do
131
+ it "should not cause a configuration error" do
132
+ expect {
133
+ plugin_class.new({})
134
+ }.not_to raise_error
135
+ end
136
+ end
137
+ end
138
+
139
+ context "#params" do
140
+ let(:plugin_class) do
141
+ Class.new(LogStash::Filters::Base) do
142
+ config_name "fake"
143
+ config :password, :validate => :password
144
+ config :bad, :validate => :string, :default => "my default", :obsolete => "not here"
145
+ end
146
+ end
147
+
148
+ subject { plugin_class.new({ "password" => "secret" }) }
149
+
150
+ it "should not return the obsolete options" do
151
+ expect(subject.params).not_to include("bad")
152
+ end
153
+
154
+ it "should include any other params" do
155
+ expect(subject.params).to include("password")
156
+ end
157
+ end
158
+ end