main
1import type { Option } from '../option.ts';
3// Named TTLs for the one cached ruleset. cloudflare.config.ts publishes the same numbers as text bindings.
4import { parseFlagKey, parseFlagSalt, type FlagKey, type FlagSalt } from './brand.ts';
6function knownFlagKey(raw: string): FlagKey {
7 const parsed = parseFlagKey(raw);
8 if (parsed.kind === 'key') return parsed.value;
9 throw new Error(parsed.reason);
10}
12function knownFlagSalt(raw: string): FlagSalt {
13 const parsed = parseFlagSalt(raw);
14 if (parsed.kind === 'salt') return parsed.value;
15 throw new Error(parsed.reason);
16}
18// max-age is the fresh window. stale-while-revalidate is how long a failed revalidation may still be served.
19// Neither value is an s-maxage, and the response must not say must-revalidate: those directives
20// disable stale-while-revalidate. An absent ruleset uses this same header. no-store is a bypass.
22export const FLAGS_MAX_AGE_S = 5;
23export const FLAGS_SWR_S = 60;
24/** One tag for the one cached ruleset. Invalidation is this tag, from the FlagsCache entrypoint. */
25export const FLAGS_CACHE_TAG = 'flags';
26/** The only R2 object. Its ETag is the revision. History is the write log, not more objects. */
27export const FLAGS_OBJECT_KEY = 'flags/config.json';
28export const FLAGS_CACHE_PATH = '/config';
29export const FLAGS_CACHE_URL = 'https://flags.internal/config';
31/** 10_000 buckets. One basis point is one bucket, so an allocation needs no rounding. */
32export const BUCKETS = 10_000;
33/** Inclusive top of a rollout: 10_000 basis points is 100% of units. */
34export const BASIS_POINTS = BUCKETS;
36/** Salt assigned when setRollout creates a flag. Changing it would rebucket everyone, so it stays put. */
37export const DEFAULT_SALT: FlagSalt = knownFlagSalt('v1');
39/**
40 * The example gate on GET /. Off unless this flag's variant is boolean true.
41 * Missing config, a missing flag, and percent 0 all leave the usage text unchanged.
42 */
43export const USAGE_NOTE_FLAG: FlagKey = knownFlagKey('ply.usage.note');
45/** The one line GET / appends when ply.usage.note resolves to boolean true. Off leaves GET / unchanged. */
46export const USAGE_NOTE_LINE = 'ply.usage.note is on for this unit.';
48export const MAX_FLAGS = 64;
49export const MAX_RULES = 16;
50export const MAX_UNITS = 128;
51export const MAX_ATTRIBUTES = 32;
52export const MAX_DOCUMENT_BYTES = 64 * 1024;
54/** Expected revision for the first create. The conditional put uses If-None-Match: *. */
55export const ABSENT_REVISION = '';
57export function cacheControl(maxAgeS: number, swrS: number): string {
58 return `public, max-age=${maxAgeS}, stale-while-revalidate=${swrS}`;
59}
61export function ttlFromEnv(raw: Option<string>, fallback: number): number {
62 if (raw.tag === 'none' || raw.value === '') return fallback;
63 if (!/^[1-9]\d{0,6}$/.test(raw.value)) return fallback;
64 const n = Number(raw.value);
65 return Number.isSafeInteger(n) ? n : fallback;
66}
Diagnostics4 git calls · 26 ms
CallStatusSizeTime026 ms
discover200152 B2 ms
git.upload-pack discover http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=2 git.response.bytes=152 git.server.agent=gitty/1.0 git.server.object_format=sha1 git.server.caps=agent ls-refs fetch object-format git.server.fetch=shallow filter sideband-all git.protocol.version=2 git.pkt.frames=8 git.pkt.data=6 git.pkt.flush=2 git.pkt.delim=0 git.pkt.bytes=152 git.pkt.payload.max=34
ls-refs200145 B3 ms
git.upload-pack ls-refs http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=ls-refs git.upstream.dur_ms=3 git.response.bytes=145 git.response.cache=UPDATING git.response.duration_ms=3 git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=145 git.pkt.payload.max=76 git.ls_refs.count=2 git.ls_refs.head=refs/heads/main
fetchblob:none · deepen 1020040 KiB · hit3 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=3 git.response.bytes=41349 git.response.cache=HIT git.response.duration_ms=3 git.fetch.filter=blob:none git.fetch.filter.requested=tree:0 git.fetch.filter.fallback=blob:none git.fetch.filter.learned=false git.fetch.wants=526b305930b8ef382f2d7a1f9c0238730a585921 git.fetch.haves.count=0 git.fetch.deepen=10 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=6 git.pkt.data=4 git.pkt.flush=1 git.pkt.delim=1 git.pkt.bytes=41349 git.pkt.payload.max=41254 git.sideband.band1.bytes=41253 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0 git.pack.objects=61 git.pack.bytes=41253 git.pack.ofs_delta=0 git.pack.ref_delta=0 git.pack.chain.max=0 git.pack.trailer=ab60efef4b7243678c75de64a4386986ee885c1c git.pack.full=61Open pack map
fetch2001.3 KiB · hit20 ms
git.upload-pack fetch http.response.status_code=200 git.upstream.cf_ray=- git.upstream.phase=fetch git.upstream.dur_ms=20 git.response.bytes=1381 git.response.cache=HIT git.response.duration_ms=20 git.fetch.wants=0cad731bb0584efb4c8978fc9ea03d5b4c2a9e5d git.fetch.haves.count=0 git.fetch.deepen=0 git.fetch.thin_pack=false git.fetch.ofs_delta=true git.protocol.version=2 git.pkt.frames=3 git.pkt.data=2 git.pkt.flush=1 git.pkt.delim=0 git.pkt.bytes=1381 git.pkt.payload.max=1360 git.sideband.band1.bytes=1359 git.sideband.band2.bytes=0 git.sideband.band3.bytes=0
Each row is one HTTP round trip ply made to the git server for this page, on one timeline. discover asks what the server speaks, ls-refs lists branch tips, fetch brings objects by id. A hit was served by Workers Cache. Tap a row for its wire details.
- Remote
- https://5ad2236b39de4c8bd8f6270ea63f3ea9.artifacts.cloudflare.net/git/public-v0/ply-web.git
- Ref
- refs/heads/main
- Commit
- 526b305930b8ef382f2d7a1f9c0238730a585921
- cf-ray
- a5e306f6d8b415db
- Request
- 81a3ed1a…
- Protocol
- v2 · sha1
- Agent
- gitty/1.0
- Filter
- advertised
- Fetch
- shallow filter sideband-all
- Capabilities
- agent ls-refs fetch object-format