Skip to content

Commit 23d0983

Browse files
n1ru4lkamilkisiela
andauthored
feat: CDN request retry race from multiple S3 buckets (#5543)
Co-authored-by: Kamil Kisiela <[email protected]>
1 parent 9eb5dcc commit 23d0983

File tree

13 files changed

+825
-137
lines changed

13 files changed

+825
-137
lines changed

.eslintrc.cjs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ const rulesToExtends = Object.fromEntries(
1717
'import/first',
1818
'no-restricted-globals',
1919
'@typescript-eslint/no-unused-vars',
20-
'unicorn/no-useless-fallback-in-spread',
2120
'unicorn/no-array-push-push',
2221
'no-else-return',
2322
'no-lonely-if',

deployment/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ const s3Mirror = deployS3Mirror();
8484

8585
const cdn = deployCFCDN({
8686
s3,
87+
s3Mirror,
8788
sentry,
8889
environment,
8990
});

deployment/services/cf-cdn.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,12 @@ export class CDNSecret extends ServiceSecret<{
1515
export function deployCFCDN({
1616
environment,
1717
s3,
18+
s3Mirror,
1819
sentry,
1920
}: {
2021
environment: Environment;
2122
s3: S3;
23+
s3Mirror: S3;
2224
sentry: Sentry;
2325
}) {
2426
const cfConfig = new pulumi.Config('cloudflareCustom');
@@ -35,6 +37,7 @@ export function deployCFCDN({
3537
sentryDsn: sentry.enabled && sentry.secret ? sentry.secret?.raw.dsn : '',
3638
release: environment.release,
3739
s3,
40+
s3Mirror,
3841
});
3942

4043
const deployedCdn = cdn.deploy();

deployment/utils/cloudflare.ts

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ export class CloudflareCDN {
1313
sentryDsn: string | pulumi.Output<string>;
1414
release: string;
1515
s3: S3;
16+
s3Mirror: S3;
1617
},
1718
) {}
1819

@@ -54,6 +55,10 @@ export class CloudflareCDN {
5455
name: 'R2_ANALYTICS',
5556
dataset: `hive_ha_cdn_r2_${this.config.envName}`,
5657
},
58+
{
59+
name: 'S3_ANALYTICS',
60+
dataset: `hive_ha_cdn_s3_${this.config.envName}`,
61+
},
5762
{
5863
name: 'RESPONSE_ANALYTICS',
5964
dataset: `hive_ha_cdn_response_${this.config.envName}`,
@@ -88,6 +93,22 @@ export class CloudflareCDN {
8893
name: 'S3_BUCKET_NAME',
8994
text: this.config.s3.secret.raw.bucket,
9095
},
96+
{
97+
name: 'S3_MIRROR_ENDPOINT',
98+
text: this.config.s3Mirror.secret.raw.endpoint,
99+
},
100+
{
101+
name: 'S3_MIRROR_ACCESS_KEY_ID',
102+
text: this.config.s3Mirror.secret.raw.accessKeyId,
103+
},
104+
{
105+
name: 'S3_MIRROR_SECRET_ACCESS_KEY',
106+
text: this.config.s3Mirror.secret.raw.secretAccessKey,
107+
},
108+
{
109+
name: 'S3_MIRROR_BUCKET_NAME',
110+
text: this.config.s3Mirror.secret.raw.bucket,
111+
},
91112
],
92113
});
93114

packages/services/cdn-worker/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
"itty-router": "4.2.2",
3030
"itty-router-extras": "0.4.6",
3131
"toucan-js": "3.4.0",
32+
"undici": "6.19.8",
3233
"zod": "3.23.8"
3334
}
3435
}

packages/services/cdn-worker/src/analytics.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ type Event =
5555
value: [string, string] | [string];
5656
}
5757
| {
58-
type: 'r2';
58+
type: 'r2' | 's3';
5959
action:
6060
| 'GET artifact'
6161
| 'GET cdn-legacy-keys'
@@ -79,6 +79,7 @@ export function createAnalytics(
7979
error: AnalyticsEngine;
8080
keyValidation: AnalyticsEngine;
8181
r2: AnalyticsEngine;
82+
s3: AnalyticsEngine;
8283
response: AnalyticsEngine;
8384
} | null = null,
8485
) {
@@ -99,7 +100,8 @@ export function createAnalytics(
99100
blobs: event.value,
100101
});
101102
case 'r2':
102-
return engines.r2.writeDataPoint({
103+
case 's3':
104+
return engines[event.type].writeDataPoint({
103105
blobs: [event.action, event.statusCodeOrErrCode.toString(), targetId],
104106
doubles: [event.duration],
105107
indexes: [targetId.substring(0, 32)],

0 commit comments

Comments
 (0)