Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions logstash-core/lib/logstash/settings.rb
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ def to_hash
}
end

def inspect
Copy link
Member Author

@yaauie yaauie Apr 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Context: this makes failing expectations involving the Setting object a lot easier to understand.

before:

expected `#<LogStash::Setting::PositiveInteger:0x1e48ac75 @name="pipeline.workers", @value=nil, @value_is_set=f...tor_proc=#<Proc:0x624fe3ee@/Users/yaauie/src/elastic/ls/logstash-core/lib/logstash/settings.rb:398>>.set?` to be truthy, got false

after:

expected `<LogStash::Setting::PositiveInteger(pipeline.workers): 16 (DEFAULT)>.set?` to be truthy, got false

"<#{self.class.name}(#{name}): #{value.inspect}" + (@value_is_set ? '' : ' (DEFAULT)') + ">"
end

def ==(other)
self.to_hash == other.to_hash
end
Expand Down
2 changes: 2 additions & 0 deletions x-pack/lib/config_management/elasticsearch_source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class RemoteConfigError < LogStash::Error; end
pipeline.workers
pipeline.batch.size
pipeline.batch.delay
pipeline.ecs_compatibility
pipeline.ordered
queue.type
queue.max_bytes
queue.checkpoint.writes
Expand Down
102 changes: 74 additions & 28 deletions x-pack/spec/config_management/elasticsearch_source_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -368,29 +368,57 @@
let(:mock_client) { double("http_client") }
let(:settings) { super().merge({ "xpack.management.pipeline.id" => pipeline_id }) }
let(:config) { "input { generator {} } filter { mutate {} } output { }" }
let(:username) { 'log.stash' }
let(:pipeline_settings) do
{
"pipeline.batch.delay" => "50",
"pipeline.workers" => "99",
"pipeline.ordered" => "false",
"pipeline.ecs_compatibility" => "v1",

# invalid settings to be ignored...
"pipeline.output.workers" => "99",
"nonsensical.invalid.setting"=> "-9999",
}
end
let(:pipeline_metadata) do
{
"version" => 5,
"type" => "logstash_pipeline",
}
end
let(:elasticsearch_response) { elasticsearch_8_response }
let(:elasticsearch_8_response) {
"{\"#{pipeline_id}\":{
\"username\":\"log.stash\",
\"modified_timestamp\":\"2017-02-28T23:02:17.023Z\",
\"pipeline_metadata\":{\"version\":5,\"type\":\"logstash_pipeline\"},
\"pipeline\":\"#{config}\",
\"pipeline_settings\":{\"pipeline.batch.delay\":\"50\", \"pipeline.workers\":\"99\", \"pipeline.output.workers\":\"99\", \"nonsensical.invalid.setting\":\"-9999\"}}}" }

let(:elasticsearch_7_9_response) {
"{ \"docs\":[{
\"_index\":\".logstash\",
\"_type\":\"pipelines\",
\"_id\":\"#{pipeline_id}\",
\"_version\":8,
\"found\":true,
\"_source\":{
\"id\":\"apache\",
\"description\":\"Process apache logs\",
\"modified_timestamp\":\"2017-02-28T23:02:17.023Z\",
\"pipeline_metadata\":{\"version\":5,\"type\":\"logstash_pipeline\",\"username\":\"elastic\"},
\"pipeline\":\"#{config}\",
\"pipeline_settings\":{\"pipeline.workers\":\"99\", \"pipeline.output.workers\":\"99\", \"nonsensical.invalid.setting\":\"-9999\"}}}]}" }
let(:elasticsearch_8_response) do
{
pipeline_id => {
username: username,
modified_timestamp: "2017-02-28T23:02:17.023Z",
pipeline_metadata: pipeline_metadata,
pipeline: config,
pipeline_settings: pipeline_settings,
}
}.to_json
end

let(:elasticsearch_7_9_response) do
{
docs: [{
_index: ".logstash",
_type: "pipelines",
_id: pipeline_id,
_version: 8,
found: true,
_source: {
id: pipeline_id,
description: "Process apache logs",
modified_timestamp: "2017-02-28T23:02:17.023Z",
pipeline_metadata: pipeline_metadata.merge(username: username),
pipeline: config,
pipeline_settings: pipeline_settings,
}
}]
}.to_json
end
let(:es_path) { ".logstash/_mget" }
let(:request_body_string) { LogStash::Json.dump({ "docs" => [{ "_id" => pipeline_id }] }) }

Expand All @@ -412,8 +440,10 @@

context "with one `pipeline_id` configured [#{es_version}]" do
context "when successfully fetching a remote configuration" do
let(:logger_stub) { double("Logger").as_null_object }
before :each do
expect_any_instance_of(described_class).to receive(:build_client).and_return(mock_client)
allow_any_instance_of(described_class).to receive(:logger).and_return(logger_stub)
allow(mock_client).to receive(:post).with(es_path, {}, request_body_string).and_return(LogStash::Json.load(elasticsearch_7_9_response))
end

Expand All @@ -426,13 +456,29 @@
expect(pipeline_config.first.pipeline_id.to_sym).to eq(pipeline_id.to_sym)
end

it "ignores non-whitelisted and invalid settings" do
it "applies allowed settings and logs warning about ignored settings" do
pipeline_config = subject.pipeline_configs
settings_hash = pipeline_config[0].settings.to_hash

expect(settings_hash["pipeline.workers"]).to eq(99)
expect(settings_hash["pipeline.output.workers"]).not_to eq(99)
expect(settings_hash["nonsensical.invalid.setting"]).to be_falsey
pipeline_settings = pipeline_config[0].settings

aggregate_failures do
# explicitly given settings
expect(pipeline_settings.get_setting("pipeline.workers")).to be_set.and(have_attributes(value: 99))
expect(pipeline_settings.get_setting("pipeline.batch.delay")).to be_set.and(have_attributes(value: 50))
expect(pipeline_settings.get_setting("pipeline.ordered")).to be_set.and(have_attributes(value: "false"))
expect(pipeline_settings.get_setting("pipeline.ecs_compatibility")).to be_set.and(have_attributes(value: "v1"))

# valid non-provided settings
expect(pipeline_settings.get_setting("queue.type")).to_not be_set

# invalid provided settings
%w(
pipeline.output.workers
nonsensical.invalid.setting
).each do |invalid_setting|
expect(pipeline_settings.registered?(invalid_setting)).to be false
expect(logger_stub).to have_received(:warn).with(/Ignoring .+ '#{Regexp.quote(invalid_setting)}'/)
end
end
end
end

Expand Down