Skip to content

Open-source status page, incident response and uptime monitoring

refactor: remove url and update pipes to utc (#750)

Maximilian Kaskeadf02ecc8af1
diff --git a/apps/server/src/v1/monitor.ts b/apps/server/src/v1/monitor.ts
index 8d324aaa1..44637bc93 100644
--- a/apps/server/src/v1/monitor.ts
+++ b/apps/server/src/v1/monitor.ts
@@ -571,6 +571,7 @@ monitorApi.openapi(getMonitorStats, async (c) => {
});
}
+ // FIXME: we should use the OSTinybird client
console.log("fetching from tinybird");
const res = await getMonitorList(tb)({
monitorId: String(monitorId),
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.tsx
index 5f5df9603..98047a553 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
@@ -42,12 +42,10 @@ export default async function MonitorPage() {
monitors.map(async (monitor) => {
const metrics = await tb.endpointMetrics("1d")({
monitorId: String(monitor.id),
- url: monitor.url,
});
const data = await tb.endpointStatusPeriod("7d")({
monitorId: String(monitor.id),
- url: monitor.url, // FIXME: we should avoid adding url to the parameters
});
const [current] = metrics?.sort((a, b) =>
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.tsx
index ec610bfdc..c405d1828 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
@@ -63,10 +63,7 @@ export default async function Page({
const allowedPeriods = ["1h", "1d", "3d", "7d"] as const;
const period = allowedPeriods.find((i) => i === search.data.period) || "1d";
- const data = await tb.endpointList(period)({
- monitorId: id,
- url: monitor.url,
- });
+ const data = await tb.endpointList(period)({ monitorId: id });
if (!data) return null;
diff --git a/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx b/apps/web/src/app/app/[workspaceSlug]/(dashboard)/monitors/[id]/overview/page.tsx
index 2dfc049f4..ae739b6ec 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
@@ -73,20 +73,15 @@ export default async function Page({
const isQuantileDisabled = intervalMinutes <= periodicityMinutes;
const minutes = isQuantileDisabled ? periodicityMinutes : intervalMinutes;
- const metrics = await tb.endpointMetrics(period)({
- monitorId: id,
- url: monitor.url,
- });
+ const metrics = await tb.endpointMetrics(period)({ monitorId: id });
const data = await tb.endpointChart(period)({
monitorId: id,
- url: monitor.url,
interval: minutes,
});
const metricsByRegion = await tb.endpointMetricsByRegion(period)({
monitorId: id,
- url: monitor.url,
});
if (!data || !metrics || !metricsByRegion) return null;
diff --git a/apps/web/src/app/play/status/_components/status-play.tsx b/apps/web/src/app/play/status/_components/status-play.tsx
index 4e7d6f8ed..6be4aaeb4 100644
--- a/apps/web/src/app/play/status/_components/status-play.tsx
+++ b/apps/web/src/app/play/status/_components/status-play.tsx
@@ -12,7 +12,6 @@ export default async function StatusPlay() {
const data = await tb.endpointStatusPeriod("45d")(
{
monitorId: "1",
- url: "https://www.openstatus.dev",
},
{
revalidate: 600, // 10 minutes
diff --git a/apps/web/src/components/marketing/status-page/tracker-example.tsx b/apps/web/src/components/marketing/status-page/tracker-example.tsx
index 5d19d081e..f019896d5 100644
--- a/apps/web/src/components/marketing/status-page/tracker-example.tsx
+++ b/apps/web/src/components/marketing/status-page/tracker-example.tsx
@@ -32,7 +32,6 @@ async function ExampleTracker() {
const data = await tb.endpointStatusPeriod("45d")(
{
monitorId: "1",
- url: "https://www.openstatus.dev",
},
{
revalidate: 600, // 10 minutes
diff --git a/apps/web/src/components/status-page/monitor.tsx b/apps/web/src/components/status-page/monitor.tsx
index 13ea9a10c..93db6ac71 100644
--- a/apps/web/src/components/status-page/monitor.tsx
+++ b/apps/web/src/components/status-page/monitor.tsx
@@ -23,7 +23,6 @@ export const Monitor = async ({
}) => {
const data = await tb.endpointStatusPeriod("45d")({
monitorId: String(monitor.id),
- url: monitor.url,
});
// TODO: we could handle the `statusReports` here instead of passing it down to the tracker
diff --git a/apps/web/src/lib/timezone.ts b/apps/web/src/lib/timezone.ts
index 4d9364d95..122171f62 100644
--- a/apps/web/src/lib/timezone.ts
+++ b/apps/web/src/lib/timezone.ts
@@ -1,5 +1,5 @@
import { headers } from "next/headers";
-import { format, getTimezoneOffset, zonedTimeToUtc } from "date-fns-tz";
+import { format, getTimezoneOffset, utcToZonedTime } from "date-fns-tz";
export function getRequestHeaderTimezone() {
const headersList = headers();
@@ -42,3 +42,49 @@ export function getServerTimezoneFormat() {
* All supported browser / node timezones
*/
export const supportedTimezones = Intl.supportedValuesOf("timeZone");
+
+export function getClosestTimezone(defaultTimezone?: string) {
+ const requestTimezone = getRequestHeaderTimezone();
+
+ /**
+ * Server region timezone as fallback
+ */
+ const clientTimezone = Intl.DateTimeFormat().resolvedOptions().timeZone;
+
+ const timezone = defaultTimezone || requestTimezone || clientTimezone;
+
+ if (!supportedTimezones.includes(timezone)) return "CET";
+
+ const now = new Date();
+
+ const estTime = utcToZonedTime(now, "America/New_York");
+ const pstTime = utcToZonedTime(now, "America/Los_Angeles");
+ const cetTime = utcToZonedTime(now, "Europe/Paris");
+ const utcTime = utcToZonedTime(now, "UTC");
+
+ const timeDifferences = {
+ EST: Math.abs(now.getTime() - estTime.getTime()),
+ PST: Math.abs(now.getTime() - pstTime.getTime()),
+ CET: Math.abs(now.getTime() - cetTime.getTime()),
+ UTC: Math.abs(now.getTime() - utcTime.getTime()),
+ };
+
+ const closestTimezone = Object.keys(timeDifferences).reduce(
+ (prev, curr) => {
+ if (
+ timeDifferences[curr as keyof typeof timeDifferences] <
+ prev.minDifference
+ ) {
+ return {
+ timezone: curr,
+ minDifference: timeDifferences[curr as keyof typeof timeDifferences],
+ };
+ } else {
+ return prev;
+ }
+ },
+ { timezone: "UTC", minDifference: Infinity },
+ );
+
+ return closestTimezone.timezone as keyof typeof timeDifferences;
+}
diff --git a/packages/tinybird/datasources/__ttl_45d_count_mv.datasource b/packages/tinybird/datasources/__ttl_45d_count_utc_mv.datasource
similarity index 61%
rename from packages/tinybird/datasources/__ttl_45d_count_mv.datasource
rename to packages/tinybird/datasources/__ttl_45d_count_utc_mv.datasource
index bda0ce2cf..9653d8658 100644
--- a/packages/tinybird/datasources/__ttl_45d_count_mv.datasource
+++ b/packages/tinybird/datasources/__ttl_45d_count_utc_mv.datasource
@@ -1,14 +1,13 @@
-# Data Source created from Pipe '__ttl_45d_count__v0'
-VERSION 0
+# Data Source created from Pipe '__ttl_45d_count_utc__v1'
+VERSION 1
SCHEMA >
- `time` DateTime,
+ `time` DateTime('UTC'),
`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_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_utc_mv.datasource
similarity index 61%
rename from packages/tinybird/datasources/__ttl_7d_count_mv.datasource
rename to packages/tinybird/datasources/__ttl_7d_count_utc_mv.datasource
index 3132069fc..03d716e7d 100644
--- a/packages/tinybird/datasources/__ttl_7d_count_mv.datasource
+++ b/packages/tinybird/datasources/__ttl_7d_count_utc_mv.datasource
@@ -1,14 +1,13 @@
-# Data Source created from Pipe '__ttl_7d_count__v0'
-VERSION 0
+# Data Source created from Pipe '__ttl_7d_count_utc__v1'
+VERSION 1
SCHEMA >
- `time` DateTime,
+ `time` DateTime('UTC'),
`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_SORTING_KEY "monitorId, time"
ENGINE_TTL "time + toIntervalDay(7)"
diff --git a/packages/tinybird/pipes/__ttl_14d_chart_get.pipe b/packages/tinybird/pipes/__ttl_14d_chart_get.pipe
index 24a12bbe7..00ef2490c 100644
--- a/packages/tinybird/pipes/__ttl_14d_chart_get.pipe
+++ b/packages/tinybird/pipes/__ttl_14d_chart_get.pipe
@@ -19,7 +19,6 @@ SQL >
FROM __ttl_14d_mv__v1
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.pipe
index b0c9cccbb..13b8fd612 100644
--- a/packages/tinybird/pipes/__ttl_14d_metrics_get.pipe
+++ b/packages/tinybird/pipes/__ttl_14d_metrics_get.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_14d_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND time >= toDateTime64(now() - INTERVAL 14 DAY, 3)
UNION ALL
SELECT
@@ -31,7 +30,6 @@ SQL >
FROM __ttl_45d_mv__v1
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.pipe
index 02538b2c4..160543f87 100644
--- a/packages/tinybird/pipes/__ttl_14d_metrics_get_by_region.pipe
+++ b/packages/tinybird/pipes/__ttl_14d_metrics_get_by_region.pipe
@@ -17,7 +17,6 @@ SQL >
FROM __ttl_14d_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
GROUP BY region
diff --git a/packages/tinybird/pipes/__ttl_1d_chart_get.pipe b/packages/tinybird/pipes/__ttl_1d_chart_get.pipe
index bea1ba3d0..72129941f 100644
--- a/packages/tinybird/pipes/__ttl_1d_chart_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1d_chart_get.pipe
@@ -21,7 +21,6 @@ SQL >
FROM __ttl_1d_mv__v1
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.pipe
index 4a92e68e0..c3b5b5b9f 100644
--- a/packages/tinybird/pipes/__ttl_1d_list_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1d_list_get.pipe
@@ -8,7 +8,6 @@ SQL >
FROM __ttl_1d_mv__v1
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.pipe
index 6579f2c39..20e2546fd 100644
--- a/packages/tinybird/pipes/__ttl_1d_metrics_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1d_metrics_get.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_1d_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND time >= toDateTime64(now() - INTERVAL 1 DAY, 3)
UNION ALL
SELECT
@@ -31,7 +30,6 @@ SQL >
FROM __ttl_3d_mv__v1
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.pipe
index 97c5e5eed..d6b551c7c 100644
--- a/packages/tinybird/pipes/__ttl_1d_metrics_get_by_region.pipe
+++ b/packages/tinybird/pipes/__ttl_1d_metrics_get_by_region.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_1d_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
GROUP BY region
diff --git a/packages/tinybird/pipes/__ttl_1h_chart_get.pipe b/packages/tinybird/pipes/__ttl_1h_chart_get.pipe
index f776c2d56..fa999b069 100644
--- a/packages/tinybird/pipes/__ttl_1h_chart_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1h_chart_get.pipe
@@ -19,7 +19,6 @@ SQL >
FROM __ttl_1h_mv__v1
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.pipe
index 92dbc1b9e..4ec0173e5 100644
--- a/packages/tinybird/pipes/__ttl_1h_last_timestamp_monitor_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1h_last_timestamp_monitor_get.pipe
@@ -8,6 +8,5 @@ SQL >
FROM __ttl_1h_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
diff --git a/packages/tinybird/pipes/__ttl_1h_list_get.pipe b/packages/tinybird/pipes/__ttl_1h_list_get.pipe
index 2231a81cf..0e9c1dbf8 100644
--- a/packages/tinybird/pipes/__ttl_1h_list_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1h_list_get.pipe
@@ -9,7 +9,6 @@ SQL >
FROM __ttl_1h_mv__v1
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.pipe
index 205aa2f5b..2f6378843 100644
--- a/packages/tinybird/pipes/__ttl_1h_metrics_get.pipe
+++ b/packages/tinybird/pipes/__ttl_1h_metrics_get.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_1h_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND time >= toDateTime64(now() - INTERVAL 1 HOUR, 3)
UNION ALL
SELECT
@@ -31,7 +30,6 @@ SQL >
FROM __ttl_1d_mv__v1
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.pipe
index e17730b1c..fe3f91e11 100644
--- a/packages/tinybird/pipes/__ttl_1h_metrics_get_by_region.pipe
+++ b/packages/tinybird/pipes/__ttl_1h_metrics_get_by_region.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_1h_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
GROUP BY region
diff --git a/packages/tinybird/pipes/__ttl_3d_chart_get.pipe b/packages/tinybird/pipes/__ttl_3d_chart_get.pipe
index 49970f659..68e271694 100644
--- a/packages/tinybird/pipes/__ttl_3d_chart_get.pipe
+++ b/packages/tinybird/pipes/__ttl_3d_chart_get.pipe
@@ -19,7 +19,6 @@ SQL >
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.pipe
index 5d80395a8..157dad7f4 100644
--- a/packages/tinybird/pipes/__ttl_3d_metrics_get.pipe
+++ b/packages/tinybird/pipes/__ttl_3d_metrics_get.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_3d_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND time >= toDateTime64(now() - INTERVAL 3 DAY, 3)
UNION ALL
SELECT
@@ -31,7 +30,6 @@ SQL >
FROM __ttl_7d_mv__v1
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.pipe
index 93a790e13..e04067d7b 100644
--- a/packages/tinybird/pipes/__ttl_3d_metrics_get_by_region.pipe
+++ b/packages/tinybird/pipes/__ttl_3d_metrics_get_by_region.pipe
@@ -17,7 +17,6 @@ SQL >
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_all_details_get.pipe b/packages/tinybird/pipes/__ttl_45d_all_details_get.pipe
index bfec76174..825b1399d 100644
--- a/packages/tinybird/pipes/__ttl_45d_all_details_get.pipe
+++ b/packages/tinybird/pipes/__ttl_45d_all_details_get.pipe
@@ -8,7 +8,6 @@ SQL >
from __ttl_45d_all_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND cronTimestamp = {{ Int64(cronTimestamp, 1709477432205) }}
AND region = {{ String(region, 'ams') }}
diff --git a/packages/tinybird/pipes/__ttl_45d_count.pipe b/packages/tinybird/pipes/__ttl_45d_count_utc.pipe
similarity index 64%
rename from packages/tinybird/pipes/__ttl_45d_count.pipe
rename to packages/tinybird/pipes/__ttl_45d_count_utc.pipe
index 3b277392d..e3796dcf4 100644
--- a/packages/tinybird/pipes/__ttl_45d_count.pipe
+++ b/packages/tinybird/pipes/__ttl_45d_count_utc.pipe
@@ -4,22 +4,20 @@ DESCRIPTION >
TODO: descripe what it is for!
-NODE __ttl_45d_count_0
+NODE __ttl_45d_count_utc_0
SQL >
SELECT
- time,
+ toStartOfDay(toTimeZone(time, 'UTC')) AS time,
monitorId,
- url,
countState() AS count,
countState(if(error = 0, 1, NULL)) AS ok
FROM __ttl_45d_mv__v1
GROUP BY
time,
- monitorId,
- url
+ monitorId
TYPE materialized
-DATASOURCE __ttl_45d_count_mv__v1
+DATASOURCE __ttl_45d_count_utc_mv__v1
diff --git a/packages/tinybird/pipes/__ttl_7d_count_get.pipe b/packages/tinybird/pipes/__ttl_45d_count_utc_get.pipe
similarity index 67%
rename from packages/tinybird/pipes/__ttl_7d_count_get.pipe
rename to packages/tinybird/pipes/__ttl_45d_count_utc_get.pipe
index 6202a353b..c21f323ee 100644
--- a/packages/tinybird/pipes/__ttl_7d_count_get.pipe
+++ b/packages/tinybird/pipes/__ttl_45d_count_utc_get.pipe
@@ -1,19 +1,18 @@
VERSION 1
-NODE __ttl_7d_count_get_0
+NODE __ttl_45d_count_utc_get_0
SQL >
%
SELECT time as day, countMerge(count) as count, countMerge(ok) as ok
- FROM __ttl_7d_count_mv__v1
+ FROM __ttl_45d_count_utc_mv__v1
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())
+ toStartOfDay(toStartOfDay(toTimeZone(now(), 'UTC')))
TO toStartOfDay(
date_sub(DAY, 7, now())
) STEP INTERVAL -1 DAY
diff --git a/packages/tinybird/pipes/__ttl_7d_all_details_get.pipe b/packages/tinybird/pipes/__ttl_7d_all_details_get.pipe
index 67612442a..4333819d4 100644
--- a/packages/tinybird/pipes/__ttl_7d_all_details_get.pipe
+++ b/packages/tinybird/pipes/__ttl_7d_all_details_get.pipe
@@ -8,7 +8,6 @@ SQL >
from __ttl_7d_all_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND cronTimestamp = {{ Int64(cronTimestamp, 1709477432205) }}
AND region = {{ String(region, 'ams') }}
diff --git a/packages/tinybird/pipes/__ttl_7d_chart_get.pipe b/packages/tinybird/pipes/__ttl_7d_chart_get.pipe
index 1e11286a9..f0483396b 100644
--- a/packages/tinybird/pipes/__ttl_7d_chart_get.pipe
+++ b/packages/tinybird/pipes/__ttl_7d_chart_get.pipe
@@ -19,7 +19,6 @@ SQL >
FROM __ttl_7d_mv__v1
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_utc.pipe
similarity index 58%
rename from packages/tinybird/pipes/__ttl_7d_count.pipe
rename to packages/tinybird/pipes/__ttl_7d_count_utc.pipe
index 78527c1c2..d5958cfa2 100644
--- a/packages/tinybird/pipes/__ttl_7d_count.pipe
+++ b/packages/tinybird/pipes/__ttl_7d_count_utc.pipe
@@ -4,22 +4,20 @@ DESCRIPTION >
TODO: descripe what it is for!
-NODE __ttl_7d_count_0
+NODE __ttl_7d_count_utc_0
SQL >
SELECT
- time,
+ toStartOfDay(toTimeZone(time, 'UTC')) AS time,
monitorId,
- url,
countState() AS count,
countState(if(error = 0, 1, NULL)) AS ok
- FROM __ttl_45d_mv__v0
+ FROM __ttl_7d_mv__v1
GROUP BY
time,
- monitorId,
- url
+ monitorId
TYPE materialized
-DATASOURCE __ttl_7d_count_mv__v1
+DATASOURCE __ttl_7d_count_utc_mv__v1
diff --git a/packages/tinybird/pipes/__ttl_45d_count_get.pipe b/packages/tinybird/pipes/__ttl_7d_count_utc_get.pipe
similarity index 58%
rename from packages/tinybird/pipes/__ttl_45d_count_get.pipe
rename to packages/tinybird/pipes/__ttl_7d_count_utc_get.pipe
index 42ebfd0f5..8b6ae3408 100644
--- a/packages/tinybird/pipes/__ttl_45d_count_get.pipe
+++ b/packages/tinybird/pipes/__ttl_7d_count_utc_get.pipe
@@ -1,21 +1,20 @@
VERSION 1
-NODE __ttl_45d_count_get_0
+NODE __ttl_7d_count_utc_get_0
SQL >
%
SELECT time as day, countMerge(count) as count, countMerge(ok) as ok
- FROM __ttl_45d_count_mv__v1
+ FROM __ttl_7d_count_utc_mv__v1
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())
+ toStartOfDay(toStartOfDay(toTimeZone(now(), 'UTC')))
TO toStartOfDay(
- date_sub(DAY, 45, now())
+ 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.pipe
index cf5dab69f..343bfa886 100644
--- a/packages/tinybird/pipes/__ttl_7d_metrics_get.pipe
+++ b/packages/tinybird/pipes/__ttl_7d_metrics_get.pipe
@@ -16,7 +16,6 @@ SQL >
FROM __ttl_7d_mv__v1
WHERE
monitorId = {{ String(monitorId, '1') }}
- {% if defined(url) %} AND url = {{ String(url) }} {% end %}
AND time >= toDateTime64(now() - INTERVAL 7 DAY, 3)
UNION ALL
SELECT
@@ -31,7 +30,6 @@ SQL >
FROM __ttl_14d_mv__v1
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.pipe
index 43c9148d7..a06a73424 100644
--- a/packages/tinybird/pipes/__ttl_7d_metrics_get_by_region.pipe
+++ b/packages/tinybird/pipes/__ttl_7d_metrics_get_by_region.pipe
@@ -17,7 +17,6 @@ SQL >
FROM __ttl_7d_mv__v1
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.ts
index 4d2f56455..583528c58 100644
--- a/packages/tinybird/src/client.ts
+++ b/packages/tinybird/src/client.ts
@@ -18,6 +18,9 @@ export const publishPingResponse = tb.buildIngestEndpoint({
event: tbIngestPingResponse,
});
+/**
+ * @deprecated but still used in server - please use OSTinybird.endpointStatusPeriod
+ */
export function getMonitorList(tb: Tinybird) {
return tb.buildPipe({
pipe: "status_timezone__v1",
@@ -31,23 +34,7 @@ export function getMonitorList(tb: Tinybird) {
}
/**
- * That pipe is used in the homepage to show the status while having cached data
- * FYI We had 3TB of processed data during August. We will be able to reduce it signifcantly.
- * The cache is only applied on the homepage.
- */
-export function getHomeMonitorList(tb: Tinybird) {
- return tb.buildPipe({
- pipe: "status_timezone__v1",
- parameters: tbParameterMonitorList,
- data: tbBuildMonitorList,
- opts: {
- revalidate: 600, // 10 minutes cache
- },
- });
-}
-
-/**
- * Homepage stats used for our marketing page.
+ * Homepage stats used for our marketing page
*/
export function getHomeStats(tb: Tinybird) {
return tb.buildPipe({
diff --git a/packages/tinybird/src/os-client.ts b/packages/tinybird/src/os-client.ts
index 0f8e8ae5f..94a6b5332 100644
--- a/packages/tinybird/src/os-client.ts
+++ b/packages/tinybird/src/os-client.ts
@@ -38,6 +38,7 @@ export class OSTinybird {
private tb: Tinybird;
// FIXME: use Tinybird instead with super(args) maybe
+ // how about passing here the `opts: {revalidate}` to access it within the functions?
constructor(private args: { token: string; baseUrl?: string | undefined }) {
this.tb = new Tinybird(args);
}
@@ -46,7 +47,6 @@ export class OSTinybird {
const parameters = z.object({
interval: z.number().int().optional(),
monitorId: z.string(),
- url: z.string().optional(),
});
return async (props: z.infer<typeof parameters>) => {
@@ -72,10 +72,7 @@ export class OSTinybird {
}
endpointMetrics(period: "1h" | "1d" | "3d" | "7d" | "14d") {
- const parameters = z.object({
- monitorId: z.string(),
- url: z.string().optional(),
- });
+ const parameters = z.object({ monitorId: z.string() });
return async (props: z.infer<typeof parameters>) => {
try {
@@ -102,10 +99,7 @@ export class OSTinybird {
}
endpointMetricsByRegion(period: "1h" | "1d" | "3d" | "7d" | "14d") {
- const parameters = z.object({
- monitorId: z.string(),
- url: z.string().optional(),
- });
+ const parameters = z.object({ monitorId: z.string() });
return async (props: z.infer<typeof parameters>) => {
try {
@@ -131,11 +125,11 @@ export class OSTinybird {
};
}
- endpointStatusPeriod(period: "7d" | "45d") {
- const parameters = z.object({
- monitorId: z.string(),
- url: z.string().optional(),
- });
+ endpointStatusPeriod(
+ period: "7d" | "45d",
+ timezone: "UTC" = "UTC", // "EST" | "PST" | "CET"
+ ) {
+ const parameters = z.object({ monitorId: z.string() });
return async (
props: z.infer<typeof parameters>,
@@ -143,7 +137,7 @@ export class OSTinybird {
) => {
try {
const res = await this.tb.buildPipe({
- pipe: `__ttl_${period}_count_get__${VERSION}`,
+ pipe: `__ttl_${period}_count_${timezone.toLowerCase()}_get__${VERSION}`,
parameters,
data: z.object({
day: z.string().transform((val) => {
@@ -167,7 +161,6 @@ export class OSTinybird {
endpointList(period: "1h" | "1d" | "3d" | "7d") {
const parameters = z.object({
monitorId: z.string(),
- url: z.string().optional(),
});
return async (props: z.infer<typeof parameters>) => {
@@ -226,7 +219,6 @@ export class OSTinybird {
endpointResponseDetails(period: "7d" | "45d") {
const parameters = z.object({
monitorId: z.string().default("").optional(),
- url: z.string().url().optional(),
region: z.enum(flyRegions).optional(),
cronTimestamp: z.number().int().optional(),
});