@@ -35,6 +35,7 @@ protected override async Task ExecuteAsync(CancellationToken cancellationToken)
3535 {
3636 try
3737 {
38+ logger . LogInformation ( $ "Performing sync for { nameof ( HeartbeatEndpointSettingsSyncHostedService ) } ") ;
3839 await PerformSync ( cancellationToken ) ;
3940 }
4041 catch ( Exception ex ) when ( ex is not OperationCanceledException )
@@ -72,10 +73,13 @@ async Task PurgeMonitoringDataThatDoesNotNeedToBeTracked(CancellationToken cance
7273 {
7374 if ( monitorEndpointsLookup . Contains ( endpointSetting . Name ) )
7475 {
75- foreach ( Guid endpointId in monitorEndpointsLookup [ endpointSetting . Name ] )
76+ // We leave one dead instance behind, so that in ServicePulse we still display the endpoint as unhealthy, and is up to the user to manually delete it.
77+ // Otherwise, we would delete all dead instances and it could be that the endpoint should be alive but all instances are down and then we display nothing in ServicePulse which is no good!
78+ foreach ( Guid endpointId in monitorEndpointsLookup [ endpointSetting . Name ] . SkipLast ( 1 ) )
7679 {
7780 endpointInstanceMonitoring . RemoveEndpoint ( endpointId ) ;
7881 await monitoringDataStore . Delete ( endpointId ) ;
82+ logger . LogInformation ( $ "Removed endpoint '{ endpointSetting . Name } ' from monitoring data.") ;
7983 }
8084 }
8185 }
@@ -102,6 +106,8 @@ async Task InitialiseSettings(HashSet<string> monitorEndpoints, CancellationToke
102106 if ( ! monitorEndpoints . Contains ( endpointSetting . Name ) )
103107 {
104108 await endpointSettingsStore . Delete ( endpointSetting . Name , cancellationToken ) ;
109+ logger . LogInformation (
110+ $ "Removed EndpointTracking setting for '{ endpointSetting . Name } ' endpoint, since this endpoint is no longer monitored.") ;
105111 }
106112
107113 settingsNames . Add ( endpointSetting . Name ) ;
@@ -113,6 +119,8 @@ async Task InitialiseSettings(HashSet<string> monitorEndpoints, CancellationToke
113119 await endpointSettingsStore . UpdateEndpointSettings (
114120 new EndpointSettings { Name = string . Empty , TrackInstances = userSetTrackInstances } ,
115121 cancellationToken ) ;
122+ logger . LogInformation (
123+ $ "Initialized default value of EndpointTracking to { ( userSetTrackInstances ? "tracking" : "not tracking" ) } .") ;
116124 }
117125
118126 // Initialise settings for any missing endpoint
@@ -121,6 +129,8 @@ await endpointSettingsStore.UpdateEndpointSettings(
121129 await endpointSettingsStore . UpdateEndpointSettings (
122130 new EndpointSettings { Name = name , TrackInstances = userSetTrackInstances } ,
123131 cancellationToken ) ;
132+ logger . LogInformation (
133+ $ "Initialized '{ name } ' value of EndpointTracking to { ( userSetTrackInstances ? "tracking" : "not tracking" ) } .") ;
124134 }
125135 }
126136}
0 commit comments