-
-
Notifications
You must be signed in to change notification settings - Fork 94
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Provide more information in health check (#635)
* Provide more information in health check * Code styling
- Loading branch information
1 parent
fca5900
commit 0e1af05
Showing
4 changed files
with
82 additions
and
44 deletions.
There are no files selected for viewing
17 changes: 14 additions & 3 deletions
17
src/Promitor.Scraper.Host/Controllers/v1/HealthController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,34 @@ | ||
using System.Net; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Swashbuckle.AspNetCore.Annotations; | ||
|
||
namespace Promitor.Scraper.Host.Controllers.v1 | ||
{ | ||
[Route("api/v1/health")] | ||
public class HealthController : Controller | ||
{ | ||
private readonly HealthCheckService _healthCheckService; | ||
|
||
public HealthController(HealthCheckService healthCheckService) | ||
{ | ||
_healthCheckService = healthCheckService; | ||
} | ||
|
||
/// <summary> | ||
/// Get Health | ||
/// </summary> | ||
/// <remarks>Provides an indication about the health of the scraper</remarks> | ||
[HttpGet] | ||
[SwaggerOperation(OperationId = "Health_Get")] | ||
[SwaggerResponse((int)HttpStatusCode.OK, Description = "Scraper is healthy")] | ||
[SwaggerResponse((int)HttpStatusCode.OK, Description = "Scraper is healthy", Type = typeof(HealthReport))] | ||
[SwaggerResponse((int)HttpStatusCode.ServiceUnavailable, Description = "Scraper is not healthy")] | ||
public IActionResult Get() | ||
public async Task<IActionResult> Get() | ||
{ | ||
return Ok(); | ||
var report = await _healthCheckService.CheckHealthAsync(); | ||
|
||
return report.Status == HealthStatus.Healthy ? Ok(report) : StatusCode((int)HttpStatusCode.ServiceUnavailable, report); | ||
} | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters