Files
UnrealEngineUWP/Engine/Source/Programs/Horde/HordeServer/Controllers/LifetimeController.cs
ben marsh 4fa010c358 Horde: Return degraded status from the health check endpoint for 15 seconds before starting to message to agents. This should allow the load balancer to start routing traffic away from the server before agents start to reconnect.
#ROBOMERGE-SOURCE: CL 16942971 in //UE5/Main/...
#ROBOMERGE-BOT: STARSHIP (Main -> Release-Engine-Test) (v838-16927207)

[CL 16942976 by ben marsh in ue5-release-engine-test branch]
2021-07-23 18:54:53 -04:00

66 lines
2.1 KiB
C#

// Copyright Epic Games, Inc. All Rights Reserved.
using HordeServer.Services;
using Microsoft.AspNetCore.Mvc;
using System.Threading.Tasks;
namespace HordeServer.Controllers
{
/// <summary>
/// Controller for app lifetime related routes
/// </summary>
[ApiController]
[Route("[controller]")]
public class LifetimeController : ControllerBase
{
/// <summary>
/// Singleton instance of the lifetime service
/// </summary>
LifetimeService LifetimeService;
/// <summary>
/// Constructor
/// </summary>
/// <param name="LifetimeService">The lifetime service singleton</param>
public LifetimeController(LifetimeService LifetimeService)
{
this.LifetimeService = LifetimeService;
}
/// <summary>
/// Readiness check for Kubernetes
/// If this return a non-successful HTTP response, Kubernetes will remove it from the load balancer,
/// preventing it from serving traffic.
/// </summary>
/// <returns>Ok if app is not stopping and all databases can be reached</returns>
[HttpGet]
[Route("/health/ready")]
public Task<ActionResult> K8sReadinessProbe()
{
// Disabled for now
bool IsRunning = !LifetimeService.IsPreStopping;
bool IsMongoDBHealthy = true; //await LifetimeService.IsMongoDbConnectionHealthy();
bool IsRedisHealthy = true; //await LifetimeService.IsRedisConnectionHealthy();
int StatusCode = IsRunning && IsMongoDBHealthy && IsRedisHealthy ? 200 : 503;
string Content = $"IsRunning={IsRunning}\n";
Content += $"IsMongoDBHealthy={IsMongoDBHealthy}\n";
Content += $"IsRedisHealthy={IsRedisHealthy}\n";
return Task.FromResult<ActionResult>(new ContentResult { ContentType = "text/plain", StatusCode = StatusCode, Content = Content });
}
/// <summary>
/// Liveness check for Kubernetes
/// If this return a non-successful HTTP response, Kubernetes will kill the pod and restart it
/// </summary>
/// <returns>Ok if app is not stopping and all databases can be reached</returns>
[HttpGet]
[Route("/health/live")]
public ActionResult K8sLivenessProbe()
{
return new ContentResult { ContentType = "text/plain", StatusCode = 200, Content = "ok" };
}
}
}