From e55d3f1e8a82ebdaef4654eeb4c905d9a3e041ad Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Wed, 12 Jan 2022 09:46:46 +0100 Subject: [PATCH] Bug 29856: Make the ES config more flexible I need to add a 'request_timeout' entry to the ES configuration to fix some timeout problems on the sandboxes. Instead of hard coding this new option it seems preferable to be flexible and allow different options to be passed from the config file. Test plan: Add to the $KOHA_CONF, inside the elasticsearch section 60 Rebuild the ES index koha-elasticsearch --rebuild kohadev Change the value of the timeout to 1 Rebuild the index It should fail (with a quite bad error 'Bad response received when submitting request to Elasticsearch') --- Koha/SearchEngine/Elasticsearch.pm | 32 +++++++++---------- .../Koha/SearchEngine/Elasticsearch.t | 5 +-- 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index 69304eddaea..203183138fe 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -1308,34 +1308,32 @@ sub _read_configuration { ); } - if ( $conf && $conf->{server} ) { - my $nodes = $conf->{server}; - if ( ref($nodes) eq 'ARRAY' ) { - $configuration->{nodes} = $nodes; - } - else { - $configuration->{nodes} = [$nodes]; - } - } - else { + unless ( exists $conf->{server} ) { Koha::Exceptions::Config::MissingEntry->throw( "Missing / entry in koha-conf.xml" ); } - if ( defined $conf->{index_name} ) { - $configuration->{index_name} = $conf->{index_name}; - } - else { + unless ( exists $conf->{index_name} ) { Koha::Exceptions::Config::MissingEntry->throw( "Missing / entry in koha-conf.xml", ); } - $configuration->{cxn_pool} = $conf->{cxn_pool} // 'Static'; + while ( my ( $var, $val ) = each %$conf ) { + if ( $var eq 'server' ) { + if ( ref($val) eq 'ARRAY' ) { + $configuration->{nodes} = $val; + } + else { + $configuration->{nodes} = [$val]; + } + } else { + $configuration->{$var} = $val; + } + } - $configuration->{trace_to} = $conf->{trace_to} if defined $conf->{trace_to}; - $configuration->{request_timeout} = 60; + $configuration->{cxn_pool} //= 'Static'; return $configuration; } diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 78d0c4e331e..f29831f504a 100755 --- a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t +++ b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t @@ -39,7 +39,7 @@ $schema->storage->txn_begin; subtest '_read_configuration() tests' => sub { - plan tests => 15; + plan tests => 16; my $configuration; t::lib::Mocks::mock_config( 'elasticsearch', undef ); @@ -107,10 +107,11 @@ subtest '_read_configuration() tests' => sub { my $params = Koha::SearchEngine::Elasticsearch::get_elasticsearch_params; is_deeply( $configuration->{nodes}, \@servers , 'get_elasticsearch_params is just a wrapper for _read_configuration' ); - t::lib::Mocks::mock_config( 'elasticsearch', { server => \@servers, index_name => 'index', cxn_pool => 'Sniff', trace_to => 'Stderr' } ); + t::lib::Mocks::mock_config( 'elasticsearch', { server => \@servers, index_name => 'index', cxn_pool => 'Sniff', trace_to => 'Stderr', request_timeout => 42 } ); $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration; is( $configuration->{trace_to}, 'Stderr', 'trace_to configuration parsed correctly' ); + is( $configuration->{request_timeout}, '42', 'additional configuration (request_timeout) parsed correctly' ); }; subtest 'get_elasticsearch_settings() tests' => sub { -- 2.25.1