Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error instance setting to stop error ingestion only #3798

Merged
merged 6 commits into from
Nov 14, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
87 changes: 46 additions & 41 deletions src/ServiceControl/Infrastructure/Settings/Settings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ public Settings(string serviceName = null)
// Overwrite the service name if it is specified in ENVVAR, reg, or config file
ServiceName = SettingsReader<string>.Read("InternalQueueName", ServiceName);

ErrorQueue = GetErrorQueue();
ErrorLogQueue = GetErrorLogQueue(ErrorQueue);
LoadErrorIngestionSettings();

TryLoadLicenseFromConfig();

Expand Down Expand Up @@ -55,6 +54,51 @@ public Settings(string serviceName = null)
DataStoreType = GetDataStoreType();
}

void LoadErrorIngestionSettings()
{
ErrorQueue = SettingsReader<string>.Read("ServiceBus", "ErrorQueue", "error");

var hasValidErrorQueueName = !string.IsNullOrEmpty(ErrorQueue) && !ErrorQueue.Equals(Disabled, StringComparison.OrdinalIgnoreCase);

IngestErrorMessages = SettingsReader<bool>.Read("IngestErrorMessages", hasValidErrorQueueName);

if (IngestErrorMessages && hasValidErrorQueueName == false)
{
throw new Exception($"Error ingestion cannot be enabled when ServiceBus/ErrorQueue is '{ErrorQueue}'");
}

if (hasValidErrorQueueName == false || IngestErrorMessages == false)
{
logger.Info("Error ingestion disabled.");
}

if (hasValidErrorQueueName == false)
{
if (string.IsNullOrEmpty(ErrorQueue))
{
logger.Warn("No configuration value set for ServiceBus/ErrorQueue. If this is not intentional provide a value.");
}

ErrorLogQueue = null;
ErrorQueue = null;
}
else
{
var errorLogQueue = SettingsReader<string>.Read("ServiceBus", "ErrorLogQueue", null);

if (errorLogQueue == null)
{
logger.Info("No settings found for error log queue to import, default name will be used");

ErrorLogQueue = Subscope(ErrorQueue);
}
else
{
ErrorLogQueue = errorLogQueue;
}
}
}

public string NotificationsFilter { get; set; }

public bool AllowMessageEditing { get; set; }
Expand Down Expand Up @@ -233,45 +277,6 @@ public string GetConnectionString()
return connectionStringSettings?.ConnectionString;
}

string GetErrorQueue()
{
var value = SettingsReader<string>.Read("ServiceBus", "ErrorQueue", "error");

if (value == null)
{
logger.Warn("No settings found for error queue to import, if this is not intentional please set add ServiceBus/ErrorQueue to your appSettings");
IngestErrorMessages = false;
return null;
}

if (value.Equals(Disabled, StringComparison.OrdinalIgnoreCase))
{
logger.Info("Error ingestion disabled.");
IngestErrorMessages = false;
return null; // needs to be null to not create the queues
}

return value;
}

string GetErrorLogQueue(string errorQueue)
{
if (errorQueue == null)
{
return null;
}

var value = SettingsReader<string>.Read("ServiceBus", "ErrorLogQueue", null);

if (value == null)
{
logger.Info("No settings found for error log queue to import, default name will be used");
return Subscope(errorQueue);
}

return value;
}

string GetDbPath()
{
var host = Hostname;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using NServiceBus.Logging;
using NServiceBus.Raw;
using NServiceBus.Transport;
using Operations;
using Operations.BodyStorage;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ namespace ServiceControl.Recoverability
using NServiceBus.Transport;
using Raven.Client;
using ServiceBus.Management.Infrastructure.Settings;
using ServiceControl.Persistence;

class ReturnToSenderDequeuer : IHostedService
{
Expand Down