Skip to content

Commit 0da20d4

Browse files
matthewdavidrodgersemily-shen
authored andcommitted
WC-3584 Add eyeball routing config
Provided via a new optional param binding. When provided, it contains info about free tier limiting for this account.
1 parent 4ef1858 commit 0da20d4

File tree

4 files changed

+44
-6
lines changed

4 files changed

+44
-6
lines changed

packages/workers-shared/router-worker/src/configuration.ts

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
1-
import type { RouterConfig } from "../../utils/types";
1+
import type { EyeballRouterConfig, RouterConfig } from "../../utils/types";
22

3-
export const applyConfigurationDefaults = (
3+
type RequiredEyeballRouterConfig = Required<Exclude<EyeballRouterConfig, null>>;
4+
5+
export const applyRouterConfigDefaults = (
46
configuration?: RouterConfig
57
): Required<RouterConfig> => {
68
return {
@@ -15,3 +17,11 @@ export const applyConfigurationDefaults = (
1517
},
1618
};
1719
};
20+
21+
export const applyEyeballConfigDefaults = (
22+
eyeballConfiguration?: EyeballRouterConfig
23+
): RequiredEyeballRouterConfig => {
24+
return {
25+
limitedAssetsOnly: eyeballConfiguration?.limitedAssetsOnly ?? false,
26+
};
27+
};

packages/workers-shared/router-worker/src/worker.ts

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,13 @@ import { PerformanceTimer } from "../../utils/performance";
33
import { setupSentry } from "../../utils/sentry";
44
import { mockJaegerBinding } from "../../utils/tracing";
55
import { Analytics, DISPATCH_TYPE, STATIC_ROUTING_DECISION } from "./analytics";
6-
import { applyConfigurationDefaults } from "./configuration";
6+
import {
7+
applyEyeballConfigDefaults,
8+
applyRouterConfigDefaults,
9+
} from "./configuration";
710
import type AssetWorker from "../../asset-worker";
811
import type {
12+
EyeballRouterConfig,
913
JaegerTracing,
1014
RouterConfig,
1115
UnsafePerformanceTimer,
@@ -16,6 +20,7 @@ export interface Env {
1620
ASSET_WORKER: Service<AssetWorker>;
1721
USER_WORKER: Fetcher;
1822
CONFIG: RouterConfig;
23+
EYEBALL_CONFIG: EyeballRouterConfig;
1924

2025
SENTRY_DSN: string;
2126
ENVIRONMENT: Environment;
@@ -55,7 +60,8 @@ export default {
5560
);
5661

5762
const hasStaticRouting = env.CONFIG.static_routing !== undefined;
58-
const config = applyConfigurationDefaults(env.CONFIG);
63+
const config = applyRouterConfigDefaults(env.CONFIG);
64+
const eyeballConfig = applyEyeballConfigDefaults(env.EYEBALL_CONFIG);
5965

6066
const url = new URL(request.url);
6167

@@ -77,7 +83,11 @@ export default {
7783

7884
const maybeSecondRequest = request.clone();
7985

80-
const routeToUserWorker = async ({ asset }: { asset: "static_routing" | "none" }) => {
86+
const routeToUserWorker = async ({
87+
asset,
88+
}: {
89+
asset: "static_routing" | "none";
90+
}) => {
8191
if (!config.has_user_worker) {
8292
throw new Error(
8393
"Fetch for user worker without having a user worker binding"
@@ -95,7 +105,11 @@ export default {
95105
});
96106
};
97107

98-
const routeToAssets = async ({ asset }: { asset: "static_routing" | "found" | "none" }) => {
108+
const routeToAssets = async ({
109+
asset,
110+
}: {
111+
asset: "static_routing" | "found" | "none";
112+
}) => {
99113
analytics.setData({ dispatchtype: DISPATCH_TYPE.ASSETS });
100114
return await env.JAEGER.enterSpan("dispatch_assets", async (span) => {
101115
span.setTags({

packages/workers-shared/router-worker/wrangler.jsonc

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,12 @@
2525
"type": "param",
2626
"param": "routerConfig",
2727
},
28+
{
29+
"name": "EYEBALL_CONFIG",
30+
"type": "param",
31+
"param": "eyeballRouterConfig",
32+
"optional": true,
33+
},
2834
{
2935
"name": "ASSET_WORKER",
3036
"type": "internal_assets",

packages/workers-shared/utils/types.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@ export const RouterConfigSchema = z.object({
2020
...InternalConfigSchema.shape,
2121
});
2222

23+
export const EyeballRouterConfigSchema = z.union([
24+
z.object({
25+
limitedAssetsOnly: z.boolean().optional(),
26+
}),
27+
z.null(),
28+
]);
29+
2330
const MetadataStaticRedirectEntry = z.object({
2431
status: z.number(),
2532
to: z.string(),
@@ -79,6 +86,7 @@ export const AssetConfigSchema = z.object({
7986
...InternalConfigSchema.shape,
8087
});
8188

89+
export type EyeballRouterConfig = z.infer<typeof EyeballRouterConfigSchema>;
8290
export type RouterConfig = z.infer<typeof RouterConfigSchema>;
8391
export type AssetConfig = z.infer<typeof AssetConfigSchema>;
8492

0 commit comments

Comments
 (0)