diff --git a/.github/workflows/bench-turborepo.yml b/.github/workflows/bench-turborepo.yml index 6c589fbec7320..203f905b15c94 100644 --- a/.github/workflows/bench-turborepo.yml +++ b/.github/workflows/bench-turborepo.yml @@ -78,14 +78,15 @@ jobs: - name: Augment ttft data run: | - cd benchmark && node -r esbuild-register ./src/ttft-augment.ts "$PWD/ttft.json" ${{github.run_id}} - cat ./ttft.json + cd benchmark && TINYBIRD_TOKEN=${{secrets.TINYBIRD_TOKEN}} node -r esbuild-register ./src/ttft-augment.ts "$PWD/ttft.json" ${{github.job_url}} + ${{github.job}} - - name: Save to Tinybird - run: | - myjson=$(cat ./benchmark/ttft.json | jq -c) - echo $myjson - curl --retry 3 -i -X POST -d "$myjson" -H "Authorization: Bearer ${{ secrets.TINYBIRD_TOKEN }}" https://api.us-east.tinybird.co/v0/events?name=turborepo_perf_ttft + # - name: Save to Tinybird + # run: | + + # myjson=$(cat ./benchmark/ttft.json) + # echo $myjson + # curl --retry 3 -i -X POST -d "$myjson" -H "Authorization: Bearer ${{ secrets.TINYBIRD_TOKEN }}" https://api.us-east.tinybird.co/v0/events?name=turborepo_perf_ttft # The benchmark always produces profile.json, but we can change the name for the purpose of saving it - name: Prep artifact diff --git a/benchmark/package.json b/benchmark/package.json index 29dc296deb635..2f16efd7828e1 100644 --- a/benchmark/package.json +++ b/benchmark/package.json @@ -5,7 +5,8 @@ "esbuild": "^0.15.0", "esbuild-register": "^3.3.2", "fs-extra": "^10.0.0", - "ndjson": "^2.0.0" + "ndjson": "^2.0.0", + "node-fetch": "^2.6.8" }, "scripts": { "benchmark": "echo done", @@ -18,6 +19,7 @@ "@types/fs-extra": "^9.0.13", "@types/ndjson": "^2.0.2", "@types/node": "^18.17.4", + "@types/node-fetch": "^2.6.6", "typescript": "^5.2.2" } } diff --git a/benchmark/src/ttft-augment.ts b/benchmark/src/ttft-augment.ts index d8a46c5612ab8..41721ac1025ce 100644 --- a/benchmark/src/ttft-augment.ts +++ b/benchmark/src/ttft-augment.ts @@ -1,16 +1,31 @@ import fs from "fs"; +import fetch from "node-fetch"; import { getCommitDetails } from "./helpers"; const filePath = process.argv[2]; -const runID = process.argv[3]; +const url = process.argv[3]; -const contents = fs.readFileSync(filePath); -const data = JSON.parse(contents.toString()); +const DATA_SOURCE_URL = + "https://api.us-east.tinybird.co/v0/events?name=turborepo_perf_ttft"; -const commitDetails = getCommitDetails(); +(async function () { + const contents = fs.readFileSync(filePath); + const data = JSON.parse(contents.toString()); -data.commitSha = commitDetails.commitSha; -data.commitTimestamp = commitDetails.commitTimestamp; -data.url = `https://github.com/vercel/turbo/actions/runs/${runID}`; + const commitDetails = getCommitDetails(); -fs.writeFileSync(filePath, JSON.stringify(data, null, 2)); + data.commitSha = commitDetails.commitSha; + data.commitTimestamp = commitDetails.commitTimestamp; + data.url = url; + + console.log("Sending data to Tinybird: ", data); + + await fetch(DATA_SOURCE_URL, { + method: "POST", + headers: { + Authorization: `Bearer ${process.env.TINYBIRD_TOKEN}`, + "Content-Type": "application/json", + }, + body: JSON.stringify(data), + }); +})(); diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index b48c486d16a84..20c6fcd7dcac9 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -125,6 +125,9 @@ importers: ndjson: specifier: ^2.0.0 version: 2.0.0 + node-fetch: + specifier: ^2.6.8 + version: 2.6.11 devDependencies: '@turbo/tsconfig': specifier: workspace:* @@ -138,6 +141,9 @@ importers: '@types/node': specifier: ^18.17.4 version: 18.17.4 + '@types/node-fetch': + specifier: ^2.6.6 + version: 2.6.6 typescript: specifier: ^5.2.2 version: 5.2.2 @@ -3576,6 +3582,13 @@ packages: '@types/through': 0.0.30 dev: true + /@types/node-fetch@2.6.6: + resolution: {integrity: sha512-95X8guJYhfqiuVVhRFxVQcf4hW/2bCuoPwDasMf/531STFoNoWTT7YDnWdXHEZKqAGUigmpG31r2FE70LwnzJw==} + dependencies: + '@types/node': 18.17.4 + form-data: 4.0.0 + dev: true + /@types/node@12.20.55: resolution: {integrity: sha512-J8xLz7q2OFulZ2cyGTLE1TbbZcjpno7FaN6zdJNrgAdrJ+DZzh/uFR6YrTb4C+nXakvud8Q4+rbhoIWlYQbUFQ==} dev: true @@ -7586,7 +7599,6 @@ packages: asynckit: 0.4.0 combined-stream: 1.0.8 mime-types: 2.1.35 - dev: false /fraction.js@4.2.0: resolution: {integrity: sha512-MhLuK+2gUcnZe8ZHlaaINnQLl0xRIGRfcGk2yl8xoQAfHrSsL3rYu6FCmBdkdbhc9EPlwyGHewaRsvwRMJtAlA==} @@ -7963,6 +7975,7 @@ packages: /graceful-fs@4.2.11: resolution: {integrity: sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ==} + requiresBuild: true /gradient-string@2.0.1: resolution: {integrity: sha512-+xDOYR2fMa4QHGysTgyQsl8g16mcAKqvvsKI014qYP2XVf1SWUPlD8KhdBJPUM8AVwDUB+ls0NFkqRzAB5URkA==}