logstash-devutils 2.0.0-java → 2.4.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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +31 -3
- data/Gemfile +1 -0
- data/Rakefile +1 -0
- data/lib/logstash/devutils/rake/test.rake +17 -0
- data/lib/logstash/devutils/rake.rb +1 -0
- data/lib/logstash/devutils/rspec/logstash_helpers.rb +38 -10
- data/lib/logstash/devutils/rspec/shared_examples.rb +5 -2
- data/lib/logstash/devutils/rspec/spec_helper.rb +11 -2
- data/lib/logstash/outputs/test_sink.rb +21 -3
- data/lib/logstash/test_pipeline.rb +7 -1
- data/logstash-devutils.gemspec +2 -1
- metadata +18 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f6acb50f9d6e040af22acda0163ef38f8bce77506f023dd8a58a4ee925d9df3c
|
|
4
|
+
data.tar.gz: 51c47c93c93335ed8cba0e0349dc712808051e77ca69ca8f79617eaa9442731a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 8fa7d3f493f223e497c7877bfc9c6a9440a269367a02d7c6f468580f0ac6d4e6156600ba30fc2fcc831a27cef74a6e65cbfa7daebd29623042557b524a3423ff
|
|
7
|
+
data.tar.gz: a6530c6d9bd097ea6f081224a7ff6254e38f3d6abc400f3b4bbaca5cea7b354e4e37b60071755eef6d05bac2afce89601b53b72b4339ba15b97696dceb541cb1
|
data/CHANGELOG.md
CHANGED
|
@@ -1,17 +1,45 @@
|
|
|
1
|
+
## 2.4.0
|
|
2
|
+
- Feat: shared test (spec) task for all! [#96](https://github.com/elastic/logstash-devutils/pull/96)
|
|
3
|
+
|
|
4
|
+
## 2.3.0
|
|
5
|
+
- Introduce `be_a_logstash_timestamp_equivalent_to` RSpec matcher to compare LogStash::Timestamp [#99](https://github.com/elastic/logstash-devutils/pull/99)
|
|
6
|
+
|
|
7
|
+
## 2.2.1
|
|
8
|
+
- Fixed `LogStashHelpers#sample` to work with pipelines whose filters add, clone, and cancel events.
|
|
9
|
+
|
|
10
|
+
## 2.2.0
|
|
11
|
+
- Add `allowed_lag` config for shared input interruptiblity spec
|
|
12
|
+
|
|
13
|
+
## 2.1.0
|
|
14
|
+
- Remove ruby pipeline dependency
|
|
15
|
+
|
|
16
|
+
## 2.0.4
|
|
17
|
+
- Fix: avoid double registering filters on `sample` spec helper
|
|
18
|
+
|
|
19
|
+
## 2.0.3
|
|
20
|
+
- Fix: add missing `events` method to QueuedBatchDelegator, which was causing test failures
|
|
21
|
+
after https://github.com/elastic/logstash/pull/11737 was committed.
|
|
22
|
+
|
|
23
|
+
## 2.0.2
|
|
24
|
+
- Fix: add plain codec as runtime dependency for TestPipeline helper
|
|
25
|
+
|
|
26
|
+
## 2.0.1
|
|
27
|
+
- Fix: unwrap output and refactor test sink (#82)
|
|
28
|
+
|
|
1
29
|
## 2.0.0
|
|
2
30
|
- Reinvented helpers using Java pipeline, only LS >= 6.x (JRuby >= 9.1) is supported.
|
|
3
31
|
- [BREAKING] changes:
|
|
4
32
|
* `plugin_input` helper no longer works - simply fails with a not implemented error
|
|
5
33
|
* `type` and `tags` helpers have no effect - they will print a deprecation warning
|
|
6
|
-
* using gem **insist** is discouraged and has to be pulled in manually
|
|
34
|
+
* using gem **insist** is discouraged and has to be pulled in manually
|
|
7
35
|
(in *plugin.gemspec* `add_development_dependency 'insist'` and `require "insist"`)
|
|
8
36
|
* shared examples need to be explicitly required, as they are not re-used that much
|
|
9
37
|
(in spec_helper.rb `require "logstash/devutils/rspec/shared_examples"'`)
|
|
10
38
|
* `input` helper now yields a Queue-like collection (with `Queue#pop` blocking semantics)
|
|
11
|
-
with a default timeout polling mechanism to guard against potential dead-locks
|
|
39
|
+
with a default timeout polling mechanism to guard against potential dead-locks
|
|
12
40
|
|
|
13
41
|
## 1.3.6
|
|
14
|
-
- Revert the removal (e.g. add back) of the log4j spec helper. It is still needed for 5.x builds.
|
|
42
|
+
- Revert the removal (e.g. add back) of the log4j spec helper. It is still needed for 5.x builds.
|
|
15
43
|
|
|
16
44
|
## 1.3.5
|
|
17
45
|
- Fix spec helper method `input` generating an invalid `output_func` that returned `nil` instead of an array
|
data/Gemfile
CHANGED
data/Rakefile
CHANGED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
begin
|
|
2
|
+
require 'rspec/core/rake_task'
|
|
3
|
+
RSpec::Core::RakeTask.new(:spec) # default glob: 'spec/**{,/*/**}/*_spec.rb'
|
|
4
|
+
rescue LoadError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
desc "Run tests including Java tests (if any)"
|
|
8
|
+
task :test => [ 'test:java', 'test:ruby' ]
|
|
9
|
+
namespace :test do
|
|
10
|
+
task :java do
|
|
11
|
+
gradlew = File.join(Dir.pwd, 'gradlew')
|
|
12
|
+
sh "#{gradlew} --no-daemon test" if File.exist?(gradlew)
|
|
13
|
+
end
|
|
14
|
+
task :ruby => :vendor do
|
|
15
|
+
Rake::Task[:spec].invoke
|
|
16
|
+
end
|
|
17
|
+
end
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
require "logstash/agent"
|
|
2
2
|
require "logstash/event"
|
|
3
3
|
require "logstash/test_pipeline"
|
|
4
|
+
require "logstash/outputs/test_sink"
|
|
4
5
|
|
|
5
6
|
require "stud/try"
|
|
6
7
|
require "rspec/expectations"
|
|
@@ -52,11 +53,30 @@ module LogStashHelper
|
|
|
52
53
|
deprecated "tags(#{tags.inspect}) - let(:default_tags) are not used"
|
|
53
54
|
end
|
|
54
55
|
|
|
55
|
-
|
|
56
|
+
##
|
|
57
|
+
# Creates a single-example example group in the current rspec context to validate the results of filter operations.
|
|
58
|
+
# The current group is expected to use `LogStashHelpers#config` to provide a pipeline configuration.
|
|
59
|
+
#
|
|
60
|
+
# The provided block has access to an [Array] `results`, and also sets an unnamed `subject` that is either a
|
|
61
|
+
# single `LogStash::Event` or an `[Array[LogStash::Event]]` containing at least two entries.
|
|
62
|
+
#
|
|
63
|
+
# @param sample_event [String, #to_json]
|
|
64
|
+
# @param validation_source [:output, :queue]
|
|
65
|
+
# @yield creates an example with expectations provided by the block
|
|
66
|
+
# @return [void]
|
|
67
|
+
def sample(sample_event, validation_source: :output, &block)
|
|
68
|
+
validation_sources = [:output, :queue].freeze
|
|
69
|
+
fail(ArgumentError, "Unexpected source `#{validation_source.inspect}`, expected one of #{validation_sources.inspect}") unless validation_sources.include?(validation_source)
|
|
70
|
+
|
|
56
71
|
name = sample_event.is_a?(String) ? sample_event : LogStash::Json.dump(sample_event)
|
|
57
72
|
name = name[0..50] + "..." if name.length > 50
|
|
58
73
|
|
|
59
|
-
describe
|
|
74
|
+
describe name.inspect do
|
|
75
|
+
if validation_source == :output
|
|
76
|
+
let(:test_sink) { LogStash::Outputs::TestSink.new("release_on_close" => false, "store_events" => true) }
|
|
77
|
+
before { expect(LogStash::Outputs::TestSink).to receive(:new).and_return(test_sink) }
|
|
78
|
+
end
|
|
79
|
+
|
|
60
80
|
let(:pipeline) { new_pipeline_from_string(config) }
|
|
61
81
|
let(:event) do
|
|
62
82
|
sample_event = [sample_event] unless sample_event.is_a?(Array)
|
|
@@ -67,14 +87,17 @@ module LogStashHelper
|
|
|
67
87
|
end
|
|
68
88
|
|
|
69
89
|
let(:results) do
|
|
70
|
-
pipeline.filters
|
|
71
|
-
|
|
90
|
+
# Java pipeline (since 6.1) registers filters from start_workers
|
|
72
91
|
pipeline.run_with(event)
|
|
73
92
|
|
|
74
93
|
# flush makes sure to empty any buffered events in the filter
|
|
75
94
|
pipeline.flush_filters(:final => true) { |flushed_event| results << flushed_event }
|
|
76
95
|
|
|
77
|
-
|
|
96
|
+
case validation_source
|
|
97
|
+
when :queue then pipeline.filter_queue_client.processed_events # legacy?
|
|
98
|
+
when :output then test_sink.event_store.to_a
|
|
99
|
+
else fail NotImplementedError("validation source `#{validation_source}` not implemented.")
|
|
100
|
+
end
|
|
78
101
|
end
|
|
79
102
|
|
|
80
103
|
# starting at logstash-core 5.3 an initialized pipeline need to be closed
|
|
@@ -84,20 +107,25 @@ module LogStashHelper
|
|
|
84
107
|
|
|
85
108
|
subject { results.length > 1 ? results : results.first }
|
|
86
109
|
|
|
87
|
-
it("
|
|
110
|
+
it("processes events as specified", &block)
|
|
88
111
|
end
|
|
89
112
|
end # def sample
|
|
90
113
|
|
|
114
|
+
org.logstash.config.ir.compiler.OutputStrategyExt::SimpleAbstractOutputStrategyExt.class_eval do
|
|
115
|
+
field_reader :output # available since LS 6.3
|
|
116
|
+
end
|
|
117
|
+
|
|
91
118
|
def input(config_string, test_sink: {}, &block); require 'logstash/outputs/test_sink'
|
|
92
119
|
config_parts = [ config_source(config_string), test_sink_output_source(**test_sink) ]
|
|
93
120
|
|
|
94
|
-
# TODO unwrapping output from LogStash::OutputDelegator is cumbersome
|
|
95
|
-
instances = LogStash::Outputs::TestSink::TRACKER.keys.to_a
|
|
96
121
|
pipeline = new_pipeline(config_parts)
|
|
97
122
|
|
|
98
|
-
|
|
123
|
+
output_delegator = pipeline.outputs.last # LogStash::OutputDelegator
|
|
124
|
+
fail('test_sink output expected') unless output_delegator.config_name.eql?('test_sink')
|
|
125
|
+
test_sink_output = output_delegator.strategy.to_java.output
|
|
126
|
+
queue = test_sink_output.init_event_store
|
|
99
127
|
|
|
100
|
-
|
|
128
|
+
start_thread = pipeline.start_and_wait
|
|
101
129
|
|
|
102
130
|
# NOTE: we used to pass a Queue here, now its a Java List/Queue collection
|
|
103
131
|
result = block.call(pipeline, queue)
|
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
require 'rspec/wait'
|
|
2
2
|
|
|
3
3
|
RSpec.shared_examples "an interruptible input plugin" do
|
|
4
|
+
# why 3? 2 is not enough, 4 is too much..
|
|
5
|
+
# a plugin that is known to be slower can override
|
|
6
|
+
let(:allowed_lag) { 3 }
|
|
7
|
+
|
|
4
8
|
describe "#stop" do
|
|
5
9
|
let(:queue) { SizedQueue.new(20) }
|
|
6
10
|
subject { described_class.new(config) }
|
|
@@ -14,8 +18,7 @@ RSpec.shared_examples "an interruptible input plugin" do
|
|
|
14
18
|
expect(plugin_thread).to be_alive
|
|
15
19
|
# now let's actually stop the plugin
|
|
16
20
|
subject.do_stop
|
|
17
|
-
|
|
18
|
-
wait(3).for { plugin_thread }.to_not be_alive
|
|
21
|
+
wait(allowed_lag).for { plugin_thread }.to_not be_alive
|
|
19
22
|
end
|
|
20
23
|
end
|
|
21
24
|
end
|
|
@@ -29,7 +29,7 @@ if RUBY_VERSION < "2.3"
|
|
|
29
29
|
raise LoadError.new("Ruby >= 2.3.0 or later is required. (You are running: " + RUBY_VERSION + ")")
|
|
30
30
|
end
|
|
31
31
|
|
|
32
|
-
if level = (ENV[
|
|
32
|
+
if level = (ENV['LOG_LEVEL'] || ENV['LOGGER_LEVEL'] || ENV["TEST_DEBUG"])
|
|
33
33
|
logger, level = level.split('=') # 'logstash.filters.grok=DEBUG'
|
|
34
34
|
level, logger = logger, nil if level.nil? # only level given e.g. 'DEBUG'
|
|
35
35
|
level = org.apache.logging.log4j.Level.toLevel(level, org.apache.logging.log4j.Level::WARN)
|
|
@@ -38,6 +38,16 @@ else
|
|
|
38
38
|
LogStash::Logging::Logger::configure_logging('ERROR')
|
|
39
39
|
end
|
|
40
40
|
|
|
41
|
+
RSpec::Matchers.define :be_a_logstash_timestamp_equivalent_to do |expected|
|
|
42
|
+
# use the Timestamp compare to avoid suffering of precision loss of time format
|
|
43
|
+
expected = LogStash::Timestamp.new(expected) unless expected.kind_of?(LogStash::Timestamp)
|
|
44
|
+
description { "be a LogStash::Timestamp equivalent to #{expected}" }
|
|
45
|
+
|
|
46
|
+
match do |actual|
|
|
47
|
+
actual.kind_of?(LogStash::Timestamp) && actual == expected
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
41
51
|
RSpec.configure do |config|
|
|
42
52
|
# for now both include and extend are required because the newly refactored "input" helper method need to be visible in a "it" block
|
|
43
53
|
# and this is only possible by calling include on LogStashHelper
|
|
@@ -57,4 +67,3 @@ RSpec.configure do |config|
|
|
|
57
67
|
# --seed 1234
|
|
58
68
|
config.order = :random
|
|
59
69
|
end
|
|
60
|
-
|
|
@@ -22,7 +22,7 @@ class LogStash::Outputs::TestSink < LogStash::Outputs::Base
|
|
|
22
22
|
|
|
23
23
|
# @override plugin hook
|
|
24
24
|
def register
|
|
25
|
-
TRACKER[self] =
|
|
25
|
+
TRACKER[self] = @_event_store || init_event_store
|
|
26
26
|
end
|
|
27
27
|
|
|
28
28
|
# @override plugin impl
|
|
@@ -32,7 +32,8 @@ class LogStash::Outputs::TestSink < LogStash::Outputs::Base
|
|
|
32
32
|
|
|
33
33
|
# @override plugin hook
|
|
34
34
|
def close
|
|
35
|
-
TRACKER.delete(self)
|
|
35
|
+
TRACKER.delete(self)
|
|
36
|
+
@_event_store = false if release_on_close?
|
|
36
37
|
end
|
|
37
38
|
|
|
38
39
|
def store_events?
|
|
@@ -50,7 +51,24 @@ class LogStash::Outputs::TestSink < LogStash::Outputs::Base
|
|
|
50
51
|
|
|
51
52
|
# @return [Queue] (enumerable) event store
|
|
52
53
|
def event_store
|
|
53
|
-
|
|
54
|
+
if @_event_store.nil?
|
|
55
|
+
warn("#{self} event store not initialized (call plugin.register to initialize)", caller_locations(2))
|
|
56
|
+
return init_event_store
|
|
57
|
+
elsif @_event_store.eql?(false)
|
|
58
|
+
warn("#{self} closed - event store no longer available (release_on_close => false if you need to retain events)", caller_locations(2))
|
|
59
|
+
return nil
|
|
60
|
+
end
|
|
61
|
+
@_event_store
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
def init_event_store
|
|
65
|
+
@_event_store = Queue.new(@event_poll_timeout.to_f * 1000)
|
|
66
|
+
end
|
|
67
|
+
|
|
68
|
+
private
|
|
69
|
+
|
|
70
|
+
def warn(msg, callstack = nil)
|
|
71
|
+
Kernel.warn("#{msg}#{callstack ? " called from #{callstack.first}" : nil}")
|
|
54
72
|
end
|
|
55
73
|
|
|
56
74
|
# TODO refactor to java.util.concurrent.ConcurrentLinkedQueue
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
require "logstash/pipeline"
|
|
2
1
|
require "logstash/java_pipeline"
|
|
3
2
|
|
|
4
3
|
module LogStash
|
|
@@ -151,6 +150,13 @@ module LogStash
|
|
|
151
150
|
@delegate.to_java.filtered_size
|
|
152
151
|
end
|
|
153
152
|
|
|
153
|
+
def events
|
|
154
|
+
@delegate.events.tap do |events|
|
|
155
|
+
# filters out rogue (cancelled) events
|
|
156
|
+
@event_tracker.filtered_events events
|
|
157
|
+
end
|
|
158
|
+
end
|
|
159
|
+
|
|
154
160
|
# @override void merge(IRubyObject event);
|
|
155
161
|
def merge(event)
|
|
156
162
|
@delegate.merge(event)
|
data/logstash-devutils.gemspec
CHANGED
|
@@ -4,7 +4,7 @@ Gem::Specification.new do |spec|
|
|
|
4
4
|
files = %x{git ls-files}.split("\n")
|
|
5
5
|
|
|
6
6
|
spec.name = "logstash-devutils"
|
|
7
|
-
spec.version = "2.
|
|
7
|
+
spec.version = "2.4.0"
|
|
8
8
|
spec.license = "Apache-2.0"
|
|
9
9
|
spec.authors = ["Elastic"]
|
|
10
10
|
spec.email = "info@elastic.co"
|
|
@@ -45,4 +45,5 @@ Gem::Specification.new do |spec|
|
|
|
45
45
|
spec.add_runtime_dependency "kramdown", '1.14.0'
|
|
46
46
|
spec.add_runtime_dependency "stud", " >= 0.0.20"
|
|
47
47
|
spec.add_runtime_dependency "fivemat"
|
|
48
|
+
spec.add_runtime_dependency "logstash-codec-plain"
|
|
48
49
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: logstash-devutils
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.4.0
|
|
5
5
|
platform: java
|
|
6
6
|
authors:
|
|
7
7
|
- Elastic
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date:
|
|
11
|
+
date: 2022-03-14 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -136,6 +136,20 @@ dependencies:
|
|
|
136
136
|
- - ">="
|
|
137
137
|
- !ruby/object:Gem::Version
|
|
138
138
|
version: '0'
|
|
139
|
+
- !ruby/object:Gem::Dependency
|
|
140
|
+
requirement: !ruby/object:Gem::Requirement
|
|
141
|
+
requirements:
|
|
142
|
+
- - ">="
|
|
143
|
+
- !ruby/object:Gem::Version
|
|
144
|
+
version: '0'
|
|
145
|
+
name: logstash-codec-plain
|
|
146
|
+
prerelease: false
|
|
147
|
+
type: :runtime
|
|
148
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
149
|
+
requirements:
|
|
150
|
+
- - ">="
|
|
151
|
+
- !ruby/object:Gem::Version
|
|
152
|
+
version: '0'
|
|
139
153
|
description: logstash-devutils gem is meant to be used as a development dependency
|
|
140
154
|
from other plugins/gems.
|
|
141
155
|
email: info@elastic.co
|
|
@@ -149,6 +163,7 @@ files:
|
|
|
149
163
|
- Rakefile
|
|
150
164
|
- lib/logstash/devutils/rake.rb
|
|
151
165
|
- lib/logstash/devutils/rake/publish.rake
|
|
166
|
+
- lib/logstash/devutils/rake/test.rake
|
|
152
167
|
- lib/logstash/devutils/rake/vendor.rake
|
|
153
168
|
- lib/logstash/devutils/rspec/log4j2.properties
|
|
154
169
|
- lib/logstash/devutils/rspec/logstash_helpers.rb
|
|
@@ -177,8 +192,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
177
192
|
- !ruby/object:Gem::Version
|
|
178
193
|
version: '0'
|
|
179
194
|
requirements: []
|
|
180
|
-
|
|
181
|
-
rubygems_version: 2.6.13
|
|
195
|
+
rubygems_version: 3.1.6
|
|
182
196
|
signing_key:
|
|
183
197
|
specification_version: 4
|
|
184
198
|
summary: An assortment of tooling/libraries to make Logstash plugin development and
|