mirror of
https://github.com/fosrl/newt.git
synced 2026-03-26 20:46:41 +00:00
fix(telemetry): enhance session observation logic for tunnel IDs and site-level aggregation
This commit is contained in:
@@ -71,14 +71,36 @@ func observeLastHeartbeatFor(o metric.Observer, sv StateView, siteID string) {
|
|||||||
|
|
||||||
func observeSessionsFor(o metric.Observer, siteID string, any interface{}) {
|
func observeSessionsFor(o metric.Observer, siteID string, any interface{}) {
|
||||||
if tm, ok := any.(interface{ SessionsByTunnel() map[string]int64 }); ok {
|
if tm, ok := any.(interface{ SessionsByTunnel() map[string]int64 }); ok {
|
||||||
for tid, n := range tm.SessionsByTunnel() {
|
sessions := tm.SessionsByTunnel()
|
||||||
|
// If tunnel_id labels are enabled, preserve existing per-tunnel observations
|
||||||
|
if ShouldIncludeTunnelID() {
|
||||||
|
for tid, n := range sessions {
|
||||||
attrs := []attribute.KeyValue{
|
attrs := []attribute.KeyValue{
|
||||||
attribute.String("site_id", siteID),
|
attribute.String("site_id", siteID),
|
||||||
}
|
}
|
||||||
if ShouldIncludeTunnelID() && tid != "" {
|
if tid != "" {
|
||||||
attrs = append(attrs, attribute.String("tunnel_id", tid))
|
attrs = append(attrs, attribute.String("tunnel_id", tid))
|
||||||
}
|
}
|
||||||
o.ObserveInt64(mTunnelSessions, n, metric.WithAttributes(attrs...))
|
o.ObserveInt64(mTunnelSessions, n, metric.WithAttributes(attrs...))
|
||||||
}
|
}
|
||||||
|
return
|
||||||
|
}
|
||||||
|
// When tunnel_id is disabled, collapse per-tunnel counts into a single site-level value
|
||||||
|
var total int64
|
||||||
|
for _, n := range sessions {
|
||||||
|
total += n
|
||||||
|
}
|
||||||
|
// If there are no per-tunnel entries, fall back to ActiveSessions() if available
|
||||||
|
if total == 0 {
|
||||||
|
if svAny := stateView.Load(); svAny != nil {
|
||||||
|
if sv, ok := svAny.(StateView); ok {
|
||||||
|
if n, ok2 := sv.ActiveSessions(siteID); ok2 {
|
||||||
|
total = n
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
o.ObserveInt64(mTunnelSessions, total, metric.WithAttributes(attribute.String("site_id", siteID)))
|
||||||
|
return
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user