feat: add coderd_api_websocket_probes_total metric (#25012)

Relates to CODAGT-115

Adds metric `coderd_api_websocket_probes_total`. Every successful
heartbeat for a given path will increment the metric.

Comparing this with `coderd_api_concurrent_websockets` will give an
indication of how many websocket connections are open but in a 'wedged'
state (when heartbeats stopped versus when we closed the connection).
This commit is contained in:
Cian Johnston
2026-06-03 10:46:07 +01:00
committed by GitHub
parent 7703e7a26e
commit 8b058dc949
22 changed files with 596 additions and 171 deletions
+4 -1
View File
@@ -68,6 +68,7 @@ type API struct {
watcher watcher.Watcher
fs afero.Fs
execer agentexec.Execer
wsWatcher *httpapi.WSWatcher
commandEnv CommandEnv
ccli ContainerCLI
containerLabelIncludeFilter map[string]string // Labels to filter containers by.
@@ -348,6 +349,8 @@ func NewAPI(logger slog.Logger, options ...Option) *API {
for _, opt := range options {
opt(api)
}
api.wsWatcher = httpapi.NewWSWatcher(quartz.NewReal(), nil)
if api.commandEnv != nil {
api.execer = newCommandEnvExecer(
api.logger,
@@ -782,7 +785,7 @@ func (api *API) watchContainers(rw http.ResponseWriter, r *http.Request) {
ctx, wsNetConn := codersdk.WebsocketNetConn(ctx, conn, websocket.MessageText)
defer wsNetConn.Close()
go httpapi.HeartbeatClose(ctx, api.logger, cancel, conn)
ctx = api.wsWatcher.Watch(ctx, api.logger, conn)
updateCh := make(chan struct{}, 1)