From 9d9c002d44777632a1154b37571c22ce30c6d1a7 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') Signed-off-by: Martin Renvoize --- Koha/SearchEngine/Elasticsearch.pm | 31 +++++++++---------- .../Koha/SearchEngine/Elasticsearch.t | 5 +-- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/Koha/SearchEngine/Elasticsearch.pm b/Koha/SearchEngine/Elasticsearch.pm index f4a2f82713..203183138f 100644 --- a/Koha/SearchEngine/Elasticsearch.pm +++ b/Koha/SearchEngine/Elasticsearch.pm @@ -1308,33 +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->{cxn_pool} //= 'Static'; return $configuration; } diff --git a/t/db_dependent/Koha/SearchEngine/Elasticsearch.t b/t/db_dependent/Koha/SearchEngine/Elasticsearch.t index 78d0c4e331..f29831f504 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.20.1