Skip to content

Open-source status page, incident response and uptime monitoring

feat: response details (header and timing phases) (#607)

Maximilian Kaske7f1e27795cd4
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/response-details.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/response-details.tsx
new file mode 100644
index 000000000..1951941b0
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/response-details.tsx
@@ -0,0 +1,43 @@
+import type { ResponseDetailsParams } from "@openstatus/tinybird";
+
+import { RegionInfo } from "@/app/play/checker/[id]/_components/region-info";
+import { ResponseHeaderTable } from "@/app/play/checker/[id]/_components/response-header-table";
+import { ResponseTimingTable } from "@/app/play/checker/[id]/_components/response-timing-table";
+import { getResponseDetailsData } from "@/lib/tb";
+
+export async function ResponseDetails(props: ResponseDetailsParams) {
+ const details = await getResponseDetailsData(props);
+
+ if (!details || details?.length === 0) return null;
+
+ const response = details[0];
+
+ return (
+ <div className="grid gap-8">
+ <RegionInfo
+ check={{
+ latency: response.latency || 0,
+ region: response.region,
+ status: response.statusCode || 0,
+ time: response.cronTimestamp || 0,
+ }}
+ />
+ {response.timing ? (
+ <ResponseTimingTable timing={response.timing} hideInfo />
+ ) : null}
+ {response?.headers ? (
+ <ResponseHeaderTable headers={response.headers} />
+ ) : null}
+ {response.message ? (
+ <div>
+ <pre className="bg-muted rounded-md p-4 text-sm">
+ {response.message}
+ </pre>
+ <p className="text-muted-foreground mt-4 text-center text-sm">
+ Response Message
+ </p>
+ </div>
+ ) : null}
+ </div>
+ );
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/loading.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/loading.tsx
new file mode 100644
index 000000000..4349ac3a6
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/loading.tsx
@@ -0,0 +1,3 @@
+export default function Loading() {
+ return null;
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/modal.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/modal.tsx
new file mode 100644
index 000000000..8ebee7659
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/modal.tsx
@@ -0,0 +1,36 @@
+"use client";
+
+import { useRouter } from "next/navigation";
+
+import {
+ Dialog,
+ DialogContent,
+ DialogDescription,
+ DialogHeader,
+ DialogTitle,
+} from "@openstatus/ui";
+
+export function Modal({ children }: { children: React.ReactNode }) {
+ const router = useRouter();
+
+ const handleOpenChange = (open: boolean) => {
+ if (!open) {
+ router.back();
+ }
+ };
+
+ return (
+ <Dialog open onOpenChange={handleOpenChange}>
+ {/* overflow-auto should happen inside content table */}
+ <DialogContent className="max-h-[80%] w-full overflow-auto sm:max-w-3xl sm:p-8">
+ <DialogHeader>
+ <DialogTitle>Details</DialogTitle>
+ <DialogDescription>
+ Response details of the request.
+ </DialogDescription>
+ </DialogHeader>
+ {children}
+ </DialogContent>
+ </Dialog>
+ );
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/page.tsx
new file mode 100644
index 000000000..386f077b3
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/(..)details/page.tsx
@@ -0,0 +1,45 @@
+import * as z from "zod";
+
+import { Separator } from "@openstatus/ui";
+import { flyRegions } from "@openstatus/utils";
+
+import { EmptyState } from "@/components/dashboard/empty-state";
+import { ResponseDetails } from "../../../_components/response-details";
+import { Modal } from "./modal";
+
+//
+
+/**
+ * allowed URL search params
+ */
+const searchParamsSchema = z.object({
+ monitorId: z.string(),
+ region: z.enum(flyRegions).optional(),
+ cronTimestamp: z.coerce.number(),
+});
+
+export default async function DetailsModal({
+ params,
+ searchParams,
+}: {
+ params: { id: string };
+ searchParams: { [key: string]: string | string[] | undefined };
+}) {
+ const search = searchParamsSchema.safeParse(searchParams);
+
+ if (!search.success)
+ return (
+ <EmptyState
+ title="No log found"
+ description="Seems like we couldn't find what you are looking for."
+ icon="alert-triangle"
+ />
+ );
+
+ return (
+ <Modal>
+ <Separator className="my-4" />
+ <ResponseDetails {...search.data} />
+ </Modal>
+ );
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/default.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/default.tsx
new file mode 100644
index 000000000..6ddf1b76f
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/@modal/default.tsx
@@ -0,0 +1,3 @@
+export default function Default() {
+ return null;
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/default.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/default.tsx
new file mode 100644
index 000000000..6ddf1b76f
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/default.tsx
@@ -0,0 +1,3 @@
+export default function Default() {
+ return null;
+}
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/layout.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/layout.tsx
new file mode 100644
index 000000000..7356e03e3
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/layout.tsx
@@ -0,0 +1,16 @@
+import * as React from "react";
+
+export default function DataTableLayout({
+ children,
+ modal,
+}: {
+ children: React.ReactNode;
+ modal: React.ReactNode;
+}) {
+ return (
+ <>
+ {children}
+ {modal}
+ </>
+ );
+}
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
new file mode 100644
index 000000000..2e0c1c5d3
--- /dev/null
+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/details/page.tsx
@@ -0,0 +1,45 @@
+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/response-details";
+
+//
+
+/**
+ * allowed URL search params
+ */
+const searchParamsSchema = z.object({
+ monitorId: z.string(),
+ region: z.enum(flyRegions).optional(),
+ cronTimestamp: z.coerce.number(),
+});
+
+export default async function Details({
+ params,
+ searchParams,
+}: {
+ params: { id: string };
+ searchParams: { [key: string]: string | string[] | undefined };
+}) {
+ const search = searchParamsSchema.safeParse(searchParams);
+
+ if (!search.success)
+ return (
+ <EmptyState
+ title="No log found"
+ description="Seems like we couldn't find what you are looking for."
+ icon="alert-triangle"
+ action={
+ <Button asChild>
+ <Link href="./data">Response Logs</Link>
+ </Button>
+ }
+ />
+ );
+
+ return <ResponseDetails {...search.data} />;
+}
diff --git a/apps/web/src/app/monitor/[id]/page.tsx b/apps/web/src/app/monitor/[id]/page.tsx
index 8a23e6c34..a21ea4b2c 100644
--- a/apps/web/src/app/monitor/[id]/page.tsx
+++ b/apps/web/src/app/monitor/[id]/page.tsx
@@ -1,6 +1,6 @@
import * as z from "zod";
-import { availableRegions } from "@openstatus/utils";
+import { flyRegions } from "@openstatus/utils";
import { columns } from "@/components/data-table/columns";
import { DataTable } from "@/components/data-table/data-table";
@@ -13,7 +13,7 @@ import { getResponseListData } from "@/lib/tb";
*/
const searchParamsSchema = z.object({
statusCode: z.coerce.number().optional(),
- region: z.enum(availableRegions).optional(),
+ region: z.enum(flyRegions).optional(),
cronTimestamp: z.coerce.number().optional(),
fromDate: z.coerce.number().optional(),
toDate: z.coerce.number().optional(),
diff --git a/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsx b/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsx
index 04a7b2f43..64578383d 100644
--- a/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsx
+++ b/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsx
@@ -1,6 +1,6 @@
import * as z from "zod";
-import { availableRegions } from "@openstatus/utils";
+import { flyRegions } from "@openstatus/utils";
import { columns } from "@/components/data-table/columns";
import { DataTable } from "@/components/data-table/data-table";
@@ -14,7 +14,7 @@ import { Modal } from "./modal";
*/
const searchParamsSchema = z.object({
statusCode: z.coerce.number().optional(),
- region: z.enum(availableRegions).optional(),
+ region: z.enum(flyRegions).optional(),
cronTimestamp: z.coerce.number().optional(),
fromDate: z.coerce.number().optional(),
toDate: z.coerce.number().optional(),
diff --git a/apps/web/src/app/play/checker/[id]/_components/region-info.tsx b/apps/web/src/app/play/checker/[id]/_components/region-info.tsx
index 3faff144a..58913ad21 100644
--- a/apps/web/src/app/play/checker/[id]/_components/region-info.tsx
+++ b/apps/web/src/app/play/checker/[id]/_components/region-info.tsx
@@ -6,33 +6,37 @@ import {
import type { RegionChecker } from "../utils";
import { StatusBadge } from "./status-badge";
-export function RegionInfo({ check }: { check: RegionChecker }) {
+export function RegionInfo({
+ check,
+}: {
+ check: Pick<RegionChecker, "region" | "time" | "latency" | "status">;
+}) {
return (
- <div className="grid grid-cols-4 gap-2 text-sm sm:grid-cols-6">
- <div className="col-span-1">
+ <div className="grid grid-cols-5 gap-2 text-sm sm:grid-cols-9">
+ <div className="col-span-2">
<p className="text-muted-foreground">Time:</p>
</div>
- <div className="col-span-3 sm:col-span-5">
+ <div className="col-span-3 sm:col-span-6">
<p>{timestampFormatter(check.time)}</p>
</div>
- <div className="col-span-1">
+ <div className="col-span-2">
<p className="text-muted-foreground">Region:</p>
</div>
- <div className="col-span-3 sm:col-span-5">
+ <div className="col-span-3 sm:col-span-6">
<p>{regionFormatter(check.region)}</p>
</div>
- <div className="col-span-1">
+ <div className="col-span-2">
<p className="text-muted-foreground">Latency:</p>
</div>
- <div className="col-span-3 sm:col-span-5">
+ <div className="col-span-3 sm:col-span-6">
<p>
<code>{latencyFormatter(check.latency)}</code>
</p>
</div>
- <div className="col-span-1">
+ <div className="col-span-2">
<p className="text-muted-foreground">Status:</p>
</div>
- <div className="col-span-3 sm:col-span-5">
+ <div className="col-span-3 sm:col-span-6">
<StatusBadge statusCode={check.status} />
</div>
</div>
diff --git a/apps/web/src/app/play/checker/[id]/_components/response-timing-table.tsx b/apps/web/src/app/play/checker/[id]/_components/response-timing-table.tsx
index f1cdf98c7..75c0bdd2a 100644
--- a/apps/web/src/app/play/checker/[id]/_components/response-timing-table.tsx
+++ b/apps/web/src/app/play/checker/[id]/_components/response-timing-table.tsx
@@ -17,7 +17,13 @@ import { timingDict } from "../config";
import type { Timing } from "../utils";
import { getTimingPhases, getTotalLatency } from "../utils";
-export function ResponseTimingTable({ timing }: { timing: Timing }) {
+export function ResponseTimingTable({
+ timing,
+ hideInfo = false,
+}: {
+ timing: Timing;
+ hideInfo?: boolean;
+}) {
const total = getTotalLatency(timing);
const timingPhases = getTimingPhases(timing);
return (
@@ -39,17 +45,19 @@ export function ResponseTimingTable({ timing }: { timing: Timing }) {
<TableCell>
<div className="flex w-[80px] items-center justify-between gap-2">
<p className="text-muted-foreground">{short}</p>
- <Popover>
- <PopoverTrigger className="text-muted-foreground hover:text-foreground data-[state=open]:text-foreground">
- <Info className="h-4 w-4" />
- </PopoverTrigger>
- <PopoverContent>
- <p className="font-medium">{long}</p>
- <p className="text-muted-foreground text-sm">
- {description}
- </p>
- </PopoverContent>
- </Popover>
+ {!hideInfo ? (
+ <Popover>
+ <PopoverTrigger className="text-muted-foreground hover:text-foreground data-[state=open]:text-foreground">
+ <Info className="h-4 w-4" />
+ </PopoverTrigger>
+ <PopoverContent>
+ <p className="font-medium">{long}</p>
+ <p className="text-muted-foreground text-sm">
+ {description}
+ </p>
+ </PopoverContent>
+ </Popover>
+ ) : null}
</div>
</TableCell>
<TableCell>
diff --git a/apps/web/src/components/dashboard/empty-state.tsx b/apps/web/src/components/dashboard/empty-state.tsx
index 1f8646679..f58e27775 100644
--- a/apps/web/src/components/dashboard/empty-state.tsx
+++ b/apps/web/src/components/dashboard/empty-state.tsx
@@ -7,7 +7,7 @@ interface Props extends React.ComponentProps<"div"> {
icon: ValidIcon;
title: string;
description: string;
- action: React.ReactNode;
+ action?: React.ReactNode;
}
export function EmptyState({ icon, title, description, action }: Props) {
@@ -20,7 +20,7 @@ export function EmptyState({ icon, title, description, action }: Props) {
<p className="text-foreground text-base">{title}</p>
<p className="text-muted-foreground text-center">{description}</p>
</div>
- <div>{action}</div>
+ {action ? <div>{action}</div> : null}
</div>
</div>
);
diff --git a/apps/web/src/components/data-table/columns.tsx b/apps/web/src/components/data-table/columns.tsx
index c336bca9b..bc6ab627e 100644
--- a/apps/web/src/components/data-table/columns.tsx
+++ b/apps/web/src/components/data-table/columns.tsx
@@ -14,6 +14,7 @@ import {
import { regionsDict } from "@openstatus/utils";
import { DataTableColumnHeader } from "./data-table-column-header";
+import { DataTableRowActions } from "./data-table-row-action";
import { DataTableStatusBadge } from "./data-table-status-badge";
export const columns: ColumnDef<Ping>[] = [
@@ -89,4 +90,14 @@ export const columns: ColumnDef<Ping>[] = [
return value.includes(row.getValue(id));
},
},
+ {
+ id: "actions",
+ cell: ({ row }) => {
+ return (
+ <div className="text-right">
+ <DataTableRowActions row={row} />
+ </div>
+ );
+ },
+ },
];
diff --git a/apps/web/src/components/data-table/data-table-row-action.tsx b/apps/web/src/components/data-table/data-table-row-action.tsx
index d7bb2b8c5..7bec7dde2 100644
--- a/apps/web/src/components/data-table/data-table-row-action.tsx
+++ b/apps/web/src/components/data-table/data-table-row-action.tsx
@@ -1,30 +1,18 @@
"use client";
+import Link from "next/link";
import type { Row } from "@tanstack/react-table";
import { MoreHorizontal } from "lucide-react";
-import * as z from "zod";
import { tbBuildResponseList } from "@openstatus/tinybird";
import {
Button,
- Dialog,
- DialogContent,
- DialogDescription,
- DialogHeader,
- DialogTitle,
- DialogTrigger,
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
- DropdownMenuLabel,
DropdownMenuTrigger,
} from "@openstatus/ui";
-// REMINDER: needed because `ResponseList` returns metadata as string, not as Record
-const schema = tbBuildResponseList.extend({
- metadata: z.record(z.string(), z.unknown()).nullable(),
-});
-
interface DataTableRowActionsProps<TData> {
row: Row<TData>;
}
@@ -32,53 +20,25 @@ interface DataTableRowActionsProps<TData> {
export function DataTableRowActions<TData>({
row,
}: DataTableRowActionsProps<TData>) {
- const ping = schema.parse(row.original);
+ const ping = tbBuildResponseList.parse(row.original);
return (
- <Dialog>
- <DropdownMenu>
- <DropdownMenuTrigger asChild>
- <Button
- variant="ghost"
- className="data-[state=open]:bg-accent h-8 w-8 p-0"
- >
- <span className="sr-only">Open menu</span>
- <MoreHorizontal className="h-4 w-4" />
- </Button>
- </DropdownMenuTrigger>
- <DropdownMenuContent align="end">
- <DropdownMenuLabel>Actions</DropdownMenuLabel>
- <DialogTrigger asChild>
- <DropdownMenuItem>View Metadata</DropdownMenuItem>
- </DialogTrigger>
- </DropdownMenuContent>
- </DropdownMenu>
- <DialogContent>
- <DialogHeader>
- <DialogTitle>Metadata</DialogTitle>
- <DialogDescription>
- Additional informations to your Response like...
- </DialogDescription>
- </DialogHeader>
- <div className="border-border rounded-lg border border-dashed p-4">
- {!Boolean(Object.keys(ping.metadata || {}).length) ? (
- <ul className="grid gap-1">
- {Object.keys(ping.metadata || {}).map((key) => {
- return (
- <li key={key} className="text-sm">
- <p>
- <code>
- {`"${key}"`}: {`${ping.metadata?.[key] || null}`}
- </code>
- </p>
- </li>
- );
- })}
- </ul>
- ) : (
- <p className="text-sm">No data collected</p>
- )}
- </div>
- </DialogContent>
- </Dialog>
+ <DropdownMenu>
+ <DropdownMenuTrigger asChild>
+ <Button
+ variant="ghost"
+ className="data-[state=open]:bg-accent h-8 w-8 p-0"
+ >
+ <span className="sr-only">Open menu</span>
+ <MoreHorizontal className="h-4 w-4" />
+ </Button>
+ </DropdownMenuTrigger>
+ <DropdownMenuContent align="end">
+ <Link
+ href={`./details?monitorId=${ping.monitorId}&cronTimestamp=${ping.cronTimestamp}&region=${ping.region}`}
+ >
+ <DropdownMenuItem>Details</DropdownMenuItem>
+ </Link>
+ </DropdownMenuContent>
+ </DropdownMenu>
);
}
diff --git a/apps/web/src/components/play/card.tsx b/apps/web/src/components/play/card.tsx
new file mode 100644
index 000000000..325994929
--- /dev/null
+++ b/apps/web/src/components/play/card.tsx
@@ -0,0 +1,62 @@
+import Link from "next/link";
+import type { LucideIcon } from "lucide-react";
+
+import { Button } from "@openstatus/ui";
+
+import { Shell } from "@/components/dashboard/shell";
+import { cn } from "@/lib/utils";
+
+interface CardProps extends React.HTMLAttributes<HTMLDivElement> {
+ href: string;
+ title: string;
+ description: string;
+ icon?: LucideIcon;
+ variant?: "default" | "primary";
+}
+
+// TODO: unify the cards of playground, oss-friends and external monitors
+
+function Card({
+ title,
+ description,
+ href,
+ variant = "default",
+ icon,
+ className,
+ ...props
+}: CardProps) {
+ const buttonVariant = variant === "default" ? "outline" : "default";
+ const shellClassName =
+ variant === "default" ? "" : "bg-accent text-accent-foreground";
+
+ const isExternal = href.startsWith("http");
+ const externalProps = isExternal
+ ? { target: "_blank", rel: "noreferrer" }
+ : {};
+
+ return (
+ <Shell
+ className={cn(
+ "group flex flex-col gap-3 hover:shadow",
+ shellClassName,
+ className,
+ )}
+ {...props}
+ >
+ <div className="flex-1 space-y-2">
+ <h2 className={cn("font-cal text-xl")}>{title}</h2>
+ <p className="text-muted-foreground">{description}</p>
+ </div>
+ <div className="flex items-center justify-between">
+ <Button variant={buttonVariant} className="rounded-full" asChild>
+ <Link href={href} {...externalProps}>
+ Learn more
+ </Link>
+ </Button>
+ <div className="border-border bg-background rounded-full border p-2 transition-transform duration-200 group-hover:-rotate-12">
+ {icon ? icon({ className: "text-muted-foreground h-5 w-5" }) : null}
+ </div>
+ </div>
+ </Shell>
+ );
+}
diff --git a/apps/web/src/lib/tb.ts b/apps/web/src/lib/tb.ts
index afea4225c..ab9c954fb 100644
--- a/apps/web/src/lib/tb.ts
+++ b/apps/web/src/lib/tb.ts
@@ -1,6 +1,7 @@
import type {
HomeStatsParams,
MonitorListParams,
+ ResponseDetailsParams,
ResponseGraphParams,
ResponseListParams,
} from "@openstatus/tinybird";
@@ -8,6 +9,7 @@ import {
getHomeMonitorList,
getHomeStats,
getMonitorList,
+ getResponseDetails,
getResponseGraph,
getResponseList,
Tinybird,
@@ -28,6 +30,18 @@ export async function getResponseListData(props: Partial<ResponseListParams>) {
return;
}
+export async function getResponseDetailsData(
+ props: Partial<ResponseDetailsParams>,
+) {
+ try {
+ const res = await getResponseDetails(tb)(props);
+ return res.data;
+ } catch (e) {
+ console.error(e);
+ }
+ return;
+}
+
export async function getMonitorListData(props: MonitorListParams) {
try {
const res = await getMonitorList(tb)(props);
diff --git a/packages/tinybird/pipes/home_stats.pipe b/packages/tinybird/pipes/home_stats.pipe
index c28336454..f9e48c15d 100644
--- a/packages/tinybird/pipes/home_stats.pipe
+++ b/packages/tinybird/pipes/home_stats.pipe
@@ -5,7 +5,7 @@ SQL >
%
SELECT COUNT(*) as count
- FROM ping_response__v5
+ FROM ping_response__v7
{% if defined(period) %}
{% if String(period) == "1h" %}
WHERE cronTimestamp > toUnixTimestamp(now() - INTERVAL 1 HOUR) * 1000
diff --git a/packages/tinybird/pipes/response_details.pipe b/packages/tinybird/pipes/response_details.pipe
new file mode 100644
index 000000000..42a01e46f
--- /dev/null
+++ b/packages/tinybird/pipes/response_details.pipe
@@ -0,0 +1,14 @@
+VERSION 0
+
+NODE response_graph_0
+SQL >
+
+ %
+ SELECT *
+ FROM ping_response__v7
+ WHERE
+ monitorId = {{ String(monitorId, '1') }}
+ AND cronTimestamp = {{ Int64(cronTimestamp, 1706467215188) }}
+ AND region = {{ String(region, 'ams') }}
+
+
diff --git a/packages/tinybird/pipes/response_graph.pipe b/packages/tinybird/pipes/response_graph.pipe
index a56213a44..5f2077d21 100644
--- a/packages/tinybird/pipes/response_graph.pipe
+++ b/packages/tinybird/pipes/response_graph.pipe
@@ -16,7 +16,7 @@ SQL >
round(quantile(0.9)(latency)) as p90Latency,
round(quantile(0.95)(latency)) as p95Latency,
round(quantile(0.99)(latency)) as p99Latency
- FROM materialized_view_ping_response_3d
+ FROM ping_response__v7
WHERE
monitorId = {{ String(monitorId, '1') }}
{% if defined(fromDate) %} AND timestamp >= {{ Int64(fromDate) }} {% end %}
diff --git a/packages/tinybird/pipes/response_list.pipe b/packages/tinybird/pipes/response_list.pipe
index a40f0af25..a1fc24aa0 100644
--- a/packages/tinybird/pipes/response_list.pipe
+++ b/packages/tinybird/pipes/response_list.pipe
@@ -5,7 +5,7 @@ SQL >
%
SELECT latency, monitorId, region, statusCode, timestamp, url, workspaceId, cronTimestamp, message
- FROM ping_response__v5
+ FROM ping_response__v7
WHERE monitorId = {{ String(monitorId, 'openstatusPing') }}
{% if defined(region) %}
AND region = {{ String(region) }}
diff --git a/packages/tinybird/pipes/status_timezone.pipe b/packages/tinybird/pipes/status_timezone.pipe
index 9b6a7dfea..8d3b1d8b1 100644
--- a/packages/tinybird/pipes/status_timezone.pipe
+++ b/packages/tinybird/pipes/status_timezone.pipe
@@ -14,7 +14,7 @@ SQL >
toStartOfDay(with_timezone) as start_of_day,
statusCode,
latency
- FROM ping_response__v5
+ FROM ping_response__v7
WHERE monitorId = {{ String(monitorId, '1') }}
-- by default, we only query the last 45 days
AND cronTimestamp >= toUnixTimestamp64Milli(
diff --git a/packages/tinybird/src/client.ts b/packages/tinybird/src/client.ts
index dc33ee18d..339ab09ef 100644
--- a/packages/tinybird/src/client.ts
+++ b/packages/tinybird/src/client.ts
@@ -4,12 +4,14 @@ import {
tbBuildHomeStats,
tbBuildMonitorList,
tbBuildPublicStatus,
+ tbBuildResponseDetails,
tbBuildResponseGraph,
tbBuildResponseList,
tbIngestPingResponse,
tbParameterHomeStats,
tbParameterMonitorList,
tbParameterPublicStatus,
+ tbParameterResponseDetails,
tbParameterResponseGraph,
tbParameterResponseList,
} from "./validation";
@@ -34,6 +36,17 @@ export function getResponseList(tb: Tinybird) {
});
}
+export function getResponseDetails(tb: Tinybird) {
+ return tb.buildPipe({
+ pipe: "response_details__v0",
+ parameters: tbParameterResponseDetails,
+ data: tbBuildResponseDetails,
+ opts: {
+ cache: "force-cache",
+ },
+ });
+}
+
export function getResponseGraph(tb: Tinybird) {
return tb.buildPipe({
pipe: "response_graph__v0",
diff --git a/packages/tinybird/src/validation.ts b/packages/tinybird/src/validation.ts
index c997a9250..4595032d5 100644
--- a/packages/tinybird/src/validation.ts
+++ b/packages/tinybird/src/validation.ts
@@ -1,6 +1,6 @@
import * as z from "zod";
-import { availableRegions } from "@openstatus/utils";
+import { flyRegions } from "@openstatus/utils";
/**
* Values for the datasource ping_response
@@ -44,7 +44,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(availableRegions),
+ region: z.enum(flyRegions),
message: z.string().nullable().optional(),
});
@@ -56,15 +56,65 @@ 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(availableRegions).optional(),
+ region: z.enum(flyRegions).optional(),
cronTimestamp: z.number().int().optional(),
});
+/**
+ * Params for pipe response_details
+ */
+export const tbParameterResponseDetails = tbParameterResponseList.pick({
+ monitorId: true,
+ cronTimestamp: true,
+ region: true,
+});
+
+export const responseHeadersSchema = z.record(z.string(), z.string());
+export const responseTimingSchema = z.object({
+ dnsStart: z.number(),
+ dnsDone: z.number(),
+ connectStart: z.number(),
+ connectDone: z.number(),
+ tlsHandshakeStart: z.number(),
+ tlsHandshakeDone: z.number(),
+ firstByteStart: z.number(),
+ firstByteDone: z.number(),
+ transferStart: z.number(),
+ transferDone: z.number(),
+});
+
+/**
+ * Values from the pipe response_details
+ */
+export const tbBuildResponseDetails = tbBuildResponseList.extend({
+ message: z.string().nullable().optional(),
+ headers: z
+ .string()
+ .nullable()
+ .optional()
+ .transform((val) => {
+ if (!val) return null;
+ const value = responseHeadersSchema.safeParse(JSON.parse(val));
+ if (value.success) return value.data;
+ return null;
+ }),
+ timing: z
+ .string()
+ .nullable()
+ .optional()
+ .transform((val) => {
+ if (!val) return null;
+ const value = responseTimingSchema.safeParse(JSON.parse(val));
+ if (value.success) return value.data;
+ return null;
+ }),
+});
+
/**
* Values from pipe response_graph
*/
export const tbBuildResponseGraph = z.object({
- region: z.enum(availableRegions),
+ region: z.enum(flyRegions),
timestamp: z.number().int(),
avgLatency: z.number().int(),
p75Latency: z.number().int(),
@@ -142,7 +192,7 @@ export const tbBuildPublicStatus = z.object({
});
export type Ping = z.infer<typeof tbBuildResponseList>;
-export type Region = (typeof availableRegions)[number]; // TODO: rename type AvailabeRegion
+export type Region = (typeof flyRegions)[number]; // TODO: rename type AvailabeRegion
export type Monitor = z.infer<typeof tbBuildMonitorList>;
export type HomeStats = z.infer<typeof tbBuildHomeStats>;
export type ResponseGraph = z.infer<typeof tbBuildResponseGraph>; // TODO: rename to ResponseQuantileChart
@@ -150,3 +200,5 @@ export type ResponseListParams = z.infer<typeof tbParameterResponseList>;
export type ResponseGraphParams = z.infer<typeof tbParameterResponseGraph>;
export type MonitorListParams = z.infer<typeof tbParameterMonitorList>;
export type HomeStatsParams = z.infer<typeof tbParameterHomeStats>;
+export type ResponseDetails = z.infer<typeof tbBuildResponseDetails>;
+export type ResponseDetailsParams = z.infer<typeof tbParameterResponseDetails>;