feat(http): unauthenticated /api/health and /api/metrics on http service#18
Merged
BlindMaster24 merged 1 commit intoApr 27, 2026
Conversation
4 tasks
Author
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds two unauthenticated HTTP endpoints served directly by
HttpServiceso they are always available whenhttpis enabled, regardless of which other services are registered. Tightens the Docker healthcheck to actually fail on non-2xx responses.Why: the previous
/api/parser-healthis served byapiand requires an API key. As Devin Review pointed out on #16, the Docker healthcheck using that endpoint was effectively just a liveness probe — 401/404 both matched^[234], so healthcheck passed even when the API wasn't routed at all. This PR fixes it.What's new:
src/http.ts:HttpServiceconstructor now acceptsapp: App(already passed byregisterService, previously ignored).GET /api/health→ JSON{ ok, uptime, services, parserOk }. Always 200 while the process is alive.servicesreports the enabled list;parserOkisraspCache.successUpdate.GET /api/metrics→ Prometheustext/plain; version=0.0.4with:bot_up/bot_uptime_secondsbot_services_enabled/bot_service_enabled{service="..."}(per-service gauge)bot_parser_ok/bot_parser_last_update_timestamp_seconds/bot_parser_staleness_secondsbot_process_memory_bytes{area="rss|heap_total|heap_used|external"}Dockerfile+docker-compose.yml: healthcheck now hits/api/healthwith strictgrep -qE '^2'— any non-2xx fails the check.AGENTS.md: documents both endpoints and the Prometheus metric names.Verification:
pnpm run test:all— 30 files / 204 tests passed (unchanged surface area, http endpoint is covered by live Docker smoke).pnpm run ts-check/pnpm run lint/pnpm run format:check— clean.pnpm audit --audit-level=low— no known vulnerabilities.docker compose build && docker compose up -dwith the defaultconfig.example.ts(services =['http', 'parser', 'timetable']):healthy(~45s).curl http://127.0.0.1:8081/api/health→{"ok":true,"uptime":54,"services":["http","parser","timetable"],"parserOk":true}.curl http://127.0.0.1:8081/api/metrics→ full Prometheus text withbot_parser_ok 1,bot_parser_staleness_seconds 13, etc.Stacked on PR #17 (service dependency graph).
Review & Testing Checklist for Human
docker compose up -dfrom a clean checkout — container should transition tohealthywithin ~60s andcurl /api/healthshould return JSON with"parserOk":trueonce the first parser run completes./api/healthworks even if theapiservice is NOT inconfig.services— it's registered onhttp, not via the API method loader./api/metricsand verify the gauges appear with expected labels (service,area).docker stop mgke-timetable-botshould flipunhealthyon the next poll).Notes
express-rate-limitonapiroutes./api/healthstays unthrottled on purpose — it's meant for container orchestrators.HttpServicewith astop()method soSIGTERMdrains connections cleanly.Link to Devin session: https://app.devin.ai/sessions/7732f5fd16e9448295cbabeb8b5f471a
Requested by: @BlindMaster24