ngx.var.upstream_* variables are not populated when using lua-resty-websocket

Aperta
#96 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
5/5
Tempo stimato
Più di una settimana
Idoneità per principianti
25/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Ferma
Stack tecnologico
lua, nginx

Direzione di ricerca

Inizia dal punto di ingresso resty.websocket.client e dalla chiamata client:connect mostrata nella riproduzione, quindi esamina come le connessioni upstream create da Lua siano correlate ai valori ngx.var.upstream_* elencati. Riproduci i valori nil per ws://127.0.0.1:9001/ws; il completamento non è definito concretamente perché l’issue propone hooks, metriche ngx.ctx o il tracciamento upstream come alternative.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

🐛 Bug Report: ngx.var.upstream_* variables are not populated when using lua-resty-websocket

Module: [openresty/lua-resty-websocket](https://github.com/openresty/lua-resty-websocket)
Problem: When using lua-resty-websocket to initiate a WebSocket connection to an upstream server manually, all of the following variables are missing or always nil:

ngx.var.upstream_addr
ngx.var.upstream_response_time
ngx.var.upstream_connect_time
ngx.var.upstream_header_time
ngx.var.upstream_bytes_received
🔍 Expected Behavior

These upstream-related variables should be available (or have an alternative way to be collected) so that access logs and metrics are still meaningful, even when the upstream connection is established in Lua.

📋 Actual Behavior

All upstream-related variables return nil or are completely unset:

ngx.log(ngx.ERR, ngx.var.upstream_addr)              -- nil
ngx.log(ngx.ERR, ngx.var.upstream_response_time)     -- nil
ngx.log(ngx.ERR, ngx.var.upstream_connect_time)      -- nil
ngx.log(ngx.ERR, ngx.var.upstream_header_time)       -- nil
ngx.log(ngx.ERR, ngx.var.upstream_bytes_received)    -- nil
📎 Context

We are using lua-resty-websocket to implement a WebSocket reverse proxy behavior with dynamic upstream selection and load balancing (e.g., round-robin / ip-hash in Lua). But since the upstream connection is made via Lua (and not via proxy_pass), OpenResty doesn’t populate any of the $upstream_* variables in access logs, which makes it difficult to monitor or troubleshoot.

✅ Suggestion

Even if these variables cannot be automatically populated, perhaps the library could expose hooks or utility functions to manually record metrics into ngx.ctx, or better integration with OpenResty’s upstream tracking mechanism (if possible).

🧪 Steps to Reproduce
local wb = require("resty.websocket.client")
local client, err = wb:new()
local ok, err = client:connect("ws://127.0.0.1:9001/ws")
-- Send/receive some data...
ngx.log(ngx.ERR, ngx.var.upstream_addr) -- nil
Lingua principale
Lua
Stelle
524
Fork
112
Merge medio
1h 20m
PR unite (30g)
3

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di openresty/lua-resty-websocket

Tutte le issue di openresty/lua-resty-websocket

Issue simili

Altre issue su Lua

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.