Skip to content

Commit

Permalink
Aligh custom checks and make sure they pass for external ravendb
Browse files Browse the repository at this point in the history
  • Loading branch information
danielmarbach committed Mar 28, 2024
1 parent 19ec5fa commit bdb1e78
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,22 +9,24 @@
using NServiceBus.Logging;
using RavenDB;

class CheckFreeDiskSpace : CustomCheck
class CheckFreeDiskSpace(DatabaseConfiguration databaseConfiguration) : CustomCheck("ServiceControl.Audit database",
"Storage space", TimeSpan.FromMinutes(5))
{
public CheckFreeDiskSpace(DatabaseConfiguration databaseConfiguration) : base("ServiceControl.Audit database", "Storage space", TimeSpan.FromMinutes(5))
{
dataPath = databaseConfiguration.ServerConfiguration.DbPath;
percentageThreshold = databaseConfiguration.DataSpaceRemainingThreshold / 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 (Logger.IsDebugEnabled)
{
Logger.Debug($"Check ServiceControl data drive space remaining custom check starting. Threshold {percentageThreshold:P0}");
}

if (!databaseConfiguration.ServerConfiguration.UseEmbeddedServer)
{
return CheckResult.Pass;
}

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

var dataDriveInfo = new DriveInfo(dataPathRoot);
Expand Down Expand Up @@ -75,8 +77,8 @@ public static int Parse(IDictionary<string, string> settings)
return threshold;
}

readonly string dataPath;
readonly decimal percentageThreshold;
readonly string dataPathRoot = Path.GetPathRoot(databaseConfiguration.ServerConfiguration.DbPath);
readonly decimal percentageThreshold = databaseConfiguration.DataSpaceRemainingThreshold / 100m;

public const int DataSpaceRemainingThresholdDefault = 20;
static readonly ILog Logger = LogManager.GetLogger(typeof(CheckFreeDiskSpace));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,29 @@
using NServiceBus.Logging;
using RavenDB;

class CheckMinimumStorageRequiredForIngestion(
MinimumRequiredStorageState stateHolder,
DatabaseConfiguration databaseConfiguration)
: CustomCheck("Audit Message Ingestion Process", "ServiceControl.Audit Health", TimeSpan.FromSeconds(5))
class CheckMinimumStorageRequiredForIngestion : CustomCheck
{
public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
public CheckMinimumStorageRequiredForIngestion(MinimumRequiredStorageState stateHolder,
DatabaseConfiguration databaseConfiguration) : base("Audit Message Ingestion Process", "ServiceControl.Audit Health", TimeSpan.FromSeconds(5))
{
var percentageThreshold = databaseConfiguration.MinimumStorageLeftRequiredForIngestion / 100m;
this.stateHolder = stateHolder;
this.databaseConfiguration = databaseConfiguration;
percentageThreshold = this.databaseConfiguration.MinimumStorageLeftRequiredForIngestion / 100m;
dataPathRoot = Path.GetPathRoot(databaseConfiguration.ServerConfiguration.DbPath);
}

var dataPathRoot = Path.GetPathRoot(databaseConfiguration.ServerConfiguration.DbPath);
if (dataPathRoot == null)
public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
if (!databaseConfiguration.ServerConfiguration.UseEmbeddedServer)
{
stateHolder.CanIngestMore = true;
return SuccessResult;
return CheckResult.Pass;
}

Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}");
if (Logger.IsDebugEnabled)
{
Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}");
}

var dataDriveInfo = new DriveInfo(dataPathRoot);
var availableFreeSpace = (decimal)dataDriveInfo.AvailableFreeSpace;
Expand All @@ -41,7 +47,7 @@ public override Task<CheckResult> PerformCheck(CancellationToken cancellationTok
if (percentRemaining > percentageThreshold)
{
stateHolder.CanIngestMore = true;
return SuccessResult;
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.";
Expand Down Expand Up @@ -84,7 +90,11 @@ public static int Parse(IDictionary<string, string> settings)

public const int MinimumStorageLeftRequiredForIngestionDefault = 5;

static readonly Task<CheckResult> SuccessResult = Task.FromResult(CheckResult.Pass);
readonly string dataPathRoot;
readonly decimal percentageThreshold;
readonly MinimumRequiredStorageState stateHolder;
readonly DatabaseConfiguration databaseConfiguration;

static readonly ILog Logger = LogManager.GetLogger(typeof(CheckMinimumStorageRequiredForIngestion));
}
}
Original file line number Diff line number Diff line change
@@ -1,29 +1,31 @@
namespace ServiceControl.Operations
namespace ServiceControl.Persistence.RavenDB.CustomChecks
{
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Persistence.RavenDB;
using ServiceControl.Persistence.RavenDB;

class CheckFreeDiskSpace : CustomCheck
class CheckFreeDiskSpace(RavenPersisterSettings settings)
: CustomCheck("ServiceControl database", "Storage space", TimeSpan.FromMinutes(5))
{
public CheckFreeDiskSpace(RavenPersisterSettings settings) : base("ServiceControl database", "Storage space", TimeSpan.FromMinutes(5))
{
dataPath = settings.DatabasePath;
percentageThreshold = settings.DataSpaceRemainingThreshold / 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 (Logger.IsDebugEnabled)
{
Logger.Debug($"Check ServiceControl data drive space remaining custom check starting. Threshold {percentageThreshold:P0}");
}

if (!settings.UseEmbeddedServer)
{
return CheckResult.Pass;
}

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

var dataDriveInfo = new DriveInfo(dataPathRoot);
Expand Down Expand Up @@ -63,8 +65,8 @@ public static void Validate(RavenPersisterSettings settings)
}
}

readonly string dataPath;
readonly decimal percentageThreshold;
readonly string dataPathRoot = Path.GetPathRoot(settings.DatabasePath);
readonly decimal percentageThreshold = settings.DataSpaceRemainingThreshold / 100m;

public const int DataSpaceRemainingThresholdDefault = 20;
static readonly ILog Logger = LogManager.GetLogger(typeof(CheckFreeDiskSpace));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,30 +1,37 @@
namespace ServiceControl.Operations
namespace ServiceControl.Persistence.RavenDB.CustomChecks
{
using System;
using System.IO;
using System.Threading;
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Persistence.RavenDB;
using ServiceControl.Persistence;
using ServiceControl.Persistence.RavenDB;

class CheckMinimumStorageRequiredForIngestion(
MinimumRequiredStorageState stateHolder,
RavenPersisterSettings settings)
: CustomCheck("Message Ingestion Process", "ServiceControl Health", TimeSpan.FromSeconds(5))
class CheckMinimumStorageRequiredForIngestion : CustomCheck
{
public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
public CheckMinimumStorageRequiredForIngestion(MinimumRequiredStorageState stateHolder,
RavenPersisterSettings settings) : base("Message Ingestion Process", "ServiceControl Health", TimeSpan.FromSeconds(5))
{
percentageThreshold = settings.MinimumStorageLeftRequiredForIngestion / 100m;
this.stateHolder = stateHolder;
this.settings = settings;
dataPathRoot = Path.GetPathRoot(settings.DatabasePath);
percentageThreshold = this.settings.MinimumStorageLeftRequiredForIngestion / 100m;
}

if (dataPathRoot == null)
public override Task<CheckResult> PerformCheck(CancellationToken cancellationToken = default)
{
if (!settings.UseEmbeddedServer)
{
stateHolder.CanIngestMore = true;
return SuccessResult;
}

Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}");
if (Logger.IsDebugEnabled)
{
Logger.Debug($"Check ServiceControl data drive space starting. Threshold {percentageThreshold:P0}");
}

var dataDriveInfo = new DriveInfo(dataPathRoot);
var availableFreeSpace = (decimal)dataDriveInfo.AvailableFreeSpace;
Expand Down Expand Up @@ -71,9 +78,10 @@ public static void Validate(RavenPersisterSettings settings)

public const int MinimumStorageLeftRequiredForIngestionDefault = 5;

readonly string dataPathRoot = Path.GetPathRoot(settings.DatabasePath);

decimal percentageThreshold;
readonly string dataPathRoot;
readonly decimal percentageThreshold;
readonly MinimumRequiredStorageState stateHolder;
readonly RavenPersisterSettings settings;

static readonly Task<CheckResult> SuccessResult = Task.FromResult(CheckResult.Pass);
static readonly ILog Logger = LogManager.GetLogger(typeof(CheckMinimumStorageRequiredForIngestion));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ServiceControl
namespace ServiceControl.Persistence.RavenDB.CustomChecks
{
using System;
using System.Linq;
Expand All @@ -7,9 +7,8 @@
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Persistence.RavenDB;
using Raven.Client.Documents;
using Raven.Client.Documents.Operations.Indexes;
using ServiceControl.Persistence.RavenDB;

class CheckRavenDBIndexErrors(IRavenDocumentStoreProvider documentStoreProvider) : CustomCheck("Error Database Index Errors",
"ServiceControl Health", TimeSpan.FromMinutes(5))
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
namespace ServiceControl
namespace ServiceControl.Persistence.RavenDB.CustomChecks
{
using System;
using System.Linq;
Expand All @@ -7,9 +7,8 @@
using System.Threading.Tasks;
using NServiceBus.CustomChecks;
using NServiceBus.Logging;
using Persistence.RavenDB;
using Raven.Client.Documents;
using Raven.Client.Documents.Operations;
using ServiceControl.Persistence.RavenDB;
using CustomCheck = NServiceBus.CustomChecks.CustomCheck;

class CheckRavenDBIndexLag(IRavenDocumentStoreProvider documentStoreProvider) : CustomCheck("Error Database Index Lag", "ServiceControl Health", TimeSpan.FromMinutes(5))
Expand Down
1 change: 1 addition & 0 deletions src/ServiceControl.Persistence.RavenDB/RavenPersistence.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace ServiceControl.Persistence.RavenDB
{
using CustomChecks;
using MessageRedirects;
using Microsoft.Extensions.DependencyInjection;
using NServiceBus.Unicast.Subscriptions.MessageDrivenSubscriptions;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System.IO;
using System.Reflection;
using Configuration;
using CustomChecks;
using ServiceControl.Operations;

class RavenPersistenceConfiguration : IPersistenceConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using System;
using ServiceControl.Operations;
using ServiceControl.Persistence;
using ServiceControl.Persistence.RavenDB.CustomChecks;

class RavenPersisterSettings : PersistenceSettings
{
Expand Down

0 comments on commit bdb1e78

Please sign in to comment.