Open-source status page, incident response and uptime monitoring
TypeScript alertingincident-managementmcpmcp-servermonitoringmonitoring-as-codeobservabilityon-callopen-sourcesrestatus-pagestatuspagesynthetic-monitoringterraformtinybirdtursouptimeuptime-checkeruptime-monitor
feat: build tb pipes (#697)
Maximilian Kaske2fa8d9ffb94d
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsxindex 84b7f968f..d3da724f5 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/(overview)/page.tsx@@ -1,16 +1,20 @@import * as React from "react";import Link from "next/link";+import { OSTinybird } from "@openstatus/tinybird";import { Button } from "@openstatus/ui";import { EmptyState } from "@/components/dashboard/empty-state";import { Limit } from "@/components/dashboard/limit";import { columns } from "@/components/data-table/monitor/columns";import { DataTable } from "@/components/data-table/monitor/data-table";-import { getMonitorListData, getResponseTimeMetricsData } from "@/lib/tb";-import { convertTimezoneToGMT } from "@/lib/timezone";+import { env } from "@/env";import { api } from "@/trpc/server";+// import { RefreshWidget } from "../_components/refresh-widget";++const tb = new OSTinybird({ token: env.TINY_BIRD_API_KEY });+export default async function MonitorPage() {const monitors = await api.monitor.getMonitorsByWorkspace.query();const isLimitReached = await api.monitor.isMonitorLimitReached.query();@@ -29,29 +33,25 @@ export default async function MonitorPage() {/>);- const gmt = convertTimezoneToGMT();-const _incidents = await api.incident.getIncidentsByWorkspace.query();// maybe not very efficient?// use Suspense and Client call instead?const monitorsWithData = await Promise.all(monitors.map(async (monitor) => {- const metrics = await getResponseTimeMetricsData({+ const metrics = await tb.endpointMetrics("1d")({monitorId: String(monitor.id),url: monitor.url,- interval: 24,});- const data = await getMonitorListData({+ const data = await tb.endpointStatusPeriod("7d")({monitorId: String(monitor.id),- url: monitor.url,- timezone: gmt,+ url: monitor.url, // FIXME: we should avoid adding url to the parameters});- const [current, _] = metrics- ? metrics.sort((a, b) => (a.time - b.time < 0 ? 1 : -1))- : [undefined];+ const [current] = metrics?.sort((a, b) =>+ (a.lastTimestamp || 0) - (b.lastTimestamp || 0) < 0 ? 1 : -1,+ ) || [undefined];const incidents = _incidents.filter((incident) => incident.monitorId === monitor.id,@@ -61,10 +61,17 @@ export default async function MonitorPage() {}),);+ // const lastCronTimestamp = monitorsWithData?.reduce((prev, acc) => {+ // const lastTimestamp = acc.metrics?.lastTimestamp || 0;+ // if (lastTimestamp > prev) return lastTimestamp;+ // return prev;+ // }, 0);+return (<><DataTable columns={columns} data={monitorsWithData} />{isLimitReached ? <Limit /> : null}+ {/* <RefreshWidget defaultValue={lastCronTimestamp} /> */}</>);}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/date-picker-preset.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/date-picker-preset.tsxindex 687c40b58..7851361e5 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/date-picker-preset.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/date-picker-preset.tsx@@ -1,46 +1,29 @@"use client";import * as React from "react";-import { usePathname, useRouter } from "next/navigation";-import { CalendarIcon } from "lucide-react";-import {- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,-} from "@openstatus/ui";--import useUpdateSearchParams from "@/hooks/use-update-search-params";-import { periodFormatter, periods } from "../utils";+import { periodFormatter } from "../utils";import type { Period } from "../utils";+import { SearchParamsPreset } from "./search-params-preset";-export function DatePickerPreset({ period }: { period: Period }) {- const router = useRouter();- const pathname = usePathname();- const updateSearchParams = useUpdateSearchParams();-- function onSelect(value: Period) {- const searchParams = updateSearchParams({ period: value });- router.replace(`${pathname}?${searchParams}`, { scroll: false });- }-+export function DatePickerPreset({+ disabled,+ defaultValue,+ values,+}: {+ disabled?: boolean;+ defaultValue?: Period;+ values: readonly Period[];+}) {return (- <Select defaultValue={period} onValueChange={onSelect}>- <SelectTrigger className="bg-background w-[150px] text-left" id="period">- <span className="flex items-center gap-2">- <CalendarIcon className="h-4 w-4" />- <SelectValue placeholder="Pick a range" />- </span>- </SelectTrigger>- <SelectContent>- {periods.map((period) => (- <SelectItem key={period} value={period}>- {periodFormatter(period)}- </SelectItem>- ))}- </SelectContent>- </Select>+ <SearchParamsPreset+ disabled={disabled}+ defaultValue={defaultValue}+ values={values}+ searchParam="period"+ icon="calendar"+ placeholder="Pick a range"+ formatter={periodFormatter}+ />);}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/interval-preset.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/interval-preset.tsxindex f339611fb..81e74b9a0 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/interval-preset.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/interval-preset.tsx@@ -1,43 +1,21 @@"use client";import * as React from "react";-import { usePathname, useRouter } from "next/navigation";-import { HelpCircle, Hourglass } from "lucide-react";+import { HelpCircle } from "lucide-react";import {Label,Popover,PopoverContent,PopoverTrigger,- Select,- SelectContent,- SelectItem,- SelectTrigger,- SelectValue,Separator,} from "@openstatus/ui";-import useUpdateSearchParams from "@/hooks/use-update-search-params";-import { cn } from "@/lib/utils";import { intervals } from "../utils";import type { Interval } from "../utils";+import { SearchParamsPreset } from "./search-params-preset";-export function IntervalPreset({- interval,- className,-}: {- interval: Interval;- className?: string;-}) {- const router = useRouter();- const pathname = usePathname();- const updateSearchParams = useUpdateSearchParams();-- function onSelect(value: Interval) {- const searchParams = updateSearchParams({ interval: value });- router.replace(`${pathname}?${searchParams}`, { scroll: false });- }-+export function IntervalPreset({ interval }: { interval: Interval }) {return (<div className="grid gap-1"><div className="flex items-center gap-1.5">@@ -56,21 +34,14 @@ export function IntervalPreset({</PopoverContent></Popover></div>- <Select onValueChange={onSelect} defaultValue={interval}>- <SelectTrigger className={cn("w-[150px]", className)} id="interval">- <span className="flex items-center gap-2">- <Hourglass className="h-4 w-4" />- <SelectValue />- </span>- </SelectTrigger>- <SelectContent>- {intervals.map((interval) => (- <SelectItem key={interval} value={interval}>- {interval}- </SelectItem>- ))}- </SelectContent>- </Select>+ <SearchParamsPreset+ disabled={false}+ defaultValue={interval}+ values={intervals}+ searchParam="interval"+ icon="hour-glass"+ placeholder="Pick an interval"+ /></div>);}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics.tsxindex 2ea1f2f3e..09032457a 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/metrics.tsx@@ -7,7 +7,7 @@ import type { Period } from "../utils";import { MetricsCard } from "./metrics-card";const metricsOrder = [- "avgLatency",+ "p50Latency","p75Latency","p90Latency","p95Latency",@@ -24,7 +24,7 @@ export function Metrics({if (!metrics) return null;const [current, last] = metrics.sort((a, b) =>- a.time - b.time < 0 ? 1 : -1,+ (a.lastTimestamp || 0) - (b.lastTimestamp || 0) < 0 ? 1 : -1,);const isEmpty = current.count === 0;@@ -81,10 +81,7 @@ export function Metrics({return (<MetricsCardkey={key}- title={- // FIXME: rename in tb- key === "avgLatency" ? "P50" : key.replace("Latency", "")- }+ title={key.replace("Latency", "")}value={value || 0}suffix="ms"delta={delta}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/quantile-preset.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/quantile-preset.tsxindex 364e30daf..d41ca1528 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/quantile-preset.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/quantile-preset.tsx@@ -2,45 +2,27 @@import * as React from "react";import { usePathname, useRouter } from "next/navigation";-import { CandlestickChart, HelpCircle } from "lucide-react";+import { HelpCircle } from "lucide-react";import {Label,Popover,PopoverContent,PopoverTrigger,- Select,- SelectContent,- SelectItem,- SelectSeparator,- SelectTrigger,- SelectValue,Separator,} from "@openstatus/ui";-import useUpdateSearchParams from "@/hooks/use-update-search-params";-import { cn } from "@/lib/utils";import { quantiles } from "../utils";import type { Quantile } from "../utils";+import { SearchParamsPreset } from "./search-params-preset";export function QuantilePreset({quantile,disabled,- className,}: {quantile: Quantile;disabled?: boolean;- className?: string;}) {- const router = useRouter();- const pathname = usePathname();- const updateSearchParams = useUpdateSearchParams();-- function onSelect(value: Quantile) {- const searchParams = updateSearchParams({ quantile: value });- router.replace(`${pathname}?${searchParams}`, { scroll: false });- }-return (<div className="grid gap-1"><div className="flex items-center gap-1.5">@@ -62,33 +44,17 @@ export function QuantilePreset({</PopoverContent></Popover></div>- <Select- onValueChange={onSelect}- defaultValue={quantile}+ <SearchParamsPresetdisabled={disabled}- >- <SelectTrigger- className={cn("w-[150px] uppercase", className)}- id="quantile"- >- <span className="flex items-center gap-2">- <CandlestickChart className="h-4 w-4" />- <SelectValue />- </span>- </SelectTrigger>- <SelectContent>- {quantiles.map((quantile) => {- return (- <React.Fragment key={quantile}>- {quantile === "avg" && <SelectSeparator />}- <SelectItem value={quantile} className="uppercase">- {quantile}- </SelectItem>- </React.Fragment>- );- })}- </SelectContent>- </Select>+ defaultValue={quantile}+ values={quantiles}+ searchParam="quantile"+ icon="candlestick-chart"+ placeholder="Pick a quantile"+ formatter={(value: Quantile) => (+ <span className="uppercase">{value}</span>+ )}+ /></div>);}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/search-params-preset.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/search-params-preset.tsxnew file mode 100644index 000000000..06f0de243--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/search-params-preset.tsx@@ -0,0 +1,67 @@+"use client";++import * as React from "react";+import { usePathname, useRouter } from "next/navigation";++import {+ Select,+ SelectContent,+ SelectItem,+ SelectTrigger,+ SelectValue,+} from "@openstatus/ui";++import { Icons } from "@/components/icons";+import type { ValidIcon } from "@/components/icons";+import useUpdateSearchParams from "@/hooks/use-update-search-params";++export function SearchParamsPreset<T extends string>({+ disabled,+ defaultValue,+ values,+ searchParam,+ icon,+ placeholder,+ formatter,+}: {+ disabled?: boolean;+ defaultValue?: T;+ values: readonly T[];+ searchParam: string;+ icon?: ValidIcon;+ placeholder?: string;+ formatter?(value: T): React.ReactNode;+}) {+ const router = useRouter();+ const pathname = usePathname();+ const updateSearchParams = useUpdateSearchParams();++ function onSelect(value: T) {+ const searchParams = updateSearchParams({ [searchParam]: value });+ router.replace(`${pathname}?${searchParams}`, { scroll: false });+ }++ const Icon = icon ? Icons[icon] : undefined;++ return (+ <Select+ defaultValue={defaultValue}+ onValueChange={onSelect}+ disabled={disabled}+ >+ <SelectTrigger className="bg-background w-[150px] text-left">+ <span className="flex items-center gap-2">+ {Icon ? <Icon className="h-4 w-4" /> : null}+ <SelectValue placeholder={placeholder} />+ </span>+ </SelectTrigger>+ <SelectContent>+ {values.map((value) => (+ <SelectItem key={value} value={value}>+ {formatter?.(value) || value}+ </SelectItem>+ ))}+ </SelectContent>+ </Select>+ );+}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsxindex 6477a727a..c0c169a9b 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsx@@ -2,12 +2,16 @@ import * as React from "react";import { notFound } from "next/navigation";import * as z from "zod";+import { OSTinybird } from "@openstatus/tinybird";+import { columns } from "@/components/data-table/columns";import { DataTable } from "@/components/data-table/data-table";-import { getResponseListData } from "@/lib/tb";+import { env } from "@/env";import { api } from "@/trpc/server";import { DatePickerPreset } from "../_components/date-picker-preset";-import { getDateByPeriod, periods } from "../utils";+import { periods } from "../utils";++const tb = new OSTinybird({ token: env.TINY_BIRD_API_KEY });/*** allowed URL search params@@ -34,13 +38,13 @@ export default async function Page({return notFound();}- const date = getDateByPeriod(search.data.period);+ // FIXME: the other pipes are missing and mv need to include `timestamp` in the data+ const allowedPeriods = ["1h", "1d"] as const;+ const period = allowedPeriods.find((i) => i === search.data.period) || "1d";- const data = await getResponseListData({+ const data = await tb.endpointList(period)({monitorId: id,url: monitor.url,- fromDate: date.from.getTime(),- toDate: date.to.getTime(),});if (!data) return null;@@ -48,7 +52,7 @@ export default async function Page({return (<div className="grid gap-4"><div className="flex flex-wrap items-center gap-2 sm:justify-end">- <DatePickerPreset period={search.data.period} />+ <DatePickerPreset defaultValue={period} values={allowedPeriods} /></div><DataTable columns={columns} data={data} /></div>diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsxindex 1993e03b8..df8afd1b7 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/combined-chart-wrapper.tsx@@ -47,15 +47,19 @@ export function CombinedChartWrapper({return (<><div className="flex flex-col gap-2 sm:flex-row sm:items-end sm:justify-between">- <div className="flex w-full gap-2 sm:flex-row sm:justify-between">- <Toggle- pressed={combinedRegions}- onPressedChange={setCombinedRegions}- variant="outline"- >- <LineChart className="mr-2 h-4 w-4" />- {!combinedRegions ? "Combine regions" : "Split regions"}- </Toggle>+ <div className="flex w-full items-end gap-2 sm:flex-row sm:justify-between">+ <div className="flex flex-col gap-1.5">+ <p className="text-muted-foreground text-xs">Change the view</p>+ <Toggle+ pressed={combinedRegions}+ onPressedChange={setCombinedRegions}+ variant="outline"+ className="w-max"+ >+ <LineChart className="mr-2 h-4 w-4" />+ {!combinedRegions ? "Combine regions" : "Split regions"}+ </Toggle>+ </div><RegionsPresetregions={monitor.regions as Region[]}selectedRegions={regions}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsxindex fdef16927..88f4e5b4c 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/region-table.tsx@@ -60,7 +60,7 @@ export function RegionTable({<SimpleChart data={data.data} region={region} /></TableCell><TableCell className="text-right font-medium">- {formatNumber(metrics?.avgLatency)}+ {formatNumber(metrics?.p50Latency)}<span className="text-muted-foreground text-xs font-normal">ms</span>diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsxindex 8750a6fc1..9bba68372 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/_components/simple-chart.tsx@@ -1,6 +1,7 @@"use client";-import type { CustomTooltipProps } from "@tremor/react";+import { useEffect, useState } from "react";+import type { CustomTooltipProps, EventProps } from "@tremor/react";import { LineChart } from "@tremor/react";import { dataFormatter } from "./utils";@@ -10,7 +11,15 @@ export interface SimpleChartProps {region: string;}+// TODO: allow click to open `./details` intercepting routeexport function SimpleChart({ data, region }: SimpleChartProps) {+ const [value, setValue] = useState<EventProps>(null);++ useEffect(() => {+ console.log(value);+ // const href = `./details?monitorId=${ping.monitorId}&cronTimestamp=${ping.cronTimestamp}®ion=${ping.region}`;+ }, [value]);+return (<LineChartdata={data}@@ -27,6 +36,8 @@ export function SimpleChart({ data, region }: SimpleChartProps) {showGridLines={false}showLegend={false}customTooltip={customTooltip}+ // FEATURE: it would be nice, if on click, the tooltip would be open+ // onValueChange={(v) => setValue(v)}showAnimation={true}/>);@@ -34,10 +45,12 @@ export function SimpleChart({ data, region }: SimpleChartProps) {const customTooltip = ({ payload, active, label }: CustomTooltipProps) => {if (!active || !payload) return null;+ const data = payload?.[0]; // BUG: when onValueChange is set, payload is duplicated+return (<div className="rounded-tremor-default text-tremor-default dark:text-dark-tremor-default bg-tremor-background dark:bg-dark-tremor-background shadow-tremor-dropdown border-tremor-border dark:border-dark-tremor-border border p-2"><div className="flex flex-col gap-3">- {payload.map((category, idx) => {+ {[data].map((category, idx) => {return (<div key={idx} className="flex flex-1 gap-2"><divdiff --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.tsxindex 7c5dde386..eca5092b1 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@@ -4,27 +4,19 @@ import * as z from "zod";import { flyRegions } from "@openstatus/db/src/schema";import type { Region } from "@openstatus/tinybird";+import { OSTinybird } from "@openstatus/tinybird";import { Separator } from "@openstatus/ui";-import {- getResponseGraphData,- getResponseTimeMetricsByRegionData,- getResponseTimeMetricsData,-} from "@/lib/tb";+import { env } from "@/env";import { api } from "@/trpc/server";import { ButtonReset } from "../_components/button-reset";import { DatePickerPreset } from "../_components/date-picker-preset";import { Metrics } from "../_components/metrics";-import {- getDateByPeriod,- getHoursByPeriod,- getMinutesByInterval,- intervals,- periods,- quantiles,-} from "../utils";+import { getMinutesByInterval, intervals, periods, quantiles } from "../utils";import { CombinedChartWrapper } from "./_components/combined-chart-wrapper";+const tb = new OSTinybird({ token: env.TINY_BIRD_API_KEY });+const DEFAULT_QUANTILE = "p95";const DEFAULT_INTERVAL = "30m";const DEFAULT_PERIOD = "1d";@@ -48,11 +40,6 @@ const searchParamsSchema = z.object({?.split(",").filter((i) => flyRegions.includes(i as Region)) ?? flyRegions,),- // fromDate: z.coerce- // .number()- // .optional()- // .default(startOfDay(new Date()).getTime()),- // toDate: z.coerce.number().optional().default(endOfDay(new Date()).getTime()),});export default async function Page({@@ -73,42 +60,33 @@ export default async function Page({return notFound();}- const date = getDateByPeriod(search.data.period);- const intervalMinutes = getMinutesByInterval(search.data.interval);+ const { period, quantile, interval, regions } = search.data;++ // TODO: work it out easier+ const intervalMinutes = getMinutesByInterval(interval);const periodicityMinutes = getMinutesByInterval(monitor.periodicity);- const periodicityHours = getHoursByPeriod(search.data.period);const isQuantileDisabled = intervalMinutes <= periodicityMinutes;const minutes = isQuantileDisabled ? periodicityMinutes : intervalMinutes;- const data = await getResponseGraphData({+ const metrics = await tb.endpointMetrics(period)({monitorId: id,url: monitor.url,- ...search.data,- /**- *- */- fromDate: date.from.getTime(),- toDate: date.to.getTime(),- interval: minutes,});- const metrics = await getResponseTimeMetricsData({+ const data = await tb.endpointChart(period)({monitorId: id,url: monitor.url,- interval: periodicityHours,+ interval: minutes,});- const metricsByRegion = await getResponseTimeMetricsByRegionData({+ const metricsByRegion = await tb.endpointMetricsByRegion(period)({monitorId: id,url: monitor.url,- interval: periodicityHours,});if (!data || !metrics || !metricsByRegion) return null;- const { period, quantile, interval, regions } = search.data;-const isDirty =period !== DEFAULT_PERIOD ||quantile !== DEFAULT_QUANTILE ||@@ -118,7 +96,7 @@ export default async function Page({return (<div className="grid gap-4"><div className="flex justify-between gap-2">- <DatePickerPreset period={period} />+ <DatePickerPreset defaultValue={period} values={periods} />{isDirty ? <ButtonReset /> : null}</div><Metrics metrics={metrics} period={period} />@@ -128,7 +106,7 @@ export default async function Page({period={period}quantile={quantile}interval={interval}- regions={regions as Region[]}+ regions={regions as Region[]} // FIXME: not properly reseted after filteredmonitor={monitor}isQuantileDisabled={isQuantileDisabled}metricsByRegion={metricsByRegion}diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/utils.ts b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/utils.tsindex 8c3ad5440..5654c1b40 100644--- a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/utils.ts+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/utils.ts@@ -10,7 +10,7 @@ import {import type { MonitorPeriodicity } from "@openstatus/db/src/schema";export const periods = ["1h", "1d", "3d", "7d", "14d"] as const; // If neeeded (e.g. Pro plans), "7d", "30d"-export const quantiles = ["p99", "p95", "p90", "p75", "avg"] as const;+export const quantiles = ["p99", "p95", "p90", "p75", "p50"] as const;export const intervals = ["1m", "10m", "30m", "1h"] as const;export type Period = (typeof periods)[number];diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/refresh-widget.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/refresh-widget.tsxnew file mode 100644index 000000000..65c5831e3--- /dev/null+++ b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/_components/refresh-widget.tsx@@ -0,0 +1,48 @@+"use client";++import { useEffect, useState } from "react";+import { useRouter } from "next/navigation";++import { Button } from "@openstatus/ui";++import { api } from "@/trpc/client";++// TODO: instead of setInterval, use staleWhileRevalidate method to fetch latest data+// also fetch data on page focus++export function RefreshWidget({ defaultValue }: { defaultValue?: number }) {+ const [refresh, setRefresh] = useState(false);+ const [value, setValue] = useState(defaultValue);+ const router = useRouter();++ useEffect(() => {+ const intervalId = setInterval(async () => {+ if (refresh) return;+ const data = await api.tinybird.lastCronTimestamp.query();+ if (data && data?.length > 0) {+ const { cronTimestamp } = data[0];+ setValue(cronTimestamp);+ if (value && cronTimestamp > value) setRefresh(true);+ }+ }, 30_000);+ return () => {+ clearInterval(intervalId);+ };+ }, [refresh, value]);++ if (!refresh) return null;++ return (+ <div>+ <Button+ onClick={() => {+ router.refresh();+ setRefresh(false);+ }}+ variant="outline"+ >+ Refresh+ </Button>+ </div>+ );+}diff --git a/apps/web/src/app/monitor/[id]/page.tsx b/apps/web/src/app/monitor/[id]/page.tsxdeleted file mode 100644index fe08e7210..000000000--- a/apps/web/src/app/monitor/[id]/page.tsx+++ /dev/null@@ -1,44 +0,0 @@-import * as z from "zod";--import { flyRegions } from "@openstatus/utils";--import { columns } from "@/components/data-table/columns";-import { DataTable } from "@/components/data-table/data-table";-import { getResponseListData } from "@/lib/tb";-import { api } from "@/trpc/server";--//--/**- * allowed URL search params- */-const searchParamsSchema = z.object({- statusCode: z.coerce.number().optional(),- region: z.enum(flyRegions).optional(),- cronTimestamp: z.coerce.number().optional(),- fromDate: z.coerce.number().optional(),- toDate: z.coerce.number().optional(),-});--export default async function Monitor({- params,- searchParams,-}: {- params: { id: string };- searchParams: { [key: string]: string | string[] | undefined };-}) {- const search = searchParamsSchema.safeParse(searchParams);- const monitor = await api.monitor.getMonitorById.query({- id: Number(params.id),- });- const data = search.success- ? // TODO: lets hard-code our `monitorId` here- await getResponseListData({- monitorId: params.id,- url: monitor.url,- ...search.data,- })- : await getResponseListData({ monitorId: params.id, url: monitor.url });- if (!data || !search.success) return <div>Something went wrong</div>;- return <DataTable columns={columns} data={data} />;-}diff --git a/apps/web/src/app/monitor/layout.tsx b/apps/web/src/app/monitor/layout.tsxdeleted file mode 100644index ff66cbefc..000000000--- a/apps/web/src/app/monitor/layout.tsx+++ /dev/null@@ -1,19 +0,0 @@-import * as React from "react";--import { Shell } from "@/components/dashboard/shell";-import { BackButton } from "@/components/layout/back-button";-import { MarketingLayout } from "@/components/layout/marketing-layout";--// same layout as /play-export default function MonitorLayout({- children,-}: {- children: React.ReactNode;-}) {- return (- <MarketingLayout>- <BackButton href="/play" />- <Shell>{children}</Shell>- </MarketingLayout>- );-}diff --git a/apps/web/src/app/play/@modal/(..)monitor/[id]/modal.tsx b/apps/web/src/app/play/@modal/(..)monitor/[id]/modal.tsxdeleted file mode 100644index 56ac1e471..000000000--- a/apps/web/src/app/play/@modal/(..)monitor/[id]/modal.tsx+++ /dev/null@@ -1,24 +0,0 @@-"use client";--import { useRouter } from "next/navigation";--import { Dialog, DialogContent } 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-screen w-full overflow-auto sm:max-w-3xl sm:p-8">- {children}- </DialogContent>- </Dialog>- );-}diff --git a/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsx b/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsxdeleted file mode 100644index 64578383d..000000000--- a/apps/web/src/app/play/@modal/(..)monitor/[id]/page.tsx+++ /dev/null@@ -1,43 +0,0 @@-import * as z from "zod";--import { flyRegions } from "@openstatus/utils";--import { columns } from "@/components/data-table/columns";-import { DataTable } from "@/components/data-table/data-table";-import { getResponseListData } from "@/lib/tb";-import { Modal } from "./modal";--//--/**- * allowed URL search params- */-const searchParamsSchema = z.object({- statusCode: z.coerce.number().optional(),- region: z.enum(flyRegions).optional(),- cronTimestamp: z.coerce.number().optional(),- fromDate: z.coerce.number().optional(),- toDate: z.coerce.number().optional(),-});--export default async function Monitor({- params,- searchParams,-}: {- params: { id: string };- searchParams: { [key: string]: string | string[] | undefined };-}) {- const search = searchParamsSchema.safeParse(searchParams);- const data = search.success- ? // TODO: lets hard-code our `monitorId` here- await getResponseListData({ monitorId: params.id, ...search.data })- : await getResponseListData({ monitorId: params.id });-- if (!data) return <div>Something went wrong</div>;-- return (- <Modal>- <DataTable columns={columns} data={data} />- </Modal>- );-}diff --git a/apps/web/src/app/play/@modal/default.tsx b/apps/web/src/app/play/@modal/default.tsxdeleted file mode 100644index 6ddf1b76f..000000000--- a/apps/web/src/app/play/@modal/default.tsx+++ /dev/null@@ -1,3 +0,0 @@-export default function Default() {- return null;-}diff --git a/apps/web/src/app/play/layout.tsx b/apps/web/src/app/play/layout.tsxindex d845a1c4a..943396585 100644--- a/apps/web/src/app/play/layout.tsx+++ b/apps/web/src/app/play/layout.tsx@@ -20,15 +20,8 @@ export const metadata: Metadata = {export default function PlayLayout({children,- modal,}: {children: React.ReactNode;- modal: React.ReactNode;}) {- return (- <MarketingLayout>- {children}- {modal}- </MarketingLayout>- );+ return <MarketingLayout>{children}</MarketingLayout>;}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.tsxindex 7bec7dde2..72d036aab 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@@ -20,6 +20,7 @@ interface DataTableRowActionsProps<TData> {export function DataTableRowActions<TData>({row,}: DataTableRowActionsProps<TData>) {+ // FIXME: DRY - this is a duplicate of the OSTinybird endpointconst ping = tbBuildResponseList.parse(row.original);return (<DropdownMenu>diff --git a/apps/web/src/components/data-table/monitor/columns.tsx b/apps/web/src/components/data-table/monitor/columns.tsxindex 285ae08a6..743b3606a 100644--- a/apps/web/src/components/data-table/monitor/columns.tsx+++ b/apps/web/src/components/data-table/monitor/columns.tsx@@ -45,7 +45,9 @@ export const columns: ColumnDef<{},{accessorKey: "tracker",- header: "Last 7 days",+ header: () => (+ <HeaderTooltip label="Last 7 days" content="UTC time period" />+ ),cell: ({ row }) => {const tracker = new Tracker({data: row.original.data?.slice(0, 7).reverse(),@@ -80,7 +82,9 @@ export const columns: ColumnDef<{},{accessorKey: "uptime",- header: () => <HeaderTooltip>Uptime</HeaderTooltip>,+ header: () => (+ <HeaderTooltip label="Uptime" content="Data from the last 24h" />+ ),cell: ({ row }) => {const { count, ok } = row.original?.metrics || {};if (!count || !ok)@@ -90,17 +94,21 @@ export const columns: ColumnDef<{},},{- accessorKey: "avgLatency",- header: () => <HeaderTooltip>P50</HeaderTooltip>,+ accessorKey: "p50Latency",+ header: () => (+ <HeaderTooltip label="P50" content="Data from the last 24h" />+ ),cell: ({ row }) => {- const latency = row.original.metrics?.avgLatency;+ const latency = row.original.metrics?.p50Latency;if (latency) return <Number value={latency} suffix="ms" />;return <span className="text-muted-foreground">-</span>;},},{accessorKey: "p95Latency",- header: () => <HeaderTooltip>P95</HeaderTooltip>,+ header: () => (+ <HeaderTooltip label="P95" content="Data from the last 24h" />+ ),cell: ({ row }) => {const latency = row.original.metrics?.p95Latency;if (latency) return <Number value={latency} suffix="ms" />;@@ -119,14 +127,14 @@ export const columns: ColumnDef<{},];-function HeaderTooltip({ children }: { children: string }) {+function HeaderTooltip({ label, content }: { label: string; content: string }) {return (<TooltipProvider><Tooltip><TooltipTrigger className="underline decoration-dotted">- {children}+ {label}</TooltipTrigger>- <TooltipContent>Data from the last 24h</TooltipContent>+ <TooltipContent>{content}</TooltipContent></Tooltip></TooltipProvider>);diff --git a/apps/web/src/components/icons.tsx b/apps/web/src/components/icons.tsxindex d256bcc0f..80826531c 100644--- a/apps/web/src/components/icons.tsx+++ b/apps/web/src/components/icons.tsx@@ -5,6 +5,7 @@ import {Book,Bot,Calendar,+ CandlestickChart,Check,Clock,Cog,@@ -12,6 +13,7 @@ import {CreditCard,Fingerprint,Globe2,+ Hourglass,Image,KeyRound,Laptop,@@ -96,6 +98,8 @@ export const Icons = {book: Book,newspaper: Newspaper,youtube: Youtube,+ "hour-glass": Hourglass,+ "candlestick-chart": CandlestickChart,discord: ({ ...props }: LucideProps) => (<svg viewBox="0 0 640 512" {...props}><pathdiff --git a/apps/web/src/lib/tb.ts b/apps/web/src/lib/tb.tsindex ae85fa2bf..bbac9031b 100644--- a/apps/web/src/lib/tb.ts+++ b/apps/web/src/lib/tb.ts@@ -2,38 +2,21 @@ import type {HomeStatsParams,MonitorListParams,ResponseDetailsParams,- ResponseGraphParams,- ResponseListParams,- ResponseTimeMetricsByRegionParams,- ResponseTimeMetricsParams,} from "@openstatus/tinybird";import {getHomeMonitorList,getHomeStats,getMonitorList,getResponseDetails,- getResponseGraph,- getResponseList,- getResponseTimeMetrics,- getResponseTimeMetricsByRegion,Tinybird,} from "@openstatus/tinybird";import { env } from "@/env";+// @depreciated in favor to use the OSTinybird client directlyconst tb = new Tinybird({ token: env.TINY_BIRD_API_KEY });-// TODO: add security layer-export async function getResponseListData(props: Partial<ResponseListParams>) {- try {- const res = await getResponseList(tb)(props);- return res.data;- } catch (e) {- console.error(e);- }- return;-}-+// TODO: not yet converted to new mvexport async function getResponseDetailsData(props: Partial<ResponseDetailsParams>,) {@@ -46,6 +29,7 @@ export async function getResponseDetailsData(return;}+// REMINDER: includes yet timezoneexport async function getMonitorListData(props: MonitorListParams) {try {const res = await getMonitorList(tb)(props);@@ -56,7 +40,7 @@ export async function getMonitorListData(props: MonitorListParams) {return;}-// Includes caching of data for 10 minutes+// REMINDER: includes yet timezoneexport async function getHomeMonitorListData(props: Pick<MonitorListParams, "timezone">,) {@@ -82,39 +66,3 @@ export async function getHomeStatsData(props: Partial<HomeStatsParams>) {}return;}--export async function getResponseGraphData(- props: Partial<ResponseGraphParams>,-) {- try {- const res = await getResponseGraph(tb)(props);- return res.data;- } catch (e) {- console.error(e);- }- return;-}--export async function getResponseTimeMetricsData(- props: ResponseTimeMetricsParams,-) {- try {- const res = await getResponseTimeMetrics(tb)(props);- return res.data;- } catch (e) {- console.error(e);- }- return;-}--export async function getResponseTimeMetricsByRegionData(- props: ResponseTimeMetricsByRegionParams,-) {- try {- const res = await getResponseTimeMetricsByRegion(tb)(props);- return res.data;- } catch (e) {- console.error(e);- }- return;-}diff --git a/packages/api/package.json b/packages/api/package.jsonindex 84970193a..2b76b3d50 100644--- a/packages/api/package.json+++ b/packages/api/package.json@@ -12,6 +12,7 @@"@openstatus/db": "workspace:*","@openstatus/emails": "workspace:*","@openstatus/plans": "workspace:*",+ "@openstatus/tinybird": "workspace:*","@t3-oss/env-core": "0.7.0","@trpc/client": "10.38.5","@trpc/server": "10.38.5",diff --git a/packages/api/src/edge.ts b/packages/api/src/edge.tsindex 9948496a4..2a8619cdd 100644--- a/packages/api/src/edge.ts+++ b/packages/api/src/edge.ts@@ -7,6 +7,7 @@ import { notificationRouter } from "./router/notification";import { pageRouter } from "./router/page";import { pageSubscriberRouter } from "./router/pageSubscriber";import { statusReportRouter } from "./router/statusReport";+import { tinybirdRouter } from "./router/tinybird";import { userRouter } from "./router/user";import { workspaceRouter } from "./router/workspace";import { createTRPCRouter } from "./trpc";@@ -24,4 +25,5 @@ export const edgeRouter = createTRPCRouter({invitation: invitationRouter,incident: incidentRouter,pageSubscriber: pageSubscriberRouter,+ tinybird: tinybirdRouter,});diff --git a/packages/api/src/env.ts b/packages/api/src/env.tsindex 5c2603f89..5ae3f1088 100644--- a/packages/api/src/env.ts+++ b/packages/api/src/env.ts@@ -7,6 +7,7 @@ export const env = createEnv({PROJECT_ID_VERCEL: z.string(),TEAM_ID_VERCEL: z.string(),VERCEL_AUTH_BEARER_TOKEN: z.string(),+ TINY_BIRD_API_KEY: z.string(),},runtimeEnv: {@@ -14,6 +15,7 @@ export const env = createEnv({PROJECT_ID_VERCEL: process.env.PROJECT_ID_VERCEL,TEAM_ID_VERCEL: process.env.TEAM_ID_VERCEL,VERCEL_AUTH_BEARER_TOKEN: process.env.VERCEL_AUTH_BEARER_TOKEN,+ TINY_BIRD_API_KEY: process.env.TINY_BIRD_API_KEY,},skipValidation: process.env.NODE_ENV === "test",});diff --git a/packages/api/src/router/tinybird/index.ts b/packages/api/src/router/tinybird/index.tsnew file mode 100644index 000000000..a6801b34e--- /dev/null+++ b/packages/api/src/router/tinybird/index.ts@@ -0,0 +1,23 @@+import { z } from "zod";++import { OSTinybird } from "@openstatus/tinybird";++import { env } from "../../env";+import { createTRPCRouter, protectedProcedure } from "../../trpc";++const tb = new OSTinybird({ token: env.TINY_BIRD_API_KEY });++// WORK IN PROGRESS - we can create a tb router to call it via TRPC server and client++export const tinybirdRouter = createTRPCRouter({+ lastCronTimestamp: protectedProcedure.query(async (opts) => {+ const workspaceId = String(opts.ctx.workspace.id);+ return await tb.endpointLastCronTimestamp("workspace")({ workspaceId });+ }),++ monitorMetricsFromWorkspace: protectedProcedure+ .input(z.object({ period: z.string() }))+ .query(async (opts) => {+ const workspaceId = String(opts.ctx.workspace.id);+ }),+});diff --git a/packages/db/package.json b/packages/db/package.jsonindex 4f77c0634..edf710cc9 100644--- a/packages/db/package.json+++ b/packages/db/package.json@@ -8,7 +8,8 @@"push": "drizzle-kit push:sqlite","migrate": "bun src/migrate.mts","studio": "drizzle-kit studio",- "seed": "bun src/seed.mts"+ "seed": "bun src/seed.mts",+ "dev": "turso dev --db-file openstatus.db"},"dependencies": {"@libsql/client": "0.5.2",diff --git a/packages/tinybird/datasources/__ttl_14d_mv.datasource b/packages/tinybird/datasources/__ttl_14d_mv.datasourcenew file mode 100644index 000000000..22c76b61b--- /dev/null+++ b/packages/tinybird/datasources/__ttl_14d_mv.datasource@@ -0,0 +1,17 @@+# Data Source created from Pipe '__ttl_14d__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `latency` Int64,+ `monitorId` String,+ `region` LowCardinality(String),+ `statusCode` Nullable(Int16),+ `url` String,+ `workspaceId` String,+ `cronTimestamp` Int64++ENGINE "MergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "monitorId, time"+ENGINE_TTL "time + toIntervalDay(14)"diff --git a/packages/tinybird/datasources/__ttl_1d_mv.datasource b/packages/tinybird/datasources/__ttl_1d_mv.datasourcenew file mode 100644index 000000000..bbd41ff36--- /dev/null+++ b/packages/tinybird/datasources/__ttl_1d_mv.datasource@@ -0,0 +1,18 @@+# Data Source created from Pipe '__ttl_1d__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `latency` Int64,+ `monitorId` String,+ `region` LowCardinality(String),+ `statusCode` Nullable(Int16),+ `url` String,+ `workspaceId` String,+ `timestamp` Int64,+ `cronTimestamp` Int64++ENGINE "MergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "monitorId, time"+ENGINE_TTL "time + toIntervalDay(1)"diff --git a/packages/tinybird/datasources/__ttl_1h_mv.datasource b/packages/tinybird/datasources/__ttl_1h_mv.datasourcenew file mode 100644index 000000000..046855a6a--- /dev/null+++ b/packages/tinybird/datasources/__ttl_1h_mv.datasource@@ -0,0 +1,18 @@+# Data Source created from Pipe '__ttl_1h__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `latency` Int64,+ `monitorId` String,+ `region` LowCardinality(String),+ `statusCode` Nullable(Int16),+ `url` String,+ `workspaceId` String,+ `timestamp` Int64,+ `cronTimestamp` Int64++ENGINE "MergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "monitorId, time"+ENGINE_TTL "time + toIntervalHour(1)"diff --git a/packages/tinybird/datasources/__ttl_3d_mv.datasource b/packages/tinybird/datasources/__ttl_3d_mv.datasourcenew file mode 100644index 000000000..27fb0811b--- /dev/null+++ b/packages/tinybird/datasources/__ttl_3d_mv.datasource@@ -0,0 +1,17 @@+# Data Source created from Pipe '__ttl_3d__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `latency` Int64,+ `monitorId` String,+ `region` LowCardinality(String),+ `statusCode` Nullable(Int16),+ `url` String,+ `workspaceId` String,+ `cronTimestamp` Int64++ENGINE "MergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "monitorId, time"+ENGINE_TTL "time + toIntervalDay(3)"diff --git a/packages/tinybird/datasources/__ttl_45d_count_mv.datasource b/packages/tinybird/datasources/__ttl_45d_count_mv.datasourcenew file mode 100644index 000000000..bda0ce2cf--- /dev/null+++ b/packages/tinybird/datasources/__ttl_45d_count_mv.datasource@@ -0,0 +1,14 @@+# Data Source created from Pipe '__ttl_45d_count__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `monitorId` String,+ `url` String,+ `count` AggregateFunction(count),+ `ok` AggregateFunction(count, Nullable(UInt8))++ENGINE "AggregatingMergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "time, monitorId, url"+ENGINE_TTL "time + toIntervalDay(45)"diff --git a/packages/tinybird/datasources/__ttl_45d_mv.datasource b/packages/tinybird/datasources/__ttl_45d_mv.datasourcenew file mode 100644index 000000000..28a9f2dd7--- /dev/null+++ b/packages/tinybird/datasources/__ttl_45d_mv.datasource@@ -0,0 +1,17 @@+# Data Source created from Pipe '__ttl_45d__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `latency` Int64,+ `monitorId` String,+ `region` LowCardinality(String),+ `statusCode` Nullable(Int16),+ `url` String,+ `workspaceId` String,+ `cronTimestamp` Int64++ENGINE "MergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "monitorId, time"+ENGINE_TTL "time + toIntervalDay(45)"diff --git a/packages/tinybird/datasources/__ttl_7d_count_mv.datasource b/packages/tinybird/datasources/__ttl_7d_count_mv.datasourcenew file mode 100644index 000000000..3132069fc--- /dev/null+++ b/packages/tinybird/datasources/__ttl_7d_count_mv.datasource@@ -0,0 +1,14 @@+# Data Source created from Pipe '__ttl_7d_count__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `monitorId` String,+ `url` String,+ `count` AggregateFunction(count),+ `ok` AggregateFunction(count, Nullable(UInt8))++ENGINE "AggregatingMergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "time, monitorId, url"+ENGINE_TTL "time + toIntervalDay(7)"diff --git a/packages/tinybird/datasources/__ttl_7d_mv.datasource b/packages/tinybird/datasources/__ttl_7d_mv.datasourcenew file mode 100644index 000000000..0dd7f5bea--- /dev/null+++ b/packages/tinybird/datasources/__ttl_7d_mv.datasource@@ -0,0 +1,17 @@+# Data Source created from Pipe '__ttl_7d__v0'+VERSION 0++SCHEMA >+ `time` DateTime,+ `latency` Int64,+ `monitorId` String,+ `region` LowCardinality(String),+ `statusCode` Nullable(Int16),+ `url` String,+ `workspaceId` String,+ `cronTimestamp` Int64++ENGINE "MergeTree"+ENGINE_PARTITION_KEY "toYYYYMM(time)"+ENGINE_SORTING_KEY "monitorId, time"+ENGINE_TTL "time + toIntervalDay(7)"diff --git a/packages/tinybird/pipes/__ttl_14d.pipe b/packages/tinybird/pipes/__ttl_14d.pipenew file mode 100644index 000000000..dd942420c--- /dev/null+++ b/packages/tinybird/pipes/__ttl_14d.pipe@@ -0,0 +1,20 @@+VERSION 0++NODE __ttl_14d_0+SQL >++ SELECT+ toDateTime(fromUnixTimestamp64Milli(cronTimestamp)) AS time,+ latency,+ monitorId,+ region,+ statusCode,+ url,+ workspaceId,+ cronTimestamp+ FROM ping_response__v7++TYPE materialized+DATASOURCE __ttl_14d_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_14d_chart_get.pipe b/packages/tinybird/pipes/__ttl_14d_chart_get.pipenew file mode 100644index 000000000..325618689--- /dev/null+++ b/packages/tinybird/pipes/__ttl_14d_chart_get.pipe@@ -0,0 +1,28 @@+VERSION 0++TOKEN "__ttl_14d_chart_get_endpoint_read_2504" READ++NODE __ttl_14d_chart_get_0+SQL >++ %+ SELECT+ region,+ toStartOfInterval(+ toDateTime(cronTimestamp / 1000),+ INTERVAL {{ Int64(interval, 30) }} MINUTE+ ) as h,+ toUnixTimestamp64Milli(toDateTime64(h, 3)) as timestamp,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency+ FROM __ttl_14d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY h, region+ ORDER BY h DESC++diff --git a/packages/tinybird/pipes/__ttl_14d_metrics_get.pipe b/packages/tinybird/pipes/__ttl_14d_metrics_get.pipenew file mode 100644index 000000000..d31fdacb0--- /dev/null+++ b/packages/tinybird/pipes/__ttl_14d_metrics_get.pipe@@ -0,0 +1,40 @@+VERSION 0++TOKEN "__ttl_14d_metrics_get_endpoint_read_3564" READ++NODE __ttl_14d_metrics_get_0+SQL >++ %+ SELECT+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_14d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 14 DAY, 3)+ UNION ALL+ SELECT+ round(quantile(0.5)(latency)) AS p50Latency,+ round(quantile(0.75)(latency)) AS p75Latency,+ round(quantile(0.9)(latency)) AS p90Latency,+ round(quantile(0.95)(latency)) AS p95Latency,+ round(quantile(0.99)(latency)) AS p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ NULL as lastTimestamp -- no need to query the `lastTimestamp` as not relevant+ FROM __ttl_45d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 28 DAY, 3)+ AND time < toDateTime64(now() - INTERVAL 14 DAY, 3)++diff --git a/packages/tinybird/pipes/__ttl_14d_metrics_get_by_region.pipe b/packages/tinybird/pipes/__ttl_14d_metrics_get_by_region.pipenew file mode 100644index 000000000..9cc1dadf2--- /dev/null+++ b/packages/tinybird/pipes/__ttl_14d_metrics_get_by_region.pipe@@ -0,0 +1,25 @@+VERSION 0++TOKEN "__ttl_14d_metrics_get_by_region_endpoint_read_0048" READ++NODE __ttl_14d_metrics_get_by_region_0+SQL >++ %+ SELECT+ region,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_14d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY region++diff --git a/packages/tinybird/pipes/__ttl_1d.pipe b/packages/tinybird/pipes/__ttl_1d.pipenew file mode 100644index 000000000..45366f12f--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1d.pipe@@ -0,0 +1,21 @@+VERSION 0++NODE __ttl_1d_0+SQL >++ SELECT+ toDateTime(fromUnixTimestamp64Milli(cronTimestamp)) AS time,+ latency,+ monitorId,+ region,+ statusCode,+ url,+ workspaceId,+ timestamp,+ cronTimestamp+ FROM ping_response__v7++TYPE materialized+DATASOURCE __ttl_1d_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_1d_chart_get.pipe b/packages/tinybird/pipes/__ttl_1d_chart_get.pipenew file mode 100644index 000000000..fc631bddf--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1d_chart_get.pipe@@ -0,0 +1,28 @@+VERSION 0++TOKEN "__ttl_1d_chart_get_endpoint_read_4815" READ++NODE __ttl_1d_chart_get_0+SQL >++ %+ SELECT+ region,+ toStartOfInterval(+ toDateTime(cronTimestamp / 1000),+ INTERVAL {{ Int64(interval, 30) }} MINUTE+ ) as h,+ toUnixTimestamp64Milli(toDateTime64(h, 3)) as timestamp,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency+ FROM __ttl_1d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY h, region+ ORDER BY h DESC++diff --git a/packages/tinybird/pipes/__ttl_1d_list_get.pipe b/packages/tinybird/pipes/__ttl_1d_list_get.pipenew file mode 100644index 000000000..b72aff148--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1d_list_get.pipe@@ -0,0 +1,16 @@+VERSION 0++TOKEN "__ttl_1d_list_get__v0_endpoint_read_1695" READ++NODE __ttl_1d_list_get__v0_0+SQL >++ %+ SELECT latency, monitorId, region, statusCode, timestamp, url, workspaceId, cronTimestamp+ FROM __ttl_1d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ ORDER BY cronTimestamp DESC++diff --git a/packages/tinybird/pipes/__ttl_1d_metrics_get.pipe b/packages/tinybird/pipes/__ttl_1d_metrics_get.pipenew file mode 100644index 000000000..a3842bc74--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1d_metrics_get.pipe@@ -0,0 +1,40 @@+VERSION 0++TOKEN "__ttl_1d_metrics_get_endpoint_read_1167" READ++NODE __ttl_1d_metrics_get_0+SQL >++ %+ SELECT+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_1d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 1 DAY, 3)+ UNION ALL+ SELECT+ round(quantile(0.5)(latency)) AS p50Latency,+ round(quantile(0.75)(latency)) AS p75Latency,+ round(quantile(0.9)(latency)) AS p90Latency,+ round(quantile(0.95)(latency)) AS p95Latency,+ round(quantile(0.99)(latency)) AS p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ NULL as lastTimestamp -- no need to query the `lastTimestamp` as not relevant+ FROM __ttl_3d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 2 DAY, 3)+ AND time < toDateTime64(now() - INTERVAL 1 DAY, 3)++diff --git a/packages/tinybird/pipes/__ttl_1d_metrics_get_by_region.pipe b/packages/tinybird/pipes/__ttl_1d_metrics_get_by_region.pipenew file mode 100644index 000000000..3c1f16f62--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1d_metrics_get_by_region.pipe@@ -0,0 +1,24 @@+VERSION 0++TOKEN "__ttl_1d_metrics_get_by_region_endpoint_read_3463" READ++NODE __ttl_1d_metrics_get_by_region_0+SQL >++ %+ SELECT+ region,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok+ FROM __ttl_1d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY region++diff --git a/packages/tinybird/pipes/__ttl_1h.pipe b/packages/tinybird/pipes/__ttl_1h.pipenew file mode 100644index 000000000..d8b40298e--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h.pipe@@ -0,0 +1,21 @@+VERSION 0++NODE __ttl_1h_0+SQL >++ SELECT+ toDateTime(fromUnixTimestamp64Milli(cronTimestamp)) AS time,+ latency,+ monitorId,+ region,+ statusCode,+ url,+ workspaceId,+ timestamp,+ cronTimestamp+ FROM ping_response__v7++TYPE materialized+DATASOURCE __ttl_1h_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_1h_chart_get.pipe b/packages/tinybird/pipes/__ttl_1h_chart_get.pipenew file mode 100644index 000000000..e40c9c4f6--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h_chart_get.pipe@@ -0,0 +1,28 @@+VERSION 0++TOKEN "__ttl_1h_chart_get__v0_endpoint_read_3603" READ++NODE __ttl_1h_chart_get_0+SQL >++ %+ SELECT+ region,+ toStartOfInterval(+ toDateTime(cronTimestamp / 1000),+ INTERVAL {{ Int64(interval, 30) }} MINUTE+ ) as h,+ toUnixTimestamp64Milli(toDateTime64(h, 3)) as timestamp,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency+ FROM __ttl_1h_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY h, region+ ORDER BY h DESC++diff --git a/packages/tinybird/pipes/__ttl_1h_last_timestamp_monitor_get.pipe b/packages/tinybird/pipes/__ttl_1h_last_timestamp_monitor_get.pipenew file mode 100644index 000000000..4a20095d3--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h_last_timestamp_monitor_get.pipe@@ -0,0 +1,15 @@+VERSION 0++TOKEN "__ttl_1h_last_timestamp_monitor_get__v0_endpoint_read_5766" READ++NODE __ttl_1h_last_timestamp_monitor_get__v0_0+SQL >++ %+ SELECT max(cronTimestamp) as cronTimestamp+ FROM __ttl_1h_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}++diff --git a/packages/tinybird/pipes/__ttl_1h_last_timestamp_workspace_get.pipe b/packages/tinybird/pipes/__ttl_1h_last_timestamp_workspace_get.pipenew file mode 100644index 000000000..c27ce7111--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h_last_timestamp_workspace_get.pipe@@ -0,0 +1,13 @@+VERSION 0++TOKEN "__ttl_1h_last_timestamp_workspace_get__v0_endpoint_read_5322" READ++NODE __ttl_1h_last_timestamp_workspace_get__v0_0+SQL >++ %+ SELECT max(cronTimestamp) as cronTimestamp+ FROM __ttl_1h_mv__v0+ WHERE workspaceId = {{ String(workspaceId, '1') }}++diff --git a/packages/tinybird/pipes/__ttl_1h_list_get.pipe b/packages/tinybird/pipes/__ttl_1h_list_get.pipenew file mode 100644index 000000000..15f110233--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h_list_get.pipe@@ -0,0 +1,17 @@+VERSION 0++TOKEN "__ttl_1h_list_get__v0_endpoint_read_0371" READ++NODE __ttl_1h_list_get__v0_0+SQL >++ %+ -- FIXME: `timestamp` is missing on 1h, 3d, 7d, 45d mv!+ SELECT latency, monitorId, region, statusCode, url, workspaceId, cronTimestamp, timestamp+ FROM __ttl_1h_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ ORDER BY cronTimestamp DESC++diff --git a/packages/tinybird/pipes/__ttl_1h_metrics_get.pipe b/packages/tinybird/pipes/__ttl_1h_metrics_get.pipenew file mode 100644index 000000000..9403bde73--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h_metrics_get.pipe@@ -0,0 +1,40 @@+VERSION 0++TOKEN "__ttl_1h_metrics_get__v0_endpoint_read_0457" READ++NODE __ttl_1h_metrics_get_0+SQL >++ %+ SELECT+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_1h_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 1 HOUR, 3)+ UNION ALL+ SELECT+ round(quantile(0.5)(latency)) AS p50Latency,+ round(quantile(0.75)(latency)) AS p75Latency,+ round(quantile(0.9)(latency)) AS p90Latency,+ round(quantile(0.95)(latency)) AS p95Latency,+ round(quantile(0.99)(latency)) AS p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ NULL as lastTimestamp -- no need to query the `lastTimestamp` as not relevant+ FROM __ttl_1d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 2 HOUR, 3)+ AND time < toDateTime64(now() - INTERVAL 1 HOUR, 3)++diff --git a/packages/tinybird/pipes/__ttl_1h_metrics_get_by_region.pipe b/packages/tinybird/pipes/__ttl_1h_metrics_get_by_region.pipenew file mode 100644index 000000000..f41865eb8--- /dev/null+++ b/packages/tinybird/pipes/__ttl_1h_metrics_get_by_region.pipe@@ -0,0 +1,24 @@+VERSION 0++TOKEN "__ttl_1h_metrics_get_by_region__v0_endpoint_read_0839" READ++NODE __ttl_1h_metrics_get_by_region_0+SQL >++ %+ SELECT+ region,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok+ FROM __ttl_1h_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY region++diff --git a/packages/tinybird/pipes/__ttl_3d.pipe b/packages/tinybird/pipes/__ttl_3d.pipenew file mode 100644index 000000000..75d739963--- /dev/null+++ b/packages/tinybird/pipes/__ttl_3d.pipe@@ -0,0 +1,20 @@+VERSION 0++NODE __ttl_3d_0+SQL >++ SELECT+ toDateTime(fromUnixTimestamp64Milli(cronTimestamp)) AS time,+ latency,+ monitorId,+ region,+ statusCode,+ url,+ workspaceId,+ cronTimestamp+ FROM ping_response__v7++TYPE materialized+DATASOURCE __ttl_3d_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_3d_chart_get.pipe b/packages/tinybird/pipes/__ttl_3d_chart_get.pipenew file mode 100644index 000000000..24589a86c--- /dev/null+++ b/packages/tinybird/pipes/__ttl_3d_chart_get.pipe@@ -0,0 +1,28 @@+VERSION 0++TOKEN "__ttl_3d_chart_get_endpoint_read_5551" READ++NODE __ttl_3d_chart_get_0+SQL >++ %+ SELECT+ region,+ toStartOfInterval(+ toDateTime(cronTimestamp / 1000),+ INTERVAL {{ Int64(interval, 30) }} MINUTE+ ) as h,+ toUnixTimestamp64Milli(toDateTime64(h, 3)) as timestamp,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency+ FROM __ttl_3d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY h, region+ ORDER BY h DESC++diff --git a/packages/tinybird/pipes/__ttl_3d_metrics_get.pipe b/packages/tinybird/pipes/__ttl_3d_metrics_get.pipenew file mode 100644index 000000000..1ed3d3df5--- /dev/null+++ b/packages/tinybird/pipes/__ttl_3d_metrics_get.pipe@@ -0,0 +1,40 @@+VERSION 0++TOKEN "__ttl_3d_metrics_get_endpoint_read_5801" READ++NODE __ttl_3d_metrics_get_0+SQL >++ %+ SELECT+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_3d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 3 DAY, 3)+ UNION ALL+ SELECT+ round(quantile(0.5)(latency)) AS p50Latency,+ round(quantile(0.75)(latency)) AS p75Latency,+ round(quantile(0.9)(latency)) AS p90Latency,+ round(quantile(0.95)(latency)) AS p95Latency,+ round(quantile(0.99)(latency)) AS p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ NULL as lastTimestamp -- no need to query the `lastTimestamp` as not relevant+ FROM __ttl_7d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 6 DAY, 3)+ AND time < toDateTime64(now() - INTERVAL 3 DAY, 3)++diff --git a/packages/tinybird/pipes/__ttl_3d_metrics_get_by_region.pipe b/packages/tinybird/pipes/__ttl_3d_metrics_get_by_region.pipenew file mode 100644index 000000000..938dd4f62--- /dev/null+++ b/packages/tinybird/pipes/__ttl_3d_metrics_get_by_region.pipe@@ -0,0 +1,25 @@+VERSION 0++TOKEN "__ttl_3d_metrics_get_by_region__v0_endpoint_read_3349" READ++NODE __ttl_3d_metrics_get_by_region_0+SQL >++ %+ SELECT+ region,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_3d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY region++diff --git a/packages/tinybird/pipes/__ttl_45d.pipe b/packages/tinybird/pipes/__ttl_45d.pipenew file mode 100644index 000000000..779a9869e--- /dev/null+++ b/packages/tinybird/pipes/__ttl_45d.pipe@@ -0,0 +1,20 @@+VERSION 0++NODE __ttl_45d_0+SQL >++ SELECT+ toStartOfDay(fromUnixTimestamp64Milli(cronTimestamp)) AS time,+ latency,+ monitorId,+ region,+ statusCode,+ url,+ workspaceId,+ cronTimestamp+ FROM ping_response__v7++TYPE materialized+DATASOURCE __ttl_45d_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_45d_count.pipe b/packages/tinybird/pipes/__ttl_45d_count.pipenew file mode 100644index 000000000..2f921cf2e--- /dev/null+++ b/packages/tinybird/pipes/__ttl_45d_count.pipe@@ -0,0 +1,25 @@+VERSION 0++DESCRIPTION >+ TODO: descripe what it is for!+++NODE __ttl_45d_count_0+SQL >++ SELECT+ time,+ monitorId,+ url,+ countState() AS count,+ countState(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok+ FROM __ttl_45d_mv__v0+ GROUP BY+ time,+ monitorId,+ url++TYPE materialized+DATASOURCE __ttl_45d_count_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_45d_count_get.pipe b/packages/tinybird/pipes/__ttl_45d_count_get.pipenew file mode 100644index 000000000..7aa520164--- /dev/null+++ b/packages/tinybird/pipes/__ttl_45d_count_get.pipe@@ -0,0 +1,23 @@+VERSION 0++TOKEN "__ttl_45d_count_get__v0_endpoint_read_2389" READ++NODE __ttl_45d_count_get_0+SQL >++ %+ SELECT time as day, countMerge(count) as count, countMerge(ok) as ok+ FROM __ttl_45d_count_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '4') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY day+ ORDER BY day DESC+ WITH FILL+ FROM+ toStartOfDay(now())+ TO toStartOfDay(+ date_sub(DAY, 45, now())+ ) STEP INTERVAL -1 DAY++diff --git a/packages/tinybird/pipes/__ttl_7d.pipe b/packages/tinybird/pipes/__ttl_7d.pipenew file mode 100644index 000000000..13e4917f9--- /dev/null+++ b/packages/tinybird/pipes/__ttl_7d.pipe@@ -0,0 +1,20 @@+VERSION 0++NODE __ttl_7d_0+SQL >++ SELECT+ toDateTime(fromUnixTimestamp64Milli(cronTimestamp)) AS time,+ latency,+ monitorId,+ region,+ statusCode,+ url,+ workspaceId,+ cronTimestamp+ FROM ping_response__v7++TYPE materialized+DATASOURCE __ttl_7d_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_7d_chart_get.pipe b/packages/tinybird/pipes/__ttl_7d_chart_get.pipenew file mode 100644index 000000000..3f6d99af1--- /dev/null+++ b/packages/tinybird/pipes/__ttl_7d_chart_get.pipe@@ -0,0 +1,28 @@+VERSION 0++TOKEN "__ttl_7d_chart_get_endpoint_read_8119" READ++NODE __ttl_7d_chart_get_0+SQL >++ %+ SELECT+ region,+ toStartOfInterval(+ toDateTime(cronTimestamp / 1000),+ INTERVAL {{ Int64(interval, 30) }} MINUTE+ ) as h,+ toUnixTimestamp64Milli(toDateTime64(h, 3)) as timestamp,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency+ FROM __ttl_7d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY h, region+ ORDER BY h DESC++diff --git a/packages/tinybird/pipes/__ttl_7d_count.pipe b/packages/tinybird/pipes/__ttl_7d_count.pipenew file mode 100644index 000000000..c1f76a6c8--- /dev/null+++ b/packages/tinybird/pipes/__ttl_7d_count.pipe@@ -0,0 +1,25 @@+VERSION 0++DESCRIPTION >+ TODO: descripe what it is for!+++NODE __ttl_7d_count_0+SQL >++ SELECT+ time,+ monitorId,+ url,+ countState() AS count,+ countState(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok+ FROM __ttl_45d_mv__v0+ GROUP BY+ time,+ monitorId,+ url++TYPE materialized+DATASOURCE __ttl_7d_count_mv__v0++diff --git a/packages/tinybird/pipes/__ttl_7d_count_get.pipe b/packages/tinybird/pipes/__ttl_7d_count_get.pipenew file mode 100644index 000000000..62b206b9e--- /dev/null+++ b/packages/tinybird/pipes/__ttl_7d_count_get.pipe@@ -0,0 +1,21 @@+VERSION 0++NODE __ttl_7d_count_get_0+SQL >++ %+ SELECT time as day, countMerge(count) as count, countMerge(ok) as ok+ FROM __ttl_7d_count_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '4') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY day+ ORDER BY day DESC+ WITH FILL+ FROM+ toStartOfDay(now())+ TO toStartOfDay(+ date_sub(DAY, 7, now())+ ) STEP INTERVAL -1 DAY++diff --git a/packages/tinybird/pipes/__ttl_7d_metrics_get.pipe b/packages/tinybird/pipes/__ttl_7d_metrics_get.pipenew file mode 100644index 000000000..2e54597b1--- /dev/null+++ b/packages/tinybird/pipes/__ttl_7d_metrics_get.pipe@@ -0,0 +1,38 @@+VERSION 0++NODE __ttl_7d_metrics_get_0+SQL >++ %+ SELECT+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_7d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 7 DAY, 3)+ UNION ALL+ SELECT+ round(quantile(0.5)(latency)) AS p50Latency,+ round(quantile(0.75)(latency)) AS p75Latency,+ round(quantile(0.9)(latency)) AS p90Latency,+ round(quantile(0.95)(latency)) AS p95Latency,+ round(quantile(0.99)(latency)) AS p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ NULL as lastTimestamp -- no need to query the `lastTimestamp` as not relevant+ FROM __ttl_14d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ AND time >= toDateTime64(now() - INTERVAL 14 DAY, 3)+ AND time < toDateTime64(now() - INTERVAL 7 DAY, 3)++diff --git a/packages/tinybird/pipes/__ttl_7d_metrics_get_by_region.pipe b/packages/tinybird/pipes/__ttl_7d_metrics_get_by_region.pipenew file mode 100644index 000000000..429e1216c--- /dev/null+++ b/packages/tinybird/pipes/__ttl_7d_metrics_get_by_region.pipe@@ -0,0 +1,25 @@+VERSION 0++TOKEN "__ttl_7d_metrics_get_by_region__v0_endpoint_read_4172" READ++NODE __ttl_7d_metrics_get_by_region_0+SQL >++ %+ SELECT+ region,+ round(quantile(0.5)(latency)) as p50Latency,+ round(quantile(0.75)(latency)) as p75Latency,+ round(quantile(0.9)(latency)) as p90Latency,+ round(quantile(0.95)(latency)) as p95Latency,+ round(quantile(0.99)(latency)) as p99Latency,+ count() as count,+ count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok,+ max(cronTimestamp) AS lastTimestamp+ FROM __ttl_7d_mv__v0+ WHERE+ monitorId = {{ String(monitorId, '1') }}+ {% if defined(url) %} AND url = {{ String(url) }} {% end %}+ GROUP BY region++diff --git a/packages/tinybird/src/client.ts b/packages/tinybird/src/client.tsindex 99255bc4a..5e83b9577 100644--- a/packages/tinybird/src/client.ts+++ b/packages/tinybird/src/client.ts@@ -5,19 +5,11 @@ import {tbBuildMonitorList,tbBuildPublicStatus,tbBuildResponseDetails,- tbBuildResponseGraph,- tbBuildResponseList,- tbBuildResponseTimeMetrics,- tbBuildResponseTimeMetricsByRegion,tbIngestPingResponse,tbParameterHomeStats,tbParameterMonitorList,tbParameterPublicStatus,tbParameterResponseDetails,- tbParameterResponseGraph,- tbParameterResponseList,- tbParameterResponseTimeMetrics,- tbParameterResponseTimeMetricsByRegion,} from "./validation";// REMINDER:@@ -28,20 +20,6 @@ export const publishPingResponse = tb.buildIngestEndpoint({event: tbIngestPingResponse,});-// TODO: add longer cache for NODE_ENV === "development"--export function getResponseList(tb: Tinybird) {- return tb.buildPipe({- pipe: "response_list__v2",- parameters: tbParameterResponseList,- data: tbBuildResponseList,- opts: {- // cache: "default",- revalidate: 600, // 10 min cache- },- });-}-export function getResponseDetails(tb: Tinybird) {return tb.buildPipe({pipe: "response_details__v0",@@ -53,17 +31,6 @@ export function getResponseDetails(tb: Tinybird) {});}-export function getResponseGraph(tb: Tinybird) {- return tb.buildPipe({- pipe: "response_graph__v0",- parameters: tbParameterResponseGraph,- data: tbBuildResponseGraph,- opts: {- revalidate: 60, // 1 min cache- },- });-}-export function getMonitorList(tb: Tinybird) {return tb.buildPipe({pipe: "status_timezone__v1",@@ -113,25 +80,3 @@ export function getPublicStatus(tb: Tinybird) {data: tbBuildPublicStatus,});}--export function getResponseTimeMetrics(tb: Tinybird) {- return tb.buildPipe({- pipe: "response_time_metrics__v0",- parameters: tbParameterResponseTimeMetrics,- data: tbBuildResponseTimeMetrics,- opts: {- revalidate: 30, // 30 sec cache - mostly for timestamp metric- },- });-}--export function getResponseTimeMetricsByRegion(tb: Tinybird) {- return tb.buildPipe({- pipe: "response_time_metrics_by_region__v0",- parameters: tbParameterResponseTimeMetricsByRegion,- data: tbBuildResponseTimeMetricsByRegion,- opts: {- revalidate: 30, // 30 sec cache - mostly for timestamp metric- },- });-}diff --git a/packages/tinybird/src/index.ts b/packages/tinybird/src/index.tsindex bbc762536..d00db5067 100644--- a/packages/tinybird/src/index.ts+++ b/packages/tinybird/src/index.ts@@ -2,3 +2,6 @@ export * from "./client";export * from "./validation";export * from "./audit-log";export * from "@chronark/zod-bird";++// OSTinybird: for specific pipes+export * from "./os-client";diff --git a/packages/tinybird/src/os-client.ts b/packages/tinybird/src/os-client.tsnew file mode 100644index 000000000..fbb8cf4c5--- /dev/null+++ b/packages/tinybird/src/os-client.ts@@ -0,0 +1,260 @@+import { Tinybird } from "@chronark/zod-bird";+import { z } from "zod";++import { flyRegions } from "@openstatus/utils";++const MIN_CACHE = 30; // 30s+const DEFAULT_CACHE = 120; // 2min++export const latencySchema = z.object({+ p50Latency: z.number().int().nullable(),+ p75Latency: z.number().int().nullable(),+ p90Latency: z.number().int().nullable(),+ p95Latency: z.number().int().nullable(),+ p99Latency: z.number().int().nullable(),+});++export const timingSchema = 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(),+});++export class OSTinybird {+ private tb: Tinybird;++ // FIXME: use Tinybird instead with super(args) maybe+ constructor(private args: { token: string; baseUrl?: string | undefined }) {+ this.tb = new Tinybird(args);+ }++ endpointChart(period: "1h" | "1d" | "3d" | "7d" | "14d") {+ const parameters = z.object({+ interval: z.number().int().optional(),+ monitorId: z.string(),+ url: z.string().optional(),+ });++ return async (props: z.infer<typeof parameters>) => {+ try {+ const res = await this.tb.buildPipe({+ pipe: `__ttl_${period}_chart_get__v0`,+ parameters,+ data: z+ .object({+ region: z.enum(flyRegions),+ timestamp: z.number().int(),+ })+ .merge(latencySchema),+ opts: {+ revalidate: DEFAULT_CACHE,+ },+ })(props);+ return res.data;+ } catch (e) {+ console.error(e);+ }+ };+ }++ endpointMetrics(period: "1h" | "1d" | "3d" | "7d" | "14d") {+ const parameters = z.object({+ monitorId: z.string(),+ url: z.string().optional(),+ });++ return async (props: z.infer<typeof parameters>) => {+ try {+ const res = await this.tb.buildPipe({+ pipe: `__ttl_${period}_metrics_get__v0`,+ parameters,+ data: z+ .object({+ region: z.enum(flyRegions).default("ams"), // FIXME: default+ count: z.number().default(0),+ ok: z.number().default(0),+ lastTimestamp: z.number().int().nullable(),+ })+ .merge(latencySchema),+ opts: {+ revalidate: DEFAULT_CACHE,+ },+ })(props);+ return res.data;+ } catch (e) {+ console.error(e);+ }+ };+ }++ endpointMetricsByRegion(period: "1h" | "1d" | "3d" | "7d" | "14d") {+ const parameters = z.object({+ monitorId: z.string(),+ url: z.string().optional(),+ });++ return async (props: z.infer<typeof parameters>) => {+ try {+ const res = await this.tb.buildPipe({+ pipe: `__ttl_${period}_metrics_get_by_region__v0`,+ parameters,+ data: z+ .object({+ region: z.enum(flyRegions),+ count: z.number().default(0),+ ok: z.number().default(0),+ lastTimestamp: z.number().int().optional(), // FIXME: optional+ })+ .merge(latencySchema),+ opts: {+ revalidate: DEFAULT_CACHE,+ },+ })(props);+ return res.data;+ } catch (e) {+ console.error(e);+ }+ };+ }++ endpointStatusPeriod(period: "7d" | "45d") {+ const parameters = z.object({+ monitorId: z.string(),+ url: z.string().optional(),+ });++ return async (props: z.infer<typeof parameters>) => {+ try {+ const res = await this.tb.buildPipe({+ pipe: `__ttl_${period}_count_get__v0`,+ parameters,+ data: z.object({+ day: z.string().transform((val) => {+ // That's a hack because clickhouse return the date in UTC but in shitty format (2021-09-01 00:00:00)+ return new Date(`${val} GMT`).toISOString();+ }),+ count: z.number().default(0),+ ok: z.number().default(0),+ }),+ opts: {+ revalidate: DEFAULT_CACHE,+ },+ })(props);+ return res.data;+ } catch (e) {+ console.error(e);+ }+ };+ }++ // TBH: not sure if we need more than 1d for that, better allow the user+ // to click on a specific region and time+ endpointList(period: "1h" | "1d") {+ const parameters = z.object({+ monitorId: z.string(),+ url: z.string().optional(),+ });++ return async (props: z.infer<typeof parameters>) => {+ try {+ const res = await this.tb.buildPipe({+ pipe: `__ttl_${period}_list_get__v0`,+ parameters,+ data: z.object({+ latency: z.number().int(), // in ms+ monitorId: z.string(),+ region: z.enum(flyRegions),+ statusCode: z.number().int().nullable().default(null),+ timestamp: z.number().int(),+ url: z.string().url(),+ workspaceId: z.string(),+ cronTimestamp: z.number().int().nullable().default(Date.now()),+ }),+ opts: {+ revalidate: DEFAULT_CACHE,+ },+ })(props);+ return res.data;+ } catch (e) {+ console.error(e);+ }+ };+ }++ // FEATURE: include a simple Widget for the user to refresh the page or display on the top of the page+ // type: "workspace" | "monitor"+ endpointLastCronTimestamp(type: "workspace") {+ const parameters = z.object({ workspaceId: z.string() });++ return async (props: z.infer<typeof parameters>) => {+ try {+ const res = await this.tb.buildPipe({+ pipe: `__ttl_1h_last_timestamp_${type}_get__v0`,+ parameters,+ data: z.object({ cronTimestamp: z.number().int() }),+ opts: {+ revalidate: MIN_CACHE,+ },+ })(props);+ return res.data;+ } catch (e) {+ console.error(e);+ }+ };+ }++ endpointResponseDetails() {+ return this.tb.buildPipe({+ pipe: "response_details__v0", // TODO: make it also a bit dynamic to avoid query through too much data+ parameters: z.object({+ monitorId: z.string().default(""),+ url: z.string().url().optional(),+ region: z.enum(flyRegions).optional(),+ cronTimestamp: z.number().int().optional(),+ }),+ data: z.object({+ monitorId: z.string().default(""),+ url: z.string().url().optional(),+ region: z.enum(flyRegions).optional(),+ cronTimestamp: z.number().int().optional(),+ message: z.string().nullable().optional(),+ headers: z+ .string()+ .nullable()+ .optional()+ .transform((val) => {+ if (!val) return null;+ const value = z+ .record(z.string(), z.string())+ .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 = timingSchema.safeParse(JSON.parse(val));+ if (value.success) return value.data;+ return null;+ }),+ }),+ opts: {+ revalidate: DEFAULT_CACHE,+ },+ });+ }+}++/**+ * TODO: if it would be possible to...+ */diff --git a/packages/tinybird/src/validation.ts b/packages/tinybird/src/validation.tsindex 879def3e2..5557bbd05 100644--- a/packages/tinybird/src/validation.ts+++ b/packages/tinybird/src/validation.ts@@ -113,7 +113,7 @@ export const tbBuildResponseDetails = tbBuildResponseList.extend({});export const latencyMetrics = z.object({- avgLatency: z.number().int().nullable(),+ p50Latency: z.number().int().nullable(),p75Latency: z.number().int().nullable(),p90Latency: z.number().int().nullable(),p95Latency: z.number().int().nullable(),@@ -213,7 +213,6 @@ export const tbBuildResponseTimeMetrics = zcount: z.number().int(),ok: z.number().int(),lastTimestamp: z.number().int().nullable().optional(),- time: z.number().int(), // only to sort the data - cannot be done on server because of UNION ALL}).merge(latencyMetrics);diff --git a/pnpm-lock.yaml b/pnpm-lock.yamlindex 595e49f83..f82eb45de 100644--- a/pnpm-lock.yaml+++ b/pnpm-lock.yaml@@ -391,6 +391,9 @@ importers:'@openstatus/plans':specifier: workspace:*version: link:../plans+ '@openstatus/tinybird':+ specifier: workspace:*+ version: link:../tinybird'@t3-oss/env-core':specifier: 0.7.0version: 0.7.0([email protected])([email protected])@@ -1389,6 +1392,10 @@ packages:peerDependencies:'@effect-ts/otel-node': '*'peerDependenciesMeta:+ '@effect-ts/core':+ optional: true+ '@effect-ts/otel':+ optional: true'@effect-ts/otel-node':optional: truedependencies: