diff --git a/includes/classes/Stats.php b/includes/classes/Stats.php index a5dae9885e..1d3faf421f 100644 --- a/includes/classes/Stats.php +++ b/includes/classes/Stats.php @@ -73,6 +73,14 @@ class Stats { */ protected $nodes = 0; + /** + * Failed queries and their errors. + * + * @since 5.0.1 + * @var string + */ + protected $failed_queries = []; + /** * Makes an api call to elasticsearch endpoint * @@ -83,13 +91,29 @@ class Stats { protected function remote_request_helper( $path ) { $request = Elasticsearch::factory()->remote_request( $path ); - if ( is_wp_error( $request ) || empty( $request ) ) { + if ( empty( $request ) ) { + return false; + } + + if ( is_wp_error( $request ) ) { + $this->failed_queries[] = [ + 'path' => $path, + 'error' => $request->get_error_message(), + ]; return false; } - $body = wp_remote_retrieve_body( $request ); + $body = wp_remote_retrieve_body( $request ); + $return = json_decode( $body, true ); - return json_decode( $body, true ); + if ( ! empty( $return['errors'] ) ) { + $this->failed_queries[] = [ + 'path' => $path, + 'error' => wp_json_encode( $return['errors'] ), + ]; + } + + return $return; } /** @@ -292,6 +316,25 @@ public function convert_to_readable_size( $size ) { return round( pow( 1024, $base - floor( $base ) ), 1 ) . $suffix[ $f_base ]; } + /** + * Return all failed queries. + * + * @return array + * @since 5.0.1 + */ + public function get_failed_queries() { + return $this->failed_queries; + } + + /** + * Clear all failed queries registered. + * + * @since 5.0.1 + */ + public function clear_failed_queries() { + $this->failed_queries = []; + } + /** * Return singleton instance of class * diff --git a/includes/partials/stats-page.php b/includes/partials/stats-page.php index 67cca3ca7c..6a63ca0ac8 100644 --- a/includes/partials/stats-page.php +++ b/includes/partials/stats-page.php @@ -25,15 +25,33 @@ Stats::factory()->build_stats(); -$index_health = Stats::factory()->get_health(); -$totals = Stats::factory()->get_totals(); +$index_health = Stats::factory()->get_health(); +$totals = Stats::factory()->get_totals(); +$failed_queries = Stats::factory()->get_failed_queries(); ?>