Skip to content

Open-source status page, incident response and uptime monitoring

πŸ“š How to use OpenStatus in CI (#878)

Thibault Le Ouay8301b23a6103
diff --git a/apps/docs/guides/introduction.mdx b/apps/docs/guides/introduction.mdx
new file mode 100644
index 000000000..c99b65dad
--- /dev/null
+++ b/apps/docs/guides/introduction.mdx
@@ -0,0 +1,8 @@
+---
+title: Introduction
+---
+
+Here's some content for the getting started with OpenStatus.
+
+- How to use OpenStatus to test latency in GitHub Actions
+
diff --git a/apps/docs/guides/latency-ci-integration-test.mdx b/apps/docs/guides/latency-ci-integration-test.mdx
new file mode 100644
index 000000000..9265e69e9
--- /dev/null
+++ b/apps/docs/guides/latency-ci-integration-test.mdx
@@ -0,0 +1,182 @@
+---
+title: How to use OpenStatus in GitHub Actions to test your Cloudflare Workers latency.
+description: 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](https://github.com/openstatusHQ/github-action-rollback).
+
+
+## Prerequisites
+
+- A Cloudflare Account.
+- A GitHub Account.
+- An [OpenStatus](https://www.openstatus.dev) Account.
+
+
+## Our API Endpoint
+
+For this guide, we are using a simple [Hono](https://www.hono.dev) server that returns `Hello OpenStatus!`.
+We are deploying it on [Cloudflare Workers](https://workers.cloudflare.com/). 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.
+
+
+```typescript
+import { Hono } from "hono";
+
+const app = new Hono();
+
+app.get("/", async (c) => {
+ return c.text("Hello OpenStatus!");
+});
+
+export default app;
+```
+
+
+## Setting up the test
+
+For the test, we are using the [OpenStatus API](https://docs.openstatus.dev/api-reference/check/post-check) 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:
+
+1. Settings -> 2. API Tokens -> 3. Create API Key
+
+<Frame caption="GitHub Settings">
+ <img
+ src="/images/guides/latency-ci-integration-test/openstatus-api-token.png"
+ alt="OpenStatus API Key Creation"
+ />
+</Frame>
+
+If you want to run the test locally copy your API key to a `.env` file.
+
+```env
+OPENSTATUS_API_KEY=your-api-key
+```
+
+Here is our test first we warm up our endpoint and then run the latency test with OpenStatus.
+
+
+
+```typescript
+test("should fail if p75 > 1000", async () => {
+
+ // Let's warm our endpoint
+ await fetch("https://github-action-rollback.thibaultleouay.workers.dev/");
+ // Run the test
+ const options = {
+ method: "POST",
+ headers: {
+ "Content-Type": "application/json",
+ "x-openstatus-key": process.env.OPENSTATUS_API_KEY || "",
+ },
+ body: '{"url":"https://github-action-rollback.thibaultleouay.workers.dev/","method":"GET","regions":["ams","iad","gru","hkg","jnb","syd"],"runCount":2,"aggregated":true}',
+ };
+
+ const data = await fetch("https://api.openstatus.dev/v1/check", options);
+ const json = await data.json();
+ const result = schema.parse(json);
+ expect(result.aggregated.firstByte.p75 < 1000).toBe(true);
+});
+```
+
+## Setting up the GitHub Actions
+
+We will use GitHub Actions to deploy our endpoint and run the test.
+We are using the bun CLI 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.
+
+
+<Frame caption="GitHub Settings">
+ <img
+ src="/images/guides/latency-ci-integration-test/github-api-token.png"
+ alt="GitHub Secrets"
+ />
+</Frame>
+
+
+
+Here is the GitHub Action workflow file:
+
+```yaml
+
+name: Deploy
+
+on:
+ push:
+ branches:
+ - main
+
+jobs:
+ deploy:
+ name: Deploy πŸ”₯
+ runs-on: ubuntu-latest
+ env:
+ OPENSTATUS_API_KEY: ${{ secrets.OPENSTATUS_API_KEY }}
+ CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
+ CLOUDFLARE_ACCOUNT_ID: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
+
+ steps:
+ - name: ⬇️ Checkout repo
+ uses: actions/checkout@v3
+
+ - name: πŸ”₯ Install bun
+ uses: oven-sh/setup-bun@v1
+ with:
+ bun-version: latest
+
+ - name: πŸ“₯ Download deps
+ run: bun install
+
+ - name: πŸ”₯ Deploy
+ run: bun run deploy
+
+
+ - name: πŸ§ͺ Test
+ run: bun test
+ id: test
+
+ - name: πŸš€ Rollback
+ if: failure() && steps.test.outcome == 'failure'
+ run: bun run rollback
+```
+
+In the workflow file, we have this step it will only run if the test fails:
+
+```yaml
+ - name: πŸš€ Rollback
+ if: failure() && steps.test.outcome == 'failure'
+ run: bun run rollback
+```
+
+and in our package.json we have the following script:
+
+```json
+{
+ "scripts": {
+ "rollback": "wrangler rollback --message 'Integration test failed'"
+ }
+}
+```
+
+If you want to see the example in action, you can check the [GitHub repository actions](https://github.com/openstatusHQ/github-action-rollback/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.
\ No newline at end of file
diff --git a/apps/docs/images/guides/latency-ci-integration-test/github-api-token.png b/apps/docs/images/guides/latency-ci-integration-test/github-api-token.png
new file mode 100644
index 000000000..78d5ae743
Binary files /dev/null and b/apps/docs/images/guides/latency-ci-integration-test/github-api-token.png differ
diff --git a/apps/docs/images/guides/latency-ci-integration-test/openstatus-api-token.png b/apps/docs/images/guides/latency-ci-integration-test/openstatus-api-token.png
new file mode 100644
index 000000000..c86536c9f
Binary files /dev/null and b/apps/docs/images/guides/latency-ci-integration-test/openstatus-api-token.png differ
diff --git a/apps/docs/mint.json b/apps/docs/mint.json
index 6aa117768..3dd131702 100644
--- a/apps/docs/mint.json
+++ b/apps/docs/mint.json
@@ -50,6 +50,10 @@
"name": "API Reference",
"url": "api-reference"
},
+ {
+ "name": "Guides",
+ "url": "guides"
+ },
{
"name": "Contributor Guides",
"url": "contributing"
@@ -202,6 +206,10 @@
]
}
]
+ },
+ {
+ "group": "Guides",
+ "pages": ["guides/introduction", "guides/latency-ci-integration-test"]
}
],
"analytics": {
diff --git a/packages/tinybird/datasources/check_response.datasource b/packages/tinybird/datasources/check_response.datasource
new file mode 100644
index 000000000..1673dffec
--- /dev/null
+++ b/packages/tinybird/datasources/check_response.datasource
@@ -0,0 +1,24 @@
+VERSION 0
+
+SCHEMA >
+ `requestId` Int64 `json:$.requestId`,
+ `workspaceId` Int64 `json:$.workspaceId`,
+ `latency` Int64 `json:$.latency`,
+ `region` String `json:$.region`,
+ `time` DateTime `json:$.time`,
+ `headers` String `json:$.headers`,
+ `timing_connectDone` Int64 `json:$.timing.connectDone`,
+ `timing_connectStart` Int64 `json:$.timing.connectStart`,
+ `timing_dnsDone` Int64 `json:$.timing.dnsDone`,
+ `timing_dnsStart` Int64 `json:$.timing.dnsStart`,
+ `timing_firstByteDone` Int64 `json:$.timing.firstByteDone`,
+ `timing_firstByteStart` Int64 `json:$.timing.firstByteStart`,
+ `timing_tlsHandshakeDone` Int64 `json:$.timing.tlsHandshakeDone`,
+ `timing_tlsHandshakeStart` Int64 `json:$.timing.tlsHandshakeStart`,
+ `timing_transferDone` Int64 `json:$.timing.transferDone`,
+ `timing_transferStart` Int64 `json:$.timing.transferStart`
+
+ENGINE "MergeTree"
+ENGINE_SORTING_KEY "workspaceId, requestId, time"
+ENGINE_TTL ""
+ENGINE_PARTITION_KEY ""
\ No newline at end of file
diff --git a/packages/tinybird/datasources/ping_response.datasource b/packages/tinybird/datasources/ping_response.datasource
index d0e796930..e5a17562a 100644
--- a/packages/tinybird/datasources/ping_response.datasource
+++ b/packages/tinybird/datasources/ping_response.datasource
@@ -10,8 +10,8 @@ SCHEMA >
`workspaceId` String `json:$.workspaceId`,
`cronTimestamp` Int64 `json:$.cronTimestamp`,
`message` Nullable(String) `json:$.message`,
- `timing` Nullable(String) `json:$.message`,
- `headers` Nullable(String) `json:$.message`
+ `timing` Nullable(String) `json:$.timing`,
+ `headers` Nullable(String) `json:$.headers`,
ENGINE "MergeTree"
ENGINE_SORTING_KEY "monitorId, cronTimestamp"