forked from elastic/logstash
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Introduce DeadLetterQueue to the Execution Context (elastic#6894)
* Introduce a DeadLetterQueueFactory DeadLetterQueueFactory is a static class that keeps a static collection of DeadLetterQueueWriteManagers per pipeline that has plugins requesting to use it. * DeadLetterQueue was added as a first-class field in the execution context that input/filter/output plugins can leverage
- Loading branch information
Showing
23 changed files
with
460 additions
and
68 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
logstash-core/lib/logstash/util/dead_letter_queue_manager.rb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
require 'logstash/environment' | ||
|
||
module LogStash; module Util | ||
class PluginDeadLetterQueueWriter | ||
|
||
attr_reader :plugin_id, :plugin_type, :inner_writer | ||
|
||
def initialize(inner_writer, plugin_id, plugin_type) | ||
@plugin_id = plugin_id | ||
@plugin_type = plugin_type | ||
@inner_writer = inner_writer | ||
end | ||
|
||
def write(logstash_event, reason) | ||
if @inner_writer && @inner_writer.is_open | ||
@inner_writer.writeEntry(logstash_event.to_java, @plugin_type, @plugin_id, reason) | ||
end | ||
end | ||
|
||
def close | ||
if @inner_writer && @inner_writer.is_open | ||
@inner_writer.close | ||
end | ||
end | ||
end | ||
|
||
class DummyDeadLetterQueueWriter | ||
# class uses to represent a writer when dead_letter_queue is disabled | ||
def initialize | ||
end | ||
|
||
def write(logstash_event, reason) | ||
# noop | ||
end | ||
|
||
def is_open | ||
false | ||
end | ||
|
||
def close | ||
# noop | ||
end | ||
end | ||
|
||
class DeadLetterQueueFactory | ||
java_import org.logstash.common.DeadLetterQueueFactory | ||
|
||
def self.get(pipeline_id) | ||
if LogStash::SETTINGS.get("dead_letter_queue.enable") | ||
return DeadLetterQueueWriter.new( | ||
DeadLetterQueueFactory.getWriter(pipeline_id, LogStash::SETTINGS.get("path.dead_letter_queue"))) | ||
else | ||
return DeadLetterQueueWriter.new(nil) | ||
end | ||
end | ||
|
||
def self.close(pipeline_id) | ||
DeadLetterQueueFactory.close(pipeline_id) | ||
end | ||
end | ||
end end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,38 @@ | ||
# encoding: utf-8 | ||
require "spec_helper" | ||
require "logstash/util/dead_letter_queue_manager" | ||
require "logstash/execution_context" | ||
|
||
describe LogStash::ExecutionContext do | ||
let(:pipeline) { double("pipeline") } | ||
let(:pipeline_id) { :main } | ||
let(:agent) { double("agent") } | ||
|
||
let(:plugin_id) { "plugin_id" } | ||
let(:plugin_type) { "plugin_type" } | ||
let(:dlq_writer) { LogStash::Util::DummyDeadLetterQueueWriter.new } | ||
|
||
before do | ||
allow(pipeline).to receive(:agent).and_return(agent) | ||
allow(pipeline).to receive(:pipeline_id).and_return(pipeline_id) | ||
end | ||
|
||
subject { described_class.new(pipeline, agent) } | ||
subject { described_class.new(pipeline, agent, plugin_id, plugin_type, dlq_writer) } | ||
|
||
it "returns the `pipeline_id`" do | ||
expect(subject.pipeline_id).to eq(pipeline_id) | ||
end | ||
|
||
it "returns the pipeline" do | ||
expect(subject.pipeline).to eq(pipeline) | ||
end | ||
|
||
it "returns the agent" do | ||
expect(subject.agent).to eq(agent) | ||
end | ||
|
||
it "returns the plugin-specific dlq writer" do | ||
expect(subject.dlq_writer.plugin_type).to eq(plugin_type) | ||
expect(subject.dlq_writer.plugin_id).to eq(plugin_id) | ||
expect(subject.dlq_writer.inner_writer).to eq(dlq_writer) | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.