package app import "time" func publishTransportRuntimeObservabilitySnapshotChanged(reason string, clientIDs []string, ifaceIDs []string) { now := time.Now().UTC() snapshot := transportRuntimeObservabilitySnapshotResponse(now) if !snapshot.OK { return } normalizedClientIDs := normalizeTransportRuntimeObservabilityClientIDs(clientIDs) normalizedIfaceIDs := resolveTransportRuntimeObservabilityEventIfaceIDs(snapshot.Items, normalizedClientIDs, ifaceIDs) events.push("transport_runtime_snapshot_changed", TransportRuntimeObservabilityChangedEvent{ Reason: reason, GeneratedAt: snapshot.GeneratedAt, Count: snapshot.Count, IfaceIDs: normalizedIfaceIDs, ClientIDs: normalizedClientIDs, Items: snapshot.Items, }) } func normalizeTransportRuntimeObservabilityClientIDs(clientIDs []string) []string { seen := map[string]struct{}{} out := make([]string, 0, len(clientIDs)) for _, raw := range clientIDs { id := sanitizeID(raw) if id == "" { continue } if _, ok := seen[id]; ok { continue } seen[id] = struct{}{} out = append(out, id) } return out } func resolveTransportRuntimeObservabilityEventIfaceIDs( items []TransportRuntimeObservabilityItem, clientIDs []string, ifaceIDs []string, ) []string { seen := map[string]struct{}{} out := make([]string, 0, len(ifaceIDs)+len(clientIDs)) add := func(raw string) { id := normalizeTransportIfaceID(raw) if id == "" { return } if _, ok := seen[id]; ok { return } seen[id] = struct{}{} out = append(out, id) } for _, raw := range ifaceIDs { add(raw) } for _, clientID := range clientIDs { for _, item := range items { if item.ClientID == clientID { add(item.IfaceID) continue } for _, memberID := range item.ClientIDs { if memberID == clientID { add(item.IfaceID) break } } } } if len(out) > 0 { return out } for _, item := range items { add(item.IfaceID) } return out }