Urgent Health Reports in Service Fabric 2.7

Share on facebook
Share on twitter
Share on linkedin

One of the nice things about writing services using Service Fabric is the ability to send health reports using the Health Reporting api. Service Fabric makes it easy for you to report health at many different levels and these health reports will roll up to their parent entities. If you create a health report on an individual replica within a service then the partition, service, application, and cluster will all report the same status. This is shown using the following diagram:

Health entities.

Up until Service Fabric 2.7 these health reports were only sent in batches on a timer. This means that there will most likely be a delay between the time that the health report is submitted and when the cluster will report the new health status. The default batch time in the health client is 30 seconds. For a mission critical application this might not be sufficient.

Service Fabric 2.7 introduced the ability to send “urgent” health reports which are reported immediately. From the Service Fabric release notes:

You can now send urgent health reports to the cluster immediately without waiting for the usual batch send interval. This is very useful in situations where a process crash is imminent, like during unhandled exceptions, where there isn’t time to wait for the next batch send interval.

Here is a code snippet showing how you can send an urgent health report in a stateless service.

// RunAsync on a stateless service instance
protected override async Task RunAsync(CancellationToken cancellationToken)
    var health = new HealthInformation("SourceID", "Property", HealthState.Warning);
    var options = new HealthReportSendOptions { Immediate = true };

    // report on application health
    Context.CodeActivationContext.ReportApplicationHealth(health, options);

    // report on the application deployed on this given node
    Context.CodeActivationContext.ReportDeployedApplicationHealth(health, options);

    // report on this deployed service package
    Context.CodeActivationContext.ReportDeployedServicePackageHealth(health, options);

More to explore