Openstatus www.openstatus.dev

Fix tb (#646)

* 🐛 fix tb

* 🐛 fix tb

* fix(tb): add url params to pipes

---------

Co-authored-by: mxkaske <maximilian@kaske.org>

authored by

Thibault Le Ouay
mxkaske
and committed by
GitHub
508b564a 92e77d1f

+41 -7
+1 -1
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/date-picker-preset.tsx
··· 23 23 24 24 function onSelect(value: Period) { 25 25 const searchParams = updateSearchParams({ period: value }); 26 - router.replace(`${pathname}?${searchParams}`); 26 + router.replace(`${pathname}?${searchParams}`, { scroll: false }); 27 27 } 28 28 29 29 return (
+1 -1
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/interval-preset.tsx
··· 35 35 36 36 function onSelect(value: Interval) { 37 37 const searchParams = updateSearchParams({ interval: value }); 38 - router.replace(`${pathname}?${searchParams}`); 38 + router.replace(`${pathname}?${searchParams}`, { scroll: false }); 39 39 } 40 40 41 41 return (
+1 -1
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/quantile-preset.tsx
··· 38 38 39 39 function onSelect(value: Quantile) { 40 40 const searchParams = updateSearchParams({ quantile: value }); 41 - router.replace(`${pathname}?${searchParams}`); 41 + router.replace(`${pathname}?${searchParams}`, { scroll: false }); 42 42 } 43 43 44 44 return (
+1 -1
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/_components/region-preset.tsx
··· 35 35 function onOpenChange(open: boolean) { 36 36 if (!open) { 37 37 const searchParams = updateSearchParams({ regions: selected.join(",") }); 38 - router.replace(`${pathname}?${searchParams}`); 38 + router.replace(`${pathname}?${searchParams}`, { scroll: false }); 39 39 } 40 40 } 41 41
+1
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/data/page.tsx
··· 38 38 39 39 const data = await getResponseListData({ 40 40 monitorId: id, 41 + url: monitor.url, 41 42 fromDate: date.from.getTime(), 42 43 toDate: date.to.getTime(), 43 44 });
+3
apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
··· 83 83 84 84 const data = await getResponseGraphData({ 85 85 monitorId: id, 86 + url: monitor.url, 86 87 ...search.data, 87 88 /** 88 89 * ··· 94 95 95 96 const metrics = await getResponseTimeMetricsData({ 96 97 monitorId: id, 98 + url: monitor.url, 97 99 interval: periodicityHours, 98 100 }); 99 101 100 102 const metricsByRegion = await getResponseTimeMetricsByRegionData({ 101 103 monitorId: id, 104 + url: monitor.url, 102 105 interval: periodicityHours, 103 106 }); 104 107
+10 -2
apps/web/src/app/monitor/[id]/page.tsx
··· 5 5 import { columns } from "@/components/data-table/columns"; 6 6 import { DataTable } from "@/components/data-table/data-table"; 7 7 import { getResponseListData } from "@/lib/tb"; 8 + import { api } from "@/trpc/server"; 8 9 9 10 // 10 11 ··· 27 28 searchParams: { [key: string]: string | string[] | undefined }; 28 29 }) { 29 30 const search = searchParamsSchema.safeParse(searchParams); 31 + const monitor = await api.monitor.getMonitorById.query({ 32 + id: Number(params.id), 33 + }); 30 34 const data = search.success 31 35 ? // TODO: lets hard-code our `monitorId` here 32 - await getResponseListData({ monitorId: params.id, ...search.data }) 33 - : await getResponseListData({ monitorId: params.id }); 36 + await getResponseListData({ 37 + monitorId: params.id, 38 + url: monitor.url, 39 + ...search.data, 40 + }) 41 + : await getResponseListData({ monitorId: params.id, url: monitor.url }); 34 42 if (!data || !search.success) return <div>Something went wrong</div>; 35 43 return <DataTable columns={columns} data={data} />; 36 44 }
+1
apps/web/src/components/status-page/monitor.tsx
··· 20 20 const data = await getMonitorListData({ 21 21 monitorId: String(monitor.id), 22 22 timezone: gmt, 23 + url: monitor.url, 23 24 }); 24 25 25 26 // TODO: we could handle the `statusReports` here instead of passing it down to the tracker
+1
apps/web/src/components/status-page/status-check.tsx
··· 43 43 monitors.map((monitor) => { 44 44 return getResponseListData({ 45 45 monitorId: String(monitor.id), 46 + url: monitor.url, 46 47 limit: 10, 47 48 }); 48 49 }),
+5 -1
apps/web/src/lib/tb.ts
··· 61 61 props: Pick<MonitorListParams, "timezone">, 62 62 ) { 63 63 try { 64 - const res = await getHomeMonitorList(tb)({ monitorId: "1", ...props }); 64 + const res = await getHomeMonitorList(tb)({ 65 + monitorId: "1", 66 + ...props, 67 + url: "https://www.openstatus.dev", 68 + }); 65 69 return res.data; 66 70 } catch (e) { 67 71 console.error(e);
+1
packages/tinybird/pipes/public_status.pipe
··· 14 14 FROM ping_response_v5 15 15 WHERE 16 16 monitorId = {{ String(monitorId, '1') }} 17 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 17 18 AND cronTimestamp 18 19 >= toUnixTimestamp64Milli(toDateTime64(now() - INTERVAL 3 HOUR, 3)) 19 20 GROUP BY cronTimestamp, monitorId
+1
packages/tinybird/pipes/response_details.pipe
··· 8 8 FROM ping_response__v7 9 9 WHERE 10 10 monitorId = {{ String(monitorId, '1') }} 11 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 11 12 AND cronTimestamp = {{ Int64(cronTimestamp, 1706467215188) }} 12 13 AND region = {{ String(region, 'ams') }} 13 14
+1
packages/tinybird/pipes/response_graph.pipe
··· 19 19 FROM ping_response__v7 20 20 WHERE 21 21 monitorId = {{ String(monitorId, '1') }} 22 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 22 23 {% if defined(fromDate) %} AND timestamp >= {{ Int64(fromDate) }} {% end %} 23 24 {% if defined(toDate) %} AND timestamp <= {{ Int64(toDate) }} {% end %} 24 25 GROUP BY h, region
+1
packages/tinybird/pipes/response_list.pipe
··· 7 7 SELECT latency, monitorId, region, statusCode, timestamp, url, workspaceId, cronTimestamp, message 8 8 FROM ping_response__v7 9 9 WHERE monitorId = {{ String(monitorId, 'openstatusPing') }} 10 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 10 11 {% if defined(region) %} 11 12 AND region = {{ String(region) }} 12 13 {% end %}
+3
packages/tinybird/pipes/response_time_metrics.pipe
··· 18 18 FROM materialized_view_ping_response_45d_ttl__v7 19 19 WHERE 20 20 monitorId = {{ String(monitorId, '1') }} 21 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 21 22 AND timestamp 22 23 >= toUnixTimestamp64Milli(toDateTime64(now() - INTERVAL {{ Int32(interval, 24)}} HOUR, 3)) 23 24 ) as lastTimestamp, ··· 26 27 FROM materialized_view_ping_response_45d_ttl__v7 27 28 WHERE 28 29 monitorId = {{ String(monitorId, '1') }} 30 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 29 31 AND timestamp 30 32 >= toUnixTimestamp64Milli(toDateTime64(now() - INTERVAL {{ Int32(interval, 24)}} HOUR, 3)) 31 33 UNION ALL ··· 43 45 FROM materialized_view_ping_response_45d_ttl__v7 44 46 WHERE 45 47 monitorId = {{ String(monitorId, '1') }} 48 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 46 49 AND timestamp 47 50 >= toUnixTimestamp64Milli(toDateTime64(now() - INTERVAL {{ Int32(interval, 24)}}*2 HOUR, 3)) 48 51 AND timestamp
+1
packages/tinybird/pipes/response_time_metrics_by_region.pipe
··· 16 16 FROM materialized_view_ping_response_45d_ttl__v7 17 17 WHERE 18 18 monitorId = {{ String(monitorId, '1') }} 19 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 19 20 AND timestamp 20 21 >= toUnixTimestamp64Milli(toDateTime64(now() - INTERVAL {{ Int32(interval, 24) }} HOUR, 3)) 21 22 GROUP BY region
+1
packages/tinybird/pipes/status_timezone.pipe
··· 15 15 statusCode, 16 16 latency 17 17 FROM ping_response__v7 18 + {% if defined(url) %} AND url = {{ String(url) }} {% end %} 18 19 WHERE monitorId = {{ String(monitorId, '1') }} 19 20 -- by default, we only query the last 45 days 20 21 AND cronTimestamp >= toUnixTimestamp64Milli(
+7
packages/tinybird/src/validation.ts
··· 53 53 */ 54 54 export const tbParameterResponseList = z.object({ 55 55 monitorId: z.string().default(""), // REMINDER: remove default once alpha 56 + url: z.string().url().optional(), 56 57 fromDate: z.number().int().default(0), // always start from a date 57 58 toDate: z.number().int().optional(), 58 59 limit: z.number().int().optional().default(7500), // one day has 2448 pings (17 (regions) * 6 (per hour) * 24) * 3 days for historical data ··· 65 66 */ 66 67 export const tbParameterResponseDetails = tbParameterResponseList.pick({ 67 68 monitorId: true, 69 + url: true, 68 70 cronTimestamp: true, 69 71 region: true, 70 72 }); ··· 133 135 */ 134 136 export const tbParameterResponseGraph = z.object({ 135 137 monitorId: z.string().default(""), 138 + url: z.string().url().optional(), 136 139 interval: z.number().int().default(10), 137 140 fromDate: z.number().int().default(0), 138 141 toDate: z.number().int().optional(), ··· 143 146 */ 144 147 export const tbParameterMonitorList = z.object({ 145 148 monitorId: z.string(), 149 + url: z.string().url().optional(), 146 150 timezone: z.string().optional(), 147 151 limit: z.number().int().default(46).optional(), // 46 days 148 152 }); ··· 181 185 */ 182 186 export const tbParameterPublicStatus = z.object({ 183 187 monitorId: z.string(), 188 + url: z.string().url().optional(), 184 189 limit: z.number().int().default(5).optional(), // 5 last cronTimestamps 185 190 }); 186 191 ··· 198 203 */ 199 204 export const tbParameterResponseTimeMetrics = z.object({ 200 205 monitorId: z.string(), 206 + url: z.string().url().optional(), 201 207 interval: z.number().int().default(24), // 24 hours 202 208 }); 203 209 ··· 218 224 */ 219 225 export const tbParameterResponseTimeMetricsByRegion = z.object({ 220 226 monitorId: z.string(), 227 + url: z.string().url().optional(), 221 228 interval: z.number().int().default(24), // 24 hours 222 229 }); 223 230