From ff3a307263073b9151f558822d6a4dafd82e9fe9 Mon Sep 17 00:00:00 2001 From: danielmarbach Date: Thu, 28 Mar 2024 17:46:09 +0100 Subject: [PATCH] Further small alignment --- ...CheckMinimumStorageRequiredForIngestion.cs | 30 +++++++++++++------ ...CheckMinimumStorageRequiredForIngestion.cs | 9 ++++-- 2 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs b/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs index 43e624ab31..2ca7d06644 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs @@ -12,7 +12,8 @@ class CheckMinimumStorageRequiredForIngestion : CustomCheck { public CheckMinimumStorageRequiredForIngestion(MinimumRequiredStorageState stateHolder, - DatabaseConfiguration databaseConfiguration) : base("Audit Message Ingestion Process", "ServiceControl.Audit Health", TimeSpan.FromSeconds(5)) + DatabaseConfiguration databaseConfiguration) : base("Audit Message Ingestion Process", + "ServiceControl.Audit Health", TimeSpan.FromSeconds(5)) { this.stateHolder = stateHolder; this.databaseConfiguration = databaseConfiguration; @@ -22,15 +23,20 @@ class CheckMinimumStorageRequiredForIngestion : CustomCheck public override Task PerformCheck(CancellationToken cancellationToken = default) { + if (Logger.IsDebugEnabled) + { + Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}"); + } + if (!databaseConfiguration.ServerConfiguration.UseEmbeddedServer) { stateHolder.CanIngestMore = true; return CheckResult.Pass; } - if (Logger.IsDebugEnabled) + if (dataPathRoot == null) { - Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}"); + throw new Exception($"Unable to find the root of the data path {dataPathRoot}"); } var dataDriveInfo = new DriveInfo(dataPathRoot); @@ -41,7 +47,8 @@ public override Task PerformCheck(CancellationToken cancellationTok if (Logger.IsDebugEnabled) { - Logger.Debug($"Free space: {availableFreeSpace} | Total: {totalSpace} | Percent remaining {percentRemaining:P0}"); + Logger.Debug( + $"Free space: {availableFreeSpace} | Total: {totalSpace} | Percent remaining {percentRemaining:P0}"); } if (percentRemaining > percentageThreshold) @@ -50,7 +57,8 @@ public override Task PerformCheck(CancellationToken cancellationTok return CheckResult.Pass; } - var message = $"Audit message ingestion stopped! {percentRemaining:P0} disk space remaining on data drive '{dataDriveInfo.VolumeLabel} ({dataDriveInfo.RootDirectory})' on '{Environment.MachineName}'. This is less than {percentageThreshold}% - the minimal required space configured. The threshold can be set using the {RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} configuration setting."; + var message = + $"Audit message ingestion stopped! {percentRemaining:P0} disk space remaining on data drive '{dataDriveInfo.VolumeLabel} ({dataDriveInfo.RootDirectory})' on '{Environment.MachineName}'. This is less than {percentageThreshold}% - the minimal required space configured. The threshold can be set using the {RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} configuration setting."; Logger.Warn(message); stateHolder.CanIngestMore = false; return CheckResult.Failed(message); @@ -58,7 +66,8 @@ public override Task PerformCheck(CancellationToken cancellationTok public static int Parse(IDictionary settings) { - if (!settings.TryGetValue(RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey, out var thresholdValue)) + if (!settings.TryGetValue(RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey, + out var thresholdValue)) { thresholdValue = $"{MinimumStorageLeftRequiredForIngestionDefault}"; } @@ -66,21 +75,24 @@ public static int Parse(IDictionary settings) string message; if (!int.TryParse(thresholdValue, out var threshold)) { - message = $"{RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} must be an integer."; + message = + $"{RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} must be an integer."; Logger.Fatal(message); throw new Exception(message); } if (threshold < 0) { - message = $"{RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} is invalid, minimum value is 0."; + message = + $"{RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} is invalid, minimum value is 0."; Logger.Fatal(message); throw new Exception(message); } if (threshold > 100) { - message = $"{RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} is invalid, maximum value is 100."; + message = + $"{RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey} is invalid, maximum value is 100."; Logger.Fatal(message); throw new Exception(message); } diff --git a/src/ServiceControl.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs b/src/ServiceControl.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs index 5223a18910..4feac0d238 100644 --- a/src/ServiceControl.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs +++ b/src/ServiceControl.Persistence.RavenDB/CustomChecks/CheckMinimumStorageRequiredForIngestion.cs @@ -22,15 +22,20 @@ class CheckMinimumStorageRequiredForIngestion : CustomCheck public override Task PerformCheck(CancellationToken cancellationToken = default) { + if (Logger.IsDebugEnabled) + { + Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}"); + } + if (!settings.UseEmbeddedServer) { stateHolder.CanIngestMore = true; return SuccessResult; } - if (Logger.IsDebugEnabled) + if (dataPathRoot == null) { - Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}"); + throw new Exception($"Unable to find the root of the data path {dataPathRoot}"); } var dataDriveInfo = new DriveInfo(dataPathRoot);