-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Remove legacy output concurrency #19003
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 6 commits
963183e
3ecd923
6eb1e2d
bedd960
a8d2940
1d56ce0
b30ee46
5989c5c
2dab9bd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,17 +33,20 @@ class LogStash::Outputs::Base < LogStash::Plugin | |
|
|
||
| # The codec used for output data. Output codecs are a convenient method for encoding your data before it leaves the output, without needing a separate filter in your Logstash pipeline. | ||
| config :codec, :validate => :codec, :default => "plain" | ||
| # TODO remove this in Logstash 6.0 | ||
| # when we no longer support the :legacy type | ||
| # This is hacky, but it can only be herne | ||
| config :workers, :type => :number, :default => 1 | ||
|
|
||
| # Set or return concurrency type | ||
| def self.concurrency(type = nil) | ||
| if type | ||
| if type == :legacy | ||
| self.logger.warn("Output plugin #{self.name} declares `concurrency :legacy` which is removed. Defaulting to :single. Please update the plugin to use `concurrency :single` or `concurrency :shared`.") | ||
| type = :single | ||
| end | ||
| if ![:shared, :single].include?(type) | ||
| raise ArgumentError, "Invalid concurrency type '#{type}', must be one of :shared, :single" | ||
| end | ||
|
andrewvc marked this conversation as resolved.
Outdated
|
||
| @concurrency = type | ||
| else | ||
| @concurrency || :legacy # default is :legacyo | ||
| @concurrency || :single | ||
| end | ||
| end | ||
|
|
||
|
|
@@ -57,12 +60,6 @@ def self.threadsafe? | |
| concurrency == :shared | ||
| end | ||
|
|
||
| # Deprecated: Favor `concurrency :single` | ||
| # Remove in Logstash 6.0.0 | ||
| def self.declare_workers_not_supported!(message = nil) | ||
| concurrency :single | ||
| end | ||
|
|
||
| public | ||
|
|
||
| def self.plugin_type | ||
|
|
@@ -72,12 +69,16 @@ def self.plugin_type | |
| public | ||
| def initialize(params = {}) | ||
| super | ||
| config_init(@params) | ||
|
|
||
| if self.workers != 1 | ||
| raise LogStash::ConfigurationError, "You are using a plugin that doesn't support workers but have set the workers value explicitly! This plugin uses the #{concurrency} and doesn't need this option" | ||
| # Outputs that never declared a concurrency strategy used the now-removed :legacy | ||
| # strategy, which accepted a `workers` setting. Strip it so existing configs with | ||
| # `workers => 1` don't blow up. | ||
| if !self.class.instance_variable_defined?(:@concurrency) && @params.delete("workers") | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I was on the fence about adding a new
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I would find it simpler to just use the |
||
| self.logger.warn("Output plugin #{self.class.name}: the `workers` setting is no longer used and will be removed in a future release.") | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. if we do our own logging, we should use the |
||
| end | ||
|
|
||
| config_init(@params) | ||
|
|
||
| # If we're running with a single thread we must enforce single-threaded concurrency by default | ||
| # Maybe in a future version we'll assume output plugins are threadsafe | ||
| @single_worker_mutex = Mutex.new | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -39,7 +39,7 @@ class LogStash::Outputs::NOOPShared < ::LogStash::Outputs::Base | |
| def register; end | ||
| end | ||
|
|
||
| class LogStash::Outputs::NOOPLegacy < ::LogStash::Outputs::Base | ||
| class LogStash::Outputs::NOOPDefault < ::LogStash::Outputs::Base | ||
| def register; end | ||
| end | ||
|
|
||
|
|
@@ -60,8 +60,7 @@ def multi_receive_encoded(events_and_encoded) | |
| let(:klass) { LogStash::Outputs::NOOPSingle } | ||
|
|
||
| it "should instantiate cleanly" do | ||
| params = { "dummy_option" => "potatoes", "codec" => "json", "workers" => 2 } | ||
| worker_params = params.dup; worker_params["workers"] = 1 | ||
| params = { "dummy_option" => "potatoes", "codec" => "json" } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here's a bug that pre-existed your change: the
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nice catch! |
||
|
|
||
| expect { subject }.not_to raise_error | ||
| end | ||
|
|
@@ -79,19 +78,22 @@ def multi_receive_encoded(events_and_encoded) | |
| end | ||
| end | ||
|
|
||
| context "legacy" do | ||
| let(:klass) { LogStash::Outputs::NOOPLegacy } | ||
| context "default (no concurrency declared)" do | ||
| let(:klass) { LogStash::Outputs::NOOPDefault } | ||
|
|
||
| it "should set concurrency correctly" do | ||
| expect(subject.concurrency).to eq(:legacy) | ||
| it "should default concurrency to :single" do | ||
| expect(subject.concurrency).to eq(:single) | ||
| end | ||
|
|
||
| it "should default the # of workers to 1" do | ||
| expect(subject.workers).to eq(1) | ||
| it "should accept the deprecated workers setting without error" do | ||
| expect { klass.new("workers" => 1) }.not_to raise_error | ||
| end | ||
|
|
||
| it "should default concurrency to :legacy" do | ||
| expect(subject.concurrency).to eq(:legacy) | ||
| it "should log a warning when workers is set" do | ||
| logger = klass.logger | ||
| expect(logger).to receive(:warn).with(/workers.*no longer used/) | ||
| output = klass.new("workers" => 1) | ||
| expect(output.params).not_to include("workers") | ||
| end | ||
| end | ||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.