2026-04-15 15:24:36 +08:00
|
|
|
package notify
|
|
|
|
|
|
|
|
|
|
import "time"
|
|
|
|
|
|
|
|
|
|
type snapshotBindingDiagnostics struct {
|
2026-04-18 16:05:57 +08:00
|
|
|
BindingOwner string
|
|
|
|
|
BindingAlive bool
|
|
|
|
|
BindingCurrent bool
|
|
|
|
|
BindingReason string
|
|
|
|
|
BindingError string
|
|
|
|
|
BindingBulkAdaptiveSoftPayloadBytes int
|
|
|
|
|
BindingStreamAdaptiveSoftPayloadBytes int
|
|
|
|
|
BindingStreamAdaptiveWaitThresholdBytes int
|
|
|
|
|
BindingStreamAdaptiveFlushDelay time.Duration
|
|
|
|
|
TransportAttached bool
|
|
|
|
|
TransportHasRuntimeConn bool
|
|
|
|
|
TransportCurrent bool
|
|
|
|
|
TransportDetachReason string
|
|
|
|
|
TransportDetachKind string
|
|
|
|
|
TransportDetachError string
|
|
|
|
|
TransportDetachGeneration uint64
|
|
|
|
|
TransportDetachedAt time.Time
|
|
|
|
|
ReattachEligible bool
|
2026-04-15 15:24:36 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func snapshotBindingDiagnosticsFromClient(c *ClientCommon, sessionEpoch uint64) snapshotBindingDiagnostics {
|
|
|
|
|
diag := snapshotBindingDiagnostics{
|
|
|
|
|
BindingOwner: "client-session",
|
|
|
|
|
}
|
|
|
|
|
if c == nil {
|
|
|
|
|
return diag
|
|
|
|
|
}
|
|
|
|
|
status := c.Status()
|
|
|
|
|
diag.BindingAlive = status.Alive
|
|
|
|
|
diag.BindingCurrent = sessionEpoch == 0 || c.isClientSessionEpochCurrent(sessionEpoch)
|
|
|
|
|
diag.BindingReason = status.Reason
|
|
|
|
|
if status.Err != nil {
|
|
|
|
|
diag.BindingError = status.Err.Error()
|
|
|
|
|
}
|
|
|
|
|
diag.TransportAttached = c.clientTransportAttachedSnapshot()
|
|
|
|
|
diag.TransportHasRuntimeConn = c.clientTransportConnSnapshot() != nil
|
|
|
|
|
diag.TransportCurrent = diag.BindingCurrent && diag.TransportAttached
|
2026-04-18 16:05:57 +08:00
|
|
|
if binding := c.clientTransportBindingSnapshot(); binding != nil {
|
|
|
|
|
diag.BindingBulkAdaptiveSoftPayloadBytes = binding.bulkAdaptiveSoftPayloadBytesSnapshot()
|
|
|
|
|
diag.BindingStreamAdaptiveSoftPayloadBytes = binding.streamAdaptiveSoftPayloadBytesSnapshot()
|
|
|
|
|
diag.BindingStreamAdaptiveWaitThresholdBytes = binding.streamAdaptiveWaitThresholdBytesSnapshot()
|
|
|
|
|
diag.BindingStreamAdaptiveFlushDelay = binding.streamAdaptiveFlushDelaySnapshot()
|
|
|
|
|
}
|
2026-04-15 15:24:36 +08:00
|
|
|
return diag
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func snapshotBindingDiagnosticsFromLogical(logical *LogicalConn, transport *TransportConn, transportGeneration uint64) snapshotBindingDiagnostics {
|
|
|
|
|
if logical == nil && transport != nil {
|
|
|
|
|
logical = transport.LogicalConn()
|
|
|
|
|
}
|
|
|
|
|
diag := snapshotBindingDiagnostics{}
|
|
|
|
|
if logical == nil {
|
|
|
|
|
return diag
|
|
|
|
|
}
|
|
|
|
|
runtime := logical.runtimeSnapshot()
|
|
|
|
|
diag.BindingOwner = "server-logical"
|
|
|
|
|
if transport != nil {
|
|
|
|
|
diag.BindingOwner = "server-transport"
|
|
|
|
|
}
|
|
|
|
|
diag.BindingAlive = runtime.Alive
|
|
|
|
|
diag.BindingReason = runtime.Reason
|
|
|
|
|
diag.BindingError = runtime.Error
|
|
|
|
|
diag.TransportAttached = runtime.TransportAttached
|
|
|
|
|
diag.TransportHasRuntimeConn = runtime.HasRuntimeConn
|
|
|
|
|
diag.TransportDetachReason = runtime.TransportDetachReason
|
|
|
|
|
diag.TransportDetachKind = runtime.TransportDetachKind
|
|
|
|
|
diag.TransportDetachError = runtime.TransportDetachError
|
|
|
|
|
diag.TransportDetachGeneration = runtime.TransportDetachGeneration
|
|
|
|
|
diag.TransportDetachedAt = runtime.TransportDetachedAt
|
|
|
|
|
diag.ReattachEligible = runtime.ReattachEligible
|
|
|
|
|
switch {
|
|
|
|
|
case transport != nil:
|
|
|
|
|
diag.TransportCurrent = transport.IsCurrent()
|
|
|
|
|
case transportGeneration != 0:
|
|
|
|
|
diag.TransportCurrent = runtime.TransportAttached && runtime.TransportGeneration == transportGeneration
|
|
|
|
|
default:
|
|
|
|
|
diag.TransportCurrent = runtime.TransportAttached
|
|
|
|
|
}
|
|
|
|
|
diag.BindingCurrent = diag.BindingAlive && diag.TransportCurrent
|
2026-04-18 16:05:57 +08:00
|
|
|
if binding := logical.transportBindingSnapshot(); binding != nil {
|
|
|
|
|
diag.BindingBulkAdaptiveSoftPayloadBytes = binding.bulkAdaptiveSoftPayloadBytesSnapshot()
|
|
|
|
|
diag.BindingStreamAdaptiveSoftPayloadBytes = binding.streamAdaptiveSoftPayloadBytesSnapshot()
|
|
|
|
|
diag.BindingStreamAdaptiveWaitThresholdBytes = binding.streamAdaptiveWaitThresholdBytesSnapshot()
|
|
|
|
|
diag.BindingStreamAdaptiveFlushDelay = binding.streamAdaptiveFlushDelaySnapshot()
|
|
|
|
|
}
|
2026-04-15 15:24:36 +08:00
|
|
|
return diag
|
|
|
|
|
}
|