twenty/packages/twenty-tinybird/pipes/getServerlessFunctionErrors.pipe
Ana Sofia Marin Alexandre 8ef4efa0f5
add twenty-tinybird package (#8030)
https://github.com/twentyhq/private-issues/issues/75

**TLDR**

Add twenty-server package, wich contains the last tinybird datasources
and pipes used in analytics.

This new version of the API endpoints, pipes and datasources are
inspired by the implementation of dub.co
(https://github.com/dubinc/dub/blob/main/packages/tinybird/).

It contains the webhooks analytics, serverless functions duration and
serverless functions error count analytics. As well as


**In order to test**

- Follow the instructions in the README.md on twenty-tinybird using your
admin token from twenty_analytics_playground if you want to modify them.
- For a better experience add the extension Tinybird support for VsCode 
- If you want more info about datasources and pipes please read the
tinybird docs.

---------

Co-authored-by: Félix Malfait <felix@twenty.com>
Co-authored-by: Félix Malfait <felix.malfait@gmail.com>
2024-10-29 10:31:05 +01:00

42 lines
1.5 KiB
Plaintext

INCLUDE "../includes/timeSeries.incl"
NODE timeSeriesServerlessFunctionErrorsData
SQL >
%
SELECT
{% if granularity == "hour" %} toStartOfHour(timestamp, {{ String(timezone, 'UTC') }})
{% elif granularity == "custom" %}
toDateTime64(
toStartOfMinute(timestamp, {{ String(timezone, 'UTC') }}),
3,
{{ String(timezone, 'UTC') }}
)
{% else %} toDateTime64(toStartOfDay(timestamp, {{ String(timezone, 'UTC') }}), 3)
{% end %} AS interval,
uniqIf(*, success = false) as error_count,
round(
if(
uniqIf(*, success = true) = 0,
0,
(uniqIf(*, success = true) - uniqIf(*, success = false)) / uniqIf(*, success = true)
),
2
) as success_rate
FROM serverlessFunctionEventMV
WHERE
true
AND functionId = {{ String(functionId, 'a9fd87c0-af86-4e17-be3a-a6d3d961678a', required=True) }}
AND workspaceId
={{ String(workspaceId, '20202020-1c25-4d02-bf25-6aeccf7ea419', required=True) }}
AND timestamp >= {{ DateTime(start, '2024-10-22 00:00:00') }}
AND timestamp < {{ DateTime(end, '2024-10-23 00:00:00') }}
GROUP BY interval
ORDER BY interval
NODE endpoint
SQL >
%
SELECT formatDateTime(interval, '%FT%T.000%z') as start, error_count, success_rate
FROM selectIntervalByGranularity
LEFT JOIN timeSeriesServerlessFunctionErrorsData USING interval