Repository navigation
Expand file tree
/
Copy path0006_users_and_containers.sql
More file actions
43 lines (39 loc) · 2.83 KB
/
Copy path0006_users_and_containers.sql
File metadata and controls
43 lines (39 loc) · 2.83 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
39
40
41
42
43
-- codegraph telemetry — who counts as a user, and which machines are containers.
--
-- The dashboard counted every machine id as a user. A machine id is a random UUID
-- in the home directory, so a fresh container or cloud sandbox is a new one each
-- time it is created, and most of the ids seen over a month are machines that
-- indexed once and were never seen again.
--
-- A user is a machine CodeGraph has been installed on for an AI agent: the
-- installer ran on it, or an agent started the engine on it (the MCP server, a
-- tool call or the prompt hook, none of which can happen before it is set up for
-- that agent). A machine that only ever indexed is not a user. Nearly all of the
-- machines that rule leaves out are seen on one day only.
--
-- Every statement here adds a column with a constant default or creates an index
-- over rows that do not exist yet: none of them reads or rewrites a table.
-- The day a machine became a user, lowered as earlier evidence arrives and never
-- raised. NULL until it is one. An upgrade is proof of an install older than
-- itself, so it sets a machine not already known to be installed to its first
-- day on record: an existing user who upgrades is counted, and is not a new
-- user on the day of the upgrade. Set by the ingest path as events are stored, and
-- once by the cron for what was stored before this column existed.
ALTER TABLE machine_first_seen ADD COLUMN installed_day TEXT;
-- Cohorts are read by the day machines became users. Partial, so creating it
-- over a table where the column is still NULL everywhere is free.
CREATE INDEX machine_first_seen_installed ON machine_first_seen (installed_day) WHERE installed_day IS NOT NULL;
-- 1 when the machine reported from inside a container or a cloud workspace that
-- day (the envelope's `container`, sent from engine schema 3 on). A container
-- that comes back on a second day is somebody's working environment and counts
-- as any machine does; one that is seen once is a run, not a user.
ALTER TABLE machine_days ADD COLUMN container INTEGER NOT NULL DEFAULT 0;
-- Users active each day: machines outside CI that had become users by that day.
-- NULL for a day rolled up before this column existed, which a chart draws as a
-- gap and not as a day with no users.
ALTER TABLE daily_machines ADD COLUMN user_machines INTEGER;
-- Users over each trailing window, beside the machine counts of 0005.
ALTER TABLE window_machines ADD COLUMN user_machines INTEGER NOT NULL DEFAULT 0; -- users seen in the window
ALTER TABLE window_machines ADD COLUMN returning_users INTEGER NOT NULL DEFAULT 0; -- of them, on two or more days
ALTER TABLE window_machines ADD COLUMN regular_users INTEGER NOT NULL DEFAULT 0; -- of them, on five or more
ALTER TABLE window_machines ADD COLUMN container_machines INTEGER NOT NULL DEFAULT 0; -- machines that reported from a container