lablink_allocator_service.db.metrics¶
lablink_allocator_service.db.metrics
¶
Persistence for the Tier-1 session-metrics columns.
A column-family split, not a table split: the SessionMetrics / Seconds / Gpu* columns live on the VM table itself, which is why this class needs table_name where OperationsDatabase needs only a pool. Nothing outside this module reads or writes those columns, with one soft exception — VmDatabase.get_all_vms_for_export does SELECT * via get_column_names() and therefore returns them too. That is a schema-shape dependency, not a code one.
Classes¶
MetricsDatabase(pool, table_name)
¶
Persistence for session-metrics columns on the VM table.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
pool
|
A psycopg2 connection pool, shared with the other db classes. |
required | |
table_name
|
str
|
The VM table name (VM_TABLE_NAME in production). |
required |
Source code in packages/allocator/src/lablink_allocator_service/db/metrics.py
Attributes¶
table_name = table_name
instance-attribute
¶
Methods:¶
bulk_seal_session_metrics()
¶
Seal every unsealed VM (called from the destroy paths).
Returns:
| Name | Type | Description |
|---|---|---|
int |
int
|
number of rows sealed. |
Source code in packages/allocator/src/lablink_allocator_service/db/metrics.py
get_session_metrics_summary()
¶
Aggregate the cohort summary for the admin page.
The AS aliases below ARE the row keys _build_summary reads —
the dict-rows cursor keys each row by them (Postgres folds the
unquoted CamelCase column names to bare lowercase, hence the
explicit snake_case aliases).
Source code in packages/allocator/src/lablink_allocator_service/db/metrics.py
update_session_metrics(hostname, payload)
¶
Last-write-wins UPDATE of session-metrics columns.
Atomic with respect to seal: the sealed-row check is folded into
the UPDATE's WHERE clause, so a concurrent bulk_seal_session_metrics
cannot land between a separate SELECT and a separate UPDATE.
When the UPDATE affects zero rows, a follow-up existence SELECT
classifies the failure as LookupError (no such row) or
ValueError (row exists but is sealed).
Returns:
| Type | Description |
|---|---|
|
The row's authoritative |
|
|
None), via RETURNING on the same UPDATE — the route echoes |
|
|
it so the client can heal a lost session anchor. |
Raises:
| Type | Description |
|---|---|
LookupError
|
if hostname unknown. |
ValueError
|
if the row is already sealed. |