Bugzilla – Attachment 169825 Details for
Bug 37509
Elasticsearch status info missing from 'Server information'
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 37509: Check elasticsearch info for both 'about' and 'sysinfo' tabs
Bug-37509-Check-elasticsearch-info-for-both-about-.patch (text/plain), 7.73 KB, created by
David Nind
on 2024-07-29 11:32:16 UTC
(
hide
)
Description:
Bug 37509: Check elasticsearch info for both 'about' and 'sysinfo' tabs
Filename:
MIME Type:
Creator:
David Nind
Created:
2024-07-29 11:32:16 UTC
Size:
7.73 KB
patch
obsolete
>From 8b0e3bc6287756fc9783e4bdbcaf5c3701a2f1b3 Mon Sep 17 00:00:00 2001 >From: Pedro Amorim <pedro.amorim@ptfs-europe.com> >Date: Mon, 29 Jul 2024 11:23:51 +0000 >Subject: [PATCH] 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> >--- > about.pl | 157 ++++++++++++++++++++++++++++--------------------------- > 1 file changed, 80 insertions(+), 77 deletions(-) > >diff --git a/about.pl b/about.pl >index 3dff63118d..6233d8be23 100755 >--- a/about.pl >+++ b/about.pl >@@ -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; > { >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 37509
:
169822
|
169825
|
170529