Skip to content

Commit 1bac1ef

Browse files
committed
fix: tracer bucket name
1 parent 966b89e commit 1bac1ef

File tree

8 files changed

+72
-181
lines changed

8 files changed

+72
-181
lines changed

packages/api/serverless.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ params:
1212
CUSTOM_DOMAIN: ${env:CUSTOM_DOMAIN, ""}
1313
HAS_CUSTOM_DOMAIN: ${strToBool(${env:HAS_CUSTOM_DOMAIN, "false"})}
1414
TRACER_TOKEN: ${env:TRACER_TOKEN, ""}
15+
BUCKET_SUFFIX: ${env:BUCKET_SUFFIX, ""}
1516

1617
custom:
1718
customDomain:
@@ -22,7 +23,7 @@ custom:
2223
endpointType: regional
2324
apiType: http
2425
logRetentionInDays: 14
25-
bucketName: ${self:service}-traces-${sls:stage}${param:TRACER_TOKEN}
26+
bucketName: ${self:service}-traces-${sls:stage}${param:BUCKET_SUFFIX}
2627

2728
package:
2829
individually: true

packages/api/src/routes/auth/index.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,15 +30,12 @@ app.post("/login", async (c) => {
3030

3131
const id = `${uuid()}.${new Date().valueOf()}`;
3232

33-
await put(
34-
{
35-
pk: `access-token#${id}`,
36-
type: 'access-token',
37-
sk: user.pk,
38-
accessTokenType: "dashboard",
39-
},
40-
true,
41-
);
33+
await put({
34+
pk: `access-token#${id}`,
35+
type: "access-token",
36+
sk: user.pk,
37+
accessTokenType: "dashboard",
38+
});
4239

4340
await update({
4441
Key: {

packages/deploy-script/src/deploy.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@ const deploy = async (answers) => {
7878
`RETENTION_DAYS=${answers.RETENTION_DAYS}\n` +
7979
`CUSTOM_DOMAIN=${answers.CUSTOM_DOMAIN}\n` +
8080
`TRACER_TOKEN=${answers.tracerToken}\n` +
81+
`BUCKET_SUFFIX=${answers.tracerToken.replace("t_", "")}\n` +
8182
`HAS_CUSTOM_DOMAIN=${answers.CUSTOM_DOMAIN ? "true" : "false"}\n`,
8283
);
8384

packages/deploy-script/src/index.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ const questions = [
3838
type: "input",
3939
name: "RETENTION_DAYS",
4040
message: "How many days do you want to retain data for?",
41-
default: previousConfig.retentionDays || 30,
41+
default: previousConfig.retentionDays || 14,
4242
validate: (value) => {
4343
const valid = !Number.isNaN(Number.parseFloat(value));
4444
return valid || "Please enter a number";

packages/e2e-test/jest.setup.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import deployTraceStack from "../deploy-script/src/deploy.js";
66
const setup = async () => {
77
await deploy("testing");
88
await deployTraceStack({
9-
tracerToken: `t_${crypto.randomBytes(16).toString("hex")}`,
9+
tracerToken: `t_test1234567890`,
1010
});
1111
};
1212

packages/e2e-test/package.json

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
"test:e2e": "yarn node --experimental-vm-modules $(yarn bin jest)"
77
},
88
"devDependencies": {
9-
"@aws-sdk/client-dynamodb": "^3.658.1",
10-
"@aws-sdk/lib-dynamodb": "^3.658.1",
9+
"@aws-sdk/client-s3": "^3.777.0",
1110
"@laconia/invoker": "^1.14.0",
1211
"@laconia/test": "^1.14.0",
1312
"aws-testing-library": "^4.0.6",

packages/e2e-test/tests/utils.js

Lines changed: 59 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,78 +1,75 @@
11
import invoker from "@laconia/test";
2-
import { DynamoDBClient } from "@aws-sdk/client-dynamodb";
32
import {
4-
DeleteCommand,
5-
DynamoDBDocumentClient,
6-
ScanCommand,
7-
QueryCommand,
8-
} from "@aws-sdk/lib-dynamodb";
9-
10-
const translateConfig = {
11-
marshallOptions: {
12-
convertEmptyValues: false,
13-
},
14-
};
15-
16-
export const dynamo = DynamoDBDocumentClient.from(
17-
new DynamoDBClient(),
18-
translateConfig,
19-
);
3+
DeleteObjectsCommand,
4+
GetObjectCommand,
5+
ListObjectsV2Command,
6+
S3Client,
7+
} from "@aws-sdk/client-s3";
208

219
export const invoke = async (lambda = "main", action = "") => {
2210
try {
2311
await invoker(`trace-e2e-testing-${lambda}`).requestResponse({ action });
2412
} catch (error) {}
2513
};
2614

15+
const Bucket = `trace-stack-traces-devtest1234567890`;
16+
2717
export const truncate = () => {
28-
return dynamo
29-
.send(
30-
new ScanCommand({
31-
TableName: "trace-stack-dev",
32-
}),
33-
)
34-
.then(async ({ Items, LastEvaluatedKey }) => {
35-
for (const item of Items || []) {
36-
await dynamo.send(
37-
new DeleteCommand({
38-
TableName: "trace-stack-dev",
39-
Key: {
40-
pk: item.pk,
41-
sk: item.sk,
42-
},
43-
}),
44-
);
45-
}
46-
if (LastEvaluatedKey) {
47-
await truncate();
48-
}
49-
});
18+
const s3 = new S3Client();
19+
const params = { Bucket };
20+
return s3.send(new ListObjectsV2Command(params)).then(({ Contents }) => {
21+
if (!Contents) return;
22+
const deleteParams = {
23+
Bucket,
24+
Delete: {
25+
Objects: Contents.map((item) => ({ Key: item.Key })),
26+
},
27+
};
28+
return s3.send(new DeleteObjectsCommand(deleteParams));
29+
});
5030
};
5131

52-
export const query = async (
53-
/** @type {Omit<import("@aws-sdk/lib-dynamodb").QueryCommandInput, "TableName">} */ params,
54-
) => {
55-
return await dynamo.send(
56-
new QueryCommand({
57-
TableName: "trace-stack-dev",
58-
...params,
59-
}),
60-
);
32+
const listByPrefix = async (prefix) => {
33+
const s3 = new S3Client();
34+
const output = [];
35+
let pageToken = undefined;
36+
37+
do {
38+
const params = {
39+
Bucket: process.env.STORAGE_BUCKET_NAME,
40+
Prefix: prefix,
41+
ContinuationToken: pageToken,
42+
};
43+
44+
const command = new ListObjectsV2Command(params);
45+
const { Contents, NextContinuationToken } = await s3.send(command);
46+
47+
output.push(...(Contents?.map((item) => item.Key) || []));
48+
pageToken = NextContinuationToken;
49+
} while (pageToken && output.length < 10000);
50+
51+
return output;
6152
};
6253

63-
export const getErrors = async () => {
64-
const { Items } = await query({
65-
KeyConditionExpression: "#type = :type",
66-
ExpressionAttributeNames: {
67-
"#type": "type",
68-
},
69-
ExpressionAttributeValues: {
70-
":type": "error",
71-
},
72-
IndexName: "type-lastSeen",
73-
Limit: 50,
74-
ScanIndexForward: false,
75-
});
54+
export const get = async (key) => {
55+
const s3 = new S3Client();
56+
const params = {
57+
Bucket,
58+
Key: key,
59+
};
60+
61+
const { Body } = await s3.send(new GetObjectCommand(params));
62+
const string = await Body?.transformToString();
63+
return string && JSON.parse(string);
64+
};
7665

77-
return Items;
66+
const listAndRead = async (prefix) => {
67+
const keys = await listByPrefix(prefix);
68+
const data = await Promise.all(keys.map(async (key) => get(key)));
69+
70+
return data;
71+
};
72+
73+
export const getErrors = async () => {
74+
return listAndRead("errors/");
7875
};

yarn.lock

Lines changed: 1 addition & 105 deletions
Original file line numberDiff line numberDiff line change
@@ -595,58 +595,6 @@ __metadata:
595595
languageName: node
596596
linkType: hard
597597

598-
"@aws-sdk/client-dynamodb@npm:^3.658.1":
599-
version: 3.658.1
600-
resolution: "@aws-sdk/client-dynamodb@npm:3.658.1"
601-
dependencies:
602-
"@aws-crypto/sha256-browser": "npm:5.2.0"
603-
"@aws-crypto/sha256-js": "npm:5.2.0"
604-
"@aws-sdk/client-sso-oidc": "npm:3.658.1"
605-
"@aws-sdk/client-sts": "npm:3.658.1"
606-
"@aws-sdk/core": "npm:3.658.1"
607-
"@aws-sdk/credential-provider-node": "npm:3.658.1"
608-
"@aws-sdk/middleware-endpoint-discovery": "npm:3.654.0"
609-
"@aws-sdk/middleware-host-header": "npm:3.654.0"
610-
"@aws-sdk/middleware-logger": "npm:3.654.0"
611-
"@aws-sdk/middleware-recursion-detection": "npm:3.654.0"
612-
"@aws-sdk/middleware-user-agent": "npm:3.654.0"
613-
"@aws-sdk/region-config-resolver": "npm:3.654.0"
614-
"@aws-sdk/types": "npm:3.654.0"
615-
"@aws-sdk/util-endpoints": "npm:3.654.0"
616-
"@aws-sdk/util-user-agent-browser": "npm:3.654.0"
617-
"@aws-sdk/util-user-agent-node": "npm:3.654.0"
618-
"@smithy/config-resolver": "npm:^3.0.8"
619-
"@smithy/core": "npm:^2.4.6"
620-
"@smithy/fetch-http-handler": "npm:^3.2.8"
621-
"@smithy/hash-node": "npm:^3.0.6"
622-
"@smithy/invalid-dependency": "npm:^3.0.6"
623-
"@smithy/middleware-content-length": "npm:^3.0.8"
624-
"@smithy/middleware-endpoint": "npm:^3.1.3"
625-
"@smithy/middleware-retry": "npm:^3.0.21"
626-
"@smithy/middleware-serde": "npm:^3.0.6"
627-
"@smithy/middleware-stack": "npm:^3.0.6"
628-
"@smithy/node-config-provider": "npm:^3.1.7"
629-
"@smithy/node-http-handler": "npm:^3.2.3"
630-
"@smithy/protocol-http": "npm:^4.1.3"
631-
"@smithy/smithy-client": "npm:^3.3.5"
632-
"@smithy/types": "npm:^3.4.2"
633-
"@smithy/url-parser": "npm:^3.0.6"
634-
"@smithy/util-base64": "npm:^3.0.0"
635-
"@smithy/util-body-length-browser": "npm:^3.0.0"
636-
"@smithy/util-body-length-node": "npm:^3.0.0"
637-
"@smithy/util-defaults-mode-browser": "npm:^3.0.21"
638-
"@smithy/util-defaults-mode-node": "npm:^3.0.21"
639-
"@smithy/util-endpoints": "npm:^2.1.2"
640-
"@smithy/util-middleware": "npm:^3.0.6"
641-
"@smithy/util-retry": "npm:^3.0.6"
642-
"@smithy/util-utf8": "npm:^3.0.0"
643-
"@smithy/util-waiter": "npm:^3.1.5"
644-
tslib: "npm:^2.6.2"
645-
uuid: "npm:^9.0.1"
646-
checksum: 10c0/42a0190abed8b512cbc4c87572161dc11863d89e958a2ffdc8e8b4891252799fd558bd0d693d5513f1fee7b4a2f7b2004f8c5bf6e80eb6fbffeeb93310dcd600
647-
languageName: node
648-
linkType: hard
649-
650598
"@aws-sdk/client-dynamodb@npm:^3.665.0":
651599
version: 3.665.0
652600
resolution: "@aws-sdk/client-dynamodb@npm:3.665.0"
@@ -2346,21 +2294,6 @@ __metadata:
23462294
languageName: node
23472295
linkType: hard
23482296

2349-
"@aws-sdk/lib-dynamodb@npm:^3.658.1":
2350-
version: 3.658.1
2351-
resolution: "@aws-sdk/lib-dynamodb@npm:3.658.1"
2352-
dependencies:
2353-
"@aws-sdk/util-dynamodb": "npm:3.658.1"
2354-
"@smithy/core": "npm:^2.4.6"
2355-
"@smithy/smithy-client": "npm:^3.3.5"
2356-
"@smithy/types": "npm:^3.4.2"
2357-
tslib: "npm:^2.6.2"
2358-
peerDependencies:
2359-
"@aws-sdk/client-dynamodb": ^3.658.1
2360-
checksum: 10c0/5708711fa26ef7d0ced3bf079535a66a19c3e87ce8e16480fab84a12ba9e745e5cfef99673cb64dac9b2ddea31af125319d3e401a03890d675998c2339cb73da
2361-
languageName: node
2362-
linkType: hard
2363-
23642297
"@aws-sdk/lib-dynamodb@npm:^3.665.0":
23652298
version: 3.665.0
23662299
resolution: "@aws-sdk/lib-dynamodb@npm:3.665.0"
@@ -2420,20 +2353,6 @@ __metadata:
24202353
languageName: node
24212354
linkType: hard
24222355

2423-
"@aws-sdk/middleware-endpoint-discovery@npm:3.654.0":
2424-
version: 3.654.0
2425-
resolution: "@aws-sdk/middleware-endpoint-discovery@npm:3.654.0"
2426-
dependencies:
2427-
"@aws-sdk/endpoint-cache": "npm:3.572.0"
2428-
"@aws-sdk/types": "npm:3.654.0"
2429-
"@smithy/node-config-provider": "npm:^3.1.7"
2430-
"@smithy/protocol-http": "npm:^4.1.3"
2431-
"@smithy/types": "npm:^3.4.2"
2432-
tslib: "npm:^2.6.2"
2433-
checksum: 10c0/1954765fca395258f9e47e8def56f554f8d91e056627cb2929d17f9a6791a46035ff54cbbc29984d6c0e847e363a7cc5dcb3a4bb959fe13adddd61d6bc5629f6
2434-
languageName: node
2435-
linkType: hard
2436-
24372356
"@aws-sdk/middleware-endpoint-discovery@npm:3.664.0":
24382357
version: 3.664.0
24392358
resolution: "@aws-sdk/middleware-endpoint-discovery@npm:3.664.0"
@@ -3100,17 +3019,6 @@ __metadata:
31003019
languageName: node
31013020
linkType: hard
31023021

3103-
"@aws-sdk/util-dynamodb@npm:3.658.1":
3104-
version: 3.658.1
3105-
resolution: "@aws-sdk/util-dynamodb@npm:3.658.1"
3106-
dependencies:
3107-
tslib: "npm:^2.6.2"
3108-
peerDependencies:
3109-
"@aws-sdk/client-dynamodb": ^3.658.1
3110-
checksum: 10c0/521fc08497671444b6e0501df2f1a6657f5b221ab5deda404f881e911e29547e73d0a1ee9aa21651aa61fd3022f3c01060289e5b9b2933f805db41e70bf330ef
3111-
languageName: node
3112-
linkType: hard
3113-
31143022
"@aws-sdk/util-dynamodb@npm:3.665.0":
31153023
version: 3.665.0
31163024
resolution: "@aws-sdk/util-dynamodb@npm:3.665.0"
@@ -9364,17 +9272,6 @@ __metadata:
93649272
languageName: node
93659273
linkType: hard
93669274

9367-
"@smithy/util-waiter@npm:^3.1.5":
9368-
version: 3.1.5
9369-
resolution: "@smithy/util-waiter@npm:3.1.5"
9370-
dependencies:
9371-
"@smithy/abort-controller": "npm:^3.1.4"
9372-
"@smithy/types": "npm:^3.4.2"
9373-
tslib: "npm:^2.6.2"
9374-
checksum: 10c0/d72733480f08a570a08eb1c4e57ac5779d2f41598d9608d62419e9adfccb86295b8c60103c51b3338167bb2f9179483db24c3dc9585da867419c5abf9efcad98
9375-
languageName: node
9376-
linkType: hard
9377-
93789275
"@smithy/util-waiter@npm:^3.1.6":
93799276
version: 3.1.6
93809277
resolution: "@smithy/util-waiter@npm:3.1.6"
@@ -9607,8 +9504,7 @@ __metadata:
96079504
version: 0.0.0-use.local
96089505
resolution: "@trace-stack/e2e-test@workspace:packages/e2e-test"
96099506
dependencies:
9610-
"@aws-sdk/client-dynamodb": "npm:^3.658.1"
9611-
"@aws-sdk/lib-dynamodb": "npm:^3.658.1"
9507+
"@aws-sdk/client-s3": "npm:^3.777.0"
96129508
"@laconia/invoker": "npm:^1.14.0"
96139509
"@laconia/test": "npm:^1.14.0"
96149510
aws-testing-library: "npm:^4.0.6"

0 commit comments

Comments
 (0)