@@ -26,31 +26,34 @@ func monitorExternalEndpointHeartbeat(ee *endpoint.ExternalEndpoint, cfg *config
2626}
2727
2828func executeExternalEndpointHeartbeat (ee * endpoint.ExternalEndpoint , cfg * config.Config , extraLabels []string ) {
29+ logger := slog .With (ee .GetLogAttribute ())
30+
2931 // Acquire semaphore to limit concurrent external endpoint monitoring
3032 if err := monitoringSemaphore .Acquire (ctx , 1 ); err != nil {
3133 // Only fails if context is cancelled (during shutdown)
32- slog .Debug ("Context cancelled, skipping execution" , "error" , err .Error ())
34+ logger .Debug ("Context cancelled; skipping execution" , "error" , err .Error ())
3335 return
3436 }
3537 defer monitoringSemaphore .Release (1 )
3638 // If there's a connectivity checker configured, check if Gatus has internet connectivity
3739 if cfg .Connectivity != nil && cfg .Connectivity .Checker != nil && ! cfg .Connectivity .Checker .IsConnected () {
38- slog .Info ("No connectivity; skipping external endpoint execution" )
40+ logger .Info ("No connectivity, skipping execution" )
3941 return
4042 }
41- slog .Debug ("Monitoring external endpoint" , "group" , ee . Group , "name" , ee . Name , "key" , ee . Key () )
43+ logger .Debug ("Monitoring start" )
4244 convertedEndpoint := ee .ToEndpoint ()
4345 hasReceivedResultWithinHeartbeatInterval , err := store .Get ().HasEndpointStatusNewerThan (ee .Key (), time .Now ().Add (- ee .Heartbeat .Interval ))
4446 if err != nil {
4547 slog .Error ("Failed to check if external endpoint has received a result within the heartbeat interval" , "group" , ee .Group , "name" , ee .Name , "key" , ee .Key (), "error" , err .Error ())
48+ logger .Error ("Monitoring error" , "error" , err .Error ())
4649 return
4750 }
4851 if hasReceivedResultWithinHeartbeatInterval {
4952 // If we received a result within the heartbeat interval, we don't want to create a successful result, so we
5053 // skip the rest. We don't have to worry about alerting or metrics, because if the previous heartbeat failed
5154 // while this one succeeds, it implies that there was a new result pushed, and that result being pushed
5255 // should've resolved the alert.
53- slog .Info ("External endpint heartbeat received within interval" , "group" , ee . Group , "name" , ee . Name , "key" , ee . Key () , "success" , hasReceivedResultWithinHeartbeatInterval , "errors" , 0 )
56+ logger .Info ("Monitoring success, heartbeat received within interval" , "success" , hasReceivedResultWithinHeartbeatInterval , "errors" , 0 )
5457 return
5558 }
5659 // All code after this point assumes the heartbeat failed
@@ -63,7 +66,7 @@ func executeExternalEndpointHeartbeat(ee *endpoint.ExternalEndpoint, cfg *config
6366 metrics .PublishMetricsForEndpoint (convertedEndpoint , result , extraLabels )
6467 }
6568 UpdateEndpointStatus (convertedEndpoint , result )
66- slog .Info ("Heartbeat checked for external endpoint" , "group" , ee . Group , "name" , ee . Name , "key" , ee . Key () , "success" , result .Success , "errors" , len (result .Errors ), "duration" , result .Duration .Round (time .Millisecond ))
69+ logger .Info ("Monitoring done" , "success" , result .Success , "errors" , len (result .Errors ), "duration" , result .Duration .Round (time .Millisecond ))
6770 inEndpointMaintenanceWindow := false
6871 for _ , maintenanceWindow := range ee .MaintenanceWindows {
6972 if maintenanceWindow .IsUnderMaintenance () {
@@ -77,7 +80,6 @@ func executeExternalEndpointHeartbeat(ee *endpoint.ExternalEndpoint, cfg *config
7780 ee .NumberOfSuccessesInARow = convertedEndpoint .NumberOfSuccessesInARow
7881 ee .NumberOfFailuresInARow = convertedEndpoint .NumberOfFailuresInARow
7982 } else {
80- slog .Debug ("Not handling alerting because currently in the maintenance window" )
83+ logger .Debug ("Not handling alerting due to maintenance window" )
8184 }
82- slog .Debug ("Waiting for next external endpoint execution" , "group" , ee .Group , "name" , ee .Name , "key" , ee .Key (), "interval" , ee .Heartbeat .Interval )
8385}
0 commit comments