Skip to content

feat: add /metrics endpoint and request timeout handling - #32

Open
tamish560 wants to merge 1 commit into
Gilfeather:mainfrom
tamish560:feat/metrics-endpoint
Open

feat: add /metrics endpoint and request timeout handling#32
tamish560 wants to merge 1 commit into
Gilfeather:mainfrom
tamish560:feat/metrics-endpoint

Conversation

@tamish560

Copy link
Copy Markdown

Summary

Addresses issues #4 and #10.

/metrics endpoint (issue #4)

  • GET /metrics returns JSON with server metrics: uptime_seconds, total_requests, total_errors, total_inferences, average_inference_time_ms, last_inference_time_ms, memory_usage_bytes, timestamp
  • Request and error counters tracked via AtomicU64 in ServerState
  • Mirrors existing model_info stats but in a dedicated monitoring-friendly format

Request timeout handling (issue #10)

  • Added request_timeout_secs to ServerConfig (default: 30s)
  • Inference runs in tokio::task::spawn_blocking wrapped with tokio::time::timeout
  • Returns 408 Request Timeout on timeout
  • Returns 500 on join errors or inference failures
  • Error counter incremented on all error paths

Other changes

  • Removed duplicate tower dependency in Cargo.toml
  • Added timeout feature to tower crate
  • All 15 existing tests pass

Test plan

  • cargo test --no-default-features --lib - 15/15 pass
  • test_metrics_endpoint - verifies /metrics returns 200 with correct fields
  • test_predict_endpoint_success - still passes with timeout wrapper
  • test_predict_endpoint_invalid_input - validation errors still return 400
  • test_predict_endpoint_empty_input - empty input still returns 400

Metrics endpoint (issue Gilfeather#4):
- GET /metrics returns JSON with uptime, total_requests, total_errors,
  total_inferences, average_inference_time_ms, memory_usage_bytes
- Request and error counters tracked via atomic counters in ServerState
- Test coverage for the new endpoint

Request timeout handling (issue Gilfeather#10):
- Configurable HTTP request timeout via ServerConfig.request_timeout_secs
- Default 30 seconds, configurable via CLI
- Inference runs in spawn_blocking with tokio::time::timeout wrapper
- Returns HTTP 408 Request Timeout on timeout
- Returns HTTP 500 on task join errors or inference errors

Also removes duplicate tower dependency in Cargo.toml.
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