Skip to content

Conversation

@houseme
Copy link
Contributor

@houseme houseme commented Nov 29, 2025

Type of Change

  • New Feature
  • Bug Fix
  • Documentation
  • Performance Improvement
  • Test/CI
  • Refactor
  • Other:

Related Issues

#935

Summary of Changes

Summary

This PR improves the health check endpoints for both the S3 endpoint and the console:

  • /health (S3 endpoint) via HealthCheckHandler
  • /rustfs/console/health via health_check in console.rs

The goal is to support proper GET/HEAD semantics, avoid panics in error paths, and keep the responses stable for monitoring systems.

Changes

  • Added explicit method filtering in HealthCheckHandler:
    • Allow only GET and HEAD
    • Return 405 Method Not Allowed with Allow: GET, HEAD for others
    • For HEAD, return only status and headers with an empty body
  • Refined console health_check handler:
    • Unified handling for GET and HEAD
    • GET returns detailed JSON health info
    • HEAD returns only status and headers with an empty body
  • Replaced unwrap() calls in health check paths with safe fallbacks:
    • Use unwrap_or_default, unwrap_or_else, and explicit error logging
    • Avoid panics on JSON serialization failures and SystemTime issues
  • Kept existing JSON schema and status codes to preserve compatibility
    with existing probes and monitoring tools.

Motivation

  • Prevent panics in health check handlers, which are frequently called by
    load balancers and monitoring systems.
  • Provide correct HEAD semantics so that probes can cheaply verify liveness
    and readiness without transferring bodies.
  • Make method handling strict and explicit (405 with Allow header) so that
    API behavior is clear and predictable.

Testing

  • Manually verified:
    • GET /health returns HTTP 200 with JSON body.
    • HEAD /health returns HTTP 200 with headers, empty body.
    • GET /rustfs/console/health returns detailed status JSON.
    • HEAD /rustfs/console/health returns HTTP 200 with headers, empty body.
    • Unsupported methods (e.g. POST) on these endpoints return 405 with Allow: GET, HEAD.
  • Ran existing unit tests:
    • cargo test -p rustfs --tests

Checklist

  • I have read and followed the CONTRIBUTING.md guidelines
  • Passed make pre-commit
  • Added/updated necessary tests
  • Documentation updated (if needed)
  • CI/CD passed (if applicable)

Impact

  • Breaking change (compatibility)
  • Requires doc/config/deployment update
  • Other impact:

Additional Notes


Thank you for your contribution! Please ensure your PR follows the community standards (CODE_OF_CONDUCT.md) and sign the CLA if this is your first contribution.

- Add unified GET/HEAD handling for `/health` and `/rustfs/console/health`
- Implement proper method filtering and 405 with `Allow: GET, HEAD`
- Avoid panics by removing `unwrap()` in health check logic
- Add safe fallbacks for JSON serialization and uptime calculation
- Ensure HEAD requests return only status and headers (empty body)
- Keep response format backward compatible for monitoring systems
@houseme houseme merged commit 9398222 into main Nov 29, 2025
14 checks passed
@houseme houseme deleted the feature/health-head branch November 29, 2025 18:44
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.

1 participant