Bug 37509: Check Elasticsearch info for both 'about' and 'sysinfo' tabs

1) Notice 'Elasticsearch:' entry at  http://localhost:8081/cgi-bin/koha/about.pl?tab=about is empty
2) Apply patch + restart plack
3) Repeat step 1) Notice it now shows elasticsearch info as expected.
4) Verify that Elasticsearch warning http://localhost:8081/cgi-bin/koha/about.pl?tab=sysinfo is the same before and applying patch.

Signed-off-by: David Nind <david@davidnind.com>
Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
Signed-off-by: Katrin Fischer <katrin.fischer@bsz-bw.de>
This commit is contained in:
Pedro Amorim 2024-07-29 11:23:51 +00:00 committed by Katrin Fischer
parent 57dc65bed5
commit 63e560a432
No known key found for this signature in database
GPG Key ID: 0EF6E2C03357A834
1 changed files with 80 additions and 77 deletions

157
about.pl
View File

@ -179,6 +179,7 @@ if ( $tab eq 'about' ) {
}
message_broker_check($template);
elasticsearch_check($template);
$template->param(
effective_caching_method => $effective_caching_method,
@ -400,83 +401,7 @@ if($tab eq 'sysinfo') {
$template->param( warnXSLT => \@warnXSLT ) if @warnXSLT;
}
if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
# Check ES configuration health and runtime status
my $es_status;
my $es_config_error;
my $es_running = 1;
my $es_has_missing = 0;
my $es_conf;
try {
$es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
}
catch {
if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
$template->param( elasticsearch_fatal_config_error => $_->message );
$es_config_error = 1;
}
};
if ( !$es_config_error ) {
my $biblios_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
my @indexes = ($biblios_index_name, $authorities_index_name);
# TODO: When new indexes get added, we could have other ways to
# fetch the list of available indexes (e.g. plugins, etc)
$es_status->{nodes} = $es_conf->{nodes};
my $es = Search::Elasticsearch->new( $es_conf );
my $es_status->{version} = $es->info->{version}->{number};
foreach my $index ( @indexes ) {
my $index_count;
try {
$index_count = $es->indices->stats( index => $index )
->{_all}{primaries}{docs}{count};
}
catch {
if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
push @{ $es_status->{errors} }, "Index not found ($index)";
$index_count = -1;
}
elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
$es_running = 0;
}
else {
# TODO: when time comes, we will cover more use cases
die $_;
}
};
my $db_count = -1;
my $missing_count = 0;
if ( $index eq $biblios_index_name ) {
$db_count = Koha::Biblios->search->count;
} elsif ( $index eq $authorities_index_name ) {
$db_count = Koha::Authorities->search->count;
}
if ( $db_count != -1 && $index_count != -1 ) {
$missing_count = $db_count - $index_count;
$es_has_missing = 1 if $missing_count > 0;
}
push @{ $es_status->{indexes} },
{
index_name => $index,
index_count => $index_count,
db_count => $db_count,
missing_count => $missing_count,
};
}
$es_status->{running} = $es_running;
$template->param(
elasticsearch_status => $es_status,
elasticsearch_has_missing => $es_has_missing,
);
}
}
elasticsearch_check( $template );
if ( C4::Context->preference('RESTOAuth2ClientCredentials') ) {
# Do we have the required deps?
@ -899,6 +824,84 @@ if ( $tab eq 'history' ) {
}
}
sub elasticsearch_check {
my $template = shift;
if ( C4::Context->preference('SearchEngine') eq 'Elasticsearch' ) {
my $es_status;
my $es_config_error;
my $es_running = 1;
my $es_has_missing = 0;
my $es_conf;
try {
$es_conf = Koha::SearchEngine::Elasticsearch::_read_configuration();
} catch {
if ( ref($_) eq 'Koha::Exceptions::Config::MissingEntry' ) {
$template->param( elasticsearch_fatal_config_error => $_->message );
$es_config_error = 1;
}
};
if ( !$es_config_error ) {
my $biblios_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::BIBLIOS_INDEX;
my $authorities_index_name = $es_conf->{index_name} . "_" . $Koha::SearchEngine::AUTHORITIES_INDEX;
my @indexes = ( $biblios_index_name, $authorities_index_name );
# TODO: When new indexes get added, we could have other ways to
# fetch the list of available indexes (e.g. plugins, etc)
$es_status->{nodes} = $es_conf->{nodes};
my $es = Search::Elasticsearch->new($es_conf);
my $es_status->{version} = $es->info->{version}->{number};
foreach my $index (@indexes) {
my $index_count;
try {
$index_count = $es->indices->stats( index => $index )->{_all}{primaries}{docs}{count};
} catch {
if ( ref($_) eq 'Search::Elasticsearch::Error::Missing' ) {
push @{ $es_status->{errors} }, "Index not found ($index)";
$index_count = -1;
} elsif ( ref($_) eq 'Search::Elasticsearch::Error::NoNodes' ) {
$es_running = 0;
} else {
# TODO: when time comes, we will cover more use cases
die $_;
}
};
my $db_count = -1;
my $missing_count = 0;
if ( $index eq $biblios_index_name ) {
$db_count = Koha::Biblios->search->count;
} elsif ( $index eq $authorities_index_name ) {
$db_count = Koha::Authorities->search->count;
}
if ( $db_count != -1 && $index_count != -1 ) {
$missing_count = $db_count - $index_count;
$es_has_missing = 1 if $missing_count > 0;
}
push @{ $es_status->{indexes} },
{
index_name => $index,
index_count => $index_count,
db_count => $db_count,
missing_count => $missing_count,
};
}
$es_status->{running} = $es_running;
$template->param(
elasticsearch_status => $es_status,
elasticsearch_has_missing => $es_has_missing,
);
}
}
}
sub message_broker_check {
my $template = shift;
{