Skip to content

Commit

Permalink
Further small alignment
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Mar 28, 2024
1 parent 2369042 commit db632b2
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
Expand Up @@ -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;
Expand All @@ -22,15 +23,20 @@ class CheckMinimumStorageRequiredForIngestion : CustomCheck

public override Task<CheckResult> 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);
Expand All @@ -41,7 +47,8 @@ public override Task<CheckResult> 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)
Expand All @@ -50,37 +57,42 @@ public override Task<CheckResult> 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);
}

public static int Parse(IDictionary<string, string> settings)
{
if (!settings.TryGetValue(RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey, out var thresholdValue))
if (!settings.TryGetValue(RavenPersistenceConfiguration.MinimumStorageLeftRequiredForIngestionKey,
out var thresholdValue))
{
thresholdValue = $"{MinimumStorageLeftRequiredForIngestionDefault}";
}

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);
}
Expand Down
Expand Up @@ -22,15 +22,20 @@ class CheckMinimumStorageRequiredForIngestion : CustomCheck

public override Task<CheckResult> 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);
Expand Down

0 comments on commit db632b2

Please sign in to comment.