Skip to content

Commit e295446

Browse files
authored
Codec pipeline context (#153)
* spec: remove facepalm spec bypass * specs: improve validation of pipeline settings
1 parent 0e37a1c commit e295446

File tree

1 file changed

+27
-15
lines changed

1 file changed

+27
-15
lines changed

spec/inputs/http_spec.rb

Lines changed: 27 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -656,27 +656,19 @@ def setup_server_client(url = self.url)
656656

657657
end
658658
end
659-
end if false
659+
end
660660

661661
# If we have a setting called `pipeline.ecs_compatibility`, we need to
662662
# ensure that our additional_codecs are instantiated with the proper
663663
# execution context in order to ensure that the pipeline setting is
664664
# respected.
665665
if LogStash::SETTINGS.registered?('pipeline.ecs_compatibility')
666666

667-
def with_setting(name, value, &block)
668-
setting = LogStash::SETTINGS.get_setting(name)
669-
was_set, orignial_value = setting.set?, setting.value
670-
setting.set(value)
671-
672-
yield(true)
673-
674-
ensure
675-
was_set ? setting.set(orignial_value) : setting.reset
676-
end
677-
678667
def setting_value_supported?(name, value)
679-
with_setting(name, value) { true }
668+
setting = ::LogStash::SETTINGS.clone.get_setting(name)
669+
setting.set(value)
670+
setting.validate_value
671+
true
680672
rescue
681673
false
682674
end
@@ -688,12 +680,32 @@ def setting_value_supported?(name, value)
688680
%w(disabled v1 v8).each do |spec|
689681
if setting_value_supported?('pipeline.ecs_compatibility', spec)
690682
context "with `pipeline.ecs_compatibility: #{spec}`" do
691-
around(:each) { |example| with_setting('pipeline.ecs_compatibility', spec, &example) }
683+
# Override DevUtils's `new_pipeline` default to inject pipeline settings that
684+
# are different than our global settings, so that we can validate the condition
685+
# where pipeline settings override global settings.
686+
def new_pipeline(config_parts, pipeline_id = :main, settings = pipeline_settings)
687+
super(config_parts, pipeline_id, settings)
688+
end
689+
690+
let(:pipeline_settings) do
691+
::LogStash::SETTINGS.clone.tap do |s|
692+
s.set('pipeline.ecs_compatibility', spec)
693+
end
694+
end
692695

693696
it 'propagates the ecs_compatibility pipeline setting to the additional_codecs' do
697+
# Ensure plugins pick up pipeline-level setting over the global default.
698+
aggregate_failures('precondition') do
699+
expect(::LogStash::SETTINGS).to_not be_set('pipeline.ecs_compatibility')
700+
expect(pipeline_settings).to be_set('pipeline.ecs_compatibility')
701+
end
702+
694703
input("input { http { port => #{port} additional_codecs => { 'application/json' => 'json' 'text/plain' => 'plain' } } }") do |pipeline, queue|
695704
http_input = pipeline.inputs.first
696-
expect(http_input).to be_a_kind_of(described_class) # precondition
705+
aggregate_failures('initialization precondition') do
706+
expect(http_input).to be_a_kind_of(described_class)
707+
expect(http_input.execution_context&.pipeline&.settings&.to_hash).to eq(pipeline_settings.to_hash)
708+
end
697709

698710
http_input.codecs.each do |key, value|
699711
aggregate_failures("Codec for `#{key}`") do

0 commit comments

Comments
 (0)