Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Status Report Page #3130

Merged
merged 70 commits into from
Nov 21, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
180b6ba
Make info "not-private" and adjust add_filter call
felipeelia Nov 11, 2022
a84973c
Add notice to sync and install page re- too many fields
felipeelia Nov 11, 2022
8626a1e
Status report page
felipeelia Nov 11, 2022
a6953f2
Add some simple style
felipeelia Nov 11, 2022
d8395ac
allow var_export
felipeelia Nov 11, 2022
4e55b03
Basic ES info
felipeelia Nov 11, 2022
76b1bb1
sort keys + support to PHP 7
felipeelia Nov 11, 2022
2a7aa89
Improve output hierarchy + more info
felipeelia Nov 14, 2022
5d2e0c5
WordPress Info
felipeelia Nov 14, 2022
d02dc51
Copy and paste functionality
felipeelia Nov 14, 2022
68cfd0e
Move StatusReport to Screen
felipeelia Nov 14, 2022
0f21577
Improve readability
felipeelia Nov 14, 2022
58d1759
Status Report intro
felipeelia Nov 14, 2022
2788d29
Move style enqueue to the StatusReport class
felipeelia Nov 14, 2022
5b9fbb4
Limited count of post meta
felipeelia Nov 15, 2022
d143b9a
Minor adjustments
felipeelia Nov 15, 2022
0de1e2c
Add more info
felipeelia Nov 15, 2022
0b1cad7
Move autosuggest report
felipeelia Nov 15, 2022
1ccdecc
Cache total fields limit
felipeelia Nov 15, 2022
8fa4a62
Lint
felipeelia Nov 15, 2022
a61930e
Remove transients on uninstall
felipeelia Nov 15, 2022
562d4dd
New ep_status_report_reports filter
felipeelia Nov 15, 2022
1d24c9a
Remove duplicated entry
felipeelia Nov 15, 2022
bcd162b
small cleanup
felipeelia Nov 15, 2022
03f2e10
Alignment
felipeelia Nov 15, 2022
8b839f1
Unit tests
felipeelia Nov 15, 2022
fc8cd02
Only add sku variations if it is really a product
felipeelia Nov 16, 2022
ba92554
Take ep_prepare_meta_data into account
felipeelia Nov 16, 2022
2012ee3
Status report refinements.
JakePT Nov 16, 2022
d22f944
Merge branch 'feature/addl-debug-info' of github.com:10up/ElasticPres…
JakePT Nov 16, 2022
59eef8b
Merge branch 'develop' into feature/addl-debug-info
felipeelia Nov 16, 2022
46d3383
Add unit tests for get_distinct_meta_field_keys_db
felipeelia Nov 16, 2022
55585d4
Unit tests for get_distinct_meta_field_keys_db_per_post_type
felipeelia Nov 16, 2022
32985ee
More unit tests
felipeelia Nov 16, 2022
8d05abe
Do not recalculate the number of objects found
felipeelia Nov 16, 2022
c41b1cb
Update the number of searchable post types
felipeelia Nov 16, 2022
4c3da44
Unit tests for get_index_total_fields_limit
felipeelia Nov 16, 2022
0d46ba2
Fix filter name
felipeelia Nov 16, 2022
9dc62fd
Update aria-controls
felipeelia Nov 16, 2022
65c58de
Cache get_distinct_meta_field_keys_db_per_post_type results
felipeelia Nov 16, 2022
00a3d56
Only allow calls from a specific page
felipeelia Nov 16, 2022
0e72515
Fix e2e test
felipeelia Nov 16, 2022
b396cbe
Expand messages a bit
felipeelia Nov 16, 2022
73a5cef
Fix lint
felipeelia Nov 16, 2022
9073aea
remove test code
felipeelia Nov 16, 2022
3dee764
Check all websites
felipeelia Nov 16, 2022
96ec317
EP also needs to be network activated
felipeelia Nov 16, 2022
016e3a6
Refactor multisite check
felipeelia Nov 16, 2022
19066f8
Fix errors when data missing.
JakePT Nov 17, 2022
20b504e
Fix error if indices are missing.
JakePT Nov 17, 2022
8ce3ad0
Add indexable content report.
JakePT Nov 17, 2022
7554b22
Adjust multisite check
felipeelia Nov 17, 2022
7de0e36
Output all keys
felipeelia Nov 17, 2022
4258eda
Make sure the method always return an array
felipeelia Nov 17, 2022
87405b8
Add a notice about limited results (to be reviewed)
felipeelia Nov 17, 2022
e746a52
Make sure the transient will be under the limit
felipeelia Nov 17, 2022
dda9d0f
Rename ES report and add timeouts
felipeelia Nov 17, 2022
a0e6612
dockblocks
felipeelia Nov 17, 2022
09308a2
Restore notice for limited meta key reports.
JakePT Nov 17, 2022
f539255
Merge branch 'feature/addl-debug-info' of github.com:10up/ElasticPres…
JakePT Nov 17, 2022
c9683e3
Adjust _n calls
felipeelia Nov 17, 2022
9c19731
Cache ep_post_meta_keys_db
felipeelia Nov 17, 2022
ee70c03
Cache clear mechanism
felipeelia Nov 17, 2022
02aef0d
Copy adjustments
felipeelia Nov 17, 2022
f2a416b
Add Instant Results template to status report.
JakePT Nov 18, 2022
a61e0bf
Rename Autosuggest report class.
JakePT Nov 18, 2022
255a2fe
Adjust "use" statements
felipeelia Nov 18, 2022
fb80648
Delete ep_meta_field_keys on uninstall
felipeelia Nov 18, 2022
05bde14
New filters + tests
felipeelia Nov 21, 2022
279a0dd
Skip nonce verification for GET
felipeelia Nov 21, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Improve output hierarchy + more info
  • Loading branch information
felipeelia committed Nov 14, 2022
commit 2a7aa89990f926717dc7599b1186c244a0d7100d
8 changes: 2 additions & 6 deletions includes/classes/AdminNotices.php
Original file line number Diff line number Diff line change
Expand Up @@ -780,12 +780,8 @@ function( $meta ) use ( $post_indexable, $empty_post ) {
$count_fields_db = count( $indexable_fields );

$index_name = $post_indexable->get_index_name();
$index_settings = Elasticsearch::factory()->get_index_settings( $index_name );
if ( is_wp_error( $index_settings ) || empty( $index_settings[ $index_name ]['settings']['index.mapping.total_fields.limit'] ) ) {
$es_field_limit = apply_filters( 'ep_total_field_limit', 5000 );
} else {
$es_field_limit = $index_settings[ $index_name ]['settings']['index.mapping.total_fields.limit'];
}
$es_field_limit = Elasticsearch::factory()->get_index_total_fields_limit( $index_name );
$es_field_limit = $index_settings ?? apply_filters( 'ep_total_field_limit', 5000 );

$predicted_es_field_count = $count_fields_db * 8;

Expand Down
4 changes: 2 additions & 2 deletions includes/classes/Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -409,9 +409,9 @@ public function get_mapping( $args, $assoc_args ) {
*/
public function get_cluster_indices( $args, $assoc_args ) {

$response = Elasticsearch::factory()->get_cluster_indices();
$cluster_indices = Elasticsearch::factory()->get_cluster_indices();

$this->print_json_response( $response, ! empty( $assoc_args['pretty'] ) );
$this->pretty_json_encode( $cluster_indices, ! empty( $assoc_args['pretty'] ) );
}

/**
Expand Down
21 changes: 19 additions & 2 deletions includes/classes/Elasticsearch.php
Original file line number Diff line number Diff line change
Expand Up @@ -1672,15 +1672,32 @@ public function get_index_names() {
* Return all indices from the cluster.
*
* @since 4.4.0
* @return WP_Error|array WP_Error on failure or The response
* @return array Array of indices in Elasticsearch
*/
public function get_cluster_indices() {
$path = '_cat/indices?format=json';

$response = $this->remote_request( $path );

return $response;
return json_decode( wp_remote_retrieve_body( $response ), true );
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this might need some more error handling and casting to ensure it is not causing any errors in case of unexpected results.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Casting added in 4258eda. Regarding error handling, do you have any specific scenario in mind @tott? So far, I'm relying on the underlying functions:

  • If $response is an error, wp_remote_retrieve_body will return an empty string
  • If json_decode fails, it will return null
    Thanks!

}

/**
* Given an index return its total fields limit
*
* @since 4.4.0
* @param string $index_name The index name
* @return int|null
*/
public function get_index_total_fields_limit( $index_name ) {
$index_settings = $this->get_index_settings( $index_name );
if ( is_wp_error( $index_settings ) || empty( $index_settings[ $index_name ]['settings']['index.mapping.total_fields.limit'] ) ) {
return null;
}

$es_field_limit = $index_settings[ $index_name ]['settings']['index.mapping.total_fields.limit'];

return (int) $es_field_limit;
}

}
4 changes: 3 additions & 1 deletion includes/classes/Screen/HealthInfo.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,11 @@ public function setup() {
public function last_sync_health_info( $debug_info ) {
$last_sync_report = new \ElasticPress\StatusReport\LastSync();

$first_group = reset( $last_sync_report->get_groups() );

$debug_info['ep-last-sync'] = [
'label' => esc_html__( 'ElasticPress - Last Sync', 'elasticpress' ),
'fields' => $last_sync_report->get_fields(),
'fields' => $first_group['fields'],
];

return $debug_info;
Expand Down
11 changes: 4 additions & 7 deletions includes/classes/Screen/Sync.php
Original file line number Diff line number Diff line change
Expand Up @@ -179,15 +179,12 @@ public function admin_enqueue_scripts() {
$sync_required = false;
$all_index_names = Elasticsearch::factory()->get_index_names();
$cluster_indices = Elasticsearch::factory()->get_cluster_indices();
$cluster_indices = json_decode( wp_remote_retrieve_body( $cluster_indices ), true );

if ( is_array( $cluster_indices ) ) {
$cluster_index_names = wp_list_pluck( $cluster_indices, 'index' );
$synced_index_names = array_intersect( $all_index_names, $cluster_index_names );
$cluster_index_names = wp_list_pluck( $cluster_indices, 'index' );
$synced_index_names = array_intersect( $all_index_names, $cluster_index_names );

if ( $synced_index_names !== $all_index_names ) {
$sync_required = true;
}
if ( $synced_index_names !== $all_index_names ) {
$sync_required = true;
}

if ( ! empty( $ep_last_index ) && ! $sync_required ) {
Expand Down
74 changes: 35 additions & 39 deletions includes/classes/StatusReport.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,12 @@ class StatusReport {
public function get_reports() : array {
$reports = [
'es_server' => new \ElasticPress\StatusReport\ElasticsearchServer(),
'indices' => new \ElasticPress\StatusReport\Indices(),
'post_meta' => new \ElasticPress\StatusReport\PostMeta(),
'last_sync' => new \ElasticPress\StatusReport\LastSync(),
'features' => new \ElasticPress\StatusReport\Features(),
];

$features = array_filter(
Features::factory()->registered_features,
function( $feature ) {
return $feature->is_active();
}
);
$features = wp_list_sort( $features, 'title' );
foreach ( $features as $feature ) {
$reports[ 'feature_' . $feature->slug ] = new \ElasticPress\StatusReport\Feature( $feature );
}

return $reports;
}

Expand All @@ -51,35 +42,40 @@ function( $feature ) {
*/
public function render_report( Report $report ) {
?>
<div class="postbox posts-info">
<div class="postbox-header">
<h2 class="hndle"><?php echo esc_html( $report->get_title() ); ?></h2>
</div>
<div class="inside">
<table cellpadding="0" cellspacing="0" class="wp-list-table widefat striped">
<tbody>
<?php
foreach ( $report->get_fields() as $slug => $field ) {
$label = $field['label'] ?? $slug;
$value = $field['value'] ?? '';
?>
<tr>
<td><?php echo esc_html( $label ); ?></td>
<td>
<?php
echo is_array( $value ) ?
'<pre>' . esc_html( var_export( $value, true ) ) . '</pre>' : // phpcs:ignore WordPress.PHP.DevelopmentFunctions
wp_kses_post( $value );
?>
</td>
</tr>
<h3 class="hndle"><?php echo esc_html( $report->get_title() ); ?></h3>
<?php
foreach ( $report->get_groups() as $group ) {
?>
<div class="postbox posts-info">
<div class="postbox-header">
<h2 class="hndle"><?php echo esc_html( $group['title'] ); ?></h2>
</div>
<div class="inside">
<table cellpadding="0" cellspacing="0" class="wp-list-table widefat striped">
<tbody>
<?php
}
?>
</tbody>
</table>
foreach ( $group['fields'] as $slug => $field ) {
$label = $field['label'] ?? $slug;
$value = $field['value'] ?? '';
?>
<tr>
<td><?php echo esc_html( $label ); ?></td>
<td>
<?php
echo is_array( $value ) ?
'<pre>' . esc_html( var_export( $value, true ) ) . '</pre>' : // phpcs:ignore WordPress.PHP.DevelopmentFunctions
wp_kses_post( $value );
?>
</td>
</tr>
<?php
}
?>
</tbody>
</table>
</div>
</div>
</div>
<?php
<?php
}
}
}
9 changes: 7 additions & 2 deletions includes/classes/StatusReport/ElasticsearchServer.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public function get_title() : string {
*
* @return array
*/
public function get_fields() : array {
public function get_groups() : array {
$is_epio = Utils\is_epio();

$fields = [];
Expand All @@ -58,6 +58,11 @@ public function get_fields() : array {
'value' => \ElasticPress\IndexHelper::factory()->get_index_default_per_page(),
];

return $fields;
return [
[
'title' => __( 'Basic ES Info', 'elasticpress' ),
'fields' => $fields,
],
];
}
}
71 changes: 0 additions & 71 deletions includes/classes/StatusReport/Feature.php

This file was deleted.

68 changes: 68 additions & 0 deletions includes/classes/StatusReport/Features.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
<?php
/**
* Feature report class
*
* @since 4.4.0
* @package elasticpress
*/

namespace ElasticPress\StatusReport;

use \ElasticPress\Features as EP_Features;

defined( 'ABSPATH' ) || exit;

/**
* Feature report class
*
* @package ElasticPress
*/
class Features extends Report {

/**
* Return the report title
*
* @return string
*/
public function get_title() : string {
return __( 'Features', 'elasticpress' );
}

/**
* Return the report fields
*
* @return array
*/
public function get_groups() : array {
$features_settings = \ElasticPress\Utils\get_option( 'ep_feature_settings', [] );

$features = array_filter(
EP_Features::factory()->registered_features,
function( $feature ) {
return $feature->is_active();
}
);
$features = wp_list_sort( $features, 'title' );

$groups = [];
foreach ( $features as $feature ) {
$feature_settings = $features_settings[ $feature->slug ] ?? [];

$fields = [];
foreach ( $feature_settings as $feature_setting => $value ) {
$fields[ $feature_setting ] = [
'label' => $feature_setting,
'value' => $value,
];
}
ksort( $fields );

$groups[] = [
'title' => $feature->title,
'fields' => $fields,
];
}

return $groups;
}
}
Loading