From 24ef5e68eb145f3f7099334d43f4e00b823d8a1e Mon Sep 17 00:00:00 2001 From: Jason Dove Date: Wed, 2 Mar 2022 14:51:15 -0600 Subject: [PATCH] add error reporting health check (#667) --- .../Health/Checks/IErrorReportsHealthCheck.cs | 5 +++ .../Health/Checks/ErrorReportsHealthCheck.cs | 33 +++++++++++++++++++ .../Health/HealthCheckService.cs | 6 ++-- ErsatzTV/Startup.cs | 2 ++ 4 files changed, 44 insertions(+), 2 deletions(-) create mode 100644 ErsatzTV.Core/Health/Checks/IErrorReportsHealthCheck.cs create mode 100644 ErsatzTV.Infrastructure/Health/Checks/ErrorReportsHealthCheck.cs diff --git a/ErsatzTV.Core/Health/Checks/IErrorReportsHealthCheck.cs b/ErsatzTV.Core/Health/Checks/IErrorReportsHealthCheck.cs new file mode 100644 index 000000000..356158e8f --- /dev/null +++ b/ErsatzTV.Core/Health/Checks/IErrorReportsHealthCheck.cs @@ -0,0 +1,5 @@ +namespace ErsatzTV.Core.Health.Checks; + +public interface IErrorReportsHealthCheck : IHealthCheck +{ +} diff --git a/ErsatzTV.Infrastructure/Health/Checks/ErrorReportsHealthCheck.cs b/ErsatzTV.Infrastructure/Health/Checks/ErrorReportsHealthCheck.cs new file mode 100644 index 000000000..1c149bb84 --- /dev/null +++ b/ErsatzTV.Infrastructure/Health/Checks/ErrorReportsHealthCheck.cs @@ -0,0 +1,33 @@ +using System.Threading.Tasks; +using ErsatzTV.Core.Errors; +using ErsatzTV.Core.Health; +using ErsatzTV.Core.Health.Checks; +using LanguageExt; +using Microsoft.Extensions.Options; + +namespace ErsatzTV.Infrastructure.Health.Checks; + +public class ErrorReportsHealthCheck : BaseHealthCheck, IErrorReportsHealthCheck +{ + private readonly IOptions _bugsnagConfiguration; + + public ErrorReportsHealthCheck(IOptions bugsnagConfiguration) + { + _bugsnagConfiguration = bugsnagConfiguration; + } + + protected override string Title => "Error Reports"; + + public Task Check() + { + if (_bugsnagConfiguration.Value.Enable) + { + return Result( + HealthCheckStatus.Pass, + "Automated error reporting is enabled, thank you! To disable, edit the file appsettings.json or set the Bugsnag:Enable environment variable to false") + .AsTask(); + } + + return InfoResult("Automated error reporting is disabled. Please enable to support bug fixing efforts!").AsTask(); + } +} diff --git a/ErsatzTV.Infrastructure/Health/HealthCheckService.cs b/ErsatzTV.Infrastructure/Health/HealthCheckService.cs index b064a1f7c..77731347b 100644 --- a/ErsatzTV.Infrastructure/Health/HealthCheckService.cs +++ b/ErsatzTV.Infrastructure/Health/HealthCheckService.cs @@ -20,7 +20,8 @@ namespace ErsatzTV.Infrastructure.Health IEpisodeMetadataHealthCheck episodeMetadataHealthCheck, IZeroDurationHealthCheck zeroDurationHealthCheck, IFileNotFoundHealthCheck fileNotFoundHealthCheck, - IVaapiDriverHealthCheck vaapiDriverHealthCheck) + IVaapiDriverHealthCheck vaapiDriverHealthCheck, + IErrorReportsHealthCheck errorReportsHealthCheck) { _checks = new List { @@ -31,7 +32,8 @@ namespace ErsatzTV.Infrastructure.Health episodeMetadataHealthCheck, zeroDurationHealthCheck, fileNotFoundHealthCheck, - vaapiDriverHealthCheck + vaapiDriverHealthCheck, + errorReportsHealthCheck }; } diff --git a/ErsatzTV/Startup.cs b/ErsatzTV/Startup.cs index c5b422b4f..9e047adae 100644 --- a/ErsatzTV/Startup.cs +++ b/ErsatzTV/Startup.cs @@ -83,6 +83,7 @@ namespace ErsatzTV public void ConfigureServices(IServiceCollection services) { BugsnagConfiguration bugsnagConfig = Configuration.GetSection("Bugsnag").Get(); + services.Configure(Configuration.GetSection("Bugsnag")); services.AddBugsnag( configuration => @@ -288,6 +289,7 @@ namespace ErsatzTV services.AddScoped(); services.AddScoped(); services.AddScoped(); + services.AddScoped(); services.AddScoped(); services.AddScoped();