feat: per-listener latency tracking
Each listener now tracks chain setup latency independently via a dict[str, LatencyTracker] on Metrics. The global aggregate stays for summary output. /status embeds per-listener latency on each listener entry; /metrics includes a listener_latency map keyed by host:port.
This commit is contained in:
@@ -135,11 +135,18 @@ class TestHandleStatus:
|
||||
],
|
||||
)
|
||||
ctx = _make_ctx(config=config)
|
||||
# record some latency for the first listener
|
||||
ctx["metrics"].get_listener_latency("0.0.0.0:1080").record(0.2)
|
||||
_, body = _handle_status(ctx)
|
||||
assert len(body["listeners"]) == 2
|
||||
assert body["listeners"][0]["chain"] == ["socks5://127.0.0.1:9050"]
|
||||
assert body["listeners"][0]["pool_hops"] == 0
|
||||
assert body["listeners"][1]["pool_hops"] == 1
|
||||
# per-listener latency present on each entry
|
||||
assert "latency" in body["listeners"][0]
|
||||
assert body["listeners"][0]["latency"]["count"] == 1
|
||||
assert "latency" in body["listeners"][1]
|
||||
assert body["listeners"][1]["latency"] is None
|
||||
|
||||
|
||||
class TestHandleMetrics:
|
||||
@@ -156,6 +163,7 @@ class TestHandleMetrics:
|
||||
assert "uptime" in body
|
||||
assert "rate" in body
|
||||
assert "latency" in body
|
||||
assert "listener_latency" in body
|
||||
|
||||
|
||||
class TestHandlePool:
|
||||
|
||||
@@ -136,6 +136,23 @@ class TestMetrics:
|
||||
assert "p50=" not in s
|
||||
assert "p95=" not in s
|
||||
|
||||
def test_listener_latency(self):
|
||||
m = Metrics()
|
||||
m.get_listener_latency("0.0.0.0:1080").record(0.5)
|
||||
m.get_listener_latency("0.0.0.0:1080").record(0.6)
|
||||
m.get_listener_latency("0.0.0.0:1081").record(0.1)
|
||||
d = m.to_dict()
|
||||
assert "listener_latency" in d
|
||||
assert "0.0.0.0:1080" in d["listener_latency"]
|
||||
assert "0.0.0.0:1081" in d["listener_latency"]
|
||||
assert d["listener_latency"]["0.0.0.0:1080"]["count"] == 2
|
||||
assert d["listener_latency"]["0.0.0.0:1081"]["count"] == 1
|
||||
|
||||
def test_listener_latency_empty(self):
|
||||
m = Metrics()
|
||||
d = m.to_dict()
|
||||
assert d["listener_latency"] == {}
|
||||
|
||||
|
||||
# -- _human_bytes ------------------------------------------------------------
|
||||
|
||||
|
||||
Reference in New Issue
Block a user