logstash/qa/docker/shared_examples/xpack.rb
Cas Donoghue c31fcfd9ee
Add helper method to wait for log message to be observed (#17589)
* Add helper method to wait for log message to be observed

There appears to be a race condition in tests whereby log messages are not
observed with a single interogation of the container logs. This commit adds a
helper method to wait for log messages. This should make the tests more
resilient when there is a delay in log messages being captured.

* Use local scop container ref

Due to a copy paste error, the wrong reference to container (instance var)
was being used. When test file that did not define this uses the helper
it failed. The helper should use the ref explicitly passed to the method.
2025-04-29 11:21:10 -07:00

59 lines
2.4 KiB
Ruby

shared_examples_for 'a container with xpack features' do |flavor|
before do
@image = find_image(flavor)
end
after do
cleanup_container(@container)
end
describe 'when configuring xpack settings' do
context 'when persists env var keys into logstash.yml' do
let(:env) { %w(XPACK_MONITORING_ENABLED=false XPACK_MONITORING_ELASTICSEARCH_HOSTS=["http://node1:9200","http://node2:9200"]) }
before do
@container = start_container(@image, {'ENV' => env})
end
it 'saves keys instead actual value which will be resolved from keystore | env later' do
settings = get_settings(@container)
expect(settings['xpack.monitoring.enabled']).to eq("${XPACK_MONITORING_ENABLED}")
expect(settings['xpack.monitoring.elasticsearch.hosts']).to eq("${XPACK_MONITORING_ELASTICSEARCH_HOSTS}")
end
end
context 'with running with env vars' do
let(:env) {
[
'XPACK_MONITORING_ENABLED=true',
'XPACK_MONITORING_ELASTICSEARCH_HOSTS="http://node1:9200"',
'XPACK_MANAGEMENT_ENABLED=true',
'XPACK_MANAGEMENT_PIPELINE_ID=["*"]', # double quotes intentionally placed
'XPACK_MANAGEMENT_ELASTICSEARCH_HOSTS=["http://node3:9200", "http://node4:9200"]'
]
}
it 'persists var keys into logstash.yml and uses their resolved actual values' do
container = create_container(@image, {'ENV' => env})
sleep(15) # wait for container run
settings = get_settings(container)
expect(settings['xpack.monitoring.enabled']).to eq("${XPACK_MONITORING_ENABLED}")
expect(settings['xpack.monitoring.elasticsearch.hosts']).to eq("${XPACK_MONITORING_ELASTICSEARCH_HOSTS}")
expect(settings['xpack.management.enabled']).to eq("${XPACK_MANAGEMENT_ENABLED}")
expect(settings['xpack.management.pipeline.id']).to eq("${XPACK_MANAGEMENT_PIPELINE_ID}")
expect(settings['xpack.management.elasticsearch.hosts']).to eq("${XPACK_MANAGEMENT_ELASTICSEARCH_HOSTS}")
# check if logs contain node3 & node4 values actually resolved and used
wait_for_log_message(container, 'pipeline_id=>["*"]', :stdout)
# note that, we are not spinning up ES nodes, so values can be in errors or in pool update logs
wait_for_log_message(container, 'http://node3:9200', :stdout)
wait_for_log_message(container, 'http://node4:9200', :stdout)
end
end
end
end