Built-in liveness/readiness health endpoints (opt-in HTTP server) #6802
Labels
No labels
Automated PR
Blocked
Blocked By: Damage Control
Blocked By: Dependency
Blocked By: Other PR
Breaking Change
Category: CI
Category: Cogs - Admin
Category: Cogs - Alias
Category: Cogs - Audio
Category: Cogs - Bank
Category: Cogs - Cleanup
Category: Cogs - CustomCommands
Category: Cogs - Dev
Category: Cogs - Downloader
Category: Cogs - Economy
Category: Cogs - Filter
Category: Cogs - General
Category: Cogs - Image
Category: Cogs - Mod
Category: Cogs - Modlog
Category: Cogs - Mutes
Category: Cogs - Permissions
Category: Cogs - Reports
Category: Cogs - Streams
Category: Cogs - Trivia
Category: Cogs - Trivia - Lists
Category: Cogs - Warnings
Category: Core - API - App Commands Package
Category: Core - API - Audio
Category: Core - API - Bank
Category: Core - API - Commands Package
Category: Core - API - Config
Category: Core - API - Other
Category: Core - API - Utils Package
Category: Core - Bot Class
Category: Core - Bot Commands
Category: Core - Command-line Interfaces
Category: Core - Downloader
Category: Core - Help
Category: Core - i18n
Category: Core - Modlog
Category: Core - Other Internals
Category: Core - RPC/ZMQ
Category: Docker
Category: Docs - Changelogs
Category: Docs - For Developers
Category: Docs - Install Guides
Category: Docs - Other
Category: Docs - User Guides
Category: Meta
Category: RPC/ZMQ methods
Category: Vendored Packages
Changelog Entry: Added
Changelog Entry: Pending
Changelog Entry: Skipped
Closed: Duplicate
Closed: External
Closed: Invalid
Closed: User Error
Closed: Won't Fix
Complex Issue
Docs-only
Feature Branch
Good First Issue
Help Wanted
High Priority
Needs Backport To stable-docs
No Activity
No Repro
QA: Bypassed
QA: Changes Requested
QA: Passed
Release Blocker
Status: Accepted
Status: Frozen
Status: In Progress
Status: Needs Discussion
Status: Needs Info
Status: Needs Triage
Status: PRs Welcome
Type: Bug
Type: Dependency Update
Type: Deprecation
Type: Enhancement
Type: Feature
Type: Informational
Type: Merge
Type: Optimisation
Type: Question
Type: Removal
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
Mrcoolgamer11/Red-DiscordBot#6802
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Type of feature request
API functionality
Description of the feature you're suggesting
Add an optional, built-in HTTP health server to Red core, enabled by a CLI flag
(mirroring how
--rpcgates the RPC server), exposing standard liveness andreadiness endpoints for external monitoring - consumable by Kubernetes
liveness/readiness probes, load balancer health checks, and monitoring systems
(Prometheus, Datadog). These are the standard ways production services expose
whether they are alive and ready, and Red has no first-party way to do it today.
When started with a flag (e.g.
--health/--health-port), Red would bind aminimal HTTP listener and serve two endpoints, following the conventional
liveness/readiness split:
GET /health/live- liveness: dependency-free, reflects only that the processis alive and the event loop is responsive. Always cheap; never gated on Discord
connectivity (a transient gateway blip must not cause an orchestrator to
kill a healthy bot). Returns e.g.
200 {"status": "ok"}.GET /health/ready- readiness: reports whether the bot is able to serve -e.g. shard/connection state,
wait_until_red_ready(), and the configuredConfig datastore's reachability. Returns
200when ready,503otherwise.Both endpoints should exist from the first version even if
/health/readyinitially mirrors the liveness response. The two carry different operational
semantics: a liveness failure tells an orchestrator to restart the process,
while a readiness failure tells it to remove the instance from rotation but
leave it running. Reserving both paths up front means operators wire their probes
at the correct endpoints immediately, and readiness can grow real dependency
checks later without ever changing the contract they already configured.
A natural later extension (out of scope for a first version) would let cogs
contribute named readiness checks that are aggregated into
/health/ready.The bind host/port should be configurable and default to loopback
(
127.0.0.1), consistent with Red's existing security-conscious posture - theRPC server is localhost-only "for security reasons". Operators running in a
container would opt into
0.0.0.0.This is new functionality, not an extension of something existing. Red's only
current external interface is the RPC server, which is websocket JSON-RPC bound
to
127.0.0.1:6133, not configurable, and provisional - it cannot serve an HTTPGETliveness/readiness probe from an orchestrator (Kubernetes kubelet), a loadbalancer health check, a Docker healthcheck, or a monitoring system (Prometheus
blackbox exporter, Datadog HTTP check).
Liveness/readiness is deploy-time infrastructure, in the same category as the RPC
server - something an operator wires into how the bot runs, not a feature a
server admin toggles. That is why it belongs in core rather than a cog: a cog can
only approximate it (see below), and requiring a cog for basic operational health
is exactly the kind of capability self-hosted deployments (increasingly on
Kubernetes) expect from the platform itself.
Anything else?
I've built this as a cog to prove the concept, and running it in production
surfaced precisely the limitations that argue for a core implementation:
aiohttpserver and manage the socket'slifecycle by hand via
cog_load/cog_unload- fragile plumbing to expectevery operator to install and babysit for something as fundamental as "is the
bot alive."
wait_until_red_ready(), and the health of the configured Config datastore -exactly the inputs a meaningful
/health/readyshould aggregate. A cog onlyobserves these indirectly.
so it can't report health during early startup - which is exactly when an
orchestrator's startup probe wants a signal. A core server could answer
/health/livefrom process start.127.0.0.1, then require amanual reconfigure to
0.0.0.0for containers. A flag-gated core feature couldhandle this cleanly and document it once.
Reference implementation - a cog that serves liveness at
GET /healthvia alifecycle-managed aiohttp server (started/stopped in
cog_load/cog_unload,loopback-default bind). It proves the liveness primitive in production; the
two-endpoint
/health/live+/health/readysplit described above is the shapethis proposal argues core should adopt (and where readiness gains access to the
signals a cog can't reach): shadow-templars/healthcheck
I'm happy to contribute a PR if the team is open to a flag-gated core health
server. I'd value guidance on the preferred shape: flag naming, endpoint paths
(
/health/live+/health/readyvs. a single/health), what belongs inreadiness for a first version (shard state? Config datastore?), whether
cog-contributed readiness checks are in scope, and the default bind address.
The main reason you are proposing for this being in Core instead of a 3rd party cog is to provide the
liveendpoint during startup for use in a clustered hosting environment like Kubernetes. The issue with this approach is that multiple instances of the same bot should not be connected to discord at the same time, despite it being possible to do so. Having multiple bots respond would be confusing for users or require additional infrastructure in Red to coordinate "disabling" an instance, which is not something we are going to add to Core.In addition, Red starts up fairly quickly, so the downtime of needing to launch Red (assuming an already live cluster with the process not started) is minimal, and totally reasonable for a discord bot. Our main focus is on small self hosted bots, and large redundant infrastructure is not necessary for that kind of user. The primary case where this type of feature would be useful for our userbase is an
isitdownrightnowstatus kind of page, which is completely fine to have the bot expose its status via a cog and the server itself via a non-bot mechanism.This feature seems too niche for something we would be interested in, and the more general alternatives are already supported by 3rd party cogs (i.e.
uptimeresponderby Vexed).Thanks for the detailed response - that's fair. Honestly, I leaned way too hard on the clustering angle in how I wrote this up, and in doing so I buried what I was actually hoping to get out of it. Let me try to explain the bigger picture better.
I run my bot on a small single-instance k3s setup - not for redundancy, just because the rest of my self-hosted stack lives there. So scaling was never really the point. The two things I was actually after are pretty mundane:
One idea if it were ever in scope: a health surface cogs could register their own readiness checks into, and optionally flag whether their check is critical. A critical cog going unhealthy could mark the whole bot unhealthy (so monitoring can restart it if configured to), while a non-critical one just surfaces as degraded without triggering a restart. Different cogs have different deps and failure modes, so it could double as an extension point rather than being purely core.
Totally understand if it still doesn't fit Red's focus - my cog covers me fine for now either way. Thanks for taking the time to think it through.
Offene Diskussion bzw. Feature-Wunsch mit geringem Nutzen im Verhältnis zum Aufwand (oder Nischenfall), der seit Langem ohne Ergebnis offen ist. Ich schließe das Issue; bei konkretem Bedarf kann es gern wieder geöffnet werden.
Generated by Claude Code