refactor(cp): first-class Env type for installation identity#281
Merged
Conversation
env_label was a free-form String threaded through config and compared
with `== "production"` in scattered places, and any DD_ENV value (incl.
typos / junk like "invalid name {uuid}") was accepted and silently baked
into Cloudflare resource names, breaking collector discovery.
Introduce `Env` (src/env.rs): parse+validate DD_ENV as a lowercase DNS
label, classify the well-known kinds (production/staging/dev/pr-N) with a
`Named` fallback so legitimately-named installs (bot, dogfood, future
envs) are never rejected — only malformed labels are. Env-intrinsic
behaviour becomes methods: `requires_intel_ita()` (replaces the
`== "production" || == "staging"` ITA-mode gate, same semantics) and
`is_ephemeral()` (for later lifecycle/GC policy).
`config::Common.env_label: String` → `env: Env` (single source of truth);
`Ita::from_env` takes `&Env`. All call sites read the string via
`env.label()`. No wire/behaviour change — CF names and /health env are
identical; this is type-safety + boot-time validation groundwork for the
CF drift/reconcile work. cf_snapshot/collector still take `&str` (threaded
to `&Env` in a follow-up).
Co-Authored-By: Claude Opus 4.8 (1M context) <[email protected]>
DD preview readyURL: https://pr-281.devopsdefender.com Browser login: visit https://pr-281.devopsdefender.com — DD redirects you to Machine-to-machine: GitHub Actions workflows in the Register endpoint for a local agent: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
First step of the unified prod+PR management / CF-reconcile arc (groundwork; no behaviour change).
Why
env_labelwas a free-formString: threaded through config, compared with== "production"in scattered spots, and anyDD_ENVvalue — including typos or junk likeinvalid name {uuid}— was accepted and baked straight into Cloudflare resource names (dd-{env}-cp-*), silently breaking collector discovery for the real env.What
src/env.rs(new):Envparses + validatesDD_ENVas a lowercase DNS label (^[a-z0-9][a-z0-9-]*$, ≤40 chars), classifies well-known kinds (production/staging/dev/pr-N) with aNamedfallback so legitimately-named installs (bot,dogfood, future envs) are not rejected — only malformed labels are. Env-intrinsic behaviour as methods:requires_intel_ita()(replaces the== "production" || == "staging"ITA gate, identical semantics) andis_ephemeral()(for later lifecycle/GC policy). Unit tests included.config.rs:Common.env_label: String→env: Env(single source of truth);Ita::from_envtakes&Env.cp.rs: call sites read the label viaenv.label().No wire or behaviour change — CF names and
/health'senvfield are byte-identical; this is type-safety + boot-time validation.cf_snapshot/collectorstill take&str(threaded to&Envin the next PR).Validation
cargo fmtclean; compiles locally (only the unrelated pre-existing macOS-targetsessiond.rserrors remain — CI builds musl).Env::parseunit tests (accept production/staging/dev/pr-7/bot, reject uppercase/whitespace/too-long)./healthenv.Part of the arc: Env type → degraded-aware snapshot → register env-binding → drift logging → reconcile plan → reconcile apply → cleanup wiring.
🤖 Generated with Claude Code