@@ -286,35 +286,22 @@ func (s *npCollectorImpl) getVPCSubnets() ([]netip.Prefix, error) {
286286}
287287
288288func (s * npCollectorImpl ) ScheduleNetworkPathTests (conns iter.Seq [npmodel.NetworkPathConnection ]) {
289- if s .collectorConfigs .connectionsMonitoringEnabled {
290- s .scheduleNetworkPathTests (payload .PathOriginNetworkTraffic , conns )
291- } else if s .collectorConfigs .baselineTestsEnabled {
292- s .scheduleBaselineNetworkPathTests (conns )
289+ if ! s .collectorConfigs .connectionsMonitoringEnabled && ! s .collectorConfigs .baselineTestsEnabled {
290+ return
293291 }
292+
293+ baseline := ! s .collectorConfigs .connectionsMonitoringEnabled
294+ s .scheduleNetworkPathTests (payload .PathOriginNetworkTraffic , conns , baseline )
294295}
295296
296297func (s * npCollectorImpl ) ScheduleNetflowPathTests (conns iter.Seq [npmodel.NetworkPathConnection ]) {
297298 if ! s .collectorConfigs .netflowMonitoringEnabled {
298299 return
299300 }
300- s .scheduleNetworkPathTests (payload .PathOriginNetflow , conns )
301- }
302-
303- func (s * npCollectorImpl ) prepareNetworkPathTest (conn npmodel.NetworkPathConnection , origin payload.PathOrigin , vpcSubnets []netip.Prefix ) (common.Pathtest , pathEvaluation , bool ) {
304- evaluation := s .evaluateNetworkPathForConn (conn , origin , vpcSubnets )
305- if ! evaluation .shouldSchedule {
306- s .logger .Tracef ("Skipped connection: addr=%s, protocol=%s" , conn .Dest , conn .Type )
307- return common.Pathtest {}, pathEvaluation {}, false
308- }
309- return s .makePathtest (conn , origin ), evaluation , true
310- }
311-
312- func (s * npCollectorImpl ) reportScheduleTelemetry (startTime time.Time , connCount int ) {
313- _ = s .statsdClient .Count (common .NetworkPathCollectorMetricPrefix + "schedule.conns_received" , int64 (connCount ), []string {}, 1 )
314- _ = s .statsdClient .Gauge (common .NetworkPathCollectorMetricPrefix + "schedule.duration" , s .TimeNowFn ().Sub (startTime ).Seconds (), nil , 1 )
301+ s .scheduleNetworkPathTests (payload .PathOriginNetflow , conns , false )
315302}
316303
317- func (s * npCollectorImpl ) scheduleNetworkPathTests (origin payload.PathOrigin , conns iter.Seq [npmodel.NetworkPathConnection ]) {
304+ func (s * npCollectorImpl ) scheduleNetworkPathTests (origin payload.PathOrigin , conns iter.Seq [npmodel.NetworkPathConnection ], baseline bool ) {
318305 var vpcSubnets []netip.Prefix
319306 if origin == payload .PathOriginNetworkTraffic {
320307 var err error
@@ -327,22 +314,46 @@ func (s *npCollectorImpl) scheduleNetworkPathTests(origin payload.PathOrigin, co
327314
328315 startTime := s .TimeNowFn ()
329316 connCount := 0
317+ var selected []baselineCandidate
318+ if baseline {
319+ selected = make ([]baselineCandidate , 0 , baselineSelectionsPerSnapshot )
320+ }
330321 for conn := range conns {
331322 connCount ++
332- pathtest , evaluation , ok := s .prepareNetworkPathTest (conn , origin , vpcSubnets )
333- if ! ok {
323+ evaluation := s .evaluateNetworkPathForConn (conn , origin , vpcSubnets )
324+ if ! evaluation .shouldSchedule {
325+ s .logger .Tracef ("Skipped connection: addr=%s, protocol=%s" , conn .Dest , conn .Type )
326+ continue
327+ }
328+ pathtest := s .makePathtest (conn , origin )
329+ if baseline {
330+ pathtest .DynamicTestProfile = payload .DynamicTestProfileBaseline
331+ selected = addBaselineCandidate (selected , baselineCandidate {
332+ path : pathtest ,
333+ pathHash : pathtest .GetHash (),
334+ diagnostic : conn .Baseline .Diagnostic ,
335+ bytes : conn .Baseline .Bytes ,
336+ })
334337 continue
335338 }
339+
336340 pathtest .TestConfigID = evaluation .testConfigID
337341 pathtest .Tags = evaluation .tags
338342 if evaluation .testConfigID != "" {
339343 pathtest .TestConfigSource = payload .TestConfigSourceRemote
340344 }
341- if err := s .scheduleOne (& pathtest ); err != nil {
345+ err := s .scheduleOne (& pathtest )
346+ if err != nil {
342347 s .logger .Errorf ("Error scheduling pathtests: %s" , err )
343348 }
344349 }
345- s .reportScheduleTelemetry (startTime , connCount )
350+ for i := range selected {
351+ if err := s .scheduleOne (& selected [i ].path ); err != nil {
352+ s .logger .Errorf ("Error scheduling baseline pathtest: %s" , err )
353+ }
354+ }
355+ _ = s .statsdClient .Count (common .NetworkPathCollectorMetricPrefix + "schedule.conns_received" , int64 (connCount ), []string {}, 1 )
356+ _ = s .statsdClient .Gauge (common .NetworkPathCollectorMetricPrefix + "schedule.duration" , s .TimeNowFn ().Sub (startTime ).Seconds (), nil , 1 )
346357}
347358
348359// scheduleOne schedules pathtests.
0 commit comments