Skip to content

feat(services): add services-scoped layered Settings - #19

Closed
rsanghvi21 wants to merge 1 commit into
feat/policies-and-loadgenfrom
feat/services-settings
Closed

rsanghvi21 wants to merge 1 commit into
feat/policies-and-loadgenfrom
feat/services-settings

Conversation

@rsanghvi21

Copy link
Copy Markdown
Collaborator

Build-Plan Step Implemented

  • Step: A1.8 (infrastructure, fix on already-completed services).

Checkpoint Execution & Output

$ uv run pytest tests/unit/services/test_settings.py -v
9 passed in 2.01s

$ uv run pytest tests/unit --ignore=tests/unit/services/test_edge_gateway.py -k "not test_run_loadgen_with_owned_client_and_zero_rps" --cov=understudy --cov-branch --cov-fail-under=100
199 passed, 1 deselected, 100.00% coverage

$ uv run ruff check . && uv run ruff format --check . && uv run mypy --strict src tests && uv run lint-imports && uv run python scripts/check_mocks.py
All green.

ADRs Relied On

  • None.

Mock Registry Disclosures

  • None.

Documentation Updates

  • docs/02-architecture.md §2.5.1 (new): documents every ServicesSettings field, its
    default, and its env var name, per §5.10 ("if you introduce a tunable, document it
    there in the same PR").

Definition of Done

  • Implementation complete for the named build-plan step
  • Unit tests written; 100% line and branch coverage of the added lines
  • make check green
  • Checkpoint command run and output matches, OR marked unverified with a reason
  • Docs updated where this change made them untrue
  • No new # MOCKED: marker without a row in docs/MOCKS.md
  • Conventional commit(s), conventional branch, PR opened, never pushed to main

Context

A /code-review pass against PR #6 flagged that every tunable across services/
(HTTP timeouts, cache sizes, poll intervals, loadgen defaults, pool sizes, fault-seed,
metrics buckets) is a hardcoded literal or ad hoc os.getenv(...) call scattered across
modules -- a §5.10 violation. This PR is the infrastructure half of the fix:
services/_common/settings.py, a layered ServicesSettings model mirroring
src/understudy/common/config.py's shape but living independently in services/
(these are separate package trees with zero imports between them).

No call site has been migrated to use it yet -- that's a separate, wide-touching PR
(10b) so this one stays a single logical change (§4) and 10b can be reviewed as a
mechanical migration on its own. 10b depends on this PR and on #8/#15 (bootstrap
refactor) and #13 (worker fault fix) to avoid conflicting with those in-flight
refactors.

Base branch is feat/policies-and-loadgen (PR #6, still open), since services/ only
exists on that branch's stack.

🤖 Generated with Claude Code

https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh

Every tunable across services/ was read ad hoc via os.getenv(...)
with a hardcoded string default, scattered per-module -- no
services/ equivalent of src/understudy/common/config.py's layered
pydantic Settings pattern existed, violating AGENTS.md §5.10 ("no
magic numbers in code... thresholds, weights, timeouts and ceilings
live in config/*.yaml and are named in docs/02-architecture.md").

Add services/_common/settings.py mirroring config.py's shape (layered
load, frozen pydantic BaseModel per section, cached singleton with a
reset hook for tests) as an independent module -- services/ and
src/understudy/ share no imports, and src/understudy/common must stay
psycopg/fastapi-free, so it cannot host these tunables either.

One deliberate divergence: fields keep the exact env var name they
already used before this module existed (e.g.
AUTH_TOKEN_CACHE_MAX_SIZE, FAULT_INJECTION_SEED), rather than a new
UNDERSTUDY_<SECTION>__<FIELD> scheme -- those names are already wired
into deploy/prod/*.yaml's env/configMapKeyRef entries and loadgen's
CLI flag fallbacks, and renaming them would silently break
already-deployed configuration for no benefit.

Adds config/services.yaml (defaults) and config/services.local.yaml
to .gitignore (mirroring config/local.yaml) for local overrides.
Documents every field in docs/02-architecture.md §2.5.1.

This is infrastructure only: no call site reads from Settings yet
(follow-up PR). Implements build-plan step A1.8.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CzBeBUsZmE38K1kWeLMhNh
@Harikeshav-R

Copy link
Copy Markdown
Owner

Closed as integrated into main via PR #6.

@Harikeshav-R
Harikeshav-R deleted the feat/services-settings branch September 11, 2026 19:49
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.

2 participants