-
Notifications
You must be signed in to change notification settings - Fork 2.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
add twenty-tinybird package #8030
Merged
Merged
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
788b357
add tinybird work to repo
anamarn b33bcad
Add tinybird CI
FelixMalfait e42744c
Add requirements.txt
FelixMalfait 3a139ad
Add .tinyenv
FelixMalfait ef27ad8
Add init scripts
FelixMalfait dfec9d5
new folder structure tinybird
anamarn 00990b0
clean code and format
anamarn 6e9437c
add fixtures and lint scripts
anamarn 8578ab3
Fixes
FelixMalfait b767a06
Merge branch 'main' into feat/twenty-tinybird
FelixMalfait 8bf4d9f
Temporarily disable tinybird
FelixMalfait File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
.tinyb |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
|
||
## How to use | ||
Create a virtual enviroment and install tinybird | ||
```sh | ||
python3 -m venv .venv | ||
source .venv/bin/activate | ||
pip install tinybird-cli | ||
``` | ||
Authenticate using your admin token from your workspace | ||
```sh | ||
tb auth -i | ||
|
||
** List of available regions: | ||
[1] us-east4 (gcp) (https://app.us-east.tinybird.co) | ||
[2] europe-west3 (gcp) (https://app.tinybird.co/gcp/europe-west3) | ||
[3] us-east-1 (aws) (https://app.tinybird.co/aws/us-east-1) | ||
[4] us-west-2 (aws) (https://app.tinybird.co/aws/us-west-2) | ||
[5] eu-central-1 (aws) (https://app.tinybird.co/aws/eu-central-1) <- this | ||
[0] Cancel | ||
|
||
Use region [1]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Region 5 no? |
||
Copy the "admin your@email" token from from https://app.tinybird.co/tokens and paste it here: <pasted Token> | ||
** Auth successful! | ||
** Configuration written to .tinyb file, consider adding it to .gitignore | ||
``` | ||
To sync your changes to Tinybird use: | ||
```sh | ||
tb push --force --push-deps | ||
``` | ||
To pull data from Tinybird use: | ||
```sh | ||
tb pull | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
|
||
SCHEMA > | ||
`action` String `json:$.action`, | ||
`timestamp` DateTime64(3) `json:$.timestamp`, | ||
`version` String `json:$.version`, | ||
`userId` String `json:$.userId` DEFAULT '', | ||
`workspaceId` String `json:$.workspaceId` DEFAULT '', | ||
`payload` String `json:$.payload` | ||
|
||
ENGINE "MergeTree" | ||
ENGINE_PARTITION_KEY "toYear(timestamp)" | ||
ENGINE_SORTING_KEY "action, timestamp" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
|
||
SCHEMA > | ||
`href` String `json:$.href`, | ||
`locale` String `json:$.locale`, | ||
`pathname` String `json:$.pathname`, | ||
`referrer` String `json:$.referrer`, | ||
`sessionId` String `json:$.sessionId`, | ||
`timeZone` String `json:$.timeZone`, | ||
`timestamp` DateTime64(3) `json:$.timestamp`, | ||
`userAgent` String `json:$.userAgent`, | ||
`userId` String `json:$.userId`, | ||
`version` String `json:$.version`, | ||
`workspaceId` String `json:$.workspaceId` | ||
|
||
ENGINE "MergeTree" | ||
ENGINE_PARTITION_KEY "toYear(timestamp)" | ||
ENGINE_SORTING_KEY "timestamp, userId, version, workspaceId" |
13 changes: 13 additions & 0 deletions
13
packages/twenty-tinybird/datasources/serverlessFunctionsEventMV.datasource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Data Source created from Pipe 'serverlessFunctionsEventMv' | ||
|
||
SCHEMA > | ||
`timestamp` DateTime64(3), | ||
`workspaceId` String, | ||
`functionId` String, | ||
`durationInMs` Int64, | ||
`success` Bool, | ||
`errorType` String | ||
|
||
ENGINE "MergeTree" | ||
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)" | ||
ENGINE_SORTING_KEY "timestamp, functionId, success" |
15 changes: 15 additions & 0 deletions
15
packages/twenty-tinybird/datasources/webhooksEventMV.datasource
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# Data Source created from Pipe 'webhooksEventMv' | ||
|
||
SCHEMA > | ||
`timestamp` DateTime64(3), | ||
`workspaceId` String, | ||
`webhookId` String, | ||
`url` String, | ||
`success` UInt8, | ||
`status` Int64, | ||
`eventName` String, | ||
`version` String | ||
|
||
ENGINE "MergeTree" | ||
ENGINE_PARTITION_KEY "toYYYYMM(timestamp)" | ||
ENGINE_SORTING_KEY "timestamp, workspaceId" |
62 changes: 62 additions & 0 deletions
62
packages/twenty-tinybird/pipes/getWebhooksAnalyticsV2.pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
TOKEN "getWebhooksAnalyticsV2_endpoint_read_4255" READ | ||
|
||
TAGS newVersion | ||
|
||
NODE getWebhooksAnalyticsV2_0 | ||
SQL > | ||
|
||
SELECT | ||
timestamp, | ||
workspaceId, | ||
JSONExtractString(payload, 'webhookId') as webhookId, | ||
JSONExtractString(payload, 'url') as url, | ||
JSONExtractBool(payload, 'success') as success, | ||
JSONExtractInt(payload, 'status') as status, | ||
JSONExtractString(payload, 'eventName') as eventName, | ||
version | ||
|
||
FROM event | ||
WHERE action = 'webhook.response' | ||
|
||
|
||
|
||
NODE getWebhooksAnalyticsV3Jwt | ||
SQL > | ||
|
||
% | ||
WITH | ||
reference_time AS ( | ||
SELECT | ||
toStartOfInterval(now(), INTERVAL {{ Int32(tickIntervalInMinutes, 420) }} MINUTE) AS ref_time | ||
), | ||
time_series AS ( | ||
SELECT | ||
toDateTime(subtractHours(ref_time, {{ Int32(windowInHours, 168) }})) | ||
+ INTERVAL number * {{ Int32(tickIntervalInMinutes, 420) }} MINUTE AS start_interval | ||
FROM reference_time, numbers(0, 12 * 2 + 1) | ||
WHERE start_interval <= now() -- Use now() instead of ref_time to include current interval | ||
) | ||
SELECT | ||
ts.start_interval, | ||
COALESCE(e.failure_count, 0) AS failure_count, | ||
COALESCE(e.success_count, 0) AS success_count | ||
FROM time_series ts | ||
LEFT JOIN | ||
( | ||
SELECT | ||
toStartOfInterval( | ||
timestamp, INTERVAL {{ Int32(tickIntervalInMinutes, 420) }} MINUTE | ||
) AS interval_start, | ||
countIf(success = 0) AS failure_count, | ||
countIf(success = 1) AS success_count | ||
FROM getWebhooksAnalyticsV2_0 | ||
WHERE | ||
timestamp >= subtractHours(now(), {{ Int32(windowInHours, 168) }}) | ||
AND webhookId = {{ String(webhookId, "c19ea782-417e-4d44-a486-fd794fc44a27") }} | ||
AND workspaceId ={{ String(workspaceId,"20202020-1c25-4d02-bf25-6aeccf7ea419") }} | ||
GROUP BY interval_start | ||
) e | ||
ON ts.start_interval = e.interval_start | ||
ORDER BY ts.start_interval | ||
|
||
|
18 changes: 18 additions & 0 deletions
18
packages/twenty-tinybird/pipes/serverlessFunctionsEventMv.pipe
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
NODE serverlessFunctionsEvent_mv | ||
SQL > | ||
|
||
SELECT | ||
timestamp, | ||
workspaceId, | ||
JSONExtractString(payload, 'functionId') as functionId, | ||
JSONExtractInt(payload, 'duration') as durationInMs, | ||
if(JSONExtractString(payload, 'status')='SUCCESS',TRUE, FALSE) as success, | ||
JSONExtractString(payload, 'errorType') as errorType | ||
|
||
FROM event | ||
WHERE action = 'serverlessFunction.executed' | ||
|
||
TYPE materialized | ||
DATASOURCE serverlessFunctionsEventMV | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add .venv to .gitignore then :)