Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
Add ratelimiter (#1185)
Thibault Le Ouay58da54a40346
diff --git a/apps/workflows/package.json b/apps/workflows/package.jsonindex f111202c8..1bf178178 100644--- a/apps/workflows/package.json+++ b/apps/workflows/package.json@@ -9,9 +9,10 @@"@google-cloud/tasks": "4.0.1","@openstatus/db": "workspace:*","@openstatus/emails": "workspace:*",- "@openstatus/utils": "workspace:*","@openstatus/upstash": "workspace:*",+ "@openstatus/utils": "workspace:*","hono": "4.5.3",+ "limiter": "^3.0.0","zod": "3.23.8"},"devDependencies": {diff --git a/apps/workflows/src/cron/monitor.ts b/apps/workflows/src/cron/monitor.tsindex f40c74db6..25ddc2fff 100644--- a/apps/workflows/src/cron/monitor.ts+++ b/apps/workflows/src/cron/monitor.ts@@ -1,3 +1,4 @@+import { CloudTasksClient } from "@google-cloud/tasks";import type { google } from "@google-cloud/tasks/build/protos/protos";import {and,@@ -12,14 +13,13 @@ import {schema,} from "@openstatus/db";import { session, user } from "@openstatus/db/src/schema";--import { CloudTasksClient } from "@google-cloud/tasks";import {MonitorDeactivationEmail,MonitorPausedEmail,} from "@openstatus/emails";import { sendWithRender } from "@openstatus/emails/src/send";import { Redis } from "@openstatus/upstash";+import { RateLimiter } from "limiter";import { z } from "zod";import { env } from "../env";@@ -39,6 +39,8 @@ const parent = client.queuePath("workflow",);+const limiter = new RateLimiter({ tokensPerInterval: 50, interval: "minute" });+export async function LaunchMonitorWorkflow() {// Expires is one month after last connection, so if we want to reach people who connected 3 months ago we need to check for people with expires 2 months agoconst twoMonthAgo = new Date().setMonth(new Date().getMonth() - 2);@@ -127,6 +129,7 @@ export async function LaunchMonitorWorkflow() {const allResult = [];for (const user of users) {+ await limiter.removeTokens(1);const workflow = workflowInit({ user });allResult.push(workflow);}@@ -154,6 +157,7 @@ async function workflowInit({// Let's check if the user is in the workflowconst isMember = await redis.sismember("workflow:users", user.userId);if (isMember) {+ console.log(`user workflow already started for ${user.userId}`);return;}// check if user has some running monitors@@ -166,6 +170,7 @@ async function workflowInit({),);if (nbRunningMonitor > 0) {+ console.log(`user has running monitors for ${user.userId}`);return;}await CreateTask({diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 69bbd433c..b9c02cf96 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -77,7 +77,7 @@ importers:version: 0.2.1([email protected])([email protected])'@libsql/client':specifier: 0.14.0- version: 0.14.0([email protected])([email protected])+ version: 0.14.0([email protected])([email protected])'@openstatus/db':specifier: workspace:*version: link:../../packages/db@@ -92,7 +92,7 @@ importers:version: 2.6.2drizzle-orm:specifier: 0.35.3- version: 0.35.3(@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])+ version: 0.35.3(@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected])(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])hono:specifier: 4.5.3version: 4.5.3@@ -223,7 +223,7 @@ importers:version: 3.9.1([email protected]([email protected]))'@libsql/client':specifier: 0.14.0- version: 0.14.0([email protected])([email protected])+ version: 0.14.0([email protected])([email protected])'@openstatus/analytics':specifier: workspace:*version: link:../../packages/analytics@@ -495,6 +495,9 @@ importers:hono:specifier: 4.5.3version: 4.5.3+ limiter:+ specifier: ^3.0.0+ version: 3.0.0zod:specifier: 3.23.8version: 3.23.8@@ -504,7 +507,7 @@ importers:version: link:../../packages/tsconfig'@types/bun':specifier: latest- version: 1.1.14+ version: 1.2.2packages/analytics:dependencies:@@ -615,10 +618,10 @@ importers:version: 0.7.0([email protected])([email protected])drizzle-orm:specifier: 0.35.3- version: 0.35.3(@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])+ version: 0.35.3(@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])drizzle-zod:specifier: 0.5.1- version: 0.5.1([email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]))([email protected])+ version: 0.5.1([email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]))([email protected])zod:specifier: 3.23.8version: 3.23.8@@ -916,7 +919,7 @@ importers:tsup:specifier: 7.2.0- version: 7.2.0([email protected])([email protected](@types/[email protected])([email protected]))([email protected])+ version: 7.2.0([email protected])([email protected](@types/[email protected])([email protected]))([email protected])typescript:specifier: 5.6.2version: 5.6.2@@ -4339,21 +4342,27 @@ packages:'@scalar/[email protected]':resolution: {integrity: sha512-NMnDzl5dHgUj0k8ZtfssDfy6wv1wO/M+GhpdGr/4OH3m8UZB27CZ3hM7wXh+fm75hZO5XIBsANW20kJVnzpaHg==}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.'@scalar/[email protected]':resolution: {integrity: sha512-9ODfi0OaEvZHdCe09c91eH1R5QPynL+FPxtYuK/9K5ElRE2NqxYysri9AsgOhr1Fqhpy5qKzDj4Gi5FHsJSGXw==}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.'@scalar/[email protected]':resolution: {integrity: sha512-fPIJlY4q1j5gbnsYSxix0IJ7hqcvm8Ly7iVoK66vaL738AIMiGZMhGKtLrTVPad77PimwO+jeq5iDIZ495UY7Q==}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.'@scalar/[email protected]':resolution: {integrity: sha512-kD6erA6aAqjHkj+JrJQKqrqcH4fnCrLi2uYw16CmELIGtqVHFau7ew2c087y4OQTltdi5rEk2zj5zOBu9yaS3Q==}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.'@scalar/[email protected]':resolution: {integrity: sha512-9NpvdMKebg82FkVWoWyOxd1JXAB8KNxmrsFFwQKNjhAw0A5hjNR5oW9lD+FtB1Laupg2FNtw9dcCydnF+LcCWw==}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.'@scalar/[email protected]':resolution: {integrity: sha512-CivUl7wgZ6vlUb01FMdqOt/NVyOWqT0iHZRp5YlPp1pflXZLnAyi5antUTtBEUHUtHM2EO/WR7vx4kRsPcrgLg==}+ deprecated: Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.'@scalar/[email protected]':resolution: {integrity: sha512-z3DEpT/FIZq9yeHL/tz2v6WvdHIiZ4uvK96RdeTPKUUJ0IXvA5vONG3PF5LE0Q/408PCzWsZpGs9f97ztaeJSQ==}@@ -4954,8 +4963,8 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-r1bzfrm0tomOI8g1SzvCaQHo6Lcv6zu0EA+W2kHrt8dyrHQxGzBBL4kdkzIS+jBMV+EYcMAEAqXqYaLJq5rOZg==}- '@types/[email protected]':- resolution: {integrity: sha512-opVYiFGtO2af0dnWBdZWlioLBoxSdDO5qokaazLhq8XQtGZbY4pY3/JxY8Zdf/hEwGubbp7ErZXoN1+h2yesxA==}+ '@types/[email protected]':+ resolution: {integrity: sha512-tr74gdku+AEDN5ergNiBnplr7hpDp3V1h7fqI2GcR/rsUaM39jpSeKH0TFibRvU0KwniRx5POgaYnaXbk0hU+w==}'@types/[email protected]':resolution: {integrity: sha512-2in/lrHRNmDvHPgyormtEralhPcN3An1gLjJzj2Bw145VBxkQ75JEXW6CTdMAwShiHQcYsl2d10IjQSdJSJz4g==}@@ -5062,9 +5071,6 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-w+tIMs3rq2afQdsPJlODhoUEKzFP1ayaoyl1CcnwtIlsVe7K7bA1NGm4s3PraqTLlXnbIN84zuBlxBWo1u9BLw==}- '@types/[email protected]':- resolution: {integrity: sha512-scnD59RpYD91xngrQQLGkE+6UrHUPzeKZWhhjBSa3HSkwjbQc38+q3RoIVEwxQGRw3M+j5hpNAM+lgV3cVormg==}-'@types/[email protected]':resolution: {integrity: sha512-DO+2/jZinXfROG7j7WKFn/3C6nFwxy2lLpgLjEXJz+0XKphZlTLJ14mo8Vfg8X5BWN6XjyESXq+LcYdT7tR3bA==}@@ -5145,9 +5151,6 @@ packages:'@types/[email protected]':resolution: {integrity: sha512-g9gZnnXVq7gM7v3tJCWV/qw7w+KeOlSHAhgF9RytFyifW6AF61hdT2ucrYhPq9hLs5JIryeupHV3qGk95dH9ow==}- '@types/[email protected]':- resolution: {integrity: sha512-vmQSUcfalpIq0R9q7uTo2lXs6eGIpt9wtnLdMv9LVpIjCA/+ufZRozlVoVelIYixx1ugCBKDhn89vnsEGOCx9A==}-'@types/[email protected]':resolution: {integrity: sha512-osM/gWBTPKgHV8XkTunnegTRIsvF6owmf5w+JtAfOw472dptdm0dlGv4xCt6GwQRcC2XVOvvRE/0bAoQcL2QkA==}@@ -5689,11 +5692,8 @@ packages:resolution: {integrity: sha512-2dNB+dBwAcFW7RSd4y5vKycRjouKVklSwPk4EjBKWvcMYUBOqZGGNzV7+b2tfKBG3BeRXnozbnegVKR1azuATg==}- resolution: {integrity: sha512-C65lv6eBr3LPJWFZ2gswyrGZ82ljnH8flVE03xeXxKhi2ZGtFiO4isRKTKnitbSqtRAcaqYSR6djt1whI66AbA==}-- resolution: {integrity: sha512-yVXBZ1/ATZJD5FvfhDydw45ED8DlmTflumPKj56p5/GLjYiHBZkirzad6MU6MSZKgZ4o1/Ks5lL/Jgg/fRXBSQ==}+ resolution: {integrity: sha512-RCbMH5elr9gjgDGDhkTTugA21XtJAy/9jkKe/G3WR2q17VPGhcquf9Sir6uay9iW+7P/BV0CAHA1XlHXMAVKHg==}resolution: {integrity: sha512-jwzPOChofl67PSTW2SGubV9HBQAhhR2i6nskiOThauo9dzwDUgOWQScFVaJkjEfYX+UXiD+LEx8EblQMc2wIag==}@@ -7461,6 +7461,7 @@ packages:resolution: {integrity: sha512-sorTJV6PNt94Wap27Sai5gtVLIea4Otb2LUiAUyr3p6BPOScGMKGt5F1b5X/XgkNtcsDKeX5qfeBDj+PdShclQ==}+ cpu: [x64, arm64, wasm32]os: [darwin, linux, win32]@@ -7475,6 +7476,9 @@ packages:resolution: {integrity: sha512-/vlFKAoH5Cgt3Ie+JLhRbwOsCQePABiU3tJ1egGvyQ+33R/vcwM2Zl2QR/LzjsBeItPt3oSVXapn+m4nQDvpzw==}engines: {node: '>=14'}+ resolution: {integrity: sha512-hev7DuXojsTFl2YwyzUJMDnZ/qBDd3yZQLSH3aD4tdL1cqfc3TMnoecEJtWFaQFdErZsKoFMBTxF/FBSkgDbEg==}+resolution: {integrity: sha512-7ylylesZQ/PV29jhEDl3Ufjo6ZX7gCqJr5F7PKrqc93v7fzSymt1BpwEU8nAUXs8qzzvqhbjhK5QZg6Mt/HkBg==}@@ -7519,6 +7523,7 @@ packages:resolution: {integrity: sha512-z+Uw/vLuy6gQe8cfaFWD7p0wVv8fJl3mbzXh33RS+0oW2wvUqiRXiQ69gLWSLpgB5/6sU+r6BlQR0MBILadqTQ==}+ deprecated: This package is deprecated. Use the optional chaining (?.) operator instead.resolution: {integrity: sha512-oSXzaWypCMHkPC3NvBEaPHf0KsA5mvPrOPgQWDsbg8n7orZ290M0BmC/jgRZ4vcJ6DTAhjrsSYgdsW/F+MFOBA==}@@ -12255,17 +12260,6 @@ snapshots:- bufferutil- utf-8-validate- dependencies:- '@libsql/core': 0.14.0- '@libsql/hrana-client': 0.7.0([email protected])([email protected])- js-base64: 3.7.5- libsql: 0.4.5- promise-limit: 2.7.0- transitivePeerDependencies:- - bufferutil- - utf-8-validate-'@libsql/[email protected]':dependencies:js-base64: 3.7.5@@ -12286,34 +12280,16 @@ snapshots:- bufferutil- utf-8-validate- dependencies:- '@libsql/isomorphic-fetch': 0.3.1- '@libsql/isomorphic-ws': 0.1.5([email protected])([email protected])- js-base64: 3.7.5- node-fetch: 3.3.2- transitivePeerDependencies:- - bufferutil- - utf-8-validate-'@libsql/[email protected]': {}dependencies:- '@types/ws': 8.5.10+ '@types/ws': 8.5.13ws: 8.17.0([email protected])([email protected])transitivePeerDependencies:- bufferutil- utf-8-validate- dependencies:- '@types/ws': 8.5.10- ws: 8.17.0([email protected])([email protected])- transitivePeerDependencies:- - bufferutil- - utf-8-validate-'@libsql/[email protected]':optional: true@@ -14772,9 +14748,9 @@ snapshots:dependencies:'@babel/types': 7.26.3- '@types/[email protected]':+ '@types/[email protected]':dependencies:- bun-types: 1.1.37+ bun-types: 1.2.2'@types/[email protected]': {}@@ -14884,10 +14860,6 @@ snapshots:'@types/[email protected]': {}- '@types/[email protected]':- dependencies:- undici-types: 5.26.5-'@types/[email protected]':dependencies:undici-types: 5.26.5@@ -14979,14 +14951,9 @@ snapshots:'@types/[email protected]': {}- '@types/[email protected]':- dependencies:- '@types/node': 22.10.2-'@types/[email protected]':dependencies:'@types/node': 22.10.2- optional: true'@uiw/[email protected](@codemirror/[email protected])(@codemirror/[email protected])(@codemirror/[email protected])':dependencies:@@ -15734,16 +15701,10 @@ snapshots:- dependencies:- '@types/node': 20.12.14- '@types/ws': 8.5.10-dependencies:- '@types/node': 20.12.14+ '@types/node': 22.10.2'@types/ws': 8.5.13- optional: truedependencies:@@ -16270,7 +16231,7 @@ snapshots:transitivePeerDependencies:- supports-color- [email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]):+ [email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]):dependencies:'@libsql/client-wasm': 0.14.0optionalDependencies:@@ -16280,25 +16241,25 @@ snapshots:'@types/pg': 8.11.10'@types/react': 19.0.1better-sqlite3: 11.4.0- bun-types: 1.1.40+ bun-types: 1.2.2react: 19.0.0- [email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]):+ [email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected])(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]):dependencies:'@libsql/client-wasm': 0.14.0optionalDependencies:'@cloudflare/workers-types': 4.20241230.0- '@libsql/client': 0.14.0([email protected])([email protected])+ '@libsql/client': 0.14.0([email protected])([email protected])'@opentelemetry/api': 1.9.0'@types/pg': 8.11.10'@types/react': 19.0.1better-sqlite3: 11.7.0- bun-types: 1.1.40+ bun-types: 1.2.2react: 19.0.0- [email protected]([email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]))([email protected]):+ [email protected]([email protected](@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected]))([email protected]):dependencies:- drizzle-orm: 0.35.3(@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])+ drizzle-orm: 0.35.3(@cloudflare/[email protected])(@libsql/[email protected])(@libsql/[email protected]([email protected])([email protected]))(@opentelemetry/[email protected])(@types/[email protected])(@types/[email protected])([email protected])([email protected])([email protected])zod: 3.23.8@@ -17724,6 +17685,8 @@ snapshots:+ [email protected]: {}+@@ -19111,12 +19074,12 @@ snapshots:camelcase-css: 2.0.1postcss: 8.4.49- [email protected]([email protected])([email protected](@types/[email protected])([email protected])):+ [email protected]([email protected])([email protected](@types/[email protected])([email protected])):dependencies:lilconfig: 2.1.0yaml: 2.3.3optionalDependencies:- postcss: 8.4.49+ postcss: 8.4.38ts-node: 10.9.2(@types/[email protected])([email protected])[email protected]([email protected])([email protected](@types/[email protected])([email protected])):@@ -20750,7 +20713,7 @@ snapshots:- [email protected]([email protected])([email protected](@types/[email protected])([email protected]))([email protected]):+ [email protected]([email protected])([email protected](@types/[email protected])([email protected]))([email protected]):dependencies:bundle-require: 4.0.2([email protected])cac: 6.7.14@@ -20760,14 +20723,14 @@ snapshots:execa: 5.1.1globby: 11.1.0joycon: 3.1.1- postcss-load-config: 4.0.1([email protected])([email protected](@types/[email protected])([email protected]))+ postcss-load-config: 4.0.1([email protected])([email protected](@types/[email protected])([email protected]))resolve-from: 5.0.0rollup: 3.29.4source-map: 0.8.0-beta.0sucrase: 3.34.0tree-kill: 1.2.2optionalDependencies:- postcss: 8.4.49+ postcss: 8.4.38typescript: 5.6.2transitivePeerDependencies:- supports-color@@ -21439,11 +21402,6 @@ snapshots:bufferutil: 4.0.8utf-8-validate: 6.0.3- optionalDependencies:- bufferutil: 4.0.8- utf-8-validate: 6.0.5-optionalDependencies:bufferutil: 4.0.8