PluginProbe
ElasticPress / 5.3.5
ElasticPress v5.3.5
5.3.5 5.3.4 3.6.5 3.6.6 4.0.0 4.0.1 4.1.0 4.2.0 4.2.1 4.2.2 4.3.0 4.3.1 4.4.0 4.4.1 4.5.0 4.5.1 4.5.2 4.6.0 4.6.1 4.7.0 4.7.1 4.7.2 5.0.0 5.0.1 5.0.2 All 108 releases
← All changes | includes/classes/Stats.php +51 -29 4.2.05.3.5 View file →
@@ -7,9 +7,9 @@
7 7 */
8 8
9 9 namespace ElasticPress;
10 10
11 -use ElasticPress\Utils as Utils;
11 +use ElasticPress\Utils;
12 12
13 13 if ( ! defined( 'ABSPATH' ) ) {
14 14 exit; // Exit if accessed directly.
15 15 }
@@ -56,15 +56,12 @@
56 56 * @var array
57 57 * @since 3.2
58 58 */
59 59 protected $localized = [
60 - 'index_total' => 0,
61 - 'index_time_in_millis' => 0,
62 - 'query_total' => 0,
63 - 'query_time_in_millis' => 0,
64 - 'suggest_time_in_millis' => 0,
65 - 'suggest_total' => 0,
66 - 'indices_data' => [],
60 + 'index_total' => 0,
61 + 'query_total' => 0,
62 + 'suggest_total' => 0,
63 + 'indices_data' => [],
67 64 ];
68 65
69 66 /**
70 67 * Cluster node data.
@@ -76,8 +73,16 @@
76 73 */
77 74 protected $nodes = 0;
78 75
79 76 /**
77 + * Failed queries and their errors.
78 + *
79 + * @since 5.0.1
80 + * @var string
81 + */
82 + protected $failed_queries = [];
83 +
84 + /**
80 85 * Makes an api call to elasticsearch endpoint
81 86 *
82 87 * @param string $path Endpoint path to query
83 88 * @since 3.2
@@ -85,15 +90,31 @@
85 90 */
86 91 protected function remote_request_helper( $path ) {
87 92 $request = Elasticsearch::factory()->remote_request( $path );
88 93
89 - if ( is_wp_error( $request ) || empty( $request ) ) {
94 + if ( empty( $request ) ) {
90 95 return false;
91 96 }
92 97
93 - $body = wp_remote_retrieve_body( $request );
98 + if ( is_wp_error( $request ) ) {
99 + $this->failed_queries[] = [
100 + 'path' => $path,
101 + 'error' => $request->get_error_message(),
102 + ];
103 + return false;
104 + }
94 105
95 - return json_decode( $body, true );
106 + $body = wp_remote_retrieve_body( $request );
107 + $return = json_decode( $body, true );
108 +
109 + if ( ! empty( $return['errors'] ) ) {
110 + $this->failed_queries[] = [
111 + 'path' => $path,
112 + 'error' => wp_json_encode( $return['errors'] ),
113 + ];
114 + }
115 +
116 + return $return;
96 117 }
97 118
98 119 /**
99 120 * Makes api calls and organizes data depending on the specified context.
@@ -116,9 +137,8 @@
116 137 return;
117 138 }
118 139
119 140 $this->populate_indices_stats();
120 - $this->populate_indices_averages();
121 141
122 142 if ( Utils\is_epio() ) {
123 143 $node_stats = $this->remote_request_helper( '_nodes/stats/discovery?format=json' );
124 144 } else {
@@ -200,25 +220,8 @@
200 220 return $indices;
201 221 }
202 222
203 223 /**
204 - * Populate cluster performance data. These use the total key so averages include both primary and replica shards
205 - *
206 - * @since 3.x
207 - */
208 - private function populate_indices_averages() {
209 -
210 - if ( empty( $this->stats['_all']['total'] ) ) {
211 - return;
212 - }
213 -
214 - // General cluster performance stats
215 - $this->localized['index_time_in_millis'] = $this->stats['_all']['total']['indexing']['index_time_in_millis'];
216 - $this->localized['query_time_in_millis'] = $this->stats['_all']['total']['search']['query_time_in_millis'];
217 - $this->localized['suggest_time_in_millis'] = $this->stats['_all']['total']['search']['suggest_time_in_millis'];
218 - }
219 -
220 - /**
221 224 * Populate index storage capacity and metrics
222 225 * Note: in the numbers below, those using the total key are counting values across all primary and replica shards
223 226 * while those using the primaries key are reading only from the primary shards
224 227 *
@@ -310,8 +313,27 @@
310 313 $suffix = array( '', 'KB', 'MB', 'GB', 'TB' );
311 314 $f_base = floor( $base );
312 315
313 316 return round( pow( 1024, $base - floor( $base ) ), 1 ) . $suffix[ $f_base ];
317 + }
318 +
319 + /**
320 + * Return all failed queries.
321 + *
322 + * @return array
323 + * @since 5.0.1
324 + */
325 + public function get_failed_queries() {
326 + return $this->failed_queries;
327 + }
328 +
329 + /**
330 + * Clear all failed queries registered.
331 + *
332 + * @since 5.0.1
333 + */
334 + public function clear_failed_queries() {
335 + $this->failed_queries = [];
314 336 }
315 337
316 338 /**
317 339 * Return singleton instance of class