How to use OpenStatus in GitHub Actions to test your Cloudflare Workers latency.
Learn how to use OpenStatus for testing latency in your GitHub Actions to verify your Cloudflare Workers’ performance.
Introduction
As a developer, you want to make sure your endpoints are fast and reliable after each deployment.
In this guide, we will show you how to use OpenStatus for testing latency in GitHub Actions to verify your endpoint’s performance.
We’ll deploy a basic API endpoint and run a latency test in a GitHub Action with OpenStatus. If the latency is higher than expected, we will roll back the deployment.
All the code showcased in this guide is available on GitHub.
Prerequisites
- A Cloudflare Account.
- A GitHub Account.
- An OpenStatus Account.
Our API Endpoint
For this guide, we are using a simple Hono server that returns Hello OpenStatus!
.
We are deploying it on Cloudflare Workers. Cloudflare Workers is a serverless platform that allows you to deploy your code globally. They are fast and reliable. But sometimes you might introduce a bug that slows down your endpoint.
Setting up the test
For the test, we are using the OpenStatus API to run a global latency test on our endpoint. If the latency is higher than expected, we will roll back the deployment. We expect our endpoint to have a 75th percentile latency of less than 1000ms in all regions.
You need to get your OpenStatus API key from the OpenStatus dashboard.
To get your API key, go to:
- Settings -> 2. API Tokens -> 3. Create API Key
GitHub Settings
If you want to run the test locally copy your API key to a .env
file.
Here is our test first we warm up our endpoint and then run the latency test with OpenStatus.
Setting up the GitHub Actions
We will use GitHub Actions to deploy our endpoint and run the test. We are using the package.json command to deploy our endpoint instead of the Cloudflare Workers Action and run the test
You need to set up your secrets in the GitHub repository settings for the OpenStatus API key and Cloudflare API token.
Go to 1. Settings -> 2. Secrets and variables -> 3. New repository secret.
GitHub Settings
Here is the GitHub Action workflow file:
In the workflow file, we have this step it will only run if the test fails:
and in our package.json we have the following script:
If you want to see the example in action, you can check the GitHub repository actions
Conclusion
We have successfully set up a GitHub Action that deploys our endpoint our Cloudflare Workers and runs a latency test against it with OpenStatus.
Don’t ever let your users experience slow endpoints, use OpenStatus to monitor your endpoint’s performance and roll back deployments if needed.