From ce683c3ade0a1a0ed06e3b874a2311d639a33cb6 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Sat, 8 Feb 2025 01:53:41 +0100 Subject: [PATCH 1/4] Enable RavenDB storage --- src/ServiceControl.Audit/App.config | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceControl.Audit/App.config b/src/ServiceControl.Audit/App.config index 83610fa6ee..90e352b92b 100644 --- a/src/ServiceControl.Audit/App.config +++ b/src/ServiceControl.Audit/App.config @@ -20,8 +20,8 @@ These settings are only here so that we can debug ServiceControl while developin - - + + From d10e1634ec4f49c9f36c466f0b56b1b89304e8e3 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Sat, 8 Feb 2025 01:53:50 +0100 Subject: [PATCH 2/4] Write files to tmp path --- src/ServiceControl.Audit/App.config | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/ServiceControl.Audit/App.config b/src/ServiceControl.Audit/App.config index 90e352b92b..57d1cfc374 100644 --- a/src/ServiceControl.Audit/App.config +++ b/src/ServiceControl.Audit/App.config @@ -8,6 +8,8 @@ These settings are only here so that we can debug ServiceControl while developin + + From 211d97a9ff239093e9746753de1be7c7e39bc26c Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Sat, 8 Feb 2025 01:54:38 +0100 Subject: [PATCH 3/4] Write RavenDB client logs to filesystem and console and set GracefulShutdownTimeout, via hack to align this with Host ShutdownTimeout options --- .../HostApplicationBuilderExtensions.cs | 2 +- .../Infrastructure/Settings/Settings.cs | 4 ++++ src/ServiceControl.RavenDB/EmbeddedDatabase.cs | 16 ++++++++++++++++ .../HostApplicationBuilderExtensions.cs | 2 +- .../Infrastructure/Settings/Settings.cs | 4 ++++ 5 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/ServiceControl.Audit/HostApplicationBuilderExtensions.cs b/src/ServiceControl.Audit/HostApplicationBuilderExtensions.cs index 8968565a50..923bbeae4b 100644 --- a/src/ServiceControl.Audit/HostApplicationBuilderExtensions.cs +++ b/src/ServiceControl.Audit/HostApplicationBuilderExtensions.cs @@ -42,7 +42,7 @@ public static void AddServiceControlAudit(this IHostApplicationBuilder builder, var transportCustomization = TransportFactory.Create(transportSettings); transportCustomization.AddTransportForAudit(services, transportSettings); - services.Configure(options => options.ShutdownTimeout = TimeSpan.FromSeconds(30)); + services.Configure(options => options.ShutdownTimeout = settings.ShutdownTimeout); services.AddSingleton(settings); services.AddSingleton(); diff --git a/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs b/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs index 183b695555..b8865298c9 100644 --- a/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs +++ b/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs @@ -51,6 +51,8 @@ public Settings(string transportType = null, string persisterType = null, Loggin EnableFullTextSearchOnBodies = SettingsReader.Read(SettingsRootNamespace, "EnableFullTextSearchOnBodies", true); AssemblyLoadContextResolver = static assemblyPath => new PluginAssemblyLoadContext(assemblyPath); + ShutdownTimeout = SettingsReader.Read(SettingsRootNamespace, "ShutdownTimeout", ShutdownTimeout); + Environment.SetEnvironmentVariable("ShutdownTimeout", ShutdownTimeout.ToString()); } void LoadAuditQueueInformation() @@ -151,6 +153,8 @@ public int MaxBodySizeToStore public bool EnableFullTextSearchOnBodies { get; set; } + public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromMinutes(5); + public TransportSettings ToTransportSettings() { var transportSettings = new TransportSettings diff --git a/src/ServiceControl.RavenDB/EmbeddedDatabase.cs b/src/ServiceControl.RavenDB/EmbeddedDatabase.cs index 9e4b711b0b..a437e28a33 100644 --- a/src/ServiceControl.RavenDB/EmbeddedDatabase.cs +++ b/src/ServiceControl.RavenDB/EmbeddedDatabase.cs @@ -15,6 +15,7 @@ namespace ServiceControl.RavenDB using Raven.Client.Documents.Conventions; using Raven.Client.ServerWide.Operations; using Raven.Embedded; + using Sparrow.Logging; public sealed class EmbeddedDatabase : IDisposable { @@ -52,9 +53,24 @@ public static EmbeddedDatabase Start(EmbeddedDatabaseConfiguration databaseConfi var nugetPackagesPath = Path.Combine(databaseConfiguration.DbPath, "Packages", "NuGet"); + LoggingSource.Instance.SetupLogMode( + (LogMode)255, + Path.Combine(databaseConfiguration.LogPath, "client"), + TimeSpan.FromDays(7), + 1024 * 1024 * 10, + false + ); + + LoggingSource.Instance.EnableConsoleLogging(); + + var gracefulShutdownTimeout = TimeSpan.Parse(Environment.GetEnvironmentVariable("ShutdownTimeout")); + // Must be less to ensure teardown of child process completes + gracefulShutdownTimeout -= TimeSpan.FromSeconds(5); + Logger.InfoFormat("Loading RavenDB license from {0}", licenseFileNameAndServerDirectory.LicenseFileName); var serverOptions = new ServerOptions { + GracefulShutdownTimeout = gracefulShutdownTimeout, CommandLineArgs = [ $"--Logs.Mode={databaseConfiguration.LogsMode}", diff --git a/src/ServiceControl/HostApplicationBuilderExtensions.cs b/src/ServiceControl/HostApplicationBuilderExtensions.cs index 0c365fecbc..a1774d4b30 100644 --- a/src/ServiceControl/HostApplicationBuilderExtensions.cs +++ b/src/ServiceControl/HostApplicationBuilderExtensions.cs @@ -51,7 +51,7 @@ public static void AddServiceControl(this IHostApplicationBuilder hostBuilder, S var transportCustomization = TransportFactory.Create(transportSettings); transportCustomization.AddTransportForPrimary(services, transportSettings); - services.Configure(options => options.ShutdownTimeout = TimeSpan.FromSeconds(30)); + services.Configure(options => options.ShutdownTimeout = settings.ShutdownTimeout); services.AddSingleton(); services.AddSingleton(); diff --git a/src/ServiceControl/Infrastructure/Settings/Settings.cs b/src/ServiceControl/Infrastructure/Settings/Settings.cs index 04b7a232bb..2dff350f9f 100644 --- a/src/ServiceControl/Infrastructure/Settings/Settings.cs +++ b/src/ServiceControl/Infrastructure/Settings/Settings.cs @@ -66,6 +66,8 @@ public Settings( DisableExternalIntegrationsPublishing = SettingsReader.Read(SettingsRootNamespace, "DisableExternalIntegrationsPublishing", false); TrackInstancesInitialValue = SettingsReader.Read(SettingsRootNamespace, "TrackInstancesInitialValue", true); AssemblyLoadContextResolver = static assemblyPath => new PluginAssemblyLoadContext(assemblyPath); + ShutdownTimeout = SettingsReader.Read(SettingsRootNamespace, "ShutdownTimeout", ShutdownTimeout); + Environment.SetEnvironmentVariable("ShutdownTimeout", ShutdownTimeout.ToString()); } [JsonIgnore] @@ -180,6 +182,8 @@ public TimeSpan HeartbeatGracePeriod public bool DisableHealthChecks { get; set; } + public TimeSpan ShutdownTimeout { get; set; } = TimeSpan.FromMinutes(5); + public string GetConnectionString() { var settingsValue = SettingsReader.Read(SettingsRootNamespace, "ConnectionString"); From 64b612b8cbca955f10d096154513a5431717e816 Mon Sep 17 00:00:00 2001 From: Ramon Smits Date: Mon, 17 Feb 2025 22:22:56 +0100 Subject: [PATCH 4/4] sigh... --- src/ServiceControl.RavenDB/EmbeddedDatabase.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ServiceControl.RavenDB/EmbeddedDatabase.cs b/src/ServiceControl.RavenDB/EmbeddedDatabase.cs index a437e28a33..9c1b40eeca 100644 --- a/src/ServiceControl.RavenDB/EmbeddedDatabase.cs +++ b/src/ServiceControl.RavenDB/EmbeddedDatabase.cs @@ -63,7 +63,7 @@ public static EmbeddedDatabase Start(EmbeddedDatabaseConfiguration databaseConfi LoggingSource.Instance.EnableConsoleLogging(); - var gracefulShutdownTimeout = TimeSpan.Parse(Environment.GetEnvironmentVariable("ShutdownTimeout")); + var gracefulShutdownTimeout = TimeSpan.Parse(Environment.GetEnvironmentVariable("ShutdownTimeout")!); // Must be less to ensure teardown of child process completes gracefulShutdownTimeout -= TimeSpan.FromSeconds(5);