logstash-core 2.1.3-java → 2.2.0-java

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 (71) hide show
  1. checksums.yaml +4 -4
  2. data/lib/logstash-core.rb +1 -3
  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 +48 -20
  6. data/lib/logstash/codecs/base.rb +2 -2
  7. data/lib/logstash/config/config_ast.rb +8 -3
  8. data/lib/logstash/environment.rb +0 -16
  9. data/lib/logstash/filters/base.rb +9 -5
  10. data/lib/logstash/inputs/base.rb +1 -1
  11. data/lib/logstash/output_delegator.rb +150 -0
  12. data/lib/logstash/outputs/base.rb +37 -40
  13. data/lib/logstash/pipeline.rb +259 -178
  14. data/lib/logstash/pipeline_reporter.rb +114 -0
  15. data/lib/logstash/plugin.rb +1 -1
  16. data/lib/logstash/{shutdown_controller.rb → shutdown_watcher.rb} +10 -37
  17. data/lib/logstash/util.rb +17 -0
  18. data/lib/logstash/util/decorators.rb +14 -7
  19. data/lib/logstash/util/worker_threads_default_printer.rb +4 -4
  20. data/lib/logstash/util/wrapped_synchronous_queue.rb +41 -0
  21. data/lib/logstash/version.rb +10 -2
  22. data/locales/en.yml +8 -3
  23. data/logstash-core.gemspec +5 -3
  24. data/spec/{core/conditionals_spec.rb → conditionals_spec.rb} +0 -0
  25. data/spec/{core/config_spec.rb → logstash/config/config_ast_spec.rb} +0 -0
  26. data/spec/{core/config_cpu_core_strategy_spec.rb → logstash/config/cpu_core_strategy_spec.rb} +0 -0
  27. data/spec/{core/config_defaults_spec.rb → logstash/config/defaults_spec.rb} +0 -0
  28. data/spec/{core/config_mixin_spec.rb → logstash/config/mixin_spec.rb} +0 -0
  29. data/spec/{core → logstash}/environment_spec.rb +0 -0
  30. data/spec/{filters → logstash/filters}/base_spec.rb +0 -0
  31. data/spec/{inputs → logstash/inputs}/base_spec.rb +0 -0
  32. data/spec/{lib/logstash → logstash}/java_integration_spec.rb +0 -0
  33. data/spec/{util → logstash}/json_spec.rb +0 -0
  34. data/spec/logstash/output_delegator_spec.rb +126 -0
  35. data/spec/logstash/outputs/base_spec.rb +40 -0
  36. data/spec/logstash/pipeline_reporter_spec.rb +85 -0
  37. data/spec/{core → logstash}/pipeline_spec.rb +128 -16
  38. data/spec/{core → logstash}/plugin_spec.rb +47 -1
  39. data/spec/logstash/runner_spec.rb +68 -0
  40. data/spec/{core/shutdown_controller_spec.rb → logstash/shutdown_watcher_spec.rb} +17 -11
  41. data/spec/{util → logstash/util}/buftok_spec.rb +0 -0
  42. data/spec/{util → logstash/util}/charset_spec.rb +0 -0
  43. data/spec/{util → logstash/util}/defaults_printer_spec.rb +4 -4
  44. data/spec/{util → logstash/util}/java_version_spec.rb +0 -0
  45. data/spec/{util → logstash/util}/plugin_version_spec.rb +0 -0
  46. data/spec/{util → logstash/util}/unicode_trimmer_spec.rb +0 -0
  47. data/spec/{util → logstash/util}/worker_threads_default_printer_spec.rb +8 -8
  48. data/spec/logstash/util/wrapped_synchronous_queue_spec.rb +28 -0
  49. data/spec/{util_spec.rb → logstash/util_spec.rb} +0 -0
  50. metadata +74 -81
  51. data/lib/logstash/event.rb +0 -275
  52. data/lib/logstash/patches/bundler.rb +0 -36
  53. data/lib/logstash/sized_queue.rb +0 -8
  54. data/lib/logstash/string_interpolation.rb +0 -140
  55. data/lib/logstash/timestamp.rb +0 -97
  56. data/lib/logstash/util/accessors.rb +0 -123
  57. data/spec/core/event_spec.rb +0 -518
  58. data/spec/core/runner_spec.rb +0 -40
  59. data/spec/core/timestamp_spec.rb +0 -84
  60. data/spec/coverage_helper.rb +0 -24
  61. data/spec/lib/logstash/bundler_spec.rb +0 -121
  62. data/spec/license_spec.rb +0 -67
  63. data/spec/outputs/base_spec.rb +0 -26
  64. data/spec/plugin_manager/install_spec.rb +0 -28
  65. data/spec/plugin_manager/update_spec.rb +0 -39
  66. data/spec/plugin_manager/util_spec.rb +0 -71
  67. data/spec/spec_helper.rb +0 -11
  68. data/spec/util/accessors_spec.rb +0 -170
  69. data/spec/util/compress_spec.rb +0 -121
  70. data/spec/util/gemfile_spec.rb +0 -212
  71. data/spec/util/retryable_spec.rb +0 -139
@@ -1,17 +1,23 @@
1
1
  # encoding: utf-8
2
2
  require "spec_helper"
3
- require "logstash/shutdown_controller"
3
+ require "logstash/shutdown_watcher"
4
4
 
5
- describe LogStash::ShutdownController do
5
+ describe LogStash::ShutdownWatcher do
6
6
 
7
7
  let(:check_every) { 0.01 }
8
8
  let(:check_threshold) { 100 }
9
- subject { LogStash::ShutdownController.new(pipeline, check_every) }
9
+ subject { LogStash::ShutdownWatcher.new(pipeline, check_every) }
10
10
  let(:pipeline) { double("pipeline") }
11
+ let(:reporter) { double("reporter") }
12
+ let(:reporter_snapshot) { double("reporter snapshot") }
11
13
  report_count = 0
12
14
 
13
15
  before :each do
14
- allow(LogStash::Report).to receive(:from_pipeline).and_wrap_original do |m, *args|
16
+ allow(pipeline).to receive(:reporter).and_return(reporter)
17
+ allow(reporter).to receive(:snapshot).and_return(reporter_snapshot)
18
+ allow(reporter_snapshot).to receive(:o_simple_hash).and_return({})
19
+
20
+ allow(subject).to receive(:pipeline_report_snapshot).and_wrap_original do |m, *args|
15
21
  report_count += 1
16
22
  m.call(*args)
17
23
  end
@@ -22,10 +28,10 @@ describe LogStash::ShutdownController do
22
28
  end
23
29
 
24
30
  context "when pipeline is stalled" do
25
- let(:increasing_count) { (1..5000).to_a.map {|i| { "total" => i } } }
31
+ let(:increasing_count) { (1..5000).to_a }
26
32
  before :each do
27
- allow(pipeline).to receive(:inflight_count).and_return(*increasing_count)
28
- allow(pipeline).to receive(:stalling_threads) { { } }
33
+ allow(reporter_snapshot).to receive(:inflight_count).and_return(*increasing_count)
34
+ allow(reporter_snapshot).to receive(:stalling_threads) { { } }
29
35
  end
30
36
 
31
37
  describe ".unsafe_shutdown = true" do
@@ -49,7 +55,7 @@ describe LogStash::ShutdownController do
49
55
 
50
56
  it "should do exactly \"abort_threshold\"*\"report_every\" stall checks" do
51
57
  allow(subject).to receive(:force_exit)
52
- expect(LogStash::Report).to receive(:from_pipeline).exactly(abort_threshold*report_every).times.and_call_original
58
+ expect(subject).to receive(:pipeline_report_snapshot).exactly(abort_threshold*report_every).times.and_call_original
53
59
  subject.start
54
60
  end
55
61
  end
@@ -70,10 +76,10 @@ describe LogStash::ShutdownController do
70
76
  end
71
77
 
72
78
  context "when pipeline is not stalled" do
73
- let(:decreasing_count) { (1..5000).to_a.reverse.map {|i| { "total" => i } } }
79
+ let(:decreasing_count) { (1..5000).to_a.reverse }
74
80
  before :each do
75
- allow(pipeline).to receive(:inflight_count).and_return(*decreasing_count)
76
- allow(pipeline).to receive(:stalling_threads) { { } }
81
+ allow(reporter_snapshot).to receive(:inflight_count).and_return(*decreasing_count)
82
+ allow(reporter_snapshot).to receive(:stalling_threads) { { } }
77
83
  end
78
84
 
79
85
  describe ".unsafe_shutdown = true" do
@@ -10,7 +10,7 @@ describe LogStash::Util::DefaultsPrinter do
10
10
  end
11
11
 
12
12
  let(:workers) { 1 }
13
- let(:expected) { "Settings: User set filter workers: #{workers}" }
13
+ let(:expected) { "Settings: User set pipeline workers: #{workers}" }
14
14
  let(:settings) { {} }
15
15
 
16
16
  describe 'class methods API' do
@@ -24,8 +24,8 @@ describe LogStash::Util::DefaultsPrinter do
24
24
  end
25
25
 
26
26
  context 'when the settings hash has content' do
27
- let(:workers) { 42 }
28
- let(:settings) { {'filter-workers' => workers} }
27
+ let(:worker_queue) { 42 }
28
+ let(:settings) { {:pipeline_workers => workers} }
29
29
  it_behaves_like "a defaults printer"
30
30
  end
31
31
  end
@@ -42,7 +42,7 @@ describe LogStash::Util::DefaultsPrinter do
42
42
 
43
43
  context 'when the settings hash has content' do
44
44
  let(:workers) { 13 }
45
- let(:settings) { {'filter-workers' => workers} }
45
+ let(:settings) { {:pipeline_workers => workers} }
46
46
 
47
47
  it_behaves_like "a defaults printer"
48
48
  end
@@ -19,26 +19,26 @@ describe LogStash::Util::WorkerThreadsDefaultPrinter do
19
19
  end
20
20
 
21
21
  context 'when the settings hash has both user and default content' do
22
- let(:settings) { {'filter-workers' => 42, 'default-filter-workers' => 5} }
22
+ let(:settings) { {:pipeline_workers => 42, :default_pipeline_workers => 5} }
23
23
 
24
24
  it 'adds two strings' do
25
- expect(collector).to eq(["User set filter workers: 42", "Default filter workers: 5"])
25
+ expect(collector).to eq(["User set pipeline workers: 42", "Default pipeline workers: 5"])
26
26
  end
27
27
  end
28
28
 
29
29
  context 'when the settings hash has only user content' do
30
- let(:settings) { {'filter-workers' => 42} }
30
+ let(:settings) { {:pipeline_workers => 42} }
31
31
 
32
- it 'adds a string with user set filter workers' do
33
- expect(collector.first).to eq("User set filter workers: 42")
32
+ it 'adds a string with user set pipeline workers' do
33
+ expect(collector.first).to eq("User set pipeline workers: 42")
34
34
  end
35
35
  end
36
36
 
37
37
  context 'when the settings hash has only default content' do
38
- let(:settings) { {'default-filter-workers' => 5} }
38
+ let(:settings) { {:default_pipeline_workers => 5} }
39
39
 
40
- it 'adds a string with default filter workers' do
41
- expect(collector.first).to eq("Default filter workers: 5")
40
+ it 'adds a string with default pipeline workers' do
41
+ expect(collector.first).to eq("Default pipeline workers: 5")
42
42
  end
43
43
  end
44
44
  end
@@ -0,0 +1,28 @@
1
+ # encoding: utf-8
2
+ require "spec_helper"
3
+ require "logstash/util/wrapped_synchronous_queue"
4
+
5
+ describe LogStash::Util::WrappedSynchronousQueue do
6
+ context "#offer" do
7
+ context "queue is blocked" do
8
+ it "fails and give feedback" do
9
+ expect(subject.offer("Bonjour", 2)).to be_falsey
10
+ end
11
+ end
12
+
13
+ context "queue is not blocked" do
14
+ before do
15
+ @consumer = Thread.new { loop { subject.take } }
16
+ sleep(0.1)
17
+ end
18
+
19
+ after do
20
+ @consumer.kill
21
+ end
22
+
23
+ it "inserts successfully" do
24
+ expect(subject.offer("Bonjour", 20)).to be_truthy
25
+ end
26
+ end
27
+ end
28
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: logstash-core
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.3
4
+ version: 2.2.0
5
5
  platform: java
6
6
  authors:
7
7
  - Jordan Sissel
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2016-02-16 00:00:00.000000000 Z
13
+ date: 2016-02-01 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ requirement: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - ~>
19
+ - !ruby/object:Gem::Version
20
+ version: 2.2.0
21
+ name: logstash-core-event
22
+ prerelease: false
23
+ type: :runtime
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ~>
27
+ - !ruby/object:Gem::Version
28
+ version: 2.2.0
15
29
  - !ruby/object:Gem::Dependency
16
30
  requirement: !ruby/object:Gem::Requirement
17
31
  requirements:
@@ -218,6 +232,8 @@ extensions: []
218
232
  extra_rdoc_files: []
219
233
  files:
220
234
  - lib/logstash-core.rb
235
+ - lib/logstash-core/logstash-core.rb
236
+ - lib/logstash-core/version.rb
221
237
  - lib/logstash/agent.rb
222
238
  - lib/logstash/codecs/base.rb
223
239
  - lib/logstash/config/config_ast.rb
@@ -229,7 +245,6 @@ files:
229
245
  - lib/logstash/config/registry.rb
230
246
  - lib/logstash/environment.rb
231
247
  - lib/logstash/errors.rb
232
- - lib/logstash/event.rb
233
248
  - lib/logstash/filters/base.rb
234
249
  - lib/logstash/inputs/base.rb
235
250
  - lib/logstash/inputs/threadable.rb
@@ -237,24 +252,21 @@ files:
237
252
  - lib/logstash/json.rb
238
253
  - lib/logstash/logging.rb
239
254
  - lib/logstash/namespace.rb
255
+ - lib/logstash/output_delegator.rb
240
256
  - lib/logstash/outputs/base.rb
241
257
  - lib/logstash/patches.rb
242
258
  - lib/logstash/patches/bugfix_jruby_2558.rb
243
- - lib/logstash/patches/bundler.rb
244
259
  - lib/logstash/patches/cabin.rb
245
260
  - lib/logstash/patches/profile_require_calls.rb
246
261
  - lib/logstash/patches/rubygems.rb
247
262
  - lib/logstash/patches/stronger_openssl_defaults.rb
248
263
  - lib/logstash/pipeline.rb
264
+ - lib/logstash/pipeline_reporter.rb
249
265
  - lib/logstash/plugin.rb
250
266
  - lib/logstash/program.rb
251
267
  - lib/logstash/runner.rb
252
- - lib/logstash/shutdown_controller.rb
253
- - lib/logstash/sized_queue.rb
254
- - lib/logstash/string_interpolation.rb
255
- - lib/logstash/timestamp.rb
268
+ - lib/logstash/shutdown_watcher.rb
256
269
  - lib/logstash/util.rb
257
- - lib/logstash/util/accessors.rb
258
270
  - lib/logstash/util/buftok.rb
259
271
  - lib/logstash/util/charset.rb
260
272
  - lib/logstash/util/decorators.rb
@@ -268,47 +280,38 @@ files:
268
280
  - lib/logstash/util/socket_peer.rb
269
281
  - lib/logstash/util/unicode_trimmer.rb
270
282
  - lib/logstash/util/worker_threads_default_printer.rb
283
+ - lib/logstash/util/wrapped_synchronous_queue.rb
271
284
  - lib/logstash/version.rb
272
285
  - locales/en.yml
273
286
  - logstash-core.gemspec
274
- - spec/core/conditionals_spec.rb
275
- - spec/core/config_cpu_core_strategy_spec.rb
276
- - spec/core/config_defaults_spec.rb
277
- - spec/core/config_mixin_spec.rb
278
- - spec/core/config_spec.rb
279
- - spec/core/environment_spec.rb
280
- - spec/core/event_spec.rb
281
- - spec/core/pipeline_spec.rb
282
- - spec/core/plugin_spec.rb
283
- - spec/core/runner_spec.rb
284
- - spec/core/shutdown_controller_spec.rb
285
- - spec/core/timestamp_spec.rb
286
- - spec/coverage_helper.rb
287
- - spec/filters/base_spec.rb
288
- - spec/inputs/base_spec.rb
289
- - spec/lib/logstash/bundler_spec.rb
290
- - spec/lib/logstash/java_integration_spec.rb
291
- - spec/license_spec.rb
287
+ - spec/conditionals_spec.rb
292
288
  - spec/logstash/agent_spec.rb
289
+ - spec/logstash/config/config_ast_spec.rb
290
+ - spec/logstash/config/cpu_core_strategy_spec.rb
291
+ - spec/logstash/config/defaults_spec.rb
292
+ - spec/logstash/config/mixin_spec.rb
293
+ - spec/logstash/environment_spec.rb
294
+ - spec/logstash/filters/base_spec.rb
295
+ - spec/logstash/inputs/base_spec.rb
296
+ - spec/logstash/java_integration_spec.rb
297
+ - spec/logstash/json_spec.rb
298
+ - spec/logstash/output_delegator_spec.rb
299
+ - spec/logstash/outputs/base_spec.rb
293
300
  - spec/logstash/patches_spec.rb
294
- - spec/outputs/base_spec.rb
295
- - spec/plugin_manager/install_spec.rb
296
- - spec/plugin_manager/update_spec.rb
297
- - spec/plugin_manager/util_spec.rb
298
- - spec/spec_helper.rb
299
- - spec/util/accessors_spec.rb
300
- - spec/util/buftok_spec.rb
301
- - spec/util/charset_spec.rb
302
- - spec/util/compress_spec.rb
303
- - spec/util/defaults_printer_spec.rb
304
- - spec/util/gemfile_spec.rb
305
- - spec/util/java_version_spec.rb
306
- - spec/util/json_spec.rb
307
- - spec/util/plugin_version_spec.rb
308
- - spec/util/retryable_spec.rb
309
- - spec/util/unicode_trimmer_spec.rb
310
- - spec/util/worker_threads_default_printer_spec.rb
311
- - spec/util_spec.rb
301
+ - spec/logstash/pipeline_reporter_spec.rb
302
+ - spec/logstash/pipeline_spec.rb
303
+ - spec/logstash/plugin_spec.rb
304
+ - spec/logstash/runner_spec.rb
305
+ - spec/logstash/shutdown_watcher_spec.rb
306
+ - spec/logstash/util/buftok_spec.rb
307
+ - spec/logstash/util/charset_spec.rb
308
+ - spec/logstash/util/defaults_printer_spec.rb
309
+ - spec/logstash/util/java_version_spec.rb
310
+ - spec/logstash/util/plugin_version_spec.rb
311
+ - spec/logstash/util/unicode_trimmer_spec.rb
312
+ - spec/logstash/util/worker_threads_default_printer_spec.rb
313
+ - spec/logstash/util/wrapped_synchronous_queue_spec.rb
314
+ - spec/logstash/util_spec.rb
312
315
  homepage: http://www.elastic.co/guide/en/logstash/current/index.html
313
316
  licenses:
314
317
  - Apache License (2.0)
@@ -334,41 +337,31 @@ signing_key:
334
337
  specification_version: 4
335
338
  summary: logstash-core - The core components of logstash
336
339
  test_files:
337
- - spec/core/conditionals_spec.rb
338
- - spec/core/config_cpu_core_strategy_spec.rb
339
- - spec/core/config_defaults_spec.rb
340
- - spec/core/config_mixin_spec.rb
341
- - spec/core/config_spec.rb
342
- - spec/core/environment_spec.rb
343
- - spec/core/event_spec.rb
344
- - spec/core/pipeline_spec.rb
345
- - spec/core/plugin_spec.rb
346
- - spec/core/runner_spec.rb
347
- - spec/core/shutdown_controller_spec.rb
348
- - spec/core/timestamp_spec.rb
349
- - spec/coverage_helper.rb
350
- - spec/filters/base_spec.rb
351
- - spec/inputs/base_spec.rb
352
- - spec/lib/logstash/bundler_spec.rb
353
- - spec/lib/logstash/java_integration_spec.rb
354
- - spec/license_spec.rb
340
+ - spec/conditionals_spec.rb
355
341
  - spec/logstash/agent_spec.rb
342
+ - spec/logstash/config/config_ast_spec.rb
343
+ - spec/logstash/config/cpu_core_strategy_spec.rb
344
+ - spec/logstash/config/defaults_spec.rb
345
+ - spec/logstash/config/mixin_spec.rb
346
+ - spec/logstash/environment_spec.rb
347
+ - spec/logstash/filters/base_spec.rb
348
+ - spec/logstash/inputs/base_spec.rb
349
+ - spec/logstash/java_integration_spec.rb
350
+ - spec/logstash/json_spec.rb
351
+ - spec/logstash/output_delegator_spec.rb
352
+ - spec/logstash/outputs/base_spec.rb
356
353
  - spec/logstash/patches_spec.rb
357
- - spec/outputs/base_spec.rb
358
- - spec/plugin_manager/install_spec.rb
359
- - spec/plugin_manager/update_spec.rb
360
- - spec/plugin_manager/util_spec.rb
361
- - spec/spec_helper.rb
362
- - spec/util/accessors_spec.rb
363
- - spec/util/buftok_spec.rb
364
- - spec/util/charset_spec.rb
365
- - spec/util/compress_spec.rb
366
- - spec/util/defaults_printer_spec.rb
367
- - spec/util/gemfile_spec.rb
368
- - spec/util/java_version_spec.rb
369
- - spec/util/json_spec.rb
370
- - spec/util/plugin_version_spec.rb
371
- - spec/util/retryable_spec.rb
372
- - spec/util/unicode_trimmer_spec.rb
373
- - spec/util/worker_threads_default_printer_spec.rb
374
- - spec/util_spec.rb
354
+ - spec/logstash/pipeline_reporter_spec.rb
355
+ - spec/logstash/pipeline_spec.rb
356
+ - spec/logstash/plugin_spec.rb
357
+ - spec/logstash/runner_spec.rb
358
+ - spec/logstash/shutdown_watcher_spec.rb
359
+ - spec/logstash/util/buftok_spec.rb
360
+ - spec/logstash/util/charset_spec.rb
361
+ - spec/logstash/util/defaults_printer_spec.rb
362
+ - spec/logstash/util/java_version_spec.rb
363
+ - spec/logstash/util/plugin_version_spec.rb
364
+ - spec/logstash/util/unicode_trimmer_spec.rb
365
+ - spec/logstash/util/worker_threads_default_printer_spec.rb
366
+ - spec/logstash/util/wrapped_synchronous_queue_spec.rb
367
+ - spec/logstash/util_spec.rb
@@ -1,275 +0,0 @@
1
- # encoding: utf-8
2
- require "time"
3
- require "date"
4
- require "cabin"
5
- require "logstash/namespace"
6
- require "logstash/util/accessors"
7
- require "logstash/timestamp"
8
- require "logstash/json"
9
- require "logstash/string_interpolation"
10
-
11
- # transcient pipeline events for normal in-flow signaling as opposed to
12
- # flow altering exceptions. for now having base classes is adequate and
13
- # in the future it might be necessary to refactor using like a BaseEvent
14
- # class to have a common interface for all pileline events to support
15
- # eventual queueing persistence for example, TBD.
16
- class LogStash::ShutdownEvent; end
17
- class LogStash::FlushEvent; end
18
-
19
- module LogStash
20
- FLUSH = LogStash::FlushEvent.new
21
-
22
- # LogStash::SHUTDOWN is used by plugins
23
- SHUTDOWN = LogStash::ShutdownEvent.new
24
- end
25
-
26
- # the logstash event object.
27
- #
28
- # An event is simply a tuple of (timestamp, data).
29
- # The 'timestamp' is an ISO8601 timestamp. Data is anything - any message,
30
- # context, references, etc that are relevant to this event.
31
- #
32
- # Internally, this is represented as a hash with only two guaranteed fields.
33
- #
34
- # * "@timestamp" - an ISO8601 timestamp representing the time the event
35
- # occurred at.
36
- # * "@version" - the version of the schema. Currently "1"
37
- #
38
- # They are prefixed with an "@" symbol to avoid clashing with your
39
- # own custom fields.
40
- #
41
- # When serialized, this is represented in JSON. For example:
42
- #
43
- # {
44
- # "@timestamp": "2013-02-09T20:39:26.234Z",
45
- # "@version": "1",
46
- # message: "hello world"
47
- # }
48
- class LogStash::Event
49
- class DeprecatedMethod < StandardError; end
50
-
51
- CHAR_PLUS = "+"
52
- TIMESTAMP = "@timestamp"
53
- VERSION = "@version"
54
- VERSION_ONE = "1"
55
- TIMESTAMP_FAILURE_TAG = "_timestampparsefailure"
56
- TIMESTAMP_FAILURE_FIELD = "_@timestamp"
57
-
58
- METADATA = "@metadata".freeze
59
- METADATA_BRACKETS = "[#{METADATA}]".freeze
60
-
61
- # Floats outside of these upper and lower bounds are forcibly converted
62
- # to scientific notation by Float#to_s
63
- MIN_FLOAT_BEFORE_SCI_NOT = 0.0001
64
- MAX_FLOAT_BEFORE_SCI_NOT = 1000000000000000.0
65
-
66
- LOGGER = Cabin::Channel.get(LogStash)
67
-
68
- public
69
- def initialize(data = {})
70
- @cancelled = false
71
- @data = data
72
- @accessors = LogStash::Util::Accessors.new(data)
73
- @data[VERSION] ||= VERSION_ONE
74
- ts = @data[TIMESTAMP]
75
- @data[TIMESTAMP] = ts ? init_timestamp(ts) : LogStash::Timestamp.now
76
-
77
- @metadata = @data.delete(METADATA) || {}
78
- @metadata_accessors = LogStash::Util::Accessors.new(@metadata)
79
- end # def initialize
80
-
81
- public
82
- def cancel
83
- @cancelled = true
84
- end # def cancel
85
-
86
- public
87
- def uncancel
88
- @cancelled = false
89
- end # def uncancel
90
-
91
- public
92
- def cancelled?
93
- return @cancelled
94
- end # def cancelled?
95
-
96
- # Create a deep-ish copy of this event.
97
- public
98
- def clone
99
- copy = {}
100
- @data.each do |k,v|
101
- # TODO(sissel): Recurse if this is a hash/array?
102
- copy[k] = begin v.clone rescue v end
103
- end
104
- return self.class.new(copy)
105
- end # def clone
106
-
107
- public
108
- def to_s
109
- "#{timestamp.to_iso8601} #{self.sprintf("%{host} %{message}")}"
110
- end # def to_s
111
-
112
- public
113
- def timestamp; return @data[TIMESTAMP]; end # def timestamp
114
- def timestamp=(val); return @data[TIMESTAMP] = val; end # def timestamp=
115
-
116
- def unix_timestamp
117
- raise DeprecatedMethod
118
- end # def unix_timestamp
119
-
120
- def ruby_timestamp
121
- raise DeprecatedMethod
122
- end # def unix_timestamp
123
-
124
- public
125
- def [](fieldref)
126
- if fieldref.start_with?(METADATA_BRACKETS)
127
- @metadata_accessors.get(fieldref[METADATA_BRACKETS.length .. -1])
128
- elsif fieldref == METADATA
129
- @metadata
130
- else
131
- @accessors.get(fieldref)
132
- end
133
- end # def []
134
-
135
- public
136
- def []=(fieldref, value)
137
- if fieldref == TIMESTAMP && !value.is_a?(LogStash::Timestamp)
138
- raise TypeError, "The field '@timestamp' must be a (LogStash::Timestamp, not a #{value.class} (#{value})"
139
- end
140
- if fieldref.start_with?(METADATA_BRACKETS)
141
- @metadata_accessors.set(fieldref[METADATA_BRACKETS.length .. -1], value)
142
- elsif fieldref == METADATA
143
- @metadata = value
144
- @metadata_accessors = LogStash::Util::Accessors.new(@metadata)
145
- else
146
- @accessors.set(fieldref, value)
147
- end
148
- end # def []=
149
-
150
- public
151
- def fields
152
- raise DeprecatedMethod
153
- end
154
-
155
- public
156
- def to_json(*args)
157
- # ignore arguments to respect accepted to_json method signature
158
- LogStash::Json.dump(@data)
159
- end # def to_json
160
-
161
- public
162
- def to_hash
163
- @data
164
- end # def to_hash
165
-
166
- public
167
- def overwrite(event)
168
- # pickup new event @data and also pickup @accessors
169
- # otherwise it will be pointing on previous data
170
- @data = event.instance_variable_get(:@data)
171
- @accessors = event.instance_variable_get(:@accessors)
172
-
173
- #convert timestamp if it is a String
174
- if @data[TIMESTAMP].is_a?(String)
175
- @data[TIMESTAMP] = LogStash::Timestamp.parse_iso8601(@data[TIMESTAMP])
176
- end
177
- end
178
-
179
- public
180
- def include?(fieldref)
181
- if fieldref.start_with?(METADATA_BRACKETS)
182
- @metadata_accessors.include?(fieldref[METADATA_BRACKETS.length .. -1])
183
- elsif fieldref == METADATA
184
- true
185
- else
186
- @accessors.include?(fieldref)
187
- end
188
- end # def include?
189
-
190
- # Append an event to this one.
191
- public
192
- def append(event)
193
- # non-destructively merge that event with ourselves.
194
-
195
- # no need to reset @accessors here because merging will not disrupt any existing field paths
196
- # and if new ones are created they will be picked up.
197
- LogStash::Util.hash_merge(@data, event.to_hash)
198
- end # append
199
-
200
- # Remove a field or field reference. Returns the value of that field when
201
- # deleted
202
- public
203
- def remove(fieldref)
204
- @accessors.del(fieldref)
205
- end # def remove
206
-
207
- # sprintf. This could use a better method name.
208
- # The idea is to take an event and convert it to a string based on
209
- # any format values, delimited by %{foo} where 'foo' is a field or
210
- # metadata member.
211
- #
212
- # For example, if the event has type == "foo" and host == "bar"
213
- # then this string:
214
- # "type is %{type} and source is %{host}"
215
- # will return
216
- # "type is foo and source is bar"
217
- #
218
- # If a %{name} value is an array, then we will join by ','
219
- # If a %{name} value does not exist, then no substitution occurs.
220
- public
221
- def sprintf(format)
222
- LogStash::StringInterpolation.evaluate(self, format)
223
- end
224
-
225
- def tag(value)
226
- # Generalize this method for more usability
227
- self["tags"] ||= []
228
- self["tags"] << value unless self["tags"].include?(value)
229
- end
230
-
231
- private
232
-
233
- def init_timestamp(o)
234
- begin
235
- timestamp = LogStash::Timestamp.coerce(o)
236
- return timestamp if timestamp
237
-
238
- LOGGER.warn("Unrecognized #{TIMESTAMP} value, setting current time to #{TIMESTAMP}, original in #{TIMESTAMP_FAILURE_FIELD}field", :value => o.inspect)
239
- rescue LogStash::TimestampParserError => e
240
- LOGGER.warn("Error parsing #{TIMESTAMP} string, setting current time to #{TIMESTAMP}, original in #{TIMESTAMP_FAILURE_FIELD} field", :value => o.inspect, :exception => e.message)
241
- end
242
-
243
- @data["tags"] ||= []
244
- @data["tags"] << TIMESTAMP_FAILURE_TAG unless @data["tags"].include?(TIMESTAMP_FAILURE_TAG)
245
- @data[TIMESTAMP_FAILURE_FIELD] = o
246
-
247
- LogStash::Timestamp.now
248
- end
249
-
250
- public
251
- def to_hash_with_metadata
252
- @metadata.empty? ? to_hash : to_hash.merge(METADATA => @metadata)
253
- end
254
-
255
- public
256
- def to_json_with_metadata(*args)
257
- # ignore arguments to respect accepted to_json method signature
258
- LogStash::Json.dump(to_hash_with_metadata)
259
- end # def to_json
260
-
261
- def self.validate_value(value)
262
- case value
263
- when String
264
- raise("expected UTF-8 encoding for value=#{value}, encoding=#{value.encoding.inspect}") unless value.encoding == Encoding::UTF_8
265
- raise("invalid UTF-8 encoding for value=#{value}, encoding=#{value.encoding.inspect}") unless value.valid_encoding?
266
- value
267
- when Array
268
- value.each{|v| validate_value(v)} # don't map, return original object
269
- value
270
- else
271
- value
272
- end
273
- end
274
-
275
- end # class LogStash::Event