Repository navigation
feat: find API paths of discovered TES instances - #451
Conversation
Take the URL that a registry lists as the base of the TES API if its service info is there (GET <url>/service-info answers with that of a TES service); otherwise append /ga4gh/tes/v1, as before. The service info is read without credentials unless probe_with_token is set, and cached per process for version_cache_ttl seconds. While it can't be read, no request is sent and nothing is cached, so tasks go to other TES instances and are not taken for gone at a wrong path. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take the default path only on 404/410 or another service info; read again after a minute on 401/403; treat redirects, 429, other errors and non-JSON pages as unknown, keeping a path settled before for a minute. Read within PROBE_TIMEOUT and take the time from forwarding. Share the service-info request and the probe_with_token hint with the version probe. Document timing and the double first read. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Take JSON that isn't a GA4GH service info (e.g., a maintenance page) as unknown, not as the default path. Don't read the path when no time is left to forward. Refusals no longer log the default path, which a settled path may override. Document that refusals keep settled paths, and extend the BackendRequestNotSent docstring; test refusal retries. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Reviewer's GuideAPIExpose the discovered-backend API path through
ImplementationImplement path discovery, caching, answer classification, credential hints, and time-bounded forwarding for discovered TES backends, while retaining the existing version-probe behavior.
ConfigurationUpdate configuration descriptions to clarify that the existing cache-TTL and credential-probe settings also govern API-path discovery.
DocumentationExplain discovered API-path resolution, its timing, caching, credential behavior, and rolling-upgrade implications across the configuration, access-control, deployment, and upgrade documentation.
TestsTest discovered-path resolution, caching and retries, credentials, unknown answers, forwarding deadlines, version probing, and unchanged configured-backend paths.
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 #451 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 24 24
Lines 2719 2799 +80
=========================================
+ Hits 2719 2799 +80 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Hey - I've found 4 issues
Prompt for AI Agents
Please address the comments from this code review:
## Individual Comments
### Comment 1
<location path="pro_tes/ga4gh/tes/backends.py" line_range="652-656" />
<code_context>
- entry.api_path if isinstance(entry, TesServiceEntry) else DEFAULT_API_PATH
- )
+ # discovered backends: read on first use
+ self._api_path: str | None = None
+ if isinstance(entry, TesServiceEntry):
+ self._api_path = entry.api_path
+ elif not isinstance(entry, RegistryEntry):
+ self._api_path = DEFAULT_API_PATH
# discovered backends: each connection is checked
self.guarded: GuardedClient | None = None
</code_context>
<issue_to_address>
**Old workers poll the wrong path**
When a rolling upgrade lets an old Celery worker poll a task submitted by the new version to a discovered TES instance that serves its API at the registry URL, an old Celery worker uses the previous default API path for a newly submitted discovered TES task whose API is at the registry URL. Its polls fail, and `_poll` stores `UNKNOWN` after the configured consecutive failures even though the remote task is running.
Drain or stop old workers before the new version submits tasks using discovered API paths, or persist the resolved path so old workers can use it.
</issue_to_address>
### Comment 2
<location path="pro_tes/ga4gh/tes/backends.py" line_range="682" />
<code_context>
+ pro_tes.exceptions.BackendAuthError: No credentials are
+ available to read it (`custom.tes.probe_with_token`).
+ """
+ if self._api_path is None:
+ self._api_path = api_paths.get(self)
+ return self._api_path
</code_context>
<issue_to_address>
**Unsent cancellations appear ambiguous**
When a discovered backend's API path cannot be determined during cancellation, `api_paths.get()` raises `BackendRequestNotSent` before `cancel_task` sends its POST, but `_cancel_at_backend` catches it as a generic `requests.RequestException` and raises `BackendOutcomeUnknown`, so callers are told a cancellation may have happened when no request was sent.
Handle `BackendRequestNotSent` separately in `_cancel_at_backend` before catching generic `requests.RequestException`.
Also at `pro_tes/ga4gh/tes/backends.py:683-684`.
</issue_to_address>
### Comment 3
<location path="pro_tes/ga4gh/tes/backends.py" line_range="1548" />
<code_context>
+ url=client.url,
+ backend=client.backend,
+ entry=client.entry,
+ timeout=PROBE_TIMEOUT,
+ )
+ try:
</code_context>
<issue_to_address>
**Path probe exceeds forwarding deadline**
When a discovered backend's API path is not cached and its service-info request takes longer than the time left to forward, `ApiPaths._read` gives its guarded request the full `PROBE_TIMEOUT` instead of the remaining `connect_timeout`, so a slow service-info read can keep forwarding blocked after its deadline; `forward` only checks the remaining time after the read completes.
Pass the remaining forwarding budget into the path probe and bound its guarded request by that budget.
</issue_to_address>
### Comment 4
<location path="tests/ga4gh/tes/test_backend_list.py" line_range="837-839" />
<code_context>
+ caplog: pytest.LogCaptureFixture,
+) -> None:
+ """Refusals of reads with credentials get no hint at reading without."""
+ config = get_custom_config(CustomConfig).tes
+ config.probe_with_token = True
+ discovering.add("a", "https://tes1.example.org")
+ fake_tes.answers["https://tes1.example.org/service-info"] = http.HttpResponse(
+ status=401
</code_context>
<issue_to_address>
**Credentialed refusal goes untested**
When the test is meant to cover a refused service-info read sent with credentials, `test_api_path_discovered_refused_with_token` sets `probe_with_token` but uses the `discovering` fixture's default `auth: none` backend, so the fake 401 is returned without credentials and the no-warning assertion passes without testing a credentialed refusal.
Configure client credentials and a token provider in this test, and assert the 401 request carried the token before checking the log.
</issue_to_address>Linked issues
#438 feat: API path for discovered TES instances · 1 of 1 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Discovered TES instances can use a non-default API path, documented in the configuration reference. | ✅ Met | For discovered instances, ApiPaths checks <url>/service-info and uses the listed URL as the API base when it identifies a TES service; the configuration reference documents this behavior and its fallback. |
Sourcery assessment
Needs a human reviewer. 4 findings to address first, and with probe_with_token enabled, API-path discovery sends proTES’ token in a service-info request to discovered TES instances, including ones tasks may not be routed to. Reverting stops future probes, but cannot undo a token already exposed to an endpoint.
Blocking findings: pro_tes/ga4gh/tes/backends.py:656, pro_tes/ga4gh/tes/backends.py:682, pro_tes/ga4gh/tes/backends.py:1548, tests/ga4gh/tes/test_backend_list.py:839
Bound the read of a discovered TES instance's API path while forwarding by the time left, not only by PROBE_TIMEOUT. Test refusals of reads with credentials with a token, and note rolling upgrades. Co-Authored-By: Claude Opus 5.5 <[email protected]>
Summary
As decided in #438: discovered TES instances use the URL that their service registry lists as the base of the TES API;
/ga4gh/tes/v1is appended only if the service info isn't found at that URL.TesClient.api_pathis now a property; for discovered TES instances it is read on first use (ApiPaths):GET <url>/service-infothrough FOCA's guarded client, withinPROBE_TIMEOUT(5 s), without credentials unlesscustom.tes.probe_with_tokenis set.org.ga4ghtes, any version): the API is at the URL itself, cached forcustom.tes.version_cache_ttl;404/410, or the service info of another GA4GH service: the default path, cached the same;401/403: the default path (as before), with a hint in the logs, asked again after 60 s;405,408,429,5xx, non-JSON or JSON that isn't a service info, request errors, timeouts, too large): unknown.BackendRequestNotSent, so forwarding tries the next TES instance, tracking retries), and nothing is cached. No path is guessed, as a request to a wrong path could take a task for gone (404after a cancel)./ga4gh/tes/v1from the URLs that registries list, so for a TES instance listed with it, proTES first tries<host>/service-info, then uses the default path; documented.is_tes()is split out ofreported_version();TesClient.get_service_info()andtoken_hint()are shared with the version probe.api_path, never read).Docs: configuration reference (API paths, TES versions, discovery, request timing), upgrade notes (To version 0.6.0), access control (credentials of service-info reads), base config comments, config model docstrings, chart README and
values.yamlcomment. No new setting.Closes #438
Verification
coverage run -m pytest(mongomock, Helm 3.22.1 for the chart tests): 1690 passed, 11 skipped; coverage 100%MONGODB_TEST_URI, ownmongod --nounixsocket): 1700 passed, 1 skipped.semgrep): passmkdocs build --strict: passCI passed, tests on mongomock and MongoDB 7.0, chart, smoke test, docs, image scan)Review
Full review (adversarial + quality, 2 rounds). Fixed: answers that don't settle the path (redirects,
429, HTML or JSON maintenance pages, transient refusals) were cached as the default path for an hour, which could make tracking take a task for gone; the path read ignored the time left to forward; duplicated service-info request and hint logic; missing tests (403, hints with credentials,probe_with_tokenrefusals and missing tokens, memoisation, retries); docs on TESP, timing and refusals; the log of a refusal named a path that a settled one may override.Sourcery: fixed, the path read while forwarding is bounded by the time left (not only by
PROBE_TIMEOUT); the refusal test withprobe_with_tokennow sends a token; documented that workers of the earlier version can't track tasks at such TES instances during a rolling upgrade.Lane: full review (request routing to discovered TES instances).
Declined review findings
PROBE_TIMEOUTs on a cold cache: documented._cancel_at_backendreports every unreached TES instance as an unknown outcome already).🤖 Generated with Claude Code
Summary by Sourcery
Resolve and safely cache the API paths of discovered TES instances before forwarding requests.
New Features:
Bug Fixes:
Enhancements:
Documentation:
Tests: