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

Add Health Checks #36

Merged
merged 25 commits into from
Jan 29, 2025
Merged

Add Health Checks #36

merged 25 commits into from
Jan 29, 2025

Conversation

bradp
Copy link
Contributor

@bradp bradp commented Dec 11, 2024

Proposed changes

Implements a variety of Health Checks to the Site Health page.

Screenshot 2024-12-10 at 1 24 01 PM

Jira tickets: PRESS7-108, PRESS7-109, PRESS7-110, PRESS7-111, PRESS7-118, PRESS7-112, PRESS7-113, PRESS7-121, PRESS7-107, PRESS7-119, PRESS7-120, PRESS7-114, PRESS7-115, PRESS7-116, PRESS7-117.

Type of Change

  • New feature (non-breaking change which adds functionality)

Screenshot

Screenshot 2024-12-10 at 1 23 43 PM

Checklist

  • I have read the CONTRIBUTING doc
  • I have viewed my change in a web-browser
  • Linting and tests pass locally with my changes
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation (if appropriate)

Further comments

This PR adds HealthCheckManager.php which is a helper class to set up and add health checks to the Site Health page. This is used in HealthChecks.php to add the health checks to the Site Health page.

This makes it so adding a new health check is as simple as:

$manager->addHealthCheck( [
  'id'    => 'example-health-check',
  'title' => __( 'Example Health Check', 'newfold-performance-module' ),
  'pass'  => __( 'Example health check passed', 'newfold-performance-module' ),
  'fail'  => __( 'Example health check failed', 'newfold-performance-module' ),
  'text'  => __( 'This is some text to explain the health check to the user.', 'newfold-performance-module' ),
  'test'  => function () {
    // Example test for a constant being defined and having a specific value.
    return ( defined( 'EXAMPLE_CONSTANT' ) && EXAMPLE_CONSTANT === 'example-value' );
  },
] );

This PR also adds Health Checks that are commented out for the following PRs

@bradp bradp added the enhancement New feature or request label Dec 11, 2024
@bradp bradp changed the title Feature/health checks Add Health Checks Dec 11, 2024
Copy link
Member

@arunshenoy99 arunshenoy99 left a comment

Choose a reason for hiding this comment

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

Just a few minor things, @bradp. Everything else looks good to me! 😃

includes/HealthCheckManager.php Outdated Show resolved Hide resolved
includes/HealthCheckManager.php Outdated Show resolved Hide resolved
includes/HealthCheckManager.php Outdated Show resolved Hide resolved
includes/HealthCheckManager.php Outdated Show resolved Hide resolved
includes/HealthChecks.php Outdated Show resolved Hide resolved
/**
* Add health checks.
*/
public function addHealthChecks() {
Copy link
Member

Choose a reason for hiding this comment

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

I think this works well for now. But if this file grows into a large monolith in the future, do you think it might make sense to create an abstract class for new health checks to inherit from?

For instance, we could have a HealthChecks directory with an AbstractHealthCheck.php file that defines and documents all the necessary fields. A class like LinkPrefetchHealthCheck.php could then inherit from it and include all tests related to link prefetching.

In this file, we can simply call $manager->addHealthCheck( new LinkPrefetchHealthCheck() );. This approach would provide better validation and typing in PHP, prevent files from becoming too large, group related functionality, and avoid people adding random data directly into the manager. What do you think?


/* // phpcs:ignore Squiz.PHP.CommentedOutCode
// Enable when https://github.com/newfold-labs/wp-module-performance/pull/26 is merged.
// PRESS7-120: Link Prefetching.
Copy link
Member

Choose a reason for hiding this comment

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

The Link Prefetch and Jetpack Boost stuff has been merged. I'm working on getting the Image Optimization changes merged as soon as possible after a review! 😃

@circlecube
Copy link
Member

@bradp can we get these comments addressed and the conflict resolved? Looks like there's a lint check issue(s) too.

@bradp
Copy link
Contributor Author

bradp commented Jan 27, 2025

I've refactored this, added unit testing, and gotten everything cleaned up!

Copy link
Member

@arunshenoy99 arunshenoy99 left a comment

Choose a reason for hiding this comment

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

@bradp Just one comment regarding the translations namespace. Everything else looks good to me. I'll approve and merge as soon as you update that namespace everywhere. I'll also get this QA'ed meanwhile. Thanks!

includes/HealthChecks/AutosaveIntervalHealthCheck.php Outdated Show resolved Hide resolved
@arunshenoy99 arunshenoy99 changed the base branch from main to release/v2.5.0 January 29, 2025 07:54
@arunshenoy99 arunshenoy99 merged commit 42494c5 into release/v2.5.0 Jan 29, 2025
1 check passed
@arunshenoy99 arunshenoy99 deleted the feature/health-checks branch January 29, 2025 09:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants