Skip to content

Commit

Permalink
🔥 tb pipe (#1039)
Browse files Browse the repository at this point in the history
  • Loading branch information
thibaultleouay authored Oct 7, 2024
1 parent dbf8956 commit 5b798e1
Show file tree
Hide file tree
Showing 17 changed files with 266 additions and 6 deletions.
2 changes: 1 addition & 1 deletion apps/web/src/components/content/callout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ export function Callout({
const Icon = Icons[getIconName(variant)];
return (
<div className={cn(calloutVariants({ variant, className }))} {...props}>
<Icon className="h-4 w-4 mr-2 my-1.5 shrink-0" />
<Icon className="my-1.5 mr-2 h-4 w-4 shrink-0" />
<p>{children}</p>
</div>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,6 @@ export function SectionScheduling({ form, limits, plan }: Props) {
<FormField
control={form.control}
name="regions"
// biome-ignore lint/correctness/noUnusedVariables: <explanation>
render={({ field }) => {
return (
<FormItem>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/forms/shared/checkbox-label.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export function CheckboxLabel({
<Label
htmlFor={`${name}-${id}`}
className={cn(
"flex h-full items-center gap-1 rounded-md border border-border bg-popover p-4 pr-10 hover:bg-accent hover:text-accent-foreground peer-data-[state=checked]:border-primary [&:has([data-state=checked])]:border-primary peer-disabled:hover:bg-background peer-disabled:text-muted-foreground",
"flex h-full items-center gap-1 rounded-md border border-border bg-popover p-4 pr-10 hover:bg-accent hover:text-accent-foreground peer-disabled:text-muted-foreground peer-disabled:hover:bg-background peer-data-[state=checked]:border-primary [&:has([data-state=checked])]:border-primary",
className,
)}
>
Expand Down
2 changes: 1 addition & 1 deletion apps/web/src/components/layout/header/app-tabs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ function IncidentsDot() {
if (!open) return null;

return (
<div className="absolute right-1 top-1">
<div className="absolute top-1 right-1">
<StatusDot status="error" active />
</div>
);
Expand Down
2 changes: 0 additions & 2 deletions packages/react/src/widget.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,12 +45,10 @@ export async function StatusWidget({ slug, href }: StatusWidgetProps) {
<span className="relative flex h-2 w-2">
{status === "operational" ? (
<span
// biome-ignore lint/nursery/useSortedClasses: color is a dynamic value
className={`absolute inline-flex h-full w-full animate-ping rounded-full ${color} opacity-75 duration-1000`}
/>
) : null}
<span
// biome-ignore lint/nursery/useSortedClasses: color is a dynamic value
className={`relative inline-flex h-2 w-2 rounded-full ${color}`}
/>
</span>
Expand Down
14 changes: 14 additions & 0 deletions packages/tinybird/datasources/__ttl_7d_count_mv.datasource
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
VERSION 1
# Data Source created from Pipe '__ttl_7d_count__v1'

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)"
12 changes: 12 additions & 0 deletions packages/tinybird/datasources/external_status.datasource
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

SCHEMA >
`description` String `json:$.description`,
`fetched_at` Int64 `json:$.fetched_at`,
`indicator` String `json:$.indicator`,
`name` String `json:$.name`,
`time_zone` String `json:$.time_zone`,
`updated_at` Int64 `json:$.updated_at`,
`url` String `json:$.url`

ENGINE "MergeTree"
ENGINE_SORTING_KEY "description, time_zone, updated_at, url"
15 changes: 15 additions & 0 deletions packages/tinybird/datasources/tcp_response.datasource
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
VERSION 0

SCHEMA >
`monitorId` Int32 `json:$.monitorId`,
`region` String `json:$.region`,
`timestamp` Int64 `json:$.timestamp`,
`timing` String `json:$.timing`,
`workspaceId` Int32 `json:$.workspaceId`,
`latency` Int64 `json:$.latency`,
`errorMessage` Nullable(String) `json:$.errorMessage`,
`error` Int16 `json:$.error`

ENGINE "MergeTree"
ENGINE_PARTITION_KEY "toYYYYMM(fromUnixTimestamp64Milli(timestamp))"
ENGINE_SORTING_KEY "monitorId, workspaceId"
25 changes: 25 additions & 0 deletions packages/tinybird/datasources/web_vitals.datasource
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
VERSION 0

SCHEMA >
`browser` String `json:$.browser`,
`city` String `json:$.city`,
`continent` String `json:$.continent`,
`country` String `json:$.country`,
`device` String `json:$.device`,
`dsn` String `json:$.dsn`,
`href` String `json:$.href`,
`id` String `json:$.id`,
`name` String `json:$.name`,
`os` String `json:$.os`,
`path` String `json:$.path`,
`rating` String `json:$.rating`,
`region_code` String `json:$.region_code`,
`screen` String `json:$.screen`,
`session_id` String `json:$.session_id`,
`speed` String `json:$.speed`,
`timezone` String `json:$.timezone`,
`value` Float32 `json:$.value`,
`timestamp` Nullable(DateTime) `json:$.timestamp`

ENGINE "MergeTree"
ENGINE_SORTING_KEY "session_id, speed, timezone"
23 changes: 23 additions & 0 deletions packages/tinybird/pipes/__ttl_14d_chart_all_regions_get.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
VERSION 1
TOKEN "__ttl_14d_chart_all_regions_get__v1_endpoint_read_6659" READ

NODE __ttl_14d_chart_all_regions_get_0
SQL >

%
SELECT
toStartOfInterval(
toDateTime(cronTimestamp / 1000), INTERVAL 1 HOUR
) 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
WHERE monitorId = {{ String(monitorId, '1') }}
GROUP BY h
ORDER BY h DESC


38 changes: 38 additions & 0 deletions packages/tinybird/pipes/__ttl_45d_statuspage_get.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
VERSION 1
TOKEN "__ttl_45d_statuspage_get_endpoint_read_1959" READ

NODE __ttl_45d_statuspage_get_0
SQL >

%
SELECT
toDateTime(cronTimestamp / 1000, 'UTC') AS day,
-- only for debugging purposes
toTimezone(day, {{ String(timezone, 'Europe/London') }}) as with_timezone,
toStartOfDay(with_timezone) as start_of_day,
statusCode
-- latency
FROM __ttl_45d_mv
WHERE monitorId = {{ String(monitorId, '4') }}



NODE __ttl_7d_statuspage_get_1
SQL >

%
SELECT
start_of_day as day,
count() AS count,
count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok
FROM __ttl_45d_statuspage_get_0
GROUP BY start_of_day
ORDER BY start_of_day DESC
WITH FILL
FROM
toStartOfDay(toTimezone(now(), {{ String(timezone, 'Europe/London') }}))
TO toStartOfDay(
toTimezone(date_sub(DAY, 46, now()), {{ String(timezone, 'Europe/London') }})
) STEP INTERVAL -1 DAY


23 changes: 23 additions & 0 deletions packages/tinybird/pipes/__ttl_7d_chart_all_regions_get.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
VERSION 1
TOKEN "__ttl_7d_chart_all_regions_get__v1_endpoint_read_8648" READ

NODE __ttl_7d_chart_all_regions_get_0
SQL >

%
SELECT
toStartOfInterval(
toDateTime(cronTimestamp / 1000), INTERVAL 1 HOUR
) 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
WHERE monitorId = {{ String(monitorId, '1') }}
GROUP BY h
ORDER BY h DESC


24 changes: 24 additions & 0 deletions packages/tinybird/pipes/__ttl_7d_count.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
VERSION 1
DESCRIPTION >
TODO: descripe what it is for!


NODE __ttl_7d_count_0
SQL >

SELECT
time,
monitorId,
url,
countState() AS count,
countState(if(error = 0, 1, NULL)) AS ok
FROM __ttl_45d_mv
GROUP BY
time,
monitorId,
url

TYPE materialized
DATASOURCE __ttl_7d_count_mv


22 changes: 22 additions & 0 deletions packages/tinybird/pipes/__ttl_7d_count_get.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
VERSION 1
TOKEN "__ttl_7d_count_get__v1_endpoint_read_7412" READ

NODE __ttl_7d_count_get_0
SQL >

%
SELECT time as day, countMerge(count) as count, countMerge(ok) as ok
FROM __ttl_7d_count_mv_test
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


38 changes: 38 additions & 0 deletions packages/tinybird/pipes/__ttl_7d_statuspage_get.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
VERSION 1
TOKEN "__ttl_7d_statuspage_get_endpoint_read_0234" READ

NODE __ttl_7d_statuspage_get_0
SQL >

%
SELECT
toDateTime(cronTimestamp / 1000, 'UTC') AS day,
-- only for debugging purposes
toTimezone(day, {{ String(timezone, 'Europe/London') }}) as with_timezone,
toStartOfDay(with_timezone) as start_of_day,
statusCode
-- latency
FROM __ttl_7d_mv
WHERE monitorId = {{ String(monitorId, '4') }}



NODE __ttl_7d_statuspage_get_1
SQL >

%
SELECT
start_of_day as day,
count() AS count,
count(multiIf((statusCode >= 200) AND (statusCode <= 299), 1, NULL)) AS ok
FROM __ttl_7d_statuspage_get_0
GROUP BY start_of_day
ORDER BY start_of_day DESC
WITH FILL
FROM
toStartOfDay(toTimezone(now(), {{ String(timezone, 'Europe/London') }}))
TO toStartOfDay(
toTimezone(date_sub(DAY, 46, now()), {{ String(timezone, 'Europe/London') }})
) STEP INTERVAL -1 DAY


17 changes: 17 additions & 0 deletions packages/tinybird/pipes/dashboard_request.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
VERSION 0
NODE dashboard_request_0
SQL >

%
SELECT * FROM monitor_request_count_7d_mv
WHERE monitorId = {{ String(monitorId, '1') }}
{% if defined(url) %} AND url = {{ String(url) }} {% end %}



NODE dashboard_request_1
SQL >

SELECT * FROM dashboard_request_0


12 changes: 12 additions & 0 deletions packages/tinybird/pipes/external_status.pipe
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
VERSION 0
NODE external_status_0
SQL >

%
SELECT *
FROM external_status
WHERE name = {{ String(name, 'OpenAI') }}
ORDER BY fetched_at DESC
LIMIT {{ Int16(limit, 10000) }}


0 comments on commit 5b798e1

Please sign in to comment.