(ctx context.Context, useSnapshots bool)
| 282 | } |
| 283 | |
| 284 | func (s *Sync) RootStats(ctx context.Context, useSnapshots bool) (map[string]*model.EndpointRootStat, error) { |
| 285 | |
| 286 | endpoints := map[string]model.Endpoint{ |
| 287 | s.Source.GetEndpointInfo().URI: s.Source, |
| 288 | s.Target.GetEndpointInfo().URI: s.Target, |
| 289 | } |
| 290 | if useSnapshots && s.Direction == model.DirectionBi && s.snapshotFactory != nil { |
| 291 | source, _ := model.AsPathSyncSource(s.Source) |
| 292 | targetAsSource, _ := model.AsPathSyncSource(s.Target) |
| 293 | if leftSnap, err := s.snapshotFactory.Load(source); err == nil { |
| 294 | endpoints[source.GetEndpointInfo().URI] = leftSnap |
| 295 | } |
| 296 | if rightSnap, err := s.snapshotFactory.Load(targetAsSource); err == nil { |
| 297 | endpoints[s.Target.GetEndpointInfo().URI] = rightSnap |
| 298 | } |
| 299 | } |
| 300 | lock := sync.Mutex{} |
| 301 | result := make(map[string]*model.EndpointRootStat, len(endpoints)) |
| 302 | |
| 303 | wg := &sync.WaitGroup{} |
| 304 | wg.Add(len(endpoints)) |
| 305 | var errs []error |
| 306 | for key, ep := range endpoints { |
| 307 | epCopy := ep |
| 308 | keyCopy := key |
| 309 | go func() { |
| 310 | defer wg.Done() |
| 311 | if sourceRoots, e := s.statRoots(ctx, epCopy); e == nil { |
| 312 | lock.Lock() |
| 313 | log.Logger(ctx).Info("Got Stats for "+keyCopy, zap.Any("stats", *sourceRoots)) |
| 314 | result[keyCopy] = sourceRoots |
| 315 | lock.Unlock() |
| 316 | if !useSnapshots && s.watchConn != nil { |
| 317 | go func() { |
| 318 | s.watchConn <- &model.EndpointStatus{ |
| 319 | WatchConnection: model.WatchStats, |
| 320 | EndpointInfo: epCopy.GetEndpointInfo(), |
| 321 | Stats: sourceRoots, |
| 322 | } |
| 323 | }() |
| 324 | } |
| 325 | } else { |
| 326 | errs = append(errs, e) |
| 327 | if !useSnapshots && s.watchConn != nil { |
| 328 | go func() { |
| 329 | s.watchConn <- &model.EndpointStatus{ |
| 330 | WatchConnection: model.WatchDisconnected, |
| 331 | EndpointInfo: epCopy.GetEndpointInfo(), |
| 332 | } |
| 333 | }() |
| 334 | } |
| 335 | } |
| 336 | }() |
| 337 | } |
| 338 | wg.Wait() |
| 339 | if len(errs) > 0 { |
| 340 | return nil, errs[0] |
| 341 | } |
no test coverage detected