Built-in liveness/readiness health endpoints (opt-in HTTP server) #6802

Closed
opened 2026-08-31 16:12:49 +02:00 by ktriponis · 3 comments
ktriponis commented 2026-08-31 16:12:49 +02:00 (Migrated from github.com)

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 --rpc gates the RPC server), exposing standard liveness and
readiness 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 a
minimal HTTP listener and serve two endpoints, following the conventional
liveness/readiness split:

  • GET /health/live - liveness: dependency-free, reflects only that the process
    is 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 configured
    Config datastore's reachability. Returns 200 when ready, 503 otherwise.

Both endpoints should exist from the first version even if /health/ready
initially 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 - the
RPC 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 HTTP
GET liveness/readiness probe from an orchestrator (Kubernetes kubelet), a load
balancer 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:

  • A cog has to bootstrap its own aiohttp server and manage the socket's
    lifecycle by hand via cog_load/cog_unload - fragile plumbing to expect
    every operator to install and babysit for something as fundamental as "is the
    bot alive."
  • A cog can't see the truest signals. Core knows shard/connection state,
    wait_until_red_ready(), and the health of the configured Config datastore -
    exactly the inputs a meaningful /health/ready should aggregate. A cog only
    observes these indirectly.
  • A cog-based endpoint only exists after the bot has connected and loaded cogs,
    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/live from process start.
  • To be safe on a shared host the cog must default to 127.0.0.1, then require a
    manual reconfigure to 0.0.0.0 for containers. A flag-gated core feature could
    handle this cleanly and document it once.

Reference implementation - a cog that serves liveness at GET /health via a
lifecycle-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/ready split described above is the shape
this 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/ready vs. a single /health), what belongs in
readiness for a first version (shard state? Config datastore?), whether
cog-contributed readiness checks are in scope, and the default bind address.

### 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 `--rpc` gates the RPC server), exposing standard **liveness** and **readiness** 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 a minimal HTTP listener and serve two endpoints, following the conventional liveness/readiness split: - `GET /health/live` - liveness: dependency-free, reflects only that the process is 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 configured Config datastore's reachability. Returns `200` when ready, `503` otherwise. Both endpoints should exist from the first version even if `/health/ready` initially 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 - the RPC 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 HTTP `GET` liveness/readiness probe from an orchestrator (Kubernetes kubelet), a load balancer 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: - A cog has to bootstrap its own `aiohttp` server and manage the socket's lifecycle by hand via `cog_load`/`cog_unload` - fragile plumbing to expect every operator to install and babysit for something as fundamental as "is the bot alive." - A cog can't see the truest signals. Core knows shard/connection state, `wait_until_red_ready()`, and the health of the configured Config datastore - exactly the inputs a meaningful `/health/ready` should aggregate. A cog only observes these indirectly. - A cog-based endpoint only exists *after* the bot has connected and loaded cogs, 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/live` from process start. - To be safe on a shared host the cog must default to `127.0.0.1`, then require a manual reconfigure to `0.0.0.0` for containers. A flag-gated core feature could handle this cleanly and document it once. Reference implementation - a cog that serves liveness at `GET /health` via a lifecycle-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/ready` split described above is the shape this proposal argues core should adopt (and where readiness gains access to the signals a cog can't reach): **[shadow-templars/healthcheck](https://github.com/shadow-templars/shadow-cogs/tree/main/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/ready` vs. a single `/health`), what belongs in readiness for a first version (shard state? Config datastore?), whether cog-contributed readiness checks are in scope, and the default bind address.
Flame442 commented 2026-09-01 01:25:58 +02:00 (Migrated from github.com)

The main reason you are proposing for this being in Core instead of a 3rd party cog is to provide the live endpoint 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 isitdownrightnow status 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. uptimeresponder by Vexed).

The main reason you are proposing for this being in Core instead of a 3rd party cog is to provide the `live` endpoint 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 `isitdownrightnow` status 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. `uptimeresponder` by Vexed).
ktriponis commented 2026-09-01 02:26:57 +02:00 (Migrated from github.com)

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:

  • Restart-on-hang. A single instance can still wedge - a stuck event loop or a dead connection where the process is up but not really doing anything. A cheap liveness endpoint lets something like Uptime Kuma (or the process manager) notice and restart it, rather than me finding out hours later.
  • IaC ordering. This is the awkward one when doing it as a cog: the endpoint only exists after the bot connects and the cog loads. So if I define a liveness probe at provision time, it fails on first deploy because the cog isn't up yet - a chicken-and-egg a cog can't really solve, whereas a process-level endpoint could answer before cogs load.

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.

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: - **Restart-on-hang.** A single instance can still wedge - a stuck event loop or a dead connection where the process is up but not really doing anything. A cheap liveness endpoint lets something like Uptime Kuma (or the process manager) notice and restart it, rather than me finding out hours later. - **IaC ordering.** This is the awkward one when doing it as a cog: the endpoint only exists after the bot connects and the cog loads. So if I define a liveness probe at provision time, it fails on first deploy because the cog isn't up yet - a chicken-and-egg a cog can't really solve, whereas a process-level endpoint could answer before cogs load. 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.
Owner

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

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](https://claude.ai/code)_
Sign in to join this conversation.
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
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
Mrcoolgamer11/Red-DiscordBot#6802
No description provided.