New: Config file setting to disable log database (#9943)

Co-authored-by: sillock1 <jprest97@gmail.com>
pull/9988/head
Jared 6 months ago committed by GitHub
parent 8b6cf34ce4
commit 086a0addba
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

@ -30,6 +30,7 @@ namespace NzbDrone.Common.Test
.AddNzbDroneLogger()
.AutoAddServices(Bootstrap.ASSEMBLIES)
.AddDummyDatabase()
.AddDummyLogDatabase()
.AddStartupContext(new StartupContext("first", "second"));
container.RegisterInstance(new Mock<IHostLifetime>().Object);

@ -11,4 +11,5 @@ public class LogOptions
public string SyslogServer { get; set; }
public int? SyslogPort { get; set; }
public string SyslogLevel { get; set; }
public bool? DbEnabled { get; set; }
}

@ -55,6 +55,7 @@ namespace NzbDrone.Core.Configuration
string SyslogServer { get; }
int SyslogPort { get; }
string SyslogLevel { get; }
bool LogDbEnabled { get; }
string PostgresHost { get; }
int PostgresPort { get; }
string PostgresUser { get; }
@ -229,6 +230,7 @@ namespace NzbDrone.Core.Configuration
public string PostgresMainDb => _postgresOptions?.MainDb ?? GetValue("PostgresMainDb", "radarr-main", persist: false);
public string PostgresLogDb => _postgresOptions?.LogDb ?? GetValue("PostgresLogDb", "radarr-log", persist: false);
public int PostgresPort => (_postgresOptions?.Port ?? 0) != 0 ? _postgresOptions.Port : GetValueInt("PostgresPort", 5432, persist: false);
public bool LogDbEnabled => _logOptions.DbEnabled ?? GetValueBoolean("LogDbEnabled", true, persist: false);
public bool LogSql => _logOptions.Sql ?? GetValueBoolean("LogSql", false, persist: false);
public int LogRotate => _logOptions.Rotate ?? GetValueInt("LogRotate", 50, persist: false);
public bool FilterSentryEvents => _logOptions.FilterSentryEvents ?? GetValueBoolean("FilterSentryEvents", true, persist: false);

@ -8,6 +8,12 @@ namespace NzbDrone.Core.Datastore.Extensions
public static IContainer AddDatabase(this IContainer container)
{
container.RegisterDelegate<IDbFactory, IMainDatabase>(f => new MainDatabase(f.Create()), Reuse.Singleton);
return container;
}
public static IContainer AddLogDatabase(this IContainer container)
{
container.RegisterDelegate<IDbFactory, ILogDatabase>(f => new LogDatabase(f.Create(MigrationType.Log)), Reuse.Singleton);
return container;
@ -16,6 +22,12 @@ namespace NzbDrone.Core.Datastore.Extensions
public static IContainer AddDummyDatabase(this IContainer container)
{
container.RegisterInstance<IMainDatabase>(new MainDatabase(null));
return container;
}
public static IContainer AddDummyLogDatabase(this IContainer container)
{
container.RegisterInstance<ILogDatabase>(new LogDatabase(null));
return container;

@ -2,6 +2,7 @@
using System.Collections.Generic;
using NLog;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Lifecycle;
using NzbDrone.Core.Messaging.Events;
using NzbDrone.Core.Update.History.Events;
@ -18,13 +19,15 @@ namespace NzbDrone.Core.Update.History
{
private readonly IUpdateHistoryRepository _repository;
private readonly IEventAggregator _eventAggregator;
private readonly IConfigFileProvider _configFileProvider;
private readonly Logger _logger;
private Version _prevVersion;
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, Logger logger)
public UpdateHistoryService(IUpdateHistoryRepository repository, IEventAggregator eventAggregator, IConfigFileProvider configFileProvider, Logger logger)
{
_repository = repository;
_eventAggregator = eventAggregator;
_configFileProvider = configFileProvider;
_logger = logger;
}
@ -58,7 +61,7 @@ namespace NzbDrone.Core.Update.History
public void Handle(ApplicationStartedEvent message)
{
if (BuildInfo.Version.Major == 10)
if (BuildInfo.Version.Major == 10 || !_configFileProvider.LogDbEnabled)
{
// Don't save dev versions, they change constantly
return;

@ -29,7 +29,7 @@ namespace NzbDrone.Core.Update
{
var branch = _configFileProvider.Branch;
var version = BuildInfo.Version;
var prevVersion = _updateHistoryService.PreviouslyInstalled();
var prevVersion = _configFileProvider.LogDbEnabled ? _updateHistoryService.PreviouslyInstalled() : null;
return _updatePackageProvider.GetRecentUpdates(branch, version, prevVersion);
}
}

@ -93,6 +93,15 @@ namespace NzbDrone.Host
.AddStartupContext(startupContext)
.Resolve<UtilityModeRouter>()
.Route(appMode);
if (config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true))
{
c.AddLogDatabase();
}
else
{
c.AddDummyLogDatabase();
}
})
.ConfigureServices(services =>
{
@ -135,6 +144,7 @@ namespace NzbDrone.Host
var enableSsl = config.GetValue<bool?>($"Radarr:Server:{nameof(ServerOptions.EnableSsl)}") ?? config.GetValue(nameof(ConfigFileProvider.EnableSsl), false);
var sslCertPath = config.GetValue<string>($"Radarr:Server:{nameof(ServerOptions.SslCertPath)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPath));
var sslCertPassword = config.GetValue<string>($"Radarr:Server:{nameof(ServerOptions.SslCertPassword)}") ?? config.GetValue<string>(nameof(ConfigFileProvider.SslCertPassword));
var logDbEnabled = config.GetValue<bool?>($"Radarr:Log:{nameof(LogOptions.DbEnabled)}") ?? config.GetValue(nameof(ConfigFileProvider.LogDbEnabled), true);
var urls = new List<string> { BuildUrl("http", bindAddress, port) };
@ -152,6 +162,15 @@ namespace NzbDrone.Host
.AddNzbDroneLogger()
.AddDatabase()
.AddStartupContext(context);
if (logDbEnabled)
{
c.AddLogDatabase();
}
else
{
c.AddDummyLogDatabase();
}
})
.ConfigureServices(services =>
{

@ -239,9 +239,13 @@ namespace NzbDrone.Host
// instantiate the databases to initialize/migrate them
_ = mainDatabaseFactory.Value;
_ = logDatabaseFactory.Value;
if (configFileProvider.LogDbEnabled)
{
_ = logDatabaseFactory.Value;
dbTarget.Register();
}
SchemaBuilder.Initialize(container);
if (OsInfo.IsNotWindows)

@ -1,5 +1,6 @@
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Instrumentation;
using Radarr.Http;
using Radarr.Http.Extensions;
@ -10,16 +11,23 @@ namespace Radarr.Api.V3.Logs
public class LogController : Controller
{
private readonly ILogService _logService;
private readonly IConfigFileProvider _configFileProvider;
public LogController(ILogService logService)
public LogController(ILogService logService, IConfigFileProvider configFileProvider)
{
_logService = logService;
_configFileProvider = configFileProvider;
}
[HttpGet]
[Produces("application/json")]
public PagingResource<LogResource> GetLogs([FromQuery] PagingRequestResource paging, string level)
{
if (!_configFileProvider.LogDbEnabled)
{
return new PagingResource<LogResource>();
}
var pagingResource = new PagingResource<LogResource>(paging);
var pageSpec = pagingResource.MapToPagingSpec<LogResource, Log>();

@ -2,6 +2,7 @@ using System.Collections.Generic;
using System.Linq;
using Microsoft.AspNetCore.Mvc;
using NzbDrone.Common.EnvironmentInfo;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Update;
using NzbDrone.Core.Update.History;
using Radarr.Http;
@ -13,11 +14,13 @@ namespace Radarr.Api.V3.Update
{
private readonly IRecentUpdateProvider _recentUpdateProvider;
private readonly IUpdateHistoryService _updateHistoryService;
private readonly IConfigFileProvider _configFileProvider;
public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService)
public UpdateController(IRecentUpdateProvider recentUpdateProvider, IUpdateHistoryService updateHistoryService, IConfigFileProvider configFileProvider)
{
_recentUpdateProvider = recentUpdateProvider;
_updateHistoryService = updateHistoryService;
_configFileProvider = configFileProvider;
}
[HttpGet]
@ -44,6 +47,11 @@ namespace Radarr.Api.V3.Update
installed.Installed = true;
}
if (!_configFileProvider.LogDbEnabled)
{
return resources;
}
var installDates = _updateHistoryService.InstalledSince(resources.Last().ReleaseDate)
.DistinctBy(v => v.Version)
.ToDictionary(v => v.Version);

@ -21,7 +21,7 @@ namespace Radarr.Http
public string SortKey { get; set; }
public SortDirection SortDirection { get; set; }
public int TotalRecords { get; set; }
public List<TResource> Records { get; set; }
public List<TResource> Records { get; set; } = new ();
public PagingResource()
{

Loading…
Cancel
Save