Repository navigation
feat!: configure service environments - #242
Conversation
Registrations (POST /services, PUT /services/{serviceId}) may only use
the environments listed in custom.endpoints.services.environments; by
default, the values that the GA4GH specification suggests (prod, test,
dev, staging). Other values are rejected with 400, naming the allowed
ones. An empty list allows any value. Stored services with other values
are served as they are and checked when they are next written.
BREAKING CHANGE: by default, environments other than prod, test, dev
and staging are rejected; allow them in the config to keep them.
Closes #239
Co-Authored-By: Claude Opus 5.5 <[email protected]>
On startup, warn of stored services whose environments are not allowed, as for URL schemes. Describe the check in the field description of the API and in the chart's README, and add unit and config tests. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Check stored environments as registrations do, so that lists are warned of too, and say that services can be updated without one. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideConfigures service environment values with GA4GH defaults, enforces exact allowed values on new and updated registrations, preserves and warns about incompatible existing records until they are rewritten, and documents the behavior for API clients and deployments. Sequence diagram for service environment validationsequenceDiagram
participant Client
participant API as ServiceAPI
participant Registry as ServiceRegistration
Client->>API: POST /services or PUT /services/{serviceId}
API->>Registry: register_metadata()
Registry->>Registry: check_environment(data, environments)
alt environment is allowed or absent
Registry-->>API: registration succeeds
API-->>Client: 2xx response
else environment is not allowed
Registry-->>API: InvalidService
API-->>Client: 400 Bad Request
end
Sequence diagram for startup warnings on stored environmentssequenceDiagram
participant App
participant Registry as ServiceRegistry
participant ServicesDB as ServicesCollection
participant Logger
App->>Registry: warn_environments()
Registry->>ServicesDB: find services with environment
loop stored services
Registry->>Registry: check_environment(service, environments)
end
alt incompatible services found
Registry->>Logger: warning with service IDs
else no incompatible services
Registry-->>App: startup continues
end
File-Level Changes
Assessment against linked issues
Possibly linked issues
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## dev #242 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 17 17
Lines 1480 1502 +22
=========================================
+ Hits 1480 1502 +22 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 3 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="cloud_registry/ga4gh/registry/service.py" line_range="643-651" />
<code_context>
+ environments = get_custom_config().endpoints.services.environments
+ if not environments:
+ return
+ ids = []
+ for service in get_collection("services").find(
+ {"environment": {"$exists": True}},
+ {"_id": False, "id": True, "environment": True},
+ ):
+ try:
+ check_environment(service, environments=environments)
+ except InvalidService:
+ ids.append(f"'{service['id']}'")
+ if ids:
+ logger.warning(
</code_context>
<issue_to_address>
**Startup warning grows without bound**
When a deployment configures a restricted environment list and has a very large number of stored services outside it, `warn_environments` appends every mismatching service ID to `ids` before joining them into one warning, so a large set of stored services with disallowed environments consumes unbounded worker memory during startup and can make workers slow to boot or run out of memory.
Limit the number of IDs retained and logged, and include the total mismatch count in the warning.
</issue_to_address>
### Comment 2
<location path="cloud_registry/service_models/custom_config.py" line_range="151" />
<code_context>
id: IdConfig
# pydantic copies mutable defaults for each instance
url_schemes: list[Literal["http", "https"]] = Field(default=["https"], min_length=1)
+ environments: list[str] = Field(default=["prod", "test", "dev", "staging"])
</code_context>
<issue_to_address>
**Allowed environments cannot be registered**
When a deployment configures an allowed environment longer than 256 characters, connexion rejects registrations at the request-schema check because the registration schema caps `environment` at 256 characters, so callers cannot register services using that configured value.
Align the registration schema’s `environment` limit with the values accepted by `ServicesConfig.environments`.
</issue_to_address>
### Comment 3
<location path="cloud_registry/ga4gh/registry/service.py" line_range="644" />
<code_context>
+ if not environments:
+ return
+ ids = []
+ for service in get_collection("services").find(
+ {"environment": {"$exists": True}},
+ {"_id": False, "id": True, "environment": True},
</code_context>
<issue_to_address>
**Late registrations go unwarned**
When an older app instance stores a registration with an unlisted environment after the new instance’s startup scan has passed its position, `warn_environments()` never revisits that service, while the new instance rejects later updates that retain its environment, so operators are left without a warning explaining the rejection.
Make the warning scan account for registrations accepted by older instances after the startup scan has passed.
Also at `cloud_registry/ga4gh/registry/service.py:374`, `cloud_registry/app.py:129`.
</issue_to_address>Sourcery assessment
Approval pending. 3 findings to address first.
Blocking findings: cloud_registry/ga4gh/registry/service.py:651, cloud_registry/service_models/custom_config.py:151, cloud_registry/ga4gh/registry/service.py:644
Allowed environments are at most 256 characters, the maximum length of environment in the API, so that every allowed value can be registered. Co-Authored-By: Claude Opus 5.5 <[email protected]>
# Conflicts: # cloud_registry/service_models/custom_config.py # docs/configuration.md
Summary
Breaking change: by default, registrations may only use the environments that the GA4GH specification suggests.
custom.endpoints.services.environments, default[prod, test, dev, staging].POST /servicesandPUT /services/{serviceId}with anotherenvironmentget400, naming the allowed values (case-sensitive). Services withoutenvironmentare accepted.configuration.md: "Service environments", next to "Service URL schemes". It says that clients (e.g., UIs) must offer the same values.api.md: Registrations.upgrading.md: Stored services.deployment/README.md.Closes #239
Decisions
feat!): values that were accepted before (e.g.,production) are now rejected by default. To keep them, deployments add them to the list or set[].Verification
pre-commit run --all-files: all passed.pytest(mongomock): 1168 passed, 228 skipped (the Helm chart tests; Helm isn't installed locally). Coverage is 100%.pytestagainst MongoDB 7.0.34: all passed.mkdocs build --strict: passed.Declined review findings
test_service_environments_configured; using config overlays in app tests (quality, low): the per-test app fixture isolates the tests, like the existing URL scheme tests.Open questions
None.
🤖 Generated with Claude Code
Summary by Sourcery
Enforce deployment-configurable service environment values during registration and updates while preserving and warning about legacy stored values.
New Features:
Enhancements:
Deployment:
Documentation:
Tests: