034058bce1
## Summary Adds observability to the task metadata cache that backs the trigger hot path. Follow-up to #3930, which made locked-version triggers fall back to the primary when the read replica returns no row; this makes the cache's effectiveness (and that fallback) measurable instead of inferred. ## What it emits A single bounded counter `task_meta_cache.resolve`, labeled by lookup path (`locked` / `current`) and the source that satisfied it (`cache` / `replica` / `writer` / `miss`): - `cache / total` is the cache hit rate (its inverse is how cold the cache runs). - `writer / total` is how often the read replica returned empty for a row the primary had (the condition #3930 recovers from). Labels are bounded, with no per-env / worker / slug cardinality. TRI-10873
39 lines
1.5 KiB
TypeScript
39 lines
1.5 KiB
TypeScript
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 });
|
|
}
|