Skip to content

Commit

Permalink
feat: auto-trace more frequently
Browse files Browse the repository at this point in the history
  • Loading branch information
tschoffelen committed Oct 6, 2024
1 parent e8c2918 commit 3b6fc6c
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 14 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
"packageManager": "[email protected]",
"scripts": {
"deploy": "yarn build && yarn turbo deploy --env-mode=loose --color",
"auto-trace": "yarn turbo auto-trace --env-mode=loose --color",
"build": "yarn turbo build --env-mode=loose --color",
"test": "yarn turbo test --env-mode=loose --color",
"start": "turbo dev --env-mode=loose --color",
Expand Down
1 change: 1 addition & 0 deletions packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"scripts": {
"dev": "serverless offline start",
"deploy": "serverless deploy --verbose",
"auto-trace": "serverless invoke local -f main -d '{\"action\": \"auto-trace\"}'",
"test": "jest"
},
"dependencies": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/serverless.yml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ functions:
path: /{proxy+}
method: any
- schedule:
rate: rate(1 day)
rate: rate(2 hours)
input:
action: auto-trace

Expand Down
3 changes: 1 addition & 2 deletions packages/api/src/events/auto-trace.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ const updateLambda = async (lambda, arnBase, edgeEndpoint) => {
},
});

const res = await new LambdaClient().send(command);
logger.info(res);
await new LambdaClient().send(command);
};

const getLambdaTags = async (lambda) => {
Expand Down
17 changes: 6 additions & 11 deletions packages/deploy-script/src/deploy.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,17 +9,17 @@ import {
} from "@aws-sdk/client-apigatewayv2";
import { checkHasUsers, createAdminUser } from "./users.js";

const exec = (command, options = {}) => {
const exec = (command, options = {}, prefix = "") => {
const child = child_process.exec(command, {
...options,
env: { ...process.env, ...(options.env || {}) },
});

child.stdout?.on("data", function (data) {
console.log(data?.trim());
console.log(prefix + data?.trim());
});
child.stderr?.on("data", function (data) {
console.error(data?.trim());
console.error(prefix + data?.trim());
});

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -85,6 +85,8 @@ const deploy = async (answers) => {
console.log(chalk.blue("Deploying..."));
await exec("yarn deploy", { cwd: tmpPath });

const endpoint = await getApiEndpoint();

// Create user
let adminPassword;
if (await checkHasUsers()) {
Expand All @@ -96,14 +98,7 @@ const deploy = async (answers) => {

// Run auto-trace
console.log(chalk.blue("Auto tracing lambdas..."));
const endpoint = await getApiEndpoint();
try {
await fetch(`https://${endpoint}/api/auto-trace`, {
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify({ token: answers.tracerToken }),
});
} catch (e) {}
await exec("yarn auto-trace", { cwd: tmpPath }, " ");

return { endpoint, adminPassword };
};
Expand Down
3 changes: 3 additions & 0 deletions turbo.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@
"test:e2e": {
"inputs": ["$TURBO_DEFAULT$", ".env*"]
},
"auto-trace": {
"inputs": ["$TURBO_DEFAULT$", ".env*"]
},
"dev": {
"cache": false,
"persistent": true
Expand Down

0 comments on commit 3b6fc6c

Please sign in to comment.