In today’s global world, there’s a growing demand to ensure your applications work correctly around the clock.
Many businesses, including UKFast, rely on open source frameworks like Laravel and Lumen to provide effective solutions for their customers. By getting involved with open source development, business owners and developers can take a framework and shape it into something with the potential to help in innovative new ways.
That’s how UKFast’s Laravel Health Check package was created.
As a development team we love using the package internally. It allows us to monitor UKFast’s expansive suite of APIs , identify and solve issues during the development process. Once we discovered how helpful it was, we knew we had to open source it so our customers and the open source community could benefit too.
UKFast’s Laravel Health Check package supports lots of core health checks out of the box, with more being added periodically. In this blog, we’re looking at how the package makes monitoring new functionality easier.
We’re going to be adding a
CacheHealthCheck for our apps, which is now a part of the Laravel Health Check package.
We’ll need to create our new check inside the
App\HealthChecks directory called
Below is the basic structure of our check file. You’ll see we’ve given the check a name and set the status to return
OK for now.
The package contains a
config/healthcheck.php file where our configuration goes. This can be published and altered by users, but for simplicity, we’ll stick to the Laravel defaults.
We want our new check to work out of the box, but we also want users to specify which cache stores to run checks against.
So, in our
healthcheck.php config file, let’s add our config.
Now if the user wants to use the
CacheHealthCheck out of the box, it’ll work.
status() method we’re going to build out our cache check.
We want to ensure that we can store something in our application’s cache and get the value back out (removing it as we go).
We also want to support checking multiple cache stores, which is as easy as using a foreach loop on the stores array we added to the config in the last step.
Now we’ve created our check, we can jump into a fresh Laravel 7 application and see the magic happen. If we add the
database store to our
config/healthcheck.php file (without having migrated the database table), the check will fail.
If we add the
array store (which is configured out of the box), it will show up in the
Finally, if we remove the database store (or migrate the
cache database table), the check will return an
As with all good code, we need to write a test, which we’ll include when committing this check into the package. The latest version of the
CacheHealthCheck can be found in the UKFast GitHub repository.
Hopefully, this post demonstrates how useful developing custom functionality using open source packages can be.
We hope you enjoy using the package as much as we do!
At UKFast we care about empowering our clients while giving back to the digital community. Find out more about our open source contributions.