Skip to content

feat(limits): stage-1 resource-limit telemetry for instance containers - #140

Merged
omarsy merged 1 commit into
mainfrom
feat/instance-limits-telemetry
Oct 12, 2026
Merged

omarsy merged 1 commit into
mainfrom
feat/instance-limits-telemetry

Conversation

@omarsy

@omarsy omarsy commented Oct 4, 2026

Copy link
Copy Markdown
Member

compose-containment Feature 4, stage 1 (telemetry only) per the HLD two-stage rollout: no measurement history exists (observe is one-shot, no pids collection), so stage 1 is the measurement — this constrains nothing.

What it adds:

  • apps/utils/docker/limits.py — docker-style size parser; the computed per-node limit set from GREFFER_INSTANCE_MEM_LIMIT / _CPUS / _PIDS (defaults 2g / 2.0 / 512, the calibration hypotheses; ''/0 disables a dimension — the semantics stage 2 will reuse); and the over-limit comparison against a stats digest. Warnings rate-limited to one per (instance, service) per 10 min — the digest is pull-driven, so every metrics poll is an observation. pids is carried for stage 2 but deliberately not compared: no observation channel exists, and a pretend measurement would be worse than none.
  • observe.instance_stats runs the pass per digested read, wrapped so a telemetry bug can never fail a stats response; the payload is unchanged.
  • Settings knobs with the typo-must-not-crash validators of the log-rotation precedent.

Tests: 16 new (parser incl. loud compound-size refusal, env override/off/fallback, exceed, multi-core CPU scale, rate limit, disabled dimensions, malformed entries); full suite 939 passed. The autouse propagation fixture exists because app/logging.py sets propagate: False and any earlier app-importing test otherwise blinds caplog.

Stage 2 (rendering mem_limit/cpus/pids_limit per service) waits for one release of these warnings — HLD open question "resource-limit values".

@chatgpt-codex-connector

Copy link
Copy Markdown

You have reached your Codex usage limits for code reviews. You can see your limits in the Codex usage dashboard.
To continue using code reviews, add credits to your account and enable them for code reviews in your settings.

@omarsy
omarsy force-pushed the feat/instance-limits-telemetry branch 2 times, most recently from 54b2431 to 01efd57 Compare October 4, 2026 22:17
@omarsy
omarsy force-pushed the feat/instance-limits-telemetry branch from 01efd57 to 0bac9b4 Compare October 9, 2026 10:33
compose-containment Feature 4, stage 1 of the HLD's two-stage rollout.
No container is constrained yet: the measurements the stage-2 limits
need do not exist (observe is one-shot, no history, no pids collection),
so this stage IS the measurement.

- apps/utils/docker/limits.py: docker-style size parser (overflow- and
  NaN-safe on the SCALED product — int(inf) once escaped the 'never
  raises' contract and crash-looped boot via the Settings validator),
  the computed per-node limit set read from
  GREFFER_INSTANCE_MEM_LIMIT / _CPUS / _PIDS (defaults 2g / 2.0 / 512,
  exported as the single source app/settings.py also binds; '' or 0
  disables a dimension — for mem too, matching docker's --memory=0 and
  the cpus/pids semantics), and the over-limit comparison against a
  stats digest. Warnings are rate-limited per (instance, service) per
  10 minutes, with an explicit membership test rather than a 0.0
  sentinel (monotonic clocks start near 0; the sentinel swallowed every
  first warning for ten minutes after boot) and a snapshot-before-
  delete prune (a live-view iteration raced concurrent digests into
  RuntimeError). pids is carried for stage 2 but deliberately not
  compared — it has no observation channel, and a pretend measurement
  would be worse than none.
- observe.instance_stats runs the pass per digested read, wrapped so a
  telemetry bug can never fail a stats response; the payload is
  unchanged (log signal, not a contract change).
- Settings gains the three knobs with the typo-must-not-crash
  validators of the log-rotation precedent, sharing limits.py's
  constants and its finite/non-negative acceptance rule so the two
  views cannot drift (a divergent validator held -1.0/nan while the
  telemetry fell back).
- tests (27): parser incl. overflow + loud compound-size refusal, env
  override/off/fallback incl. MEM=0 and CPUS=nan, exceed, multi-core
  CPU scale, rate limit, disabled dimensions, malformed entries, the
  concurrent-prune snapshot, first-warn-after-boot, and the Settings
  coercions that had zero coverage when the boot crash was found. An
  autouse fixture clears/restores the limits cache and rate-limit map
  (the test_observe convention) and forces greffer-logger propagation
  (app/logging.py sets propagate False, blinding caplog otherwise).

Independent adversarial review (DO NOT SHIP -> folded): the three P1s
above with their reproductions, the P2s (defaults single-sourced,
Settings validator coverage, reformat churn reverted to base style so
the feature hunks are the whole diff of the two touched files).

Stage 2 (rendering mem_limit/cpus/pids_limit per service) waits for one
release of these warnings; HLD open question 'resource-limit values'.

Codex CLI review (bundled 0.162): P2 — docker's two-letter size suffixes
(kb/mb/gb) fell back to the default, silently disabling the operator's
threshold ('512mb' -> 2g, a 1GiB container warned nothing); the parser
now strips the trailing b before the suffix lookup, with regression
tests. P3 — the concurrency test leaked the 1e-6 switch interval into
the rest of the suite; restored in the finally (the prior verification
round had flagged this as a future one-liner; codex promoted it).
@omarsy
omarsy force-pushed the feat/instance-limits-telemetry branch from 0bac9b4 to 80ae6f3 Compare October 10, 2026 11:58
@omarsy
omarsy merged commit 0f2844b into main Oct 12, 2026
1 check failed
@omarsy
omarsy deleted the feat/instance-limits-telemetry branch October 12, 2026 07:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant