Browse Source

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>
22.05.x
Jonathan Druart 2 years ago
committed by Fridolin Somers
parent
commit
cd0d647c61
  1. 31
      Koha/SearchEngine/Elasticsearch.pm
  2. 5
      t/db_dependent/Koha/SearchEngine/Elasticsearch.t

31
Koha/SearchEngine/Elasticsearch.pm

@ -1308,33 +1308,32 @@ sub _read_configuration {
); );
} }
if ( $conf && $conf->{server} ) { unless ( exists $conf->{server} ) {
my $nodes = $conf->{server};
if ( ref($nodes) eq 'ARRAY' ) {
$configuration->{nodes} = $nodes;
}
else {
$configuration->{nodes} = [$nodes];
}
}
else {
Koha::Exceptions::Config::MissingEntry->throw( Koha::Exceptions::Config::MissingEntry->throw(
"Missing <elasticsearch>/<server> entry in koha-conf.xml" "Missing <elasticsearch>/<server> entry in koha-conf.xml"
); );
} }
if ( defined $conf->{index_name} ) { unless ( exists $conf->{index_name} ) {
$configuration->{index_name} = $conf->{index_name};
}
else {
Koha::Exceptions::Config::MissingEntry->throw( Koha::Exceptions::Config::MissingEntry->throw(
"Missing <elasticsearch>/<index_name> entry in koha-conf.xml", "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; return $configuration;
} }

5
t/db_dependent/Koha/SearchEngine/Elasticsearch.t

@ -39,7 +39,7 @@ $schema->storage->txn_begin;
subtest '_read_configuration() tests' => sub { subtest '_read_configuration() tests' => sub {
plan tests => 15; plan tests => 16;
my $configuration; my $configuration;
t::lib::Mocks::mock_config( 'elasticsearch', undef ); t::lib::Mocks::mock_config( 'elasticsearch', undef );
@ -107,10 +107,11 @@ subtest '_read_configuration() tests' => sub {
my $params = Koha::SearchEngine::Elasticsearch::get_elasticsearch_params; my $params = Koha::SearchEngine::Elasticsearch::get_elasticsearch_params;
is_deeply( $configuration->{nodes}, \@servers , 'get_elasticsearch_params is just a wrapper for _read_configuration' ); 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; $configuration = Koha::SearchEngine::Elasticsearch::_read_configuration;
is( $configuration->{trace_to}, 'Stderr', 'trace_to configuration parsed correctly' ); 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 { subtest 'get_elasticsearch_settings() tests' => sub {

Loading…
Cancel
Save