Skip to content

Open-source status page, incident response and uptime monitoring

๐ŸŒ More regions (#881)

Thibault Le Ouay59d180d29a69
diff --git a/apps/checker/README.md b/apps/checker/README.md
index 61674c22c..135f8a8f3 100644
--- a/apps/checker/README.md
+++ b/apps/checker/README.md
@@ -28,3 +28,9 @@ docker run -p 8080:8080 checker
```bash
fly deploy
```
+
+## Deploy to all region
+
+```bash
+fly scale count 35 --region ams,arn,atl,bog,bom,bos,cdg,den,dfw,ewr,eze,fra,gdl,gig,gru,hkg,iad,jnb,lax,lhr,mad,mia,nrt,ord,otp,phx,qro,scl,sjc,sea,sin,syd,waw,yul,yyz
+```
diff --git a/apps/server/src/env.ts b/apps/server/src/env.ts
index 255e074c1..fc2dc20c7 100644
--- a/apps/server/src/env.ts
+++ b/apps/server/src/env.ts
@@ -1,7 +1,7 @@
import { createEnv } from "@t3-oss/env-core";
import { z } from "zod";
-import { flyRegions } from "@openstatus/utils";
+import { flyRegions } from "@openstatus/db/src/schema";
export const env = createEnv({
server: {
diff --git a/apps/server/src/v1/monitors/post.ts b/apps/server/src/v1/monitors/post.ts
index 2a8ac1bb4..32acc4e7c 100644
--- a/apps/server/src/v1/monitors/post.ts
+++ b/apps/server/src/v1/monitors/post.ts
@@ -70,6 +70,12 @@ export function registerPostMonitor(api: typeof monitorsApi) {
throw new HTTPException(403, { message: "Forbidden" });
}
+ for (const region of input.regions) {
+ if (!workspacePlan.limits.regions.includes(region)) {
+ throw new HTTPException(403, { message: "Upgrade for more region" });
+ }
+ }
+
const { headers, regions, assertions, ...rest } = input;
const assert = assertions ? getAssertions(assertions) : [];
diff --git a/apps/server/src/v1/monitors/put.ts b/apps/server/src/v1/monitors/put.ts
index da563b758..5dbd22c27 100644
--- a/apps/server/src/v1/monitors/put.ts
+++ b/apps/server/src/v1/monitors/put.ts
@@ -50,6 +50,11 @@ export function registerPutMonitor(api: typeof monitorsApi) {
throw new HTTPException(403, { message: "Forbidden" });
}
+ for (const region of input.regions) {
+ if (!workspacePlan.limits.regions.includes(region)) {
+ throw new HTTPException(403, { message: "Upgrade for more region" });
+ }
+ }
const _monitor = await db
.select()
.from(monitor)
diff --git a/apps/web/public/assets/changelog/more-regions.png b/apps/web/public/assets/changelog/more-regions.png
new file mode 100644
index 000000000..c0457f80d
Binary files /dev/null and b/apps/web/public/assets/changelog/more-regions.png differ
diff --git a/apps/web/src/app/api/checker/cron/_cron.ts b/apps/web/src/app/api/checker/cron/_cron.ts
index 5952eb463..7e75e9762 100644
--- a/apps/web/src/app/api/checker/cron/_cron.ts
+++ b/apps/web/src/app/api/checker/cron/_cron.ts
@@ -45,7 +45,7 @@ export const cron = async ({
const parent = client.queuePath(
env.GCP_PROJECT_ID,
env.GCP_LOCATION,
- periodicity,
+ periodicity
);
const timestamp = Date.now();
@@ -54,7 +54,7 @@ export const cron = async ({
.select({ id: maintenance.id })
.from(maintenance)
.where(
- and(lte(maintenance.from, new Date()), gte(maintenance.to, new Date())),
+ and(lte(maintenance.from, new Date()), gte(maintenance.to, new Date()))
)
.as("currentMaintenance");
@@ -63,7 +63,7 @@ export const cron = async ({
.from(maintenancesToMonitors)
.innerJoin(
currentMaintenance,
- eq(maintenancesToMonitors.maintenanceId, currentMaintenance.id),
+ eq(maintenancesToMonitors.maintenanceId, currentMaintenance.id)
);
const result = await db
@@ -73,8 +73,8 @@ export const cron = async ({
and(
eq(monitor.periodicity, periodicity),
eq(monitor.active, true),
- notInArray(monitor.id, currentMaintenanceMonitors),
- ),
+ notInArray(monitor.id, currentMaintenanceMonitors)
+ )
)
.all();
@@ -84,7 +84,7 @@ export const cron = async ({
const allResult = [];
for (const row of monitors) {
- const selectedRegions = row.regions.length > 0 ? row.regions : ["auto"];
+ const selectedRegions = row.regions.length > 0 ? row.regions : ["ams"];
const result = await db
.select()
@@ -127,7 +127,7 @@ export const cron = async ({
const failed = allRequests.filter((r) => r.status === "rejected").length;
console.log(
- `End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`,
+ `End cron for ${periodicity} with ${allResult.length} jobs with ${success} success and ${failed} failed`
);
};
// timestamp needs to be in ms
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx
index 5cbc10105..c01963f51 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/_components/data-table-wrapper.tsx
@@ -19,6 +19,8 @@ import { DataTable } from "@/components/data-table/data-table";
import { LoadingAnimation } from "@/components/loading-animation";
import { ResponseDetailTabs } from "@/components/ping-response-analysis/response-detail-tabs";
import { api } from "@/trpc/client";
+import type { z } from "zod";
+import type { monitorFlyRegionSchema } from "@openstatus/db/src/schema";
// EXAMPLE: get the type of the response of the endpoint
// biome-ignore lint/correctness/noUnusedVariables: <explanation>
@@ -29,7 +31,7 @@ export type Monitor = {
monitorId: string;
url: string;
latency: number;
- region: "ams" | "iad" | "hkg" | "jnb" | "syd" | "gru";
+ region: z.infer<typeof monitorFlyRegionSchema>;
statusCode: number | null;
timestamp: number;
workspaceId: string;
@@ -80,7 +82,7 @@ function Details({ row }: { row: Row<Monitor> }) {
url: row.original.url,
region: row.original.region,
cronTimestamp: row.original.cronTimestamp || undefined,
- }),
+ })
);
if (!data || data.length === 0) return <p>Something went wrong</p>;
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/details/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/details/page.tsx
index fad1aee19..940cd9d7a 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/details/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/details/page.tsx
@@ -2,12 +2,11 @@ import Link from "next/link";
import * as z from "zod";
import { Button } from "@openstatus/ui";
-import { flyRegions } from "@openstatus/utils";
import { EmptyState } from "@/components/dashboard/empty-state";
import { ResponseDetails } from "@/components/monitor-dashboard/response-details";
import { api } from "@/trpc/server";
-
+import { monitorFlyRegionSchema } from "@openstatus/db/src/schema";
//
/**
@@ -16,7 +15,7 @@ import { api } from "@/trpc/server";
const searchParamsSchema = z.object({
monitorId: z.string(),
url: z.string(),
- region: z.enum(flyRegions).optional(),
+ region: monitorFlyRegionSchema.optional(),
cronTimestamp: z.coerce.number(),
});
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
index 7933cd5a9..7807bf13b 100644
--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
@@ -44,7 +44,7 @@ const searchParamsSchema = z.object({
value
?.trim()
?.split(",")
- .filter((i) => flyRegions.includes(i as Region)) ?? flyRegions,
+ .filter((i) => flyRegions.includes(i as Region)) ?? []
),
});
@@ -117,7 +117,7 @@ export default async function Page({
period={period}
quantile={quantile}
interval={interval}
- regions={regions as Region[]} // FIXME: not properly reseted after filtered
+ regions={regions.length ? (regions as Region[]) : monitor.regions} // FIXME: not properly reseted after filtered
monitor={monitor}
isQuantileDisabled={isQuantileDisabled}
metricsByRegion={metricsByRegion}
diff --git a/apps/web/src/components/data-table/columns.tsx b/apps/web/src/components/data-table/columns.tsx
index 10f825c26..b39e875b9 100644
--- a/apps/web/src/components/data-table/columns.tsx
+++ b/apps/web/src/components/data-table/columns.tsx
@@ -11,7 +11,7 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@openstatus/ui";
-import { regionsDict } from "@openstatus/utils";
+import { flyRegionsDict } from "@openstatus/utils";
import { DataTableColumnHeader } from "./data-table-column-header";
import { DataTableStatusBadge } from "./data-table-status-badge";
@@ -98,7 +98,7 @@ export const columns: ColumnDef<Ping>[] = [
<div>
<span className="font-mono">{String(row.getValue("region"))} </span>
<span className="text-muted-foreground text-xs">
- {regionsDict[row.original.region]?.location}
+ {flyRegionsDict[row.original.region]?.location}
</span>
</div>
);
diff --git a/apps/web/src/components/forms/monitor-form.tsx b/apps/web/src/components/forms/monitor-form.tsx
index c37971b57..5e195582d 100644
--- a/apps/web/src/components/forms/monitor-form.tsx
+++ b/apps/web/src/components/forms/monitor-form.tsx
@@ -17,6 +17,7 @@ import {
monitorMethods,
monitorMethodsSchema,
monitorPeriodicitySchema,
+ workspacePlans,
} from "@openstatus/db/src/schema";
import { getLimit } from "@openstatus/plans";
import {
@@ -103,8 +104,7 @@ export function MonitorForm({
periodicity: defaultValues?.periodicity || "30m",
active: defaultValues?.active ?? true,
id: defaultValues?.id || 0,
- regions:
- defaultValues?.regions || (flyRegions as Writeable<typeof flyRegions>),
+ regions: defaultValues?.regions || getLimit("free", "regions"),
headers: defaultValues?.headers?.length
? defaultValues?.headers
: [{ key: "", value: "" }],
@@ -441,7 +441,7 @@ export function MonitorForm({
<Select
onValueChange={(value) =>
field.onChange(
- monitorPeriodicitySchema.parse(value),
+ monitorPeriodicitySchema.parse(value)
)
}
defaultValue={field.value}
@@ -494,7 +494,7 @@ export function MonitorForm({
role="combobox"
className={cn(
"h-10 w-full justify-between",
- !field.value && "text-muted-foreground",
+ !field.value && "text-muted-foreground"
)}
>
{renderText()}
@@ -526,9 +526,9 @@ export function MonitorForm({
"regions",
currentRegions.includes(code)
? currentRegions.filter(
- (r) => r !== code,
+ (r) => r !== code
)
- : [...currentRegions, code],
+ : [...currentRegions, code]
);
}}
>
@@ -537,13 +537,13 @@ export function MonitorForm({
"mr-2 h-4 w-4",
isSelected
? "opacity-100"
- : "opacity-0",
+ : "opacity-0"
)}
/>
{location}
</CommandItem>
);
- },
+ }
)}
</CommandGroup>
</Command>
@@ -650,8 +650,8 @@ export function MonitorForm({
])
: field.onChange(
field.value?.filter(
- (value) => value !== item.id,
- ),
+ (value) => value !== item.id
+ )
);
}}
/>
diff --git a/apps/web/src/components/forms/monitor/form.tsx b/apps/web/src/components/forms/monitor/form.tsx
index 7a717e40d..246e979b6 100644
--- a/apps/web/src/components/forms/monitor/form.tsx
+++ b/apps/web/src/components/forms/monitor/form.tsx
@@ -4,6 +4,7 @@ import { zodResolver } from "@hookform/resolvers/zod";
import { usePathname, useRouter } from "next/navigation";
import * as React from "react";
import { useForm } from "react-hook-form";
+import { getLimit } from "@openstatus/plans";
import * as assertions from "@openstatus/assertions";
import type {
@@ -14,7 +15,7 @@ import type {
Page,
WorkspacePlan,
} from "@openstatus/db/src/schema";
-import { flyRegions, insertMonitorSchema } from "@openstatus/db/src/schema";
+import { insertMonitorSchema } from "@openstatus/db/src/schema";
import { Badge, Form } from "@openstatus/ui";
import {
@@ -72,8 +73,7 @@ export function MonitorForm({
periodicity: defaultValues?.periodicity || "30m",
active: defaultValues?.active ?? true,
id: defaultValues?.id || 0,
- regions:
- defaultValues?.regions || (flyRegions as Writeable<typeof flyRegions>),
+ regions: defaultValues?.regions || getLimit("free", "regions"),
headers: defaultValues?.headers?.length
? defaultValues?.headers
: [{ key: "", value: "" }],
@@ -138,7 +138,7 @@ export function MonitorForm({
finally: () => {
setPending(false);
},
- },
+ }
);
};
@@ -187,7 +187,7 @@ export function MonitorForm({
JSON.stringify([
...(statusAssertions || []),
...(headerAssertions || []),
- ]),
+ ])
);
const data = (await res.json()) as RegionChecker;
@@ -223,7 +223,7 @@ export function MonitorForm({
if (error instanceof Error && error.name === "AbortError") {
return {
error: `Abort error: request takes more then ${formatDuration(
- ABORT_TIMEOUT,
+ ABORT_TIMEOUT
)}.`,
};
}
diff --git a/apps/web/src/components/forms/monitor/request-test-button.tsx b/apps/web/src/components/forms/monitor/request-test-button.tsx
index c077934d6..5f385f9e9 100644
--- a/apps/web/src/components/forms/monitor/request-test-button.tsx
+++ b/apps/web/src/components/forms/monitor/request-test-button.tsx
@@ -7,6 +7,7 @@ import type {
InsertMonitor,
MonitorFlyRegion,
} from "@openstatus/db/src/schema";
+import { flyRegions } from "@openstatus/db/src/schema";
import {
Button,
Dialog,
@@ -23,18 +24,19 @@ import {
TooltipProvider,
TooltipTrigger,
} from "@openstatus/ui";
-import { flyRegions, flyRegionsDict } from "@openstatus/utils";
+import { flyRegionsDict } from "@openstatus/utils";
import { LoadingAnimation } from "@/components/loading-animation";
import { RegionInfo } from "@/components/ping-response-analysis/region-info";
import { ResponseDetailTabs } from "@/components/ping-response-analysis/response-detail-tabs";
import type { RegionChecker } from "@/components/ping-response-analysis/utils";
import { toast, toastAction } from "@/lib/toast";
+import { getLimit } from "@openstatus/plans";
interface Props {
form: UseFormReturn<InsertMonitor>;
pingEndpoint(
- region?: MonitorFlyRegion,
+ region?: MonitorFlyRegion
): Promise<{ data?: RegionChecker; error?: string }>;
}
@@ -75,6 +77,8 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {
const { statusAssertions, headerAssertions } = form.getValues();
+ const regions = getLimit("free", "regions");
+
return (
<Dialog open={!!check} onOpenChange={() => setCheck(undefined)}>
<div className="group flex h-10 items-center rounded-md bg-transparent text-sm ring-offset-background focus-within:outline-none focus-within:ring-2 focus-within:ring-ring focus-within:ring-offset-2">
@@ -89,7 +93,7 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {
<SelectValue>{flag}</SelectValue>
</SelectTrigger>
<SelectContent>
- {flyRegions.map((region) => {
+ {regions.map((region) => {
const { flag } = flyRegionsDict[region];
return (
<SelectItem key={region} value={region}>
@@ -138,7 +142,7 @@ export function RequestTestButton({ form, pingEndpoint }: Props) {
JSON.stringify([
...(statusAssertions || []),
...(headerAssertions || []),
- ]),
+ ])
)}
/>
</div>
diff --git a/apps/web/src/components/forms/monitor/section-scheduling.tsx b/apps/web/src/components/forms/monitor/section-scheduling.tsx
index 52711e216..55b8f3357 100644
--- a/apps/web/src/components/forms/monitor/section-scheduling.tsx
+++ b/apps/web/src/components/forms/monitor/section-scheduling.tsx
@@ -3,7 +3,10 @@
import type { UseFormReturn } from "react-hook-form";
import type { InsertMonitor, WorkspacePlan } from "@openstatus/db/src/schema";
-import { monitorPeriodicitySchema } from "@openstatus/db/src/schema";
+import {
+ flyRegions,
+ monitorPeriodicitySchema,
+} from "@openstatus/db/src/schema";
import { getLimit } from "@openstatus/plans";
import {
FormControl,
@@ -18,7 +21,7 @@ import {
SelectTrigger,
SelectValue,
} from "@openstatus/ui";
-import { flyRegions, flyRegionsDict } from "@openstatus/utils";
+import { groupByContinent } from "@openstatus/utils";
import { CheckboxLabel } from "../shared/checkbox-label";
import { SectionHeader } from "../shared/section-header";
@@ -40,6 +43,8 @@ interface Props {
export function SectionScheduling({ form, plan }: Props) {
const periodicityLimit = getLimit(plan, "periodicity");
+ const regionsLimit = getLimit(plan, "regions");
+ console.log(form.getValues());
return (
<div className="grid w-full gap-4">
<SectionHeader
@@ -94,46 +99,84 @@ export function SectionScheduling({ form, plan }: Props) {
<div className="mb-4">
<FormLabel className="text-base">Regions</FormLabel>
<FormDescription>
- Select the regions you want to monitor your endpoint from.
+ Select the regions you want to monitor your endpoint from.{" "}
+ <br />
+ {plan === "free"
+ ? "Only a few regions are available in the free plan. Upgrade to access all regions."
+ : ""}
</FormDescription>
</div>
- <div className="grid grid-cols-1 grid-rows-1 gap-4 md:grid-cols-3 sm:grid-cols-2">
- {flyRegions.map((item) => (
- <FormField
- key={item}
- control={form.control}
- name="regions"
- render={({ field }) => {
- const { flag, location } = flyRegionsDict[item];
- return (
- <FormItem key={item} className="h-full w-full">
- <FormControl className="h-full">
- <CheckboxLabel
- id={item}
- name="region"
- checked={field.value?.includes(item)}
- onCheckedChange={(checked) => {
- return checked
- ? field.onChange([
- ...(field.value ? field.value : []),
- item,
- ])
- : field.onChange(
- field.value?.filter(
- (value) => value !== item,
- ),
+ <div>
+ {Object.entries(groupByContinent)
+ .sort((a, b) => a[0].localeCompare(b[0]))
+ .map(([continent, regions]) => {
+ return { continent, regions };
+ })
+ .map((current) => {
+ return (
+ <div key={current.continent} className="py-2">
+ {current.continent}
+
+ <div className="grid grid-cols-3 grid-rows-1 gap-2 pt-1">
+ {current.regions
+ .sort((a, b) =>
+ a.location.localeCompare(b.location)
+ )
+ .map((item) => {
+ return (
+ <FormField
+ key={item.code}
+ control={form.control}
+ name="regions"
+ render={({ field }) => {
+ const { flag, location } = item;
+ return (
+ <FormItem
+ key={item.code}
+ className="h-full w-full"
+ >
+ <FormControl className="h-full">
+ <CheckboxLabel
+ disabled={
+ !regionsLimit.includes(item.code)
+ }
+ id={item.code}
+ name="region"
+ checked={field.value?.includes(
+ item.code
+ )}
+ onCheckedChange={(checked) => {
+ console.log(field.value);
+ return checked
+ ? field.onChange([
+ ...(field.value
+ ? field.value
+ : []),
+ item.code,
+ ])
+ : field.onChange(
+ field.value?.filter(
+ (value) =>
+ value !== item.code
+ )
+ );
+ }}
+ >
+ {location} {flag}
+ </CheckboxLabel>
+ </FormControl>
+ </FormItem>
);
- }}
- >
- {location} {flag}
- </CheckboxLabel>
- </FormControl>
- </FormItem>
- );
- }}
- />
- ))}
+ }}
+ />
+ );
+ })}
+ </div>
+ </div>
+ );
+ })}
</div>
+
<FormMessage />
</FormItem>
);
diff --git a/apps/web/src/components/forms/shared/checkbox-label.tsx b/apps/web/src/components/forms/shared/checkbox-label.tsx
index 861133653..8473c0dfa 100644
--- a/apps/web/src/components/forms/shared/checkbox-label.tsx
+++ b/apps/web/src/components/forms/shared/checkbox-label.tsx
@@ -11,6 +11,7 @@ interface Props {
onCheckedChange(checked: boolean): void;
className?: string;
name: string;
+ disabled?: boolean;
}
export function CheckboxLabel({
@@ -20,6 +21,7 @@ export function CheckboxLabel({
onCheckedChange,
className,
name,
+ disabled,
}: Props) {
return (
<div className="relative h-full">
@@ -29,12 +31,13 @@ export function CheckboxLabel({
className="peer sr-only"
checked={checked}
onCheckedChange={onCheckedChange}
+ disabled={disabled}
/>
<Label
htmlFor={`${name}-${id}`}
className={cn(
"flex h-full items-center gap-1 rounded-md border border-border bg-popover p-4 pr-10 [&:has([data-state=checked])]:border-primary peer-data-[state=checked]:border-primary hover:bg-accent hover:text-accent-foreground",
- className,
+ className
)}
>
{children}
diff --git a/apps/web/src/components/monitor-charts/utils.tsx b/apps/web/src/components/monitor-charts/utils.tsx
index 5b506a0d8..a44d7cd05 100644
--- a/apps/web/src/components/monitor-charts/utils.tsx
+++ b/apps/web/src/components/monitor-charts/utils.tsx
@@ -1,7 +1,7 @@
import { format } from "date-fns";
import type { Region, ResponseGraph } from "@openstatus/tinybird";
-import { regionsDict } from "@openstatus/utils";
+import { flyRegionsDict } from "@openstatus/utils";
import type { Period, Quantile } from "@/lib/monitor/utils";
@@ -14,41 +14,38 @@ import type { Period, Quantile } from "@/lib/monitor/utils";
export function groupDataByTimestamp(
data: ResponseGraph[],
period: Period,
- quantile: Quantile,
+ quantile: Quantile
) {
let currentTimestamp = 0;
const regions: Record<
string,
{ code: string; location: string; flag: string }
> = {};
- const _data = data.reduce(
- (acc, curr) => {
- const { timestamp, region } = curr;
- const latency = curr[`${quantile}Latency`];
- const { flag, code, location } = regionsDict[region];
- const fullNameRegion = `${code}`;
- regions[fullNameRegion] = { flag, code, location }; // to get the region keys
- if (timestamp === currentTimestamp) {
- // overwrite last object in acc
- const last = acc.pop();
- if (last) {
- acc.push({
- ...last,
- [fullNameRegion]: latency,
- });
- }
- } else if (timestamp) {
- currentTimestamp = timestamp;
- // create new object in acc
+ const _data = data.reduce((acc, curr) => {
+ const { timestamp, region } = curr;
+ const latency = curr[`${quantile}Latency`];
+ const { flag, code, location } = flyRegionsDict[region];
+ const fullNameRegion = `${code}`;
+ regions[fullNameRegion] = { flag, code, location }; // to get the region keys
+ if (timestamp === currentTimestamp) {
+ // overwrite last object in acc
+ const last = acc.pop();
+ if (last) {
acc.push({
- timestamp: renderTimestamp(timestamp, period),
+ ...last,
[fullNameRegion]: latency,
});
}
- return acc;
- },
- [] as (Partial<Record<Region, string>> & { timestamp: string })[],
- );
+ } else if (timestamp) {
+ currentTimestamp = timestamp;
+ // create new object in acc
+ acc.push({
+ timestamp: renderTimestamp(timestamp, period),
+ [fullNameRegion]: latency,
+ });
+ }
+ return acc;
+ }, [] as (Partial<Record<Region, string>> & { timestamp: string })[]);
// regions are sorted by the flag utf-8 code
return {
@@ -74,6 +71,6 @@ export function dataFormatter(number: number) {
}
export function regionFormatter(region: Region) {
- const { code, flag } = regionsDict[region];
+ const { code, flag } = flyRegionsDict[region];
return `${flag} ${code}`;
}
diff --git a/apps/web/src/content/changelog/more-regions.mdx b/apps/web/src/content/changelog/more-regions.mdx
new file mode 100644
index 000000000..6d29cd8e8
--- /dev/null
+++ b/apps/web/src/content/changelog/more-regions.mdx
@@ -0,0 +1,11 @@
+---
+title: More regions available ๐ŸŒ
+description: You can now monitor your endpoint from 35 regions.
+image: /assets/changelog/more-regions.png
+publishedAt: 2024-06-19
+---
+We have added more regions to OpenStatus.
+
+You can now monitor your endpoint from 35 regions.
+
+Let's make synthetic monitoring more global! ๐ŸŒ
diff --git a/packages/api/src/router/monitor.ts b/packages/api/src/router/monitor.ts
index 3d1651b7b..8c8bf9fa7 100644
--- a/packages/api/src/router/monitor.ts
+++ b/packages/api/src/router/monitor.ts
@@ -38,12 +38,13 @@ export const monitorRouter = createTRPCRouter({
const monitorLimit = allPlans[opts.ctx.workspace.plan].limits.monitors;
const periodicityLimit =
allPlans[opts.ctx.workspace.plan].limits.periodicity;
+ const regionsLimit = allPlans[opts.ctx.workspace.plan].limits.regions;
const monitorNumbers = (
await opts.ctx.db.query.monitor.findMany({
where: and(
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
})
).length;
@@ -67,6 +68,20 @@ export const monitorRouter = createTRPCRouter({
});
}
+ if (
+ opts.input.regions !== undefined &&
+ opts.input.regions?.length !== 0
+ ) {
+ for (const region of opts.input.regions) {
+ if (!regionsLimit.includes(region)) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "You don't have access to this region.",
+ });
+ }
+ }
+ }
+
// FIXME: this is a hotfix
const {
regions,
@@ -106,7 +121,7 @@ export const monitorRouter = createTRPCRouter({
const allNotifications = await opts.ctx.db.query.notification.findMany({
where: and(
eq(notification.workspaceId, opts.ctx.workspace.id),
- inArray(notification.id, notifications),
+ inArray(notification.id, notifications)
),
});
@@ -122,7 +137,7 @@ export const monitorRouter = createTRPCRouter({
const allTags = await opts.ctx.db.query.monitorTag.findMany({
where: and(
eq(monitorTag.workspaceId, opts.ctx.workspace.id),
- inArray(monitorTag.id, tags),
+ inArray(monitorTag.id, tags)
),
});
@@ -138,7 +153,7 @@ export const monitorRouter = createTRPCRouter({
const allPages = await opts.ctx.db.query.page.findMany({
where: and(
eq(page.workspaceId, opts.ctx.workspace.id),
- inArray(page.id, pages),
+ inArray(page.id, pages)
),
});
@@ -165,7 +180,7 @@ export const monitorRouter = createTRPCRouter({
where: and(
eq(monitor.id, opts.input.id),
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
with: {
monitorTagsToMonitors: { with: { monitorTag: true } },
@@ -190,7 +205,7 @@ export const monitorRouter = createTRPCRouter({
maintenance: _monitor?.maintenancesToMonitors.some(
(item) =>
item.maintenance.from.getTime() <= Date.now() &&
- item.maintenance.to.getTime() >= Date.now(),
+ item.maintenance.to.getTime() >= Date.now()
),
});
@@ -212,7 +227,7 @@ export const monitorRouter = createTRPCRouter({
where: and(
eq(monitor.id, opts.input.id),
isNull(monitor.deletedAt),
- eq(monitor.public, true),
+ eq(monitor.public, true)
),
});
if (!_monitor) return undefined;
@@ -224,7 +239,7 @@ export const monitorRouter = createTRPCRouter({
});
const hasPageRelation = _page?.monitorsToPages.find(
- ({ monitorId }) => _monitor.id === monitorId,
+ ({ monitorId }) => _monitor.id === monitorId
);
if (!hasPageRelation) return undefined;
@@ -241,6 +256,8 @@ export const monitorRouter = createTRPCRouter({
const periodicityLimit =
allPlans[opts.ctx.workspace.plan].limits.periodicity;
+ const regionsLimit = allPlans[opts.ctx.workspace.plan].limits.regions;
+
// the user is not allowed to use the cron job
if (
opts.input?.periodicity &&
@@ -252,6 +269,20 @@ export const monitorRouter = createTRPCRouter({
});
}
+ if (
+ opts.input.regions !== undefined &&
+ opts.input.regions?.length !== 0
+ ) {
+ for (const region of opts.input.regions) {
+ if (!regionsLimit.includes(region)) {
+ throw new TRPCError({
+ code: "FORBIDDEN",
+ message: "You don't have access to this region.",
+ });
+ }
+ }
+ }
+
const {
regions,
headers,
@@ -284,8 +315,8 @@ export const monitorRouter = createTRPCRouter({
and(
eq(monitor.id, opts.input.id),
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
- ),
+ isNull(monitor.deletedAt)
+ )
)
.returning()
.get();
@@ -300,7 +331,7 @@ export const monitorRouter = createTRPCRouter({
(x) =>
!currentMonitorNotifications
.map(({ notificationId }) => notificationId)
- ?.includes(x),
+ ?.includes(x)
);
if (addedNotifications.length > 0) {
@@ -324,9 +355,9 @@ export const monitorRouter = createTRPCRouter({
eq(notificationsToMonitors.monitorId, currentMonitor.id),
inArray(
notificationsToMonitors.notificationId,
- removedNotifications,
- ),
- ),
+ removedNotifications
+ )
+ )
)
.run();
}
@@ -341,7 +372,7 @@ export const monitorRouter = createTRPCRouter({
(x) =>
!currentMonitorTags
.map(({ monitorTagId }) => monitorTagId)
- ?.includes(x),
+ ?.includes(x)
);
if (addedTags.length > 0) {
@@ -363,8 +394,8 @@ export const monitorRouter = createTRPCRouter({
.where(
and(
eq(monitorTagsToMonitors.monitorId, currentMonitor.id),
- inArray(monitorTagsToMonitors.monitorTagId, removedTags),
- ),
+ inArray(monitorTagsToMonitors.monitorTagId, removedTags)
+ )
)
.run();
}
@@ -376,7 +407,7 @@ export const monitorRouter = createTRPCRouter({
.all();
const addedPages = pages.filter(
- (x) => !currentMonitorPages.map(({ pageId }) => pageId)?.includes(x),
+ (x) => !currentMonitorPages.map(({ pageId }) => pageId)?.includes(x)
);
if (addedPages.length > 0) {
@@ -398,8 +429,8 @@ export const monitorRouter = createTRPCRouter({
.where(
and(
eq(monitorsToPages.monitorId, currentMonitor.id),
- inArray(monitorsToPages.pageId, removedPages),
- ),
+ inArray(monitorsToPages.pageId, removedPages)
+ )
)
.run();
}
@@ -410,7 +441,7 @@ export const monitorRouter = createTRPCRouter({
insertMonitorSchema
.pick({ public: true, active: true })
.partial() // batched updates
- .extend({ ids: z.number().array() }), // array of monitor ids to update
+ .extend({ ids: z.number().array() }) // array of monitor ids to update
)
.mutation(async (opts) => {
const _monitors = await opts.ctx.db
@@ -420,8 +451,8 @@ export const monitorRouter = createTRPCRouter({
and(
inArray(monitor.id, opts.input.ids),
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
- ),
+ isNull(monitor.deletedAt)
+ )
);
}),
@@ -431,20 +462,20 @@ export const monitorRouter = createTRPCRouter({
ids: z.number().array(),
tagId: z.number(),
action: z.enum(["add", "remove"]),
- }),
+ })
)
.mutation(async (opts) => {
const _monitorTag = await opts.ctx.db.query.monitorTag.findFirst({
where: and(
eq(monitorTag.workspaceId, opts.ctx.workspace.id),
- eq(monitorTag.id, opts.input.tagId),
+ eq(monitorTag.id, opts.input.tagId)
),
});
const _monitors = await opts.ctx.db.query.monitor.findMany({
where: and(
eq(monitor.workspaceId, opts.ctx.workspace.id),
- inArray(monitor.id, opts.input.ids),
+ inArray(monitor.id, opts.input.ids)
),
});
@@ -462,7 +493,7 @@ export const monitorRouter = createTRPCRouter({
opts.input.ids.map((id) => ({
monitorId: id,
monitorTagId: opts.input.tagId,
- })),
+ }))
)
.onConflictDoNothing()
.run();
@@ -474,8 +505,8 @@ export const monitorRouter = createTRPCRouter({
.where(
and(
inArray(monitorTagsToMonitors.monitorId, opts.input.ids),
- eq(monitorTagsToMonitors.monitorTagId, opts.input.tagId),
- ),
+ eq(monitorTagsToMonitors.monitorTagId, opts.input.tagId)
+ )
)
.run();
}
@@ -490,8 +521,8 @@ export const monitorRouter = createTRPCRouter({
.where(
and(
eq(monitor.id, opts.input.id),
- eq(monitor.workspaceId, opts.ctx.workspace.id),
- ),
+ eq(monitor.workspaceId, opts.ctx.workspace.id)
+ )
)
.get();
if (!monitorToDelete) return;
@@ -530,8 +561,8 @@ export const monitorRouter = createTRPCRouter({
.where(
and(
inArray(monitor.id, opts.input.ids),
- eq(monitor.workspaceId, opts.ctx.workspace.id),
- ),
+ eq(monitor.workspaceId, opts.ctx.workspace.id)
+ )
)
.all();
@@ -571,7 +602,7 @@ export const monitorRouter = createTRPCRouter({
const monitors = await opts.ctx.db.query.monitor.findMany({
where: and(
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
with: {
monitorTagsToMonitors: { with: { monitorTag: true } },
@@ -584,7 +615,7 @@ export const monitorRouter = createTRPCRouter({
monitorTagsToMonitors: z
.array(z.object({ monitorTag: selectMonitorTagSchema }))
.default([]),
- }),
+ })
)
.parse(monitors);
}),
@@ -595,7 +626,7 @@ export const monitorRouter = createTRPCRouter({
const _page = await opts.ctx.db.query.page.findFirst({
where: and(
eq(page.id, opts.input.id),
- eq(page.workspaceId, opts.ctx.workspace.id),
+ eq(page.workspaceId, opts.ctx.workspace.id)
),
});
@@ -604,7 +635,7 @@ export const monitorRouter = createTRPCRouter({
const monitors = await opts.ctx.db.query.monitor.findMany({
where: and(
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
with: {
monitorTagsToMonitors: { with: { monitorTag: true } },
@@ -620,14 +651,14 @@ export const monitorRouter = createTRPCRouter({
monitorTagsToMonitors: z
.array(z.object({ monitorTag: selectMonitorTagSchema }))
.default([]),
- }),
+ })
)
.parse(
monitors.filter((monitor) =>
monitor.monitorsToPages
.map(({ pageId }) => pageId)
- .includes(_page.id),
- ),
+ .includes(_page.id)
+ )
);
}),
@@ -641,8 +672,8 @@ export const monitorRouter = createTRPCRouter({
and(
eq(monitor.id, opts.input.id),
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
- ),
+ isNull(monitor.deletedAt)
+ )
)
.get();
@@ -661,8 +692,8 @@ export const monitorRouter = createTRPCRouter({
.where(
and(
eq(monitor.id, opts.input.id),
- eq(monitor.workspaceId, opts.ctx.workspace.id),
- ),
+ eq(monitor.workspaceId, opts.ctx.workspace.id)
+ )
)
.run();
}),
@@ -690,8 +721,8 @@ export const monitorRouter = createTRPCRouter({
notification,
and(
eq(notificationsToMonitors.notificationId, notification.id),
- eq(notification.workspaceId, opts.ctx.workspace.id),
- ),
+ eq(notification.workspaceId, opts.ctx.workspace.id)
+ )
)
.where(eq(notificationsToMonitors.monitorId, opts.input.id))
.all();
@@ -704,7 +735,7 @@ export const monitorRouter = createTRPCRouter({
await opts.ctx.db.query.monitor.findMany({
where: and(
eq(monitor.workspaceId, opts.ctx.workspace.id),
- isNull(monitor.deletedAt),
+ isNull(monitor.deletedAt)
),
})
).length;
diff --git a/packages/db/src/schema/monitor_status/validation.ts b/packages/db/src/schema/monitor_status/validation.ts
index 636b24a35..5beaff5b9 100644
--- a/packages/db/src/schema/monitor_status/validation.ts
+++ b/packages/db/src/schema/monitor_status/validation.ts
@@ -8,16 +8,16 @@ export const selectMonitorStatusSchema = createSelectSchema(
monitorStatusTable,
{
status: monitorStatusSchema.default("active"),
- region: monitorRegionSchema.default("auto"),
- },
+ region: monitorRegionSchema.default("ams"),
+ }
);
export const insertMonitorStatusSchema = createInsertSchema(
monitorStatusTable,
{
status: monitorStatusSchema.default("active"),
- region: monitorRegionSchema.default("auto"),
- },
+ region: monitorRegionSchema.default("ams"),
+ }
);
// export type InsertMonitorStatus = z.infer<typeof insertMonitorStatusSchema>;
diff --git a/packages/db/src/schema/monitors/constants.ts b/packages/db/src/schema/monitors/constants.ts
index 0aaf335aa..3e98e3490 100644
--- a/packages/db/src/schema/monitors/constants.ts
+++ b/packages/db/src/schema/monitors/constants.ts
@@ -1,29 +1,41 @@
-/**
- * @deprecated
- */
-export const vercelRegions = [
- "arn1",
- "bom1",
- "cdg1",
- "cle1",
- "cpt1",
- "dub1",
- "fra1",
- "gru1",
- "hkg1",
- "hnd1",
- "iad1",
- "icn1",
- "kix1",
- "lhr1",
- "pdx1",
- "sfo1",
- "sin1",
- "syd1",
+export const flyRegions = [
+ "ams",
+ "arn",
+ "atl",
+ "bog",
+ "bom",
+ "bos",
+ "cdg",
+ "den",
+ "dfw",
+ "ewr",
+ "eze",
+ "fra",
+ "gdl",
+ "gig",
+ "gru",
+ "hkg",
+ "iad",
+ "jnb",
+ "lax",
+ "lhr",
+ "mad",
+ "mia",
+ "nrt",
+ "ord",
+ "otp",
+ "phx",
+ "qro",
+ "scl",
+ "sjc",
+ "sea",
+ "sin",
+ "syd",
+ "waw",
+ "yul",
+ "yyz",
] as const;
-export const flyRegions = ["ams", "iad", "hkg", "jnb", "syd", "gru"] as const;
-
export const monitorPeriodicity = [
"30s",
"1m",
@@ -35,10 +47,6 @@ export const monitorPeriodicity = [
] as const;
export const monitorMethods = ["GET", "POST", "HEAD"] as const;
export const monitorStatus = ["active", "error"] as const;
-export const monitorRegions = [
- ...flyRegions,
- ...vercelRegions,
- "auto",
-] as const;
+export const monitorRegions = [...flyRegions] as const;
export const monitorJobTypes = ["website", "cron", "other"] as const;
diff --git a/packages/db/tsconfig.json b/packages/db/tsconfig.json
index b5e190444..c3ede0904 100644
--- a/packages/db/tsconfig.json
+++ b/packages/db/tsconfig.json
@@ -18,5 +18,5 @@
"resolveJsonModule": true,
"noUncheckedIndexedAccess": true
},
- "include": ["src", "*.ts", "env.mjs", "**/*.ts"]
+ "include": ["src", "*.ts", "env.mjs", "**/*.ts", "../utils/try.ts"]
}
diff --git a/packages/plans/src/config.ts b/packages/plans/src/config.ts
index 6c3432cac..f61b59949 100644
--- a/packages/plans/src/config.ts
+++ b/packages/plans/src/config.ts
@@ -20,6 +20,7 @@ export const allPlans: Record<
monitors: 3,
periodicity: ["10m", "30m", "1h"],
"multi-region": true,
+ "max-regions": 6,
"data-retention": "14 days",
"status-pages": 1,
maintenance: true,
@@ -32,6 +33,7 @@ export const allPlans: Record<
"notification-channels": 1,
members: 1,
"audit-log": false,
+ regions: ["ams", "gru", "iad", "jnb", "hkg", "syd"],
},
},
starter: {
@@ -42,6 +44,7 @@ export const allPlans: Record<
monitors: 30,
periodicity: ["1m", "5m", "10m", "30m", "1h"],
"multi-region": true,
+ "max-regions": 35,
"data-retention": "3 months",
"status-pages": 1,
maintenance: true,
@@ -54,6 +57,40 @@ export const allPlans: Record<
"notification-channels": 10,
members: "Unlimited",
"audit-log": false,
+ regions: [
+ "ams",
+ "arn",
+ "atl",
+ "bog",
+ "bom",
+ "bos",
+ "cdg",
+ "den",
+ "dfw",
+ "ewr",
+ "eze",
+ "fra",
+ "gdl",
+ "gig",
+ "gru",
+ "hkg",
+ "iad",
+ "jnb",
+ "lax",
+ "lhr",
+ "mad",
+ "mia",
+ "nrt",
+ "ord",
+ "otp",
+ "phx",
+ "qro",
+ "scl",
+ "syd",
+ "waw",
+ "yul",
+ "yyz",
+ ],
},
},
team: {
@@ -64,6 +101,7 @@ export const allPlans: Record<
monitors: 100,
periodicity: ["30s", "1m", "5m", "10m", "30m", "1h"],
"multi-region": true,
+ "max-regions": 35,
"data-retention": "12 months",
"status-pages": 5,
maintenance: true,
@@ -76,6 +114,40 @@ export const allPlans: Record<
"notification-channels": 20,
members: "Unlimited",
"audit-log": true,
+ regions: [
+ "ams",
+ "arn",
+ "atl",
+ "bog",
+ "bom",
+ "bos",
+ "cdg",
+ "den",
+ "dfw",
+ "ewr",
+ "eze",
+ "fra",
+ "gdl",
+ "gig",
+ "gru",
+ "hkg",
+ "iad",
+ "jnb",
+ "lax",
+ "lhr",
+ "mad",
+ "mia",
+ "nrt",
+ "ord",
+ "otp",
+ "phx",
+ "qro",
+ "scl",
+ "syd",
+ "waw",
+ "yul",
+ "yyz",
+ ],
},
},
pro: {
@@ -86,6 +158,7 @@ export const allPlans: Record<
monitors: 500,
periodicity: ["30s", "1m", "5m", "10m", "30m", "1h"],
"multi-region": true,
+ "max-regions": 35,
"data-retention": "24 months",
"status-pages": 20,
maintenance: true,
@@ -98,6 +171,40 @@ export const allPlans: Record<
"notification-channels": 50,
members: "Unlimited",
"audit-log": true,
+ regions: [
+ "ams",
+ "arn",
+ "atl",
+ "bog",
+ "bom",
+ "bos",
+ "cdg",
+ "den",
+ "dfw",
+ "ewr",
+ "eze",
+ "fra",
+ "gdl",
+ "gig",
+ "gru",
+ "hkg",
+ "iad",
+ "jnb",
+ "lax",
+ "lhr",
+ "mad",
+ "mia",
+ "nrt",
+ "ord",
+ "otp",
+ "phx",
+ "qro",
+ "scl",
+ "syd",
+ "waw",
+ "yul",
+ "yyz",
+ ],
},
},
};
diff --git a/packages/plans/src/pricing-table.ts b/packages/plans/src/pricing-table.ts
index c199de918..c1de31b0d 100644
--- a/packages/plans/src/pricing-table.ts
+++ b/packages/plans/src/pricing-table.ts
@@ -22,6 +22,7 @@ export const pricingTableConfig: Record<
value: "multi-region",
label: "Multi-region monitoring",
},
+ { value: "max-regions", label: "Number of Regions" },
{ value: "data-retention", label: "Data retention" },
],
},
diff --git a/packages/plans/src/types.ts b/packages/plans/src/types.ts
index 233aeb0eb..3bf835aa4 100644
--- a/packages/plans/src/types.ts
+++ b/packages/plans/src/types.ts
@@ -1,10 +1,14 @@
-import type { MonitorPeriodicity } from "@openstatus/db/src/schema";
+import type {
+ MonitorFlyRegion,
+ MonitorPeriodicity,
+} from "@openstatus/db/src/schema";
export type Limits = {
// monitors
monitors: number;
periodicity: Partial<MonitorPeriodicity>[];
"multi-region": boolean;
+ "max-regions": number;
"data-retention": string;
// status pages
"status-pages": number;
@@ -20,4 +24,5 @@ export type Limits = {
// collaboration
members: "Unlimited" | number;
"audit-log": boolean;
+ regions: Partial<MonitorFlyRegion>[];
};
diff --git a/packages/tinybird/src/os-client.ts b/packages/tinybird/src/os-client.ts
index f8ae3b27b..1e5220dcf 100644
--- a/packages/tinybird/src/os-client.ts
+++ b/packages/tinybird/src/os-client.ts
@@ -1,7 +1,7 @@
import { NoopTinybird, Tinybird } from "@chronark/zod-bird";
import { z } from "zod";
-import { flyRegions } from "@openstatus/utils";
+import { flyRegions } from "../../db/src/schema/monitors/constants";
import type { tbIngestWebVitalsArray } from "./validation";
import {
@@ -118,7 +118,7 @@ export class OSTinybird {
opts?: {
cache?: RequestCache | undefined;
revalidate: number | undefined;
- }, // RETHINK: not the best way to handle it
+ } // RETHINK: not the best way to handle it
) => {
try {
const res = await this.tb.buildPipe({
@@ -178,7 +178,7 @@ export class OSTinybird {
endpointStatusPeriod(
period: "7d" | "45d",
- timezone: "UTC" = "UTC", // "EST" | "PST" | "CET"
+ timezone: "UTC" = "UTC" // "EST" | "PST" | "CET"
) {
const parameters = z.object({ monitorId: z.string() });
@@ -187,7 +187,7 @@ export class OSTinybird {
opts?: {
cache?: RequestCache | undefined;
revalidate: number | undefined;
- }, // RETHINK: not the best way to handle it
+ } // RETHINK: not the best way to handle it
) => {
try {
const res = await this.tb.buildPipe({
diff --git a/packages/tinybird/src/validation.ts b/packages/tinybird/src/validation.ts
index f229a41b5..4a8d3886c 100644
--- a/packages/tinybird/src/validation.ts
+++ b/packages/tinybird/src/validation.ts
@@ -1,6 +1,6 @@
import * as z from "zod";
-
-import { flyRegions } from "@openstatus/utils";
+import { monitorFlyRegionSchema } from "../../db/src/schema/monitors/validation";
+import type { flyRegions } from "../../db/src/schema/monitors/constants";
export const tbIngestWebVitals = z.object({
dsn: z.string(),
@@ -92,7 +92,7 @@ export const tbBuildResponseList = z.object({
latency: z.number().int(), // in ms
cronTimestamp: z.number().int().nullable().default(Date.now()),
url: z.string().url(),
- region: z.enum(flyRegions),
+ region: monitorFlyRegionSchema,
message: z.string().nullable().optional(),
assertions: z.string().nullable().optional(),
});
@@ -106,7 +106,7 @@ export const tbParameterResponseList = z.object({
fromDate: z.number().int().default(0), // always start from a date
toDate: z.number().int().optional(),
limit: z.number().int().optional().default(7500), // one day has 2448 pings (17 (regions) * 6 (per hour) * 24) * 3 days for historical data
- region: z.enum(flyRegions).optional(),
+ region: monitorFlyRegionSchema.optional(),
cronTimestamp: z.number().int().optional(),
});
@@ -174,7 +174,7 @@ export const latencyMetrics = z.object({
*/
export const tbBuildResponseGraph = z
.object({
- region: z.enum(flyRegions),
+ region: monitorFlyRegionSchema,
timestamp: z.number().int(),
})
.merge(latencyMetrics);
@@ -279,7 +279,7 @@ export const tbParameterResponseTimeMetricsByRegion = z.object({
*/
export const tbBuildResponseTimeMetricsByRegion = z
.object({
- region: z.enum(flyRegions),
+ region: monitorFlyRegionSchema,
})
.merge(latencyMetrics);
diff --git a/packages/utils/index.ts b/packages/utils/index.ts
index e52c112fd..2858d5475 100644
--- a/packages/utils/index.ts
+++ b/packages/utils/index.ts
@@ -2,165 +2,398 @@
* AWS data center informations from 18 regions, supported by vercel.
* https://vercel.com/docs/concepts/edge-network/regions#region-list
*/
-export const vercelRegionsDict = {
- /**
- * A random location will be chosen
- */
- auto: {
- code: "auto",
- name: "random",
- location: "Random",
- flag: "๐ŸŒ",
- },
- arn1: {
- code: "arn1",
- name: "eu-north-1",
+
+import type { MonitorFlyRegion } from "@openstatus/db/src/schema";
+
+// export const vercelRegionsDict = {
+// /**
+// * A random location will be chosen
+// */
+// auto: {
+// code: "auto",
+// name: "random",
+// location: "Random",
+// flag: "๐ŸŒ",
+// },
+// arn1: {
+// code: "arn1",
+// name: "eu-north-1",
+// location: "Stockholm, Sweden",
+// flag: "๐Ÿ‡ธ๐Ÿ‡ช",
+// },
+// bom1: {
+// code: "bom1",
+// name: "ap-south-1",
+// location: "Mumbai, India",
+// flag: "๐Ÿ‡ฎ๐Ÿ‡ณ",
+// },
+// cdg1: {
+// code: "cdg1",
+// name: "eu-west-3",
+// location: "Paris, France",
+// flag: "๐Ÿ‡ซ๐Ÿ‡ท",
+// },
+// cle1: {
+// code: "cle1",
+// name: "us-east-2",
+// location: "Cleveland, USA",
+// flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+// },
+// cpt1: {
+// code: "cpt1",
+// name: "af-south-1",
+// location: "Cape Town, South Africa",
+// flag: "๐Ÿ‡ฟ๐Ÿ‡ฆ",
+// },
+// dub1: {
+// code: "dub1",
+// name: "eu-west-1",
+// location: "Dublin, Ireland",
+// flag: "๐Ÿ‡ฎ๐Ÿ‡ช",
+// },
+// fra1: {
+// code: "fra1",
+// name: "eu-central-1",
+// location: "Frankfurt, Germany",
+// flag: "๐Ÿ‡ฉ๐Ÿ‡ช",
+// },
+// gru1: {
+// code: "gru1",
+// name: "sa-east-1",
+// location: "Sรฃo Paulo, Brazil",
+// flag: "๐Ÿ‡ง๐Ÿ‡ท",
+// },
+// hkg1: {
+// code: "hkg1",
+// name: "ap-east-1",
+// location: "Hong Kong",
+// flag: "๐Ÿ‡ญ๐Ÿ‡ฐ",
+// },
+// hnd1: {
+// code: "hnd1",
+// name: "ap-northeast-1",
+// location: "Tokyo, Japan",
+// flag: "๐Ÿ‡ฏ๐Ÿ‡ต",
+// },
+// iad1: {
+// code: "iad1",
+// name: "us-east-1",
+// location: "Washington, D.C., USA",
+// flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+// },
+// icn1: {
+// code: "icn1",
+// name: "ap-northeast-2",
+// location: "Seoul, South Korea",
+// flag: "๐Ÿ‡ฐ๐Ÿ‡ท",
+// },
+// kix1: {
+// code: "kix1",
+// name: "ap-northeast-3",
+// location: "Osaka, Japan",
+// flag: "๐Ÿ‡ฏ๐Ÿ‡ต",
+// },
+// lhr1: {
+// code: "lhr1",
+// name: "eu-west-2",
+// location: "London, United Kingdom",
+// flag: "๐Ÿ‡ฌ๐Ÿ‡ง",
+// },
+// pdx1: {
+// code: "pdx1",
+// name: "us-west-2",
+// location: "Portland, USA",
+// flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+// },
+// sfo1: {
+// code: "sfo1",
+// name: "us-west-1",
+// location: "San Francisco, USA",
+// flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+// },
+// sin1: {
+// code: "sin1",
+// name: "ap-southeast-1",
+// location: "Singapore",
+// flag: "๐Ÿ‡ธ๐Ÿ‡ฌ",
+// },
+// syd1: {
+// code: "syd1",
+// name: "ap-southeast-2",
+// location: "Sydney, Australia",
+// flag: "๐Ÿ‡ฆ๐Ÿ‡บ",
+// },
+// } as const;
+
+export const flyRegionsDict: Record<
+ MonitorFlyRegion,
+ {
+ code: MonitorFlyRegion;
+ location: string;
+ flag: string;
+ continent:
+ | "Europe"
+ | "North America"
+ | "South America"
+ | "Asia"
+ | "Africa"
+ | "Oceania";
+ }
+> = {
+ ams: {
+ code: "ams",
+ location: "Amsterdam, Netherlands",
+ flag: "๐Ÿ‡ณ๐Ÿ‡ฑ",
+ continent: "Europe",
+ },
+ arn: {
+ code: "arn",
location: "Stockholm, Sweden",
flag: "๐Ÿ‡ธ๐Ÿ‡ช",
+ continent: "Europe",
+ },
+
+ atl: {
+ code: "atl",
+ location: "Atlanta, Georgia, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
+ },
+ bog: {
+ code: "bog",
+ location: "Bogotรก, Colombia",
+ flag: "๐Ÿ‡จ๐Ÿ‡ด",
+ continent: "South America",
},
- bom1: {
- code: "bom1",
- name: "ap-south-1",
+ bom: {
+ code: "bom",
location: "Mumbai, India",
flag: "๐Ÿ‡ฎ๐Ÿ‡ณ",
+ continent: "Asia",
},
- cdg1: {
- code: "cdg1",
- name: "eu-west-3",
+ bos: {
+ code: "bos",
+ location: "Boston, Massachusetts, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
+ },
+ cdg: {
+ code: "cdg",
location: "Paris, France",
flag: "๐Ÿ‡ซ๐Ÿ‡ท",
+ continent: "Europe",
},
- cle1: {
- code: "cle1",
- name: "us-east-2",
- location: "Cleveland, USA",
+ den: {
+ code: "den",
+ location: "Denver, Colorado, USA",
flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
- cpt1: {
- code: "cpt1",
- name: "af-south-1",
- location: "Cape Town, South Africa",
- flag: "๐Ÿ‡ฟ๐Ÿ‡ฆ",
+ dfw: {
+ code: "dfw",
+ location: "Dallas, Texas, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
+ },
+ ewr: {
+ code: "ewr",
+ location: "Secaucus, New Jersey, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
- dub1: {
- code: "dub1",
- name: "eu-west-1",
- location: "Dublin, Ireland",
- flag: "๐Ÿ‡ฎ๐Ÿ‡ช",
+ eze: {
+ code: "eze",
+ location: "Ezeiza, Argentina",
+ flag: "๐Ÿ‡ฆ๐Ÿ‡ท",
+ continent: "South America",
},
- fra1: {
- code: "fra1",
- name: "eu-central-1",
+ fra: {
+ code: "fra",
location: "Frankfurt, Germany",
flag: "๐Ÿ‡ฉ๐Ÿ‡ช",
+ continent: "Europe",
},
- gru1: {
- code: "gru1",
- name: "sa-east-1",
- location: "Sรฃo Paulo, Brazil",
+ gdl: {
+ code: "gdl",
+ location: "Guadalajara, Mexico",
+ flag: "๐Ÿ‡ฒ๐Ÿ‡ฝ",
+ continent: "North America",
+ },
+ gig: {
+ code: "gig",
+ location: "Rio de Janeiro, Brazil",
flag: "๐Ÿ‡ง๐Ÿ‡ท",
+ continent: "South America",
},
- hkg1: {
- code: "hkg1",
- name: "ap-east-1",
- location: "Hong Kong",
- flag: "๐Ÿ‡ญ๐Ÿ‡ฐ",
+ gru: {
+ code: "gru",
+ location: "Sao Paulo, Brazil",
+ flag: "๐Ÿ‡ง๐Ÿ‡ท",
+ continent: "South America",
},
- hnd1: {
- code: "hnd1",
- name: "ap-northeast-1",
- location: "Tokyo, Japan",
- flag: "๐Ÿ‡ฏ๐Ÿ‡ต",
+ hkg: {
+ code: "hkg",
+ location: "Hong Kong, Hong Kong",
+ flag: "๐Ÿ‡ญ๐Ÿ‡ฐ",
+ continent: "Asia",
},
- iad1: {
- code: "iad1",
- name: "us-east-1",
- location: "Washington, D.C., USA",
+
+ iad: {
+ code: "iad",
+ location: "Ashburn, Virginia, USA",
flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
- icn1: {
- code: "icn1",
- name: "ap-northeast-2",
- location: "Seoul, South Korea",
- flag: "๐Ÿ‡ฐ๐Ÿ‡ท",
+ jnb: {
+ code: "jnb",
+ location: "Johannesburg, South Africa",
+ flag: "๐Ÿ‡ฟ๐Ÿ‡ฆ",
+ continent: "Africa",
},
- kix1: {
- code: "kix1",
- name: "ap-northeast-3",
- location: "Osaka, Japan",
- flag: "๐Ÿ‡ฏ๐Ÿ‡ต",
+ lax: {
+ code: "lax",
+ location: "Los Angeles, California, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
- lhr1: {
- code: "lhr1",
- name: "eu-west-2",
+ lhr: {
+ code: "lhr",
location: "London, United Kingdom",
flag: "๐Ÿ‡ฌ๐Ÿ‡ง",
+ continent: "Europe",
},
- pdx1: {
- code: "pdx1",
- name: "us-west-2",
- location: "Portland, USA",
- flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ mad: {
+ code: "mad",
+ location: "Madrid, Spain",
+ flag: "๐Ÿ‡ช๐Ÿ‡ธ",
+ continent: "Europe",
},
- sfo1: {
- code: "sfo1",
- name: "us-west-1",
- location: "San Francisco, USA",
+ mia: {
+ code: "mia",
+ location: "Miami, Florida, USA",
flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
- sin1: {
- code: "sin1",
- name: "ap-southeast-1",
- location: "Singapore",
- flag: "๐Ÿ‡ธ๐Ÿ‡ฌ",
+ nrt: {
+ code: "nrt",
+ location: "Tokyo, Japan",
+ flag: "๐Ÿ‡ฏ๐Ÿ‡ต",
+ continent: "Asia",
},
- syd1: {
- code: "syd1",
- name: "ap-southeast-2",
- location: "Sydney, Australia",
- flag: "๐Ÿ‡ฆ๐Ÿ‡บ",
+ ord: {
+ code: "ord",
+ location: "Chicago, Illinois, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
-} as const;
-
-export const flyRegionsDict = {
- ams: {
- code: "ams",
- name: "",
- location: "Amsterdam, Netherlands",
- flag: "๐Ÿ‡ณ๐Ÿ‡ฑ",
+ otp: {
+ code: "otp",
+ location: "Bucharest, Romania",
+ flag: "๐Ÿ‡ท๐Ÿ‡ด",
+ continent: "Europe",
},
- iad: {
- code: "iad",
- name: "us-east-1",
- location: "Ashburn, Virginia, USA",
+ phx: {
+ code: "phx",
+ location: "Phoenix, Arizona, USA",
flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
},
- jnb: {
- code: "jnb",
- name: "",
- location: "Johannesburg, South Africa",
- flag: "๐Ÿ‡ฟ๐Ÿ‡ฆ",
+ qro: {
+ code: "qro",
+ location: "Querรฉtaro, Mexico",
+ flag: "๐Ÿ‡ฒ๐Ÿ‡ฝ",
+ continent: "North America",
},
- hkg: {
- code: "hkg",
- name: "",
- location: "Hong Kong, Hong Kong",
- flag: "๐Ÿ‡ญ๐Ÿ‡ฐ",
+ scl: {
+ code: "scl",
+ location: "Santiago, Chile",
+ flag: "๐Ÿ‡จ๐Ÿ‡ฑ",
+ continent: "South America",
},
- gru: {
- code: "gru",
- name: "",
- location: "Sao Paulo, Brazil",
- flag: "๐Ÿ‡ง๐Ÿ‡ท",
+ sjc: {
+ code: "sjc",
+ location: "San Jose, California, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
+ },
+ sea: {
+ code: "sea",
+ location: "Seattle, Washington, USA",
+ flag: "๐Ÿ‡บ๐Ÿ‡ธ",
+ continent: "North America",
+ },
+ sin: {
+ code: "sin",
+ location: "Singapore, Singapore",
+ flag: "๐Ÿ‡ธ๐Ÿ‡ฌ",
+ continent: "Asia",
},
syd: {
code: "syd",
- name: "",
location: "Sydney, Australia",
flag: "๐Ÿ‡ฆ๐Ÿ‡บ",
+ continent: "Oceania",
+ },
+ waw: {
+ code: "waw",
+ location: "Warsaw, Poland",
+ flag: "๐Ÿ‡ต๐Ÿ‡ฑ",
+ continent: "Europe",
+ },
+ yul: {
+ code: "yul",
+ location: "Montreal, Canada",
+ flag: "๐Ÿ‡จ๐Ÿ‡ฆ",
+ continent: "North America",
+ },
+ yyz: {
+ code: "yyz",
+ location: "Toronto, Canada",
+ flag: "๐Ÿ‡จ๐Ÿ‡ฆ",
+ continent: "North America",
},
} as const;
+// const r = t.flatMap((u) => u[1].continent);
+
+export const groupByContinent = Object.entries(flyRegionsDict).reduce<
+ Record<
+ | "Europe"
+ | "North America"
+ | "South America"
+ | "Asia"
+ | "Africa"
+ | "Oceania",
+ {
+ code: MonitorFlyRegion;
+ location: string;
+ flag: string;
+ continent:
+ | "Europe"
+ | "North America"
+ | "South America"
+ | "Asia"
+ | "Africa"
+ | "Oceania";
+ }[]
+ >
+>(
+ (acc, [_key, value]) => {
+ Object.assign(acc, {
+ [value.continent]: [...acc[value.continent], value],
+ });
+ return acc;
+ },
+ {
+ "North America": [],
+ Europe: [],
+ "South America": [],
+ Oceania: [],
+ Asia: [],
+ Africa: [],
+ }
+);
+
export const vercelRegions = [
"arn1",
"bom1",
@@ -182,8 +415,6 @@ export const vercelRegions = [
"syd1",
] as const;
-export const flyRegions = ["ams", "iad", "hkg", "jnb", "syd", "gru"] as const;
-
-export const availableRegions = [...vercelRegions, ...flyRegions] as const;
+// export const availableRegions = [...vercelRegions, ...flyRegions] as const;
-export const regionsDict = { ...vercelRegionsDict, ...flyRegionsDict } as const;
+// export const regionsDict = { ...vercelRegionsDict, ...flyRegionsDict } as const;
diff --git a/packages/utils/package.json b/packages/utils/package.json
index 6e391c9ae..ac1354399 100644
--- a/packages/utils/package.json
+++ b/packages/utils/package.json
@@ -6,6 +6,7 @@
"scripts": {},
"dependencies": {},
"devDependencies": {
+ "@openstatus/db": "workspace:*",
"@openstatus/tsconfig": "workspace:*",
"typescript": "5.4.5"
},
diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml
index cc4b4bd2f..ba915e3d8 100644
--- a/pnpm-lock.yaml
+++ b/pnpm-lock.yaml
@@ -1137,6 +1137,9 @@ importers:
packages/utils:
devDependencies:
+ '@openstatus/db':
+ specifier: workspace:*
+ version: link:../db
'@openstatus/tsconfig':
specifier: workspace:*
version: link:../tsconfig