Skip to content

feat!: configure service environments - #242

Merged
uniqueg merged 5 commits into
devfrom
feat/service-environments
Oct 25, 2026
Merged

uniqueg merged 5 commits into
devfrom
feat/service-environments

Conversation

@uniqueg

@uniqueg uniqueg commented Oct 25, 2026 •

Copy link
Copy Markdown
Member

Summary

Breaking change: by default, registrations may only use the environments that the GA4GH specification suggests.

  • New config list custom.endpoints.services.environments, default [prod, test, dev, staging].
  • POST /services and PUT /services/{serviceId} with another environment get 400, naming the allowed values (case-sensitive). Services without environment are accepted.
  • An empty list allows any value.
  • Stored services are left untouched until they are written. The app logs a warning on startup that names stored services with other values, as for URL schemes.
  • Docs:
    • 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.
    • OpenAPI descriptions: the field and the request body.

Closes #239

Decisions

  • Marked breaking (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 [].
  • Exact matching: no case folding or aliases, so filters by environment stay consistent.

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%.
  • pytest against MongoDB 7.0.34: all passed.
  • mkdocs build --strict: passed.
  • Review: two rounds with the adversarial and quality reviewers. Findings were fixed except those listed below.

Declined review findings

  • Validating list items (e.g., no empty strings or duplicates) (quality, low): deployments set the list; an empty string as an allowed value is the deployment's choice.
  • Splitting 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.
  • Capping the IDs in the startup warning (quality, low): consistent with the URL scheme warning; any cap would cover both, in a separate change.
  • Commit trailer model name (quality, low): it matches the attribution this session was instructed to use.

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:

  • Add configurable service environment validation with GA4GH-suggested defaults and support for allowing any environment when configured with an empty list.

Enhancements:

  • Warn at startup about stored services using environments outside the configured allowlist while continuing to serve them until they are updated or deleted.
  • Document service environment requirements, client expectations, deployment configuration, and upgrade behavior across API, configuration, deployment, and OpenAPI documentation.

Deployment:

  • Expose service environment allowlist configuration for deployments.

Documentation:

  • Document environment validation, configuration options, client requirements, and handling of legacy stored services.

Tests:

  • Add coverage for default and custom environment allowlists, case-sensitive validation, legacy services, startup warnings, and configuration limits.

uniqueg and others added 3 commits October 25, 2026 21:47
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]>
@sourcery-ai

sourcery-ai Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Reviewer's Guide

Configures 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 validation

sequenceDiagram
    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
Loading

Sequence diagram for startup warnings on stored environments

sequenceDiagram
    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
Loading

File-Level Changes

Change Details Files
Adds configurable, exact-match validation for service environments during registration and updates.
  • Introduces the custom.endpoints.services.environments setting with GA4GH-recommended defaults and an empty-list opt-out.
  • Rejects disallowed environment values with a 400 response while accepting omitted values.
  • Applies validation through the shared service registration path used by POST and PUT operations.
cloud_registry/ga4gh/registry/service.py
cloud_registry/service_models/custom_config.py
cloud_registry/config.yaml
tests/test_app.py
tests/service_models/test_custom_config.py
tests/ga4gh/registry/test_service.py
Preserves legacy stored services while identifying records that conflict with the configured environment policy.
  • Adds startup scanning and warnings that name stored services with disallowed environments.
  • Leaves existing records readable and validates their environment only when they are subsequently written.
  • Registers the startup warning alongside the existing URL and service integrity checks.
cloud_registry/ga4gh/registry/service.py
cloud_registry/app.py
tests/ga4gh/registry/test_service.py
tests/test_app.py
Documents the new environment policy and its deployment and client implications across API and operational references.
  • Updates OpenAPI request-body and field descriptions with the configurable allowed-value behavior.
  • Documents defaults, case sensitivity, empty-list behavior, client expectations, and upgrade handling.
  • Adds deployment configuration guidance and test coverage for defaults, overrides, rejected values, compatibility, and startup warnings.
cloud_registry/api/additions.openapi.yaml
docs/api.md
docs/configuration.md
docs/upgrading.md
deployment/README.md
tests/test_config.py

Assessment against linked issues

Issue Objective Addressed Explanation
#239 Add a configurable list of allowed service environment values, defaulting to prod, test, dev, and staging, with an empty list allowing any value. ✅
#239 Reject writes that specify an environment outside the configured list with a clear 400 response, while leaving existing stored services unchanged and validating them only when they are next written. ✅
#239 Document the configuration alongside service URL scheme options and state that clients such as UIs must offer the same allowed values. ✅

Possibly linked issues


Tips and commands

Interacting with Sourcery

  • Trigger a new review: Comment @sourcery-ai review on the pull request.
  • Continue discussions: Reply directly to Sourcery's review comments.
  • Generate a GitHub issue from a review comment: Ask Sourcery to create an
    issue from a review comment by replying to it. You can also reply to a
    review comment with @sourcery-ai issue to create an issue from it.
  • Generate a pull request title: Write @sourcery-ai anywhere in the pull
    request title to generate a title at any time. You can also comment
    @sourcery-ai title on the pull request to (re-)generate the title at any time.
  • Generate a pull request summary: Write @sourcery-ai summary anywhere in
    the pull request body to generate a PR summary at any time exactly where you
    want it. You can also comment @sourcery-ai summary on the pull request to
    (re-)generate the summary at any time.
  • Generate reviewer's guide: Comment @sourcery-ai guide on the pull
    request to (re-)generate the reviewer's guide at any time.
  • Resolve all Sourcery comments: Comment @sourcery-ai resolve on the
    pull request to resolve all Sourcery comments. Useful if you've already
    addressed all the comments and don't want to see them anymore.
  • Dismiss all Sourcery reviews: Comment @sourcery-ai dismiss on the pull
    request to dismiss all existing Sourcery reviews. Especially useful if you
    want to start fresh with a new review - don't forget to comment
    @sourcery-ai review to trigger a new review!

Customizing Your Experience

Access your dashboard to:

  • Enable or disable review features such as the Sourcery-generated pull request
    summary, the reviewer's guide, and others.
  • Change the review language.
  • Add, remove or edit custom review instructions.
  • Adjust other review settings.

Getting Help

@codecov

codecov Bot commented Oct 25, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 100.00%. Comparing base (df986fc) to head (15b3983).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@uniqueg
uniqueg marked this pull request as ready for review October 25, 2026 21:31

@sourcery-ai sourcery-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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


Sourcery is free for open source - if you like our reviews please consider sharing them ✨

uniqueg and others added 2 commits October 25, 2026 22:41
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
@uniqueg
uniqueg merged commit d6bcf73 into dev Oct 25, 2026
19 checks passed
@uniqueg
uniqueg deleted the feat/service-environments branch October 25, 2026 21:55
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.

feat: configure service environments

1 participant