Skip to content

feat: Add health check for Datasette service - #1230

Merged
gibahjoe merged 2 commits into
mainfrom
1222-add-a-health-endpoint-for-status-monitoring-the-endpoint-should-ensure-to-make-a-call-to-datasette
Jul 14, 2026
Merged

feat: Add health check for Datasette service#1230
gibahjoe merged 2 commits into
mainfrom
1222-add-a-health-endpoint-for-status-monitoring-the-endpoint-should-ensure-to-make-a-call-to-datasette

Conversation

@gibahjoe

@gibahjoe gibahjoe commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

What type of PR is this? (check all applicable)

  • Refactor
  • Feature
  • Bug Fix
  • Optimization
  • Documentation Update

Description

Adds Datasette to the /health endpoint dependency checks and introduces an overall health status.

The endpoint now reports ok, degraded, or down at the top level. Required dependencies such as S3, request API, and Datasette returning down cause the endpoint to return HTTP 500. Redis is marked as required: false, so if Redis is down the top-level status becomes degraded while the endpoint still returns HTTP 200.

Related Tickets & Documents

  • Ticket Link
  • Related Issue #
  • Closes #

QA Instructions, Screenshots, Recordings

Run the focused health tests and lint:

npx vitest run test/unit/health.test.js test/integration/health.test.js
npx standard src/routes/health.js test/unit/health.test.js test/integration/health.test.js

Expected result: all tests pass and lint returns no errors.

No screenshots or recordings are included because this is a backend health endpoint change.

Added/updated tests?

  • Yes
  • No, and this is why:
  • I need help with writing tests

[optional] Are there any post deployment tasks we need to perform?

Configure monitoring, such as Upptime, to treat HTTP 500 responses as down and top-level {"status":"degraded"} responses as degraded.

[optional] Are there any dependencies on other PRs or Work?

None.

Summary by CodeRabbit

  • New Features

    • Added Datasette service monitoring to the health endpoint.
    • Health responses now distinguish between ok, degraded, and down states.
    • Optional Redis outages are reported as degraded, while required service failures remain down.
  • Bug Fixes

    • Improved health reporting for unavailable dependencies, including clearer service-level statuses.

@coderabbitai

coderabbitai Bot commented Jul 14, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Walkthrough

The health endpoint now checks Datasette, represents dependencies as ok or down, treats Redis as optional, and reports ok, degraded, or down. Unit and integration tests cover the new checks and response scenarios.

Changes

Health monitoring

Layer / File(s) Summary
Health route and status aggregation
src/routes/health.js
Adds the Datasette query check, optional Redis handling, aggregate status calculation, and new exports.
Status and Datasette unit validation
test/unit/health.test.js
Tests Datasette success and failure handling plus ok, degraded, and down aggregation.
Endpoint response scenarios
test/integration/health.test.js
Updates health responses for four dependencies and covers required-service, optional Redis, and Datasette failures.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant HealthRoute
  participant checkDatasette
  participant datasette
  participant getStatus
  HealthRoute->>checkDatasette: Check Datasette
  checkDatasette->>datasette: runQuery("SELECT 1")
  datasette-->>checkDatasette: Return success or failure
  HealthRoute->>getStatus: Aggregate dependency states
  getStatus-->>HealthRoute: Return overall status
Loading

Possibly related issues

  • digital-land/submit#1222 — Adds the Datasette health check described by this change.

Poem

A rabbit checks the services bright,
Datasette answers, “All is right!”
Redis may wobble, soft and slow,
So “degraded” tells the tale below.
Required faults make warnings hop—
Healthy carrots never stop!

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly matches the main change: adding a Datasette health check to the health endpoint.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch 1222-add-a-health-endpoint-for-status-monitoring-the-endpoint-should-ensure-to-make-a-call-to-datasette

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@github-actions

github-actions Bot commented Jul 14, 2026

Copy link
Copy Markdown

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.07% 2551 / 3589
🔵 Statements 70.26% 2692 / 3831
🔵 Functions 64.39% 510 / 792
🔵 Branches 63.96% 1255 / 1962
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
src/routes/health.js 58.69% 25% 66.66% 56.81% 17-52, 92-109
Generated in workflow #1557 for commit 062383b by the Vitest Coverage Report Action

…ring-the-endpoint-should-ensure-to-make-a-call-to-datasette

@coderabbitai coderabbitai Bot 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.

🧹 Nitpick comments (2)
src/routes/health.js (2)

16-38: 🚀 Performance & Scalability | 🔵 Trivial | ⚡ Quick win

Run the independent health checks concurrently.

checkS3Bucket(), checkRequestApi(), checkDatasette(), and (conditionally) checkRedis() are awaited sequentially inside the array/object literals. Each is an independent network call, so this PR adds a fourth serialized round trip to /health, multiplying worst-case latency for a route that's typically polled with tight timeouts.

♻️ Proposed fix using Promise.all
 router.get('/', async (req, res) => {
-  const dependencies = [
-    {
-      name: 's3-bucket',
-      status: await checkS3Bucket() ? 'ok' : 'down'
-    },
-    {
-      name: 'request-api',
-      status: await checkRequestApi() ? 'ok' : 'down'
-    },
-    {
-      name: 'datasette',
-      status: await checkDatasette() ? 'ok' : 'down'
-    }
-  ]
+  const [s3Ok, requestApiOk, datasetteOk] = await Promise.all([
+    checkS3Bucket(),
+    checkRequestApi(),
+    checkDatasette()
+  ])
+  const dependencies = [
+    { name: 's3-bucket', status: s3Ok ? 'ok' : 'down' },
+    { name: 'request-api', status: requestApiOk ? 'ok' : 'down' },
+    { name: 'datasette', status: datasetteOk ? 'ok' : 'down' }
+  ]
   if (config.redis) {
     dependencies.push({
       name: 'redis',
       status: await checkRedis() ? 'ok' : 'down',
       required: false
     })
   }
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routes/health.js` around lines 16 - 38, Update the health route handler
to start the independent checks concurrently with Promise.all, including
checkRedis only when config.redis is enabled, then build the dependencies array
from the resolved results while preserving each existing name, status, and
optional required field.

82-89: 🩺 Stability & Availability | 🔵 Trivial | ⚡ Quick win

Add a timeout to datasette.runQueryaxios.get(url) has no timeout here, so a stalled Datasette request can leave /health hanging indefinitely instead of returning down.

🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/routes/health.js` around lines 82 - 89, Update checkDatasette so the
datasette.runQuery call enforces a finite timeout, using the existing Datasette
or HTTP client timeout configuration if available. Preserve the current true
result on success and false result when the request times out or otherwise
fails.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In `@src/routes/health.js`:
- Around line 16-38: Update the health route handler to start the independent
checks concurrently with Promise.all, including checkRedis only when
config.redis is enabled, then build the dependencies array from the resolved
results while preserving each existing name, status, and optional required
field.
- Around line 82-89: Update checkDatasette so the datasette.runQuery call
enforces a finite timeout, using the existing Datasette or HTTP client timeout
configuration if available. Preserve the current true result on success and
false result when the request times out or otherwise fails.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Repository UI

Review profile: CHILL

Plan: Pro

Run ID: e559f402-e118-4da5-92bf-7f1bc52fa99e

📥 Commits

Reviewing files that changed from the base of the PR and between 797367b and 662fcfe.

📒 Files selected for processing (3)
  • src/routes/health.js
  • test/integration/health.test.js
  • test/unit/health.test.js

@gibahjoe
gibahjoe merged commit 956a817 into main Jul 14, 2026
5 checks passed
@gibahjoe
gibahjoe deleted the 1222-add-a-health-endpoint-for-status-monitoring-the-endpoint-should-ensure-to-make-a-call-to-datasette branch July 14, 2026 14:58
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.

Add a health endpoint for status monitoring. The endpoint should ensure to make a call to datasette

2 participants