Orleans Health Checks using ASP.NET Core

Orleans Health Checks

One of the nicest things with the introduction of the Generic Host in Orleans v3.0 is that it allows you to run Orleans side by side with ASP.NET Core. One of the main benefits that I could think of is creating Orleans health checks using ASP.NET Core Health Checks.

Co-Hosting

Since Orleans 3.0, there is now support for the GenericHost via extensions on IHostBuilder, this allows you to run multiple services within the same process all sharing things such as logging, services, configuration, etc.

In a recent blog post, I covered how you can co-host Orleans and ASP.NET Core. This post is an extension of that. If you have not read that already, go take a look first.

ASP.NET Core Health Checks

The reason for wanting health checks for services like an Orleans Silo are varied. One primary use case is when running a silo that is hosted under some type of container orchestration, such as Kubernetes, AWS ECS, etc.

These orchestrators generally provide a mechanism to determine if your service is healthy or unhealthy. If unhealthy, the will create new instances based on your configuration.

ASP.NET Core has a middleware that simplifies providing such health status. I’ve blogged about creating ASP.NET Core Health Checks over on the Telerik Blog.

Orleans Health Checks

In order to verify that a local silo is healthy, we are going to use a stateless grain. The reason being, stateless grains are always executed locally.

Requests made to Stateless Worker grains are always executed locally, that is on the same silo where the request originated, either made by a grain running on the silo or received by the silo’s client gateway. Hence, calls to Stateless Worker grains from other grains or from client gateways never incur a remote message.

Our grain isn’t really doing anything, and it doesn’t need to. I’ve made it return a bool however, it could just return a Task. Returning a bool might be useful if you plan on doing any other check within the grain, such as maybe verify connections to db, etc.

Next, we’ll create our actual ASP.NET Core Health Check by implementing the IHealthCheck.

All our implementation is going to do is get the IHealthCheckGrain. If anything fails, we’ll return Unhealthy, otherwise its all good so we’ll return Healthy.

As you can see, I also added an extension method off of IHealthChecksBuilder just to simplify registering our new health check.

Finally, to wire up our new health check, we need to add AddHealthChecks and AddOrleansHealthCheck to our ConfigureServices. As well we need to call UseHealthChecks in the Configure method.

Results

Now if you browse or make an HTTP call to the /health endpoint, you get a 200 OK with Healthy if the local silo is running.

Related Links

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Roundup #58: Orleans 3.0, Snitch, What’s Your Problem? Next 5 years of ASP.NET Core

Here are the things that caught my eye recently in .NET.  I’d love to hear what you found most interesting this week.  Let me know in the comments or on Twitter.

Introducing Orleans 3.0

We are excited to announce the Orleans 3.0 release. A great number of improvements and fixes went in, as well as several new features, since Orleans 2.0. These changes were driven by the experience of many people running Orleans-based applications in production in a wide range of scenarios and environments, and by the ingenuity and passion of the global Orleans community that always strives to make the codebase better, faster, and more flexible. A BIG Thank You to all who contributed to this release in various ways!

I was happy to see the generic host for co-hosting with something like ASP.NET Core. I’ve blogged Co-Hosting Orleans and ASP.NET Core which this about this feature.

Link: https://devblogs.microsoft.com/dotnet/orleans-3-0/

Snitch

A tool that helps you find transitive package references that can be removed.

> snitch Foo.csproj --tfm net462

Building Foo (net462)...

Building Bar (netstandard2.0)...

Building Baz (netstandard2.0)...

The following packages can be removed:

Autofac (ref by Baz)

Newtonsoft.Json (ref by Bar)

The following packages might be removed:

Castle.Core (ref by Baz) 4.4.0 <- 4.3.1 (Baz)

Link: https://github.com/spectresystems/snitch

What’s Your Problem? – Asbjørn Ulsberg

A talk given by Asbjørn Ulsberg from PayEx at the 2019 Platform Summit in Stockholm.

An API isn’t stronger than its weakest link and what’s often ignored in the ongoing maintenance and development of an API is the constant effort required to provide great self-servicable error messages. What this means is that without great, user-friendly error messages, your API is not going to be great.

Just think about your first interaction with an API. How many failing requests have you sent before you have dug yourself through swathes of error messages and documentation to get to that one penultimate successful request making your heart sing and fists shaking in the air?

Great error messages make them not feel like errors, but like friendly guidance towards a working request. They should be detailed enough to let the developer fix whatever problem there is themselves, like a dialogue between a customer and a support technician.

This talk will give you ideas of how to handle errors and exceptions that occur in your application, be it with the incoming request, database failures or errors received from a 3rd party and how to serialize them into user friendly and actionable problem messages.

Link: https://www.youtube.com/watch?v=ZWIUn5BHDBc

The next 5 years of ASP.NET Core – Ryan Nowak

Join Ryan Nowak on a tour of ASP.NET Core’s evolution from “Project K” to present day and look forward to a few possible futures. We’ll discuss technical design details of how the ASP.NET Core stack is changing from bottom (hosting and startup), through the server, middleware pipeline, and up to high-level frameworks like MVC and Blazor.

This is a technical deep-dive talk, and will explore possible design directions of .NET 5 and future releases.

Link: https://www.youtube.com/watch?v=7dJBmV_psW0

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.

Co-Hosting Orleans and ASP.NET Core

Orleans and ASP.NET Core

With the release of Orleans 3.0 comes the ability to co-host with ASP.NET Core (or any other framework that uses the generic host builder).

What this means is you can run Orleans and ASP.NET Core in the same process.

The advantage to this is both services will share the same service provider, logging, etc that is configured with the host builder.

Orleans and ASP.NET Core

The extension method UseOrleans() is available now on the IHostBuilder. Just like you would configure the ASP.NET Core via ConfigureWebHostDefaults, you can configure the Orleans silo.

Benefits

One of the nice benefits here is that because both services share service registrations, an ASP.NET Core MVC controller can have the IClusterClient injected into it.

Also since logging is configured it is shared between both ASP.NET Core and Orleans. When I run my demo application, you can see both services in my console logs.

Health Checks

Another benefit of co-hosting Orleans and ASP.NET Core is you can provide a frontend via ASP.NET Core to expose status of your Orleans silo. I’ve written about the ASP.NET Core Health Checks over on the Telerik Blog.

If you’re running in something Docker, AWS ECS or Kubernetes, this would provide you information to determine the health/liveness of your services

Orleans 3.0

If you want more info on the 3.0 release, check out the Announcement for all the details.

Also, check out other related posts:

Enjoy this post? Subscribe!

Subscribe to our weekly Newsletter and stay tuned.