logstash-core 2.2.4.snapshot1

Sign up to get free protection for your applications and to get access to all the features.

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,13 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+
4
+ # Global config registry.
5
+ module LogStash::Config::Registry
6
+ @registry = Hash.new
7
+ class << self
8
+ attr_accessor :registry
9
+
10
+ # TODO(sissel): Add some helper methods here.
11
+ end
12
+ end # module LogStash::Config::Registry
13
+
@@ -0,0 +1,98 @@
1
+ # encoding: utf-8
2
+ require "logstash/errors"
3
+
4
+ module LogStash
5
+ module Environment
6
+ extend self
7
+
8
+ LOGSTASH_CORE = ::File.expand_path(::File.join(::File.dirname(__FILE__), "..", ".."))
9
+ LOGSTASH_ENV = (ENV["LS_ENV"] || 'production').to_s.freeze
10
+
11
+ def env
12
+ LOGSTASH_ENV
13
+ end
14
+
15
+ def production?
16
+ env.downcase == "production"
17
+ end
18
+
19
+ def development?
20
+ env.downcase == "development"
21
+ end
22
+
23
+ def test?
24
+ env.downcase == "test"
25
+ end
26
+
27
+ def runtime_jars_root(dir_name, package)
28
+ ::File.join(dir_name, package, "runtime-jars")
29
+ end
30
+
31
+ def test_jars_root(dir_name, package)
32
+ ::File.join(dir_name, package, "test-jars")
33
+ end
34
+
35
+ def load_runtime_jars!(dir_name="vendor", package="jar-dependencies")
36
+ load_jars!(::File.join(runtime_jars_root(dir_name, package), "*.jar"))
37
+ end
38
+
39
+ def load_test_jars!(dir_name="vendor", package="jar-dependencies")
40
+ load_jars!(::File.join(test_jars_root(dir_name, package), "*.jar"))
41
+ end
42
+
43
+ def load_jars!(pattern)
44
+ raise(LogStash::EnvironmentError, I18n.t("logstash.environment.jruby-required")) unless LogStash::Environment.jruby?
45
+
46
+ jar_files = find_jars(pattern)
47
+ require_jars! jar_files
48
+ end
49
+
50
+ def find_jars(pattern)
51
+ require 'java'
52
+ jar_files = Dir.glob(pattern)
53
+ raise(LogStash::EnvironmentError, I18n.t("logstash.environment.missing-jars", :pattern => pattern)) if jar_files.empty?
54
+ jar_files
55
+ end
56
+
57
+ def require_jars!(files)
58
+ files.each do |jar_file|
59
+ loaded = require jar_file
60
+ puts("Loaded #{jar_file}") if $DEBUG && loaded
61
+ end
62
+ end
63
+
64
+ def ruby_bin
65
+ ENV["USE_RUBY"] == "1" ? "ruby" : File.join("vendor", "jruby", "bin", "jruby")
66
+ end
67
+
68
+ def jruby?
69
+ @jruby ||= !!(RUBY_PLATFORM == "java")
70
+ end
71
+
72
+ def windows?
73
+ ::Gem.win_platform?
74
+ end
75
+
76
+ def locales_path(path)
77
+ return ::File.join(LOGSTASH_CORE, "locales", path)
78
+ end
79
+
80
+ def load_locale!
81
+ require "i18n"
82
+ I18n.enforce_available_locales = true
83
+ I18n.load_path << LogStash::Environment.locales_path("en.yml")
84
+ I18n.reload!
85
+ fail "No locale? This is a bug." if I18n.available_locales.empty?
86
+ end
87
+
88
+ # add path for bare/ungemified plugins lookups. the path must be the base path that will include
89
+ # the dir structure 'logstash/TYPE/NAME.rb' where TYPE is 'inputs' 'filters', 'outputs' or 'codecs'
90
+ # and NAME is the name of the plugin
91
+ # @param path [String] plugins path to add
92
+ def add_plugin_path(path)
93
+ $LOAD_PATH << path
94
+ end
95
+ end
96
+ end
97
+
98
+ require "logstash/patches"
@@ -0,0 +1,12 @@
1
+ # encoding: utf-8
2
+ module LogStash
3
+ class Error < ::StandardError; end
4
+ class EnvironmentError < Error; end
5
+ class ConfigurationError < Error; end
6
+ class PluginLoadingError < Error; end
7
+ class ShutdownSignal < StandardError; end
8
+ class PluginNoVersionError < Error; end
9
+
10
+ class Bug < Error; end
11
+ class ThisMethodWasRemoved < Bug; end
12
+ end
@@ -0,0 +1,205 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+ require "logstash/event"
4
+ require "logstash/logging"
5
+ require "logstash/plugin"
6
+ require "logstash/config/mixin"
7
+ require "logstash/util/decorators"
8
+
9
+ class LogStash::Filters::Base < LogStash::Plugin
10
+ include LogStash::Config::Mixin
11
+
12
+ config_name "filter"
13
+
14
+ config :type, :validate => :string, :default => "", :obsolete => "You can achieve this same behavior with the new conditionals, like: `if [type] == \"sometype\" { %PLUGIN% { ... } }`."
15
+
16
+ config :tags, :validate => :array, :default => [], :obsolete => "You can achieve similar behavior with the new conditionals, like: `if \"sometag\" in [tags] { %PLUGIN% { ... } }`"
17
+
18
+ config :exclude_tags, :validate => :array, :default => [], :obsolete => "You can achieve similar behavior with the new conditionals, like: `if (\"sometag\" not in [tags]) { %PLUGIN% { ... } }`"
19
+
20
+ # If this filter is successful, add arbitrary tags to the event.
21
+ # Tags can be dynamic and include parts of the event using the `%{field}`
22
+ # syntax.
23
+ #
24
+ # Example:
25
+ # [source,ruby]
26
+ # filter {
27
+ # %PLUGIN% {
28
+ # add_tag => [ "foo_%{somefield}" ]
29
+ # }
30
+ # }
31
+ # [source,ruby]
32
+ # # You can also add multiple tags at once:
33
+ # filter {
34
+ # %PLUGIN% {
35
+ # add_tag => [ "foo_%{somefield}", "taggedy_tag"]
36
+ # }
37
+ # }
38
+ #
39
+ # If the event has field `"somefield" == "hello"` this filter, on success,
40
+ # would add a tag `foo_hello` (and the second example would of course add a `taggedy_tag` tag).
41
+ config :add_tag, :validate => :array, :default => []
42
+
43
+ # If this filter is successful, remove arbitrary tags from the event.
44
+ # Tags can be dynamic and include parts of the event using the `%{field}`
45
+ # syntax.
46
+ #
47
+ # Example:
48
+ # [source,ruby]
49
+ # filter {
50
+ # %PLUGIN% {
51
+ # remove_tag => [ "foo_%{somefield}" ]
52
+ # }
53
+ # }
54
+ # [source,ruby]
55
+ # # You can also remove multiple tags at once:
56
+ # filter {
57
+ # %PLUGIN% {
58
+ # remove_tag => [ "foo_%{somefield}", "sad_unwanted_tag"]
59
+ # }
60
+ # }
61
+ #
62
+ # If the event has field `"somefield" == "hello"` this filter, on success,
63
+ # would remove the tag `foo_hello` if it is present. The second example
64
+ # would remove a sad, unwanted tag as well.
65
+ config :remove_tag, :validate => :array, :default => []
66
+
67
+ # If this filter is successful, add any arbitrary fields to this event.
68
+ # Field names can be dynamic and include parts of the event using the `%{field}`.
69
+ #
70
+ # Example:
71
+ # [source,ruby]
72
+ # filter {
73
+ # %PLUGIN% {
74
+ # add_field => { "foo_%{somefield}" => "Hello world, from %{host}" }
75
+ # }
76
+ # }
77
+ # [source,ruby]
78
+ # # You can also add multiple fields at once:
79
+ # filter {
80
+ # %PLUGIN% {
81
+ # add_field => {
82
+ # "foo_%{somefield}" => "Hello world, from %{host}"
83
+ # "new_field" => "new_static_value"
84
+ # }
85
+ # }
86
+ # }
87
+ #
88
+ # If the event has field `"somefield" == "hello"` this filter, on success,
89
+ # would add field `foo_hello` if it is present, with the
90
+ # value above and the `%{host}` piece replaced with that value from the
91
+ # event. The second example would also add a hardcoded field.
92
+ config :add_field, :validate => :hash, :default => {}
93
+
94
+ # If this filter is successful, remove arbitrary fields from this event.
95
+ # Fields names can be dynamic and include parts of the event using the %{field}
96
+ # Example:
97
+ # [source,ruby]
98
+ # filter {
99
+ # %PLUGIN% {
100
+ # remove_field => [ "foo_%{somefield}" ]
101
+ # }
102
+ # }
103
+ # [source,ruby]
104
+ # # You can also remove multiple fields at once:
105
+ # filter {
106
+ # %PLUGIN% {
107
+ # remove_field => [ "foo_%{somefield}", "my_extraneous_field" ]
108
+ # }
109
+ # }
110
+ #
111
+ # If the event has field `"somefield" == "hello"` this filter, on success,
112
+ # would remove the field with name `foo_hello` if it is present. The second
113
+ # example would remove an additional, non-dynamic field.
114
+ config :remove_field, :validate => :array, :default => []
115
+
116
+ # Call the filter flush method at regular interval.
117
+ # Optional.
118
+ config :periodic_flush, :validate => :boolean, :default => false
119
+
120
+ public
121
+ def initialize(params)
122
+ super
123
+ config_init(@params)
124
+ @threadsafe = true
125
+ end # def initialize
126
+
127
+ public
128
+ def register
129
+ raise "#{self.class}#register must be overidden"
130
+ end # def register
131
+
132
+ public
133
+ def filter(event)
134
+ raise "#{self.class}#filter must be overidden"
135
+ end # def filter
136
+
137
+ # in 1.5.0 multi_filter is meant to be used in the generated filter function in LogStash::Config::AST::Plugin only
138
+ # and is temporary until we refactor the filter method interface to accept events list and return events list,
139
+ # just list in multi_filter see https://github.com/elastic/logstash/issues/2872.
140
+ # refactoring the filter method will mean updating all plugins which we want to avoid doing for 1.5.0.
141
+ #
142
+ # @param events [Array<LogStash::Event] list of events to filter
143
+ # @return [Array<LogStash::Event] filtered events and any new events generated by the filter
144
+ public
145
+ def multi_filter(events)
146
+ LogStash::Util.set_thread_plugin(self)
147
+ result = []
148
+ events.each do |event|
149
+ unless event.cancelled?
150
+ result << event
151
+ filter(event){|new_event| result << new_event}
152
+ end
153
+ end
154
+ result
155
+ end
156
+
157
+ public
158
+ def execute(event, &block)
159
+ filter(event, &block)
160
+ end # def execute
161
+
162
+ public
163
+ def threadsafe?
164
+ @threadsafe
165
+ end
166
+
167
+ # a filter instance should call filter_matched from filter if the event
168
+ # matches the filter's conditions (right type, etc)
169
+ protected
170
+ def filter_matched(event)
171
+ LogStash::Util::Decorators.add_fields(@add_field,event,"filters/#{self.class.name}")
172
+
173
+ @remove_field.each do |field|
174
+ field = event.sprintf(field)
175
+ @logger.debug? and @logger.debug("filters/#{self.class.name}: removing field",
176
+ :field => field)
177
+ event.remove(field)
178
+ end
179
+
180
+ LogStash::Util::Decorators.add_tags(@add_tag,event,"filters/#{self.class.name}")
181
+
182
+ # note below that the tags array field needs to be updated then reassigned to the event.
183
+ # this is important because a construct like event["tags"].delete(tag) will not work
184
+ # in the current Java event implementation. see https://github.com/elastic/logstash/issues/4140
185
+ @remove_tag.each do |tag|
186
+ tags = event["tags"]
187
+ break if tags.nil? || tags.empty?
188
+ tag = event.sprintf(tag)
189
+ @logger.debug? and @logger.debug("filters/#{self.class.name}: removing tag", :tag => tag)
190
+ tags.delete(tag)
191
+ event["tags"] = tags
192
+ end
193
+ end # def filter_matched
194
+
195
+ protected
196
+ def filter?(event)
197
+ # TODO: noop for now, remove this once we delete this call from all plugins
198
+ true
199
+ end # def filter?
200
+
201
+ public
202
+ def close
203
+ # Nothing to do by default.
204
+ end
205
+ end # class LogStash::Filters::Base
@@ -0,0 +1,116 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+ require "logstash/event"
4
+ require "logstash/plugin"
5
+ require "logstash/logging"
6
+ require "logstash/config/mixin"
7
+ require "logstash/codecs/base"
8
+ require "logstash/util/decorators"
9
+
10
+ # This is the base class for Logstash inputs.
11
+ class LogStash::Inputs::Base < LogStash::Plugin
12
+ include LogStash::Config::Mixin
13
+ config_name "input"
14
+
15
+ # Add a `type` field to all events handled by this input.
16
+ #
17
+ # Types are used mainly for filter activation.
18
+ #
19
+ # The type is stored as part of the event itself, so you can
20
+ # also use the type to search for it in Kibana.
21
+ #
22
+ # If you try to set a type on an event that already has one (for
23
+ # example when you send an event from a shipper to an indexer) then
24
+ # a new input will not override the existing type. A type set at
25
+ # the shipper stays with that event for its life even
26
+ # when sent to another Logstash server.
27
+ config :type, :validate => :string
28
+
29
+ config :debug, :validate => :boolean, :default => false, :obsolete => "This setting no longer has any effect. In past releases, it existed, but almost no plugin made use of it."
30
+
31
+ config :format, :validate => ["plain", "json", "json_event", "msgpack_event"], :obsolete => "You should use the newer 'codec' setting instead."
32
+
33
+ config :charset, :obsolete => "Use the codec setting instead. For example: input { %PLUGIN% { codec => plain { charset => \"UTF-8\" } }"
34
+
35
+ config :message_format, :validate => :string, :obsolete => "Setting is no longer valid."
36
+
37
+ # The codec used for input data. Input codecs are a convenient method for decoding your data before it enters the input, without needing a separate filter in your Logstash pipeline.
38
+ config :codec, :validate => :codec, :default => "plain"
39
+
40
+ # Add any number of arbitrary tags to your event.
41
+ #
42
+ # This can help with processing later.
43
+ config :tags, :validate => :array
44
+
45
+ # Add a field to an event
46
+ config :add_field, :validate => :hash, :default => {}
47
+
48
+ attr_accessor :params
49
+ attr_accessor :threadable
50
+
51
+ public
52
+ def initialize(params={})
53
+ super
54
+ @threadable = false
55
+ @stop_called = Concurrent::AtomicBoolean.new(false)
56
+ config_init(@params)
57
+ @tags ||= []
58
+ end # def initialize
59
+
60
+ public
61
+ def register
62
+ raise "#{self.class}#register must be overidden"
63
+ end # def register
64
+
65
+ public
66
+ def tag(newtag)
67
+ @tags << newtag
68
+ end # def tag
69
+
70
+ public
71
+ # override stop if you need to do more than do_stop to
72
+ # enforce the input plugin to return from `run`.
73
+ # e.g. a tcp plugin might need to close the tcp socket
74
+ # so blocking read operation aborts
75
+ def stop
76
+ # override if necessary
77
+ end
78
+
79
+ public
80
+ def do_stop
81
+ @logger.debug("stopping", :plugin => self)
82
+ @stop_called.make_true
83
+ stop
84
+ end
85
+
86
+ # stop? should never be overriden
87
+ public
88
+ def stop?
89
+ @stop_called.value
90
+ end
91
+
92
+ protected
93
+ def decorate(event)
94
+ # Only set 'type' if not already set. This is backwards-compatible behavior
95
+ event["type"] = @type if @type && !event.include?("type")
96
+
97
+ LogStash::Util::Decorators.add_fields(@add_field,event,"inputs/#{self.class.name}")
98
+ LogStash::Util::Decorators.add_tags(@tags,event,"inputs/#{self.class.name}")
99
+ end
100
+
101
+ protected
102
+ def fix_streaming_codecs
103
+ require "logstash/codecs/plain"
104
+ require "logstash/codecs/line"
105
+ require "logstash/codecs/json"
106
+ require "logstash/codecs/json_lines"
107
+ case @codec
108
+ when LogStash::Codecs::Plain
109
+ @logger.info("Automatically switching from #{@codec.class.config_name} to line codec", :plugin => self.class.config_name)
110
+ @codec = LogStash::Codecs::Line.new("charset" => @codec.charset)
111
+ when LogStash::Codecs::JSON
112
+ @logger.info("Automatically switching from #{@codec.class.config_name} to json_lines codec", :plugin => self.class.config_name)
113
+ @codec = LogStash::Codecs::JSONLines.new("charset" => @codec.charset)
114
+ end
115
+ end
116
+ end # class LogStash::Inputs::Base
@@ -0,0 +1,18 @@
1
+ # encoding: utf-8
2
+ require "logstash/namespace"
3
+ require "logstash/inputs/base"
4
+
5
+ # This is the threadable class for logstash inputs.
6
+ # Use this class in your inputs if it can support multiple threads
7
+ class LogStash::Inputs::Threadable < LogStash::Inputs::Base
8
+
9
+ # Set this to the number of threads you want this input to spawn.
10
+ # This is the same as declaring the input multiple times
11
+ config :threads, :validate => :number, :default => 1
12
+
13
+ def initialize(params)
14
+ super
15
+ @threadable = true
16
+ end
17
+
18
+ end # class LogStash::Inputs::Threadable