Skip to content

[Draft] OBI-32: Capacity snapshots and safe placement #21

Done
2 of 2 issues completed
Done

Description

@ephico2real2

Part of #9

Story

As a platform operator, I want to place requests without synchronous monitoring dependencies.

Business value

The plan (#6) sets this release exit for phase 3: "prod placement uses stored snapshots without a Thanos call; fresh-capacity rnd medium auto-approval succeeds; oversized quota change requires platform approval."

Context

cmapi/src/cmapi/core/capacity_backend.py simulates capacity (#62). cmapi-capacity is not built (build-tracker.md, "Not built, by area").

Acceptance criteria

  • Internal capacity service stores snapshots at configured intervals; gateway enforces scope, shown by a new test in cmapi/tests/service/, not written yet
  • Placement checks CPU and memory separately, freshness, reservations and zone-failure headroom, shown by a new test in cmapi/tests/service/, not written yet
  • Concurrent reservations cannot overbook; expired reservations are reclaimed, shown by a new test in cmapi/tests/service/, not written yet
  • Namespace creation makes no Thanos query, shown by a new test in cmapi/tests/service/, not written yet

Tasks

Out of scope

  • The source states none for this story.

Evidence

  • None yet.

Definition of done

  • Mockup approved, or the work has no screen and no API shape
  • Draft pull request open
  • Build: tests fail before the change and pass after it
  • Documented where a reader looks for it
  • Review ruled
  • Merged with its proof
  • Released on the default branch
  • The owner approves, after a comment cites the proof for each criterion and its cluster

Class

INV. The story adds a new capability to the product.

Source

Status: Draft backlog. No sprint commitment.

Owner in Paperclip: Ahsoka. Ahsoka mentors Luke and assigns bounded engineering work after technical review.

Source: OBI-32.
Epic: #9. Plan, release windows, and review gates: #6.

Dependencies: #8 (OBI-26), OBI-19, OBI-20.

Planned story; phase 3, provisional 8 points (Ahsoka/Yoda to validate).

  • Attach automated or reproducible evidence for each criterion; cover denial/failure paths.
  • Read the plan; Yoda owns design choices. Keep this in backlog until prerequisite phase evidence is accepted. Ahsoka may split and delegate to Luke with mentorship.

Language acceptance criterion

Before sprint entry, the owner must define technical terms and attach language review evidence for this text revision.
Use simple-english 2.1.1, Strict mode. Index #6 records the vocabulary source and review limits.

The source criteria remain unchanged. Language review remains open.

Sub-issues

Sub-issues

2 of 2 Issues completed
Loading 2 sub-issues

Activity

  1. added
    Backlog
    class:INV
    status:open
    story
    on Nov 13, 2026
  2. added
    In-Progress
    status:partly-fixed
    and removed
    status:open
    Backlog
    on Nov 19, 2026
  3. ephico2real2 commented on Nov 19, 2026

    @ephico2real2
    OwnerAuthor

    Work tag In-Progress. Evidence: merged part(s) of this issue: #305. The issue stays open for the rest; status:partly-fixed. Moved up from Backlog (records sweep 2026-11-19).

  4. added 7 commits that reference this issue on Nov 26, 2026
  5. ephico2real2 commented on Nov 27, 2026

    @ephico2real2
    OwnerAuthor

    The owner approved closing this story on 2026-11-27, after CRC run 45 (main 96b1621). The coordinator first overstated which criteria run 45 proved live, corrected it, and the owner approved again on the corrected picture: each criterion's named test is its proof (as the criterion says), live CRC evidence is added where it exists, and each test-only part is marked below.

    Story #21, Capacity snapshots and safe placement: proof for each acceptance criterion.

    Part of #9. Built by #725 (reservations, migration 0011, also closes #62) and #738 (snapshots, placement, migration 0012, also closes #303). Both merged on 2026-11-26.

    Where the proof comes from:

    • CRC. Run 45 (main 96b1621, deployed 2026-11-27 03:00Z) and run 45b (same build, no redeploy, 14:37Z to 14:42Z). Records: workbench/cmapi/ob1-run45/resume.md, logs in ob1-run45/logs/. Read-only beyond the deploy: dry runs only, no Idempotency-Key, no object created by hand.
    • Service tests. PostgreSQL 16 on 127.0.0.1:55432, no cluster. They ran in the PRs and in the reviewers' runs. CI runs the whole service suite.
    • Design decisions and the review rulings: docs/reviews/2026-11-26-issue-21/README.md (D1 to D13) and docs/reviews/2026-11-26-issue-62/README.md.

    Summary:

    # Criterion Service tests Live on CRC
    1 Snapshots at intervals; gateway enforces scope Yes Snapshots and the read: yes. Scope refusal: not run live
    2 Placement checks Yes Ranking by one dry run: yes. Freshness, reservations and zone headroom: not live
    3 No overbooking; expired holds reclaimed Yes Not live (no write allowed)
    4 Creation makes no Thanos query Yes Not live

    Criterion 1

    Internal capacity service stores snapshots at configured intervals; gateway enforces scope, shown by a new test in cmapi/tests/service/, not written yet

    Built by: #738. Worker job capacity_snapshot runs in embedded mode (decision D1; docs/01 "One interface, two modes"). It writes rows for the cluster, each zone and each node role, every snapshotInterval of capacity.yaml (15 to 60 minutes, 30 default). GET /api/v1/clusters/{id}/capacity needs capacity:read in the cluster's environment, else 404. POST .../capacity/snapshots:run needs operations:run. Migration 0012 adds capacity_snapshots.

    Tests, all in cmapi/tests/service/test_placement_21.py:

    • test_the_snapshot_job_stores_the_cluster_its_zones_and_roles_at_the_configured_interval
    • test_with_thanos_the_snapshot_measures_requests_and_use_per_node
    • test_a_failed_query_or_a_gap_over_5_percent_marks_the_snapshot_incomplete
    • test_the_gateway_answers_a_cluster_s_snapshot_only_within_the_caller_s_environments
    • test_the_capacity_tab_shows_each_cluster_s_snapshot (the Capacity tab)

    Counts: before the change the file had 21 failed, after it 21 passed (PR #738). After review, reviewer 2's final tree: 349 service tests passed, tests/core 856 passed, portal 199 ok.

    Live proof, cluster CRC.

    • Run 45, logs/cap45-end.txt, logs/c45-capacity.out. Job 10845 capacity_snapshot done 2026-11-27 03:00:22Z; next job 10847 due 03:30:00Z. In capacity_snapshots: "3 rows at 2026-11-27T03:00:00Z: cluster, role:master, role:worker", source thanos, complete.
    • Run 45, logs/c45-capacity/. GET /api/v1/clusters/CRC/capacity as cmapi.requester and cmapi.operator: 200, snapshot ok, takenAt 03:00:00Z, CPU allocatable 7800 m, requested 6733, usedAvg 1722, usedPeak 2351, quotaCommitted 80000; memory allocatable 20493352960 B; pods 112/250.
    • Run 45b, logs/c45b-sweep.out. "capacity_snapshot: 28 job rows, every one since 03:00Z done on attempt 1, each capacity_snapshot log line rows 3, source thanos, complete true; next 11614 at 15:00Z." That shows the 30-minute interval holding for about 12 hours.
    • Run 45b, logs/ui45b-capacity.out: Capacity tab, 6 checks, ALL PASSED, in the installed Chrome at 1440 and 390 px. CRC's Snapshot cell 14:30 equals the answer's snapshot (ok, takenAt 14:30:00Z, source thanos); pill "snapshot 14:30 · every 30 min".

    Not proven live:

    • Scope refusal (404 outside the caller's environments): service test only. Run 45 called the endpoint as cmapi.requester and cmapi.operator and got 200 for both. No out-of-scope call was made.
    • No zone row on CRC. The record: "CRC's only node has no topology.kubernetes.io/zone label (measured), and snapshots.py:249 writes a zone row only for a labelled zone." Zone rows are proven by the service test only.
    • POST .../capacity/snapshots:run was not called live.

    Criterion 2

    Placement checks CPU and memory separately, freshness, reservations and zone-failure headroom, shown by a new test in cmapi/tests/service/, not written yet

    Built by: #738 (POST /api/v1/capacity:place, core/placement.py, plugins/capacity/placement.py): docs/02's hard filters, each with a named reason; the score; a 15-minute hold on the first cluster that still fits, under its advisory lock (201). dryRun=true ranks and holds nothing. A create's placementId turns the hold into the request's own. #725 adds the holds that placement counts.

    Tests, in cmapi/tests/service/test_placement_21.py unless named:

    • test_cpu_and_memory_are_checked_separately
    • test_a_stale_or_incomplete_snapshot_excludes_the_cluster
    • test_placement_counts_the_holds_of_requests_and_of_other_placements
    • test_zone_failure_headroom_excludes_a_cluster_that_would_not_survive_losing_its_largest_zone
    • test_placement_ranks_from_a_fresh_snapshot_and_holds_the_winner_for_15_minutes
    • test_a_create_with_its_placement_turns_the_hold_into_the_request_s_own
    • test_a_team_holds_at_most_three_placements_in_an_environment, test_with_no_team_the_cap_of_three_placements_is_the_caller_s, test_ranking_needs_capacity_read_and_the_hold_needs_namespaces_create
    • cmapi/tests/core/test_placement_21.py (14 passed in the PR; 33 with the rate-limit tests)

    Counts as for criterion 1. The review fixed F1 (High: one capacity arithmetic for node-sized clusters), F3, F4 (Medium) and five Low findings. F2 was refuted against docs/02 and is owner question B1 in #737.

    Live proof, cluster CRC.

    • Run 45, logs/c45-place.out. POST /api/v1/capacity:place?dryRun=true as cmapi.requester, body {dev, team cmapi-live, small}: "200; CRC ranked, score 34, reserved false, placementId null", basis simulated, bound by CPU (48000 to 40000 m) and memory (160 to 144 GiB), usage p95 CPU 0.2208 / memory 0.8103. Holds before and after: 1 reservation, 0 active, 0 placement holds.
    • Run 45b, logs/ui45b-new.out: the New namespace tab's placement preview, 6 checks, ALL PASSED: the page's POST /api/v1/capacity:place?dryRun=true, no Idempotency-Key, 200, placementId null. "Ranked clusters": 1 CRC cpu 48 → 32 cores · memory 160 → 128 Gi · p95 0.81 30. No Check and no Submit pressed.

    Not proven live:

    • The ranking is one dry run on one cluster, so ordering between clusters was not shown.
    • Freshness exclusion, the holds' effect on a rank and zone-failure headroom: service tests only. CRC has one node and no zone label, so zone headroom cannot be shown on it.
    • The real hold (201) and the create that claims it: not run. Run 45 allowed dry runs only.

    Criterion 3

    Concurrent reservations cannot overbook; expired reservations are reclaimed, shown by a new test in cmapi/tests/service/, not written yet

    Built by: #725 (migration 0011 capacity_reservations; Pipeline.submit checks every hold taken since the plan, under the cluster's pg_advisory_xact_lock; the last :approve and a :retry from failed check again; expired holds stop counting and are marked expired by the next hold). #738 adds the same for placements.

    Tests:

    • cmapi/tests/service/test_capacity_reservations_62.py: test_concurrent_submits_cannot_overbook, test_two_plans_made_before_either_submits_are_checked_again_under_the_lock, test_an_expired_hold_is_reclaimed, test_a_request_holds_its_increase_and_a_second_that_fits_alone_is_refused, test_a_request_for_more_than_the_cluster_has_free_is_refused, test_the_last_approval_checks_the_hold_again, test_a_retry_from_failed_holds_again_only_when_it_still_fits, test_a_request_that_ends_releases_its_hold, test_a_synced_request_releases_its_hold_and_its_quota_is_counted_once.
    • cmapi/tests/service/test_placement_21.py: test_concurrent_placements_cannot_overbook, test_an_expired_placement_is_reclaimed_and_holds_nothing, test_a_placement_used_or_lapsed_between_the_plan_and_the_submit_records_nothing.

    Counts (PR #725, PostgreSQL 16): before the fix 11 failed, 3 passed (the 3 are guards), including "8 of 8 concurrent submits held on room for 3"; with the fix 14 passed. Review record: 57 service tests plus reviewer 2's 261 service tests and 843 core tests passed; 5 of 5 mutants caught. Fixed after review: H1a, H1b, H2 (approval part), H3 (the 40P01 deadlock, now 409), H4 (migration 0011 fills holds for requests in flight), and the M1 rounding. M2 was refuted. PR #738: the race, rollback and migration 0012 were checked on PostgreSQL by reviewer 2.

    Live proof, cluster CRC: the schema only.

    • Run 45, logs/migrator.txt, logs/readiness-0012.txt. The worker's migrate applied 0011 and 0012 at 03:00:12.97Z (from_revision 0010, revision 0012). The API became Ready at 03:00:25Z after the database reached 0012. /readyz 200, {"status":"ok","database":"ok","schema":"ok"}.
    • Run 45, logs/cap45-end.txt. Table capacity_reservations exists. Migration 0011's backfill made one hold, req-20261115-0002 (the one failed request), released at 03:00:12.70Z with released_why failed. Active holds: 0. Run 45b end: "Reservations 1, active 0 (no hold taken)".

    Not proven live: concurrent holds and expiry. A hold needs a real request or a real placement, and run 45 allowed none. This criterion has service-test proof only.

    Criterion 4

    Namespace creation makes no Thanos query, shown by a new test in cmapi/tests/service/, not written yet

    Built by: #738. The create path reads only the stored snapshot (decision D1).

    Test: cmapi/tests/service/test_placement_21.py::test_placing_and_creating_a_namespace_make_no_thanos_query (a fake metrics source that counts queries). Reviewer 2 re-checked "zero Thanos on create" on PostgreSQL (docs/reviews/2026-11-26-issue-21/README.md).

    Not proven live. No create ran in run 45 or 45b (no write, no Idempotency-Key). The story audit cites older creates on CRC with monitoring scaled to 0 (run 32); they predate #738 and do not show that a create sends no query now. This criterion has service-test proof only.

    Open follow-ups

    For the owner

    • Criteria 3 and 4 have service-test proof only. A real write run on CRC (one request with a hold, one create) would add live proof for both.
    • Criterion 1's zone rows and scope refusal, and criterion 2's zone headroom, cannot be shown live on CRC as it is: its one node has no zone label.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-Progressclass:INVstatus:partly-fixedstory

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions