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
  <request_timeout>60</request_timeout>
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 <martin.renvoize@ptfs-europe.com>
Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Signed-off-by: Fridolin Somers <fridolin.somers@biblibre.com>
This commit is contained in:
Jonathan Druart 2022-01-12 09:46:46 +01:00 committed by Fridolin Somers
parent 9f8c77e864
commit cd0d647c61
2 changed files with 18 additions and 18 deletions

View File

@ -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 <elasticsearch>/<server> 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 <elasticsearch>/<index_name> 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;
}

View File

@ -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 {