MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / meta

Function meta

telemetry-dashboard/src/api.ts:239–306  ·  view source on GitHub ↗

* How fresh the data is, and whether either writer has stopped. * * The page's ranges end on today; this is what tells it how much of that range * each kind of number actually covers. Machine counts (`machine_days`, * `machine_first_seen`) are written by the ingest worker as events arrive, so th

(env: Env)

Source from the content-addressed store, hash-verified

237 * for seven weeks. Each flag is a fact the page states, not a tuned threshold.
238 */
239async function meta(env: Env): Promise<ApiResult> {
240 const now = Date.now();
241 const today = utcDay(now);
242 const yesterday = utcDay(now - DAY_MS);
243 const row = await env.DB.prepare(
244 `SELECT (SELECT max(day) FROM daily_event_counts) AS latest_rollup_day,
245 (SELECT min(day) FROM daily_event_counts) AS earliest_rollup_day,
246 (SELECT max(day) FROM machine_days) AS latest_active_day,
247 (SELECT min(day) FROM machine_days) AS earliest_active_day,
248 (SELECT min(day) FROM events) AS earliest_raw_day,
249 (SELECT max(day) FROM events) AS latest_raw_day,
250 (SELECT max(day) FROM usage_daily) AS latest_usage_day,
251 (SELECT count(*) FROM machine_days WHERE day = ?) AS machines_yesterday`,
252 )
253 .bind(yesterday)
254 .first<MetaRow>();
255
256 const latestRollup = row?.latest_rollup_day ?? null;
257 const latestRaw = row?.latest_raw_day ?? null;
258 const latestUsage = row?.latest_usage_day ?? null;
259 const latestActive = row?.latest_active_day ?? null;
260 // Ingest stores lifecycle events in `events` and usage counters in `usage_daily`, so
261 // either one arriving means it is working — a day of usage and no installs or index
262 // runs is quiet, not stalled.
263 const latestIngest =
264 latestUsage !== null && (latestRaw === null || latestUsage > latestRaw) ? latestUsage : latestRaw;
265
266 // Stalled: nothing stored since before yesterday. (Client clocks may run a few
267 // minutes ahead, so the latest day can be tomorrow — that is fresh, not stale.) Usage
268 // counters get a day more, because a client uploads a day's counters only once that
269 // day is over: just after midnight UTC the newest one can be the day before yesterday.
270 const ingestStalled =
271 latestIngest !== null &&
272 (latestRaw === null || latestRaw < yesterday) &&
273 (latestUsage === null || latestUsage < addDays(today, -2));
274 // The 00:30 UTC run rolls up yesterday, so the day before that must always be in
275 // by now. Only "behind" if there was activity after the last rolled-up day — a day
276 // nobody used codegraph would be a silent rollup, not a missed one.
277 const rollupBehind =
278 latestActive !== null &&
279 (latestRollup === null || (latestRollup < addDays(today, -2) && latestActive > latestRollup));
280
281 return {
282 body: {
283 today,
284 /** The last day the nightly rollup covers. Kept under its old name for callers. */
285 latest_day: latestRollup ?? latestActive,
286 earliest_day: row?.earliest_rollup_day ?? row?.earliest_active_day ?? null,
287 latest_rollup_day: latestRollup,
288 latest_active_day: latestActive,
289 earliest_raw_day: row?.earliest_raw_day ?? null,
290 /** The last day of a stored lifecycle event (install, index, uninstall). */
291 latest_raw_day: latestRaw,
292 /** The last day of a stored usage counter. */
293 latest_usage_day: latestUsage,
294 /** The later of the two: the last day ingest stored anything, which the stall banner names. */
295 latest_ingest_day: latestIngest,
296 machines_yesterday: row?.machines_yesterday ?? 0,

Callers 1

handleApiFunction · 0.70

Calls 4

bindMethod · 0.80
utcDayFunction · 0.70
addDaysFunction · 0.70
prepareMethod · 0.65

Tested by

no test coverage detected