Expose QUIC fabric capacity pressure

This commit is contained in:
2026-05-16 12:46:36 +03:00
parent 5c02667398
commit 28c26a5103
3 changed files with 30 additions and 7 deletions
@@ -48,10 +48,13 @@ type QUICFabricTransportStats struct {
}
type QUICFabricTransportSnapshot struct {
SchemaVersion string `json:"schema_version"`
ActiveCount int `json:"active_count"`
ActiveStreams int `json:"active_streams"`
Stats QUICFabricTransportStats `json:"stats"`
SchemaVersion string `json:"schema_version"`
ActiveCount int `json:"active_count"`
ActiveStreams int `json:"active_streams"`
MaxStreamsPerConn int `json:"max_streams_per_conn"`
SaturatedConnections int `json:"saturated_connections"`
CapacityPressurePercent int `json:"capacity_pressure_percent"`
Stats QUICFabricTransportStats `json:"stats"`
}
type quicFabricSession struct {
@@ -334,9 +337,14 @@ func (t *QUICFabricTransport) Snapshot() QUICFabricTransportSnapshot {
t.mu.Lock()
defer t.mu.Unlock()
t.pruneIdleLocked(time.Now())
limit := t.MaxStreamsPerConn
if limit <= 0 {
limit = defaultQUICFabricMaxStreamsPerConn
}
snapshot := QUICFabricTransportSnapshot{
SchemaVersion: "rap.quic_fabric_transport.v1",
Stats: t.stats,
SchemaVersion: "rap.quic_fabric_transport.v1",
MaxStreamsPerConn: limit,
Stats: t.stats,
}
for key, entry := range t.conns {
if entry == nil || entry.conn == nil {
@@ -350,6 +358,15 @@ func (t *QUICFabricTransport) Snapshot() QUICFabricTransportSnapshot {
default:
snapshot.ActiveCount++
snapshot.ActiveStreams += entry.activeStreams
if entry.activeStreams >= limit {
snapshot.SaturatedConnections++
}
}
}
if snapshot.ActiveCount > 0 && limit > 0 {
capacity := snapshot.ActiveCount * limit
if capacity > 0 {
snapshot.CapacityPressurePercent = (snapshot.ActiveStreams * 100) / capacity
}
}
return snapshot
@@ -267,7 +267,11 @@ func TestQUICFabricTransportLimitsStreamsPerConnection(t *testing.T) {
t.Fatal("second connect succeeded past stream limit")
}
snapshot := transport.Snapshot()
if snapshot.ActiveStreams != 1 || snapshot.Stats.StreamLimitRejects != 1 {
if snapshot.ActiveStreams != 1 ||
snapshot.MaxStreamsPerConn != 1 ||
snapshot.SaturatedConnections != 1 ||
snapshot.CapacityPressurePercent != 100 ||
snapshot.Stats.StreamLimitRejects != 1 {
t.Fatalf("unexpected stream limit snapshot: %+v", snapshot)
}
if err := first.Close(); err != nil {