Skip to content

Fix health check query not executed#4927

Open
JC-wk wants to merge 3 commits into
microsoft:mainfrom
JC-wk:api-health-check
Open

Fix health check query not executed#4927
JC-wk wants to merge 3 commits into
microsoft:mainfrom
JC-wk:api-health-check

Conversation

@JC-wk

@JC-wk JC-wk commented Jun 8, 2026

Copy link
Copy Markdown
Collaborator

Resolves #4926

What is being addressed

The existing code container.query_items("SELECT TOP 1 * FROM c") does not actually execute the query so the health check can falsely return OK even if Cosmos is down or inaccessible.

How is this addressed

  • Ensure the query runs
  • Add tests
  • Update CHANGELOG.md
  • Increment version

* Health check can falsely return OK even if Cosmos is down or inaccessible. ([microsoft#4926](microsoft#4926))
Copilot AI review requested due to automatic review settings June 8, 2026 10:45
@JC-wk JC-wk requested a review from a team as a code owner June 8, 2026 10:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

This pull request fixes the Cosmos DB health check so it actually executes a query (preventing false “OK” results when Cosmos is unreachable), and updates the API’s unit tests, changelog, and version accordingly.

Changes:

  • Execute the Cosmos query by iterating the async result (async for ... break) with max_item_count=1.
  • Add unit tests covering Cosmos HTTP errors and query-time request errors.
  • Update CHANGELOG.md and bump api_app version.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
api_app/services/health_checker.py Forces Cosmos query execution during health check and maps CosmosHttpResponseError to “not accessible”.
api_app/tests_ma/test_services/test_health_checker.py Adds tests for Cosmos HTTP/query-time failures (but one existing “responding” test needs updating to reflect the new iteration behavior).
CHANGELOG.md Documents the bug fix under Unreleased “BUG FIXES”.
api_app/_version.py Bumps API version from 0.25.16 to 0.25.17.

Comment thread api_app/tests_ma/test_services/test_health_checker.py
@github-actions

github-actions Bot commented Jun 8, 2026

Copy link
Copy Markdown

Unit Test Results

675 tests   675 ✅  7s ⏱️
  1 suites    0 💤
  1 files      0 ❌

Results for commit 8541ce2.

♻️ This comment has been updated with latest results.

James Chapman added 2 commits June 8, 2026 10:52
api.dependencies.database.Database.
  get_container_proxy  instead of  azure.cosmos.aio.ContainerProxy.query_items .
  • Configured the return value of  get_container_proxy_mock  to be a mock container whose
  query_items  function returns a real async iterator:  AsyncIterator([{"id": "item"}]) .
  • Verified that all unit tests pass, and successfully ran the entire test suite (all 675 tests
  passed).
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.

Health check can falsely return OK even if Cosmos is down or inaccessible

2 participants