-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Expand file tree
/
Copy pathtaskMetadataCacheTelemetry.server.ts
More file actions
38 lines (34 loc) · 1.49 KB
/
Copy pathtaskMetadataCacheTelemetry.server.ts
File metadata and controls
38 lines (34 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
import { getMeter } from "@internal/tracing";
const meter = getMeter("task-meta-cache");
/**
* One counter for every task-metadata resolution on the trigger path, with two
* bounded labels:
*
* path: "locked" - lockToVersion / triggerAndWait (reads the by-worker hash)
* "current" - default trigger (reads the env hash)
* source: where the metadata was resolved from:
* "cache" - Redis hit (warm)
* "replica" - cache miss, the read replica had the row
* "writer" - cache miss + replica empty, the primary had the row
* (i.e. the replica was stale for an existing row)
* "miss" - not found anywhere (genuinely not registered)
*
* Derived signals:
* cache / total -> cache hit rate (the inverse is coldness)
* writer / total -> how often the replica returned empty for
* a row the primary had
*
* No env / worker / slug labels: those are unbounded in production.
*/
const resolveCounter = meter.createCounter("task_meta_cache.resolve", {
description:
"Task metadata resolutions on the trigger path, by lookup path and the source that satisfied them",
});
export type TaskMetaResolvePath = "locked" | "current";
export type TaskMetaResolveSource = "cache" | "replica" | "writer" | "miss";
export function recordTaskMetaResolve(
path: TaskMetaResolvePath,
source: TaskMetaResolveSource
): void {
resolveCounter.add(1, { path, source });
}