Skip to content

Commit

Permalink
Move CheckFreeDiskSpace into persistence layer
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Mar 21, 2024
1 parent edf5fb0 commit d136277
Show file tree
Hide file tree
Showing 5 changed files with 79 additions and 100 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
namespace ServiceControl.Audit.Persistence.RavenDB.CustomChecks
{
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using RavenDB;

class CheckFreeDiskSpace : CustomCheck
{
public CheckFreeDiskSpace(DatabaseConfiguration databaseConfiguration) : base("ServiceControl.Audit database", "Storage space", TimeSpan.FromMinutes(5))
{
dataPath = databaseConfiguration.ServerConfiguration.DbPath;
percentageThreshold = databaseConfiguration.MinimumStorageLeftRequiredForIngestion / 100m;
Logger.Debug($"Check ServiceControl data drive space remaining custom check starting. Threshold {percentageThreshold:P0}");
}

public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
var dataPathRoot = Path.GetPathRoot(dataPath);

if (dataPathRoot == null)
{
throw new Exception($"Unable to find the root of the data path {dataPath}");
}

var dataDriveInfo = new DriveInfo(dataPathRoot);
var availableFreeSpace = (decimal)dataDriveInfo.AvailableFreeSpace;
var totalSpace = (decimal)dataDriveInfo.TotalSize;

var percentRemaining = (decimal)dataDriveInfo.AvailableFreeSpace / dataDriveInfo.TotalSize;

if (Logger.IsDebugEnabled)
{
Logger.Debug($"Free space: {availableFreeSpace:N0}B | Total: {totalSpace:N0}B | Percent remaining {percentRemaining:P1}");
}

return percentRemaining > percentageThreshold
? CheckResult.Pass
: CheckResult.Failed($"{percentRemaining:P0} disk space remaining on data drive '{dataDriveInfo.VolumeLabel} ({dataDriveInfo.RootDirectory})' on '{Environment.MachineName}'.");
}

readonly string dataPath;
readonly decimal percentageThreshold;

static readonly ILog Logger = LogManager.GetLogger(typeof(CheckFreeDiskSpace));
}
}
Original file line number Diff line number Diff line change
@@ -1,23 +1,18 @@
namespace ServiceControl
namespace ServiceControl.Audit.Persistence.RavenDB.CustomChecks
{
using System;
using System.Linq;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using Audit.Persistence.RavenDB;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Raven.Client.Documents.Operations;
using ServiceControl.Audit.Persistence.RavenDB;

class CheckRavenDBIndexLag : CustomCheck
class CheckRavenDBIndexLag(IRavenDocumentStoreProvider documentStoreProvider)
: CustomCheck("Audit Database Index Lag", "ServiceControl.Audit Health", TimeSpan.FromMinutes(5))
{
public CheckRavenDBIndexLag(IRavenDocumentStoreProvider documentStoreProvider)
: base("Audit Database Index Lag", "ServiceControl.Audit Health", TimeSpan.FromMinutes(5))
{
this.documentStoreProvider = documentStoreProvider;
}

public override async Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
var store = documentStoreProvider.GetDocumentStore();
Expand Down Expand Up @@ -84,7 +79,5 @@ static void CreateDiagnosticsLogEntry(DatabaseStatistics statistics, IndexInform
static readonly TimeSpan IndexLagThresholdWarning = TimeSpan.FromMinutes(1);
static readonly TimeSpan IndexLagThresholdError = TimeSpan.FromMinutes(10);
static readonly ILog Log = LogManager.GetLogger<CheckRavenDBIndexLag>();

readonly IRavenDocumentStoreProvider documentStoreProvider;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,39 +3,29 @@
using System;
using Sparrow.Json;

public class DatabaseConfiguration
public class DatabaseConfiguration(
string name,
int expirationProcessTimerInSeconds,
bool enableFullTextSearch,
TimeSpan auditRetentionPeriod,
int maxBodySizeToStore,
int minimumStorageLeftRequiredForIngestion,
ServerConfiguration serverConfiguration)
{
public DatabaseConfiguration(string name,
int expirationProcessTimerInSeconds,
bool enableFullTextSearch,
TimeSpan auditRetentionPeriod,
int maxBodySizeToStore,
int minimumStorageLeftRequiredForIngestion,
ServerConfiguration serverConfiguration)
{
Name = name;
ExpirationProcessTimerInSeconds = expirationProcessTimerInSeconds;
EnableFullTextSearch = enableFullTextSearch;
AuditRetentionPeriod = auditRetentionPeriod;
MaxBodySizeToStore = maxBodySizeToStore;
ServerConfiguration = serverConfiguration;
MinimumStorageLeftRequiredForIngestion = minimumStorageLeftRequiredForIngestion;
}

public string Name { get; }

public int ExpirationProcessTimerInSeconds { get; }

public bool EnableFullTextSearch { get; }
public string Name { get; } = name;

public int ExpirationProcessTimerInSeconds { get; } = expirationProcessTimerInSeconds;

public bool EnableFullTextSearch { get; } = enableFullTextSearch;

public Func<string, BlittableJsonReaderObject, string> FindClrType { get; }

public ServerConfiguration ServerConfiguration { get; }
public ServerConfiguration ServerConfiguration { get; } = serverConfiguration;

public TimeSpan AuditRetentionPeriod { get; }
public TimeSpan AuditRetentionPeriod { get; } = auditRetentionPeriod;

public int MaxBodySizeToStore { get; }
public int MaxBodySizeToStore { get; } = maxBodySizeToStore;

public int MinimumStorageLeftRequiredForIngestion { get; internal set; } //Setting for ATT only
public int MinimumStorageLeftRequiredForIngestion { get; internal set; } = minimumStorageLeftRequiredForIngestion; //Setting for ATT only
}
}
62 changes: 0 additions & 62 deletions src/ServiceControl.Audit/Infrastructure/CheckFreeDiskSpace.cs

This file was deleted.

8 changes: 8 additions & 0 deletions src/ServiceControl/MessageFailures/Api/ErrorResponse.http
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
### Pending retries resolve with unique message ids
PATCH http://localhost:33333/api/pendingretries/resolve
Content-Type: application/json

{
"from": "2020-03-08T14:37:46.9793888Z",
"to": "2020-04-08T14:37:46.9793888Z"
}

0 comments on commit d136277

Please sign in to comment.