diff --git a/src/ServiceControl.Audit.UnitTests/ApprovalFiles/APIApprovals.PublicClr.approved.txt b/src/ServiceControl.Audit.UnitTests/ApprovalFiles/APIApprovals.PublicClr.approved.txt index 02a397459c..09d03666f0 100644 --- a/src/ServiceControl.Audit.UnitTests/ApprovalFiles/APIApprovals.PublicClr.approved.txt +++ b/src/ServiceControl.Audit.UnitTests/ApprovalFiles/APIApprovals.PublicClr.approved.txt @@ -13,7 +13,6 @@ namespace ServiceControl.Audit.Infrastructure.Settings public class Settings { public const string DEFAULT_SERVICE_NAME = "Particular.ServiceControl.Audit"; - public const string Disabled = "!disable"; public Settings(string serviceName, string transportType = null, string persisterType = null) { } public string ApiUrl { get; } public string AuditLogQueue { get; set; } diff --git a/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs b/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs index c359dfbd42..37590166c1 100644 --- a/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs +++ b/src/ServiceControl.Audit/Infrastructure/Settings/Settings.cs @@ -28,8 +28,7 @@ public Settings(string serviceName, string transportType = null, string persiste TransportConnectionString = GetConnectionString(); - AuditQueue = GetAuditQueue(); - AuditLogQueue = GetAuditLogQueue(AuditQueue); + LoadAuditQueueInformation(); TryLoadLicenseFromConfig(); @@ -44,6 +43,31 @@ public Settings(string serviceName, string transportType = null, string persiste EnableFullTextSearchOnBodies = SettingsReader.Read("EnableFullTextSearchOnBodies", true); } + void LoadAuditQueueInformation() + { + AuditQueue = SettingsReader.Read("ServiceBus", "AuditQueue", "audit"); + + if (string.IsNullOrEmpty(AuditQueue)) + { + throw new Exception("ServiceBus/AuditQueue value is required to start the instance"); + } + + IngestAuditMessages = SettingsReader.Read("ServiceControl", "IngestAuditMessages", true); + + if (IngestAuditMessages == false) + { + logger.Info("Audit ingestion disabled."); + } + + AuditLogQueue = SettingsReader.Read("ServiceBus", "AuditLogQueue", null); + + if (AuditLogQueue == null) + { + logger.Info("No settings found for audit log queue to import, default name will be used"); + AuditLogQueue = Subscope(AuditQueue); + } + } + //HINT: acceptance tests only public Func MessageFilter { get; set; } @@ -170,38 +194,6 @@ TimeSpan GetTimeToRestartAuditIngestionAfterFailure() return result; } - string GetAuditLogQueue(string auditQueue) - { - if (auditQueue == null) - { - return null; - } - - var value = SettingsReader.Read("ServiceBus", "AuditLogQueue", null); - - if (value == null) - { - logger.Info("No settings found for audit log queue to import, default name will be used"); - return Subscope(auditQueue); - } - - return value; - } - - string GetAuditQueue() - { - var value = SettingsReader.Read("ServiceBus", "AuditQueue", "audit"); - - if (value.Equals(Disabled, StringComparison.OrdinalIgnoreCase)) - { - logger.Info("Audit ingestion disabled."); - IngestAuditMessages = false; - return null; // needs to be null to not create the queues - } - - return value; - } - static bool GetForwardAuditMessages() { var forwardAuditMessages = NullableSettingsReader.Read("ForwardAuditMessages"); @@ -304,7 +296,6 @@ void TryLoadLicenseFromConfig() ILog logger = LogManager.GetLogger(typeof(Settings)); int maxBodySizeToStore = SettingsReader.Read("MaxBodySizeToStore", MaxBodySizeToStoreDefault); public const string DEFAULT_SERVICE_NAME = "Particular.ServiceControl.Audit"; - public const string Disabled = "!disable"; const int MaxBodySizeToStoreDefault = 102400; //100 kb const int DataSpaceRemainingThresholdDefault = 20; diff --git a/src/ServiceControl.Audit/Infrastructure/SetupBootstrapper.cs b/src/ServiceControl.Audit/Infrastructure/SetupBootstrapper.cs index a430f1b9ef..89a1d13d14 100644 --- a/src/ServiceControl.Audit/Infrastructure/SetupBootstrapper.cs +++ b/src/ServiceControl.Audit/Infrastructure/SetupBootstrapper.cs @@ -25,7 +25,6 @@ public async Task Run(string username) var transportSettings = MapSettings(settings); var transportCustomization = settings.LoadTransportCustomization(); - // if audit queue is ("!disable") IngestAuditMessages will be false if (settings.IngestAuditMessages) { if (settings.SkipQueueCreation) diff --git a/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs b/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs index a24b0ed599..c6ef6b28f9 100644 --- a/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs +++ b/src/ServiceControl.Config/Commands/UpgradeServiceControlInstanceCommand.cs @@ -46,15 +46,6 @@ public override async Task ExecuteAsync(InstanceDetailsViewModel model) return; } - if (instance.IsErrorQueueDisabled()) - { - await windowManager.ShowMessage("UPGRADE INCOMPATIBLE", - "You cannot upgrade the instance of ServiceControl with error ingestion disabled. Please contact support.", - hideCancel: true); - - return; - } - var upgradeOptions = new ServiceControlUpgradeOptions(); if (!instance.AppConfig.AppSettingExists(ServiceControlSettings.ForwardErrorMessages.Name)) diff --git a/src/ServiceControl.Config/Extensions/Validations.cs b/src/ServiceControl.Config/Extensions/Validations.cs index 2241ea52bc..4f2262a513 100644 --- a/src/ServiceControl.Config/Extensions/Validations.cs +++ b/src/ServiceControl.Config/Extensions/Validations.cs @@ -56,9 +56,7 @@ public static List UsedErrorQueueNames(TransportInfo transportInfo = nul { p.ErrorLogQueue, p.ErrorQueue - }).Where(queuename => !string.IsNullOrEmpty(queuename) && - string.Compare(queuename, "!disable", StringComparison.OrdinalIgnoreCase) != 0 && - string.Compare(queuename, "!disable.log", StringComparison.OrdinalIgnoreCase) != 0) + }).Where(queuename => !string.IsNullOrEmpty(queuename)) .Distinct() .ToList(); } @@ -75,10 +73,7 @@ public static List UsedAuditQueueNames(TransportInfo transportInfo = nul { p.AuditQueue, p.AuditLogQueue - }).Where(queuename => !string.IsNullOrEmpty(queuename) && - string.Compare(queuename, "!disable", StringComparison.OrdinalIgnoreCase) != 0 && - string.Compare(queuename, "!disable.log", StringComparison.OrdinalIgnoreCase) != 0 - ) + }).Where(queuename => !string.IsNullOrEmpty(queuename)) .Distinct() .ToList(); } diff --git a/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddViewModelValidator.cs b/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddViewModelValidator.cs index ebc4a37ada..d4baf0686a 100644 --- a/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddViewModelValidator.cs +++ b/src/ServiceControl.Config/UI/InstanceAdd/ServiceControlAddViewModelValidator.cs @@ -123,7 +123,7 @@ public ServiceControlAddViewModelValidator() .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Error")) .MustNotBeIn(x => Validations.UsedAuditQueueNames(x.SelectedTransport, x.ErrorInstanceName, x.ConnectionString)) .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Error")) - .When(x => x.InstallErrorInstance && x.ErrorQueueName != "!disable"); + .When(x => x.InstallErrorInstance); RuleFor(x => x.ErrorForwardingQueueName) .NotEmpty() @@ -226,7 +226,7 @@ public ServiceControlAddViewModelValidator() .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Audit")) .MustNotBeIn(x => Validations.UsedAuditQueueNames(x.SelectedTransport, x.AuditInstanceName, x.ConnectionString)) .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Audit")) - .When(x => x.InstallAuditInstance && x.AuditQueueName != "!disable"); + .When(x => x.InstallAuditInstance); RuleFor(x => x.AuditForwardingQueueName) .NotEmpty() diff --git a/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlAuditEditViewModelValidator.cs b/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlAuditEditViewModelValidator.cs index 936f077ecd..4cd60f941f 100644 --- a/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlAuditEditViewModelValidator.cs +++ b/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlAuditEditViewModelValidator.cs @@ -71,7 +71,7 @@ public ServiceControlAuditEditViewModelValidator() .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Audit")) .MustNotBeIn(x => Validations.UsedAuditQueueNames(x.SelectedTransport, x.InstanceName, x.ConnectionString)) .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Audit")) - .When(x => x.SubmitAttempted && x.AuditQueueName != "!disable"); + .When(x => x.SubmitAttempted); RuleFor(x => x.AuditForwardingQueueName) .NotEmpty() diff --git a/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlEditViewModelValidator.cs b/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlEditViewModelValidator.cs index 507cb5901d..d91d0f78da 100644 --- a/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlEditViewModelValidator.cs +++ b/src/ServiceControl.Config/UI/InstanceEdit/ServiceControlEditViewModelValidator.cs @@ -73,7 +73,7 @@ public ServiceControlEditViewModelValidator() .MustNotBeIn(x => Validations.UsedErrorQueueNames(x.SelectedTransport, x.InstanceName, x.ConnectionString)) .WithMessage(string.Format(Validation.Validations.MSG_QUEUE_ALREADY_ASSIGNED, "Error")) - .When(x => x.SubmitAttempted && x.ErrorQueueName != "!disable"); + .When(x => x.SubmitAttempted); RuleFor(x => x.ErrorForwardingQueueName) .NotEmpty() diff --git a/src/ServiceControl/Infrastructure/Settings/Settings.cs b/src/ServiceControl/Infrastructure/Settings/Settings.cs index 22368d557c..080175370e 100644 --- a/src/ServiceControl/Infrastructure/Settings/Settings.cs +++ b/src/ServiceControl/Infrastructure/Settings/Settings.cs @@ -33,8 +33,7 @@ public Settings( // Overwrite the service name if it is specified in ENVVAR, reg, or config file ServiceName = SettingsReader.Read("InternalQueueName", ServiceName); - ErrorQueue = GetErrorQueue(); - ErrorLogQueue = GetErrorLogQueue(ErrorQueue); + LoadErrorIngestionSettings(); TryLoadLicenseFromConfig(); @@ -185,45 +184,6 @@ public string GetConnectionString() return connectionStringSettings?.ConnectionString; } - string GetErrorQueue() - { - var value = SettingsReader.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.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; - } - static bool GetForwardErrorMessages() { var forwardErrorMessages = SettingsReader.Read("ForwardErrorMessages"); @@ -426,6 +386,31 @@ int GetDataSpaceRemainingThreshold() return threshold; } + void LoadErrorIngestionSettings() + { + ErrorQueue = SettingsReader.Read("ServiceBus", "ErrorQueue", "error"); + + if (string.IsNullOrEmpty(ErrorQueue)) + { + throw new Exception("ServiceBus/ErrorQueue requires a value to start the instance"); + } + + IngestErrorMessages = SettingsReader.Read("IngestErrorMessages", true); + + if (!IngestErrorMessages) + { + logger.Info("Error ingestion disabled."); + } + + ErrorLogQueue = SettingsReader.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); + } + } + void TryLoadLicenseFromConfig() { LicenseFileText = SettingsReader.Read("LicenseText"); @@ -433,7 +418,6 @@ void TryLoadLicenseFromConfig() static readonly ILog logger = LogManager.GetLogger(typeof(Settings)); public const string DEFAULT_SERVICE_NAME = "Particular.ServiceControl"; - public const string Disabled = "!disable"; const int DataSpaceRemainingThresholdDefault = 20; } diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs index c61ee419f4..f69fc6c19c 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlBaseService.cs @@ -343,8 +343,6 @@ protected virtual IEnumerable GetPersistencePathsToCleanUp() return Enumerable.Empty(); } - protected bool IsQueueDisabled(string queueName) => queueName != null && queueName.Equals("!disable", StringComparison.InvariantCultureIgnoreCase); - protected virtual void ValidateConnectionString() { } diff --git a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs index e88bc2ea79..7dfeffa1f5 100644 --- a/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs +++ b/src/ServiceControlInstaller.Engine/Instances/ServiceControlInstance.cs @@ -54,10 +54,6 @@ public override void RunQueueCreation() QueueCreation.RunQueueCreation(this); } - public bool IsAuditQueueDisabled() => IsQueueDisabled(AuditQueue); - - public bool IsErrorQueueDisabled() => IsQueueDisabled(ErrorQueue); - protected override void ValidateQueueNames() { try diff --git a/src/ServiceControlInstaller.Engine/Validation/QueueNameValidator.cs b/src/ServiceControlInstaller.Engine/Validation/QueueNameValidator.cs index 4cfae15aaf..28892ef1ad 100644 --- a/src/ServiceControlInstaller.Engine/Validation/QueueNameValidator.cs +++ b/src/ServiceControlInstaller.Engine/Validation/QueueNameValidator.cs @@ -107,6 +107,7 @@ internal void CheckQueueNamesAreUniqueWithinInstance() var duplicatedQueues = queues .Where(x => x.QueueName != null) .ToLookup(x => x.QueueName.ToLower()) + //HINT: we need to filter out `!disable` as the user can still have old instances with this value .Where(x => x.Key != "!disable" && x.Key != "!disable.log" && x.Count() > 1); if (duplicatedQueues.Any()) @@ -124,6 +125,7 @@ where allQueues.Any(p => p.QueueType != QueueType.Audit && string.Equals(p.ConnectionString, queue.ConnectionString, StringComparison.OrdinalIgnoreCase) && string.Equals(p.QueueName, queue.QueueName, StringComparison.OrdinalIgnoreCase) && + //HINT: we need to filter out `!disable` as the user can still have old instances with this value string.Compare("!disable", queue.QueueName, StringComparison.OrdinalIgnoreCase) != 0 && string.Compare("!disable.log", queue.QueueName, StringComparison.OrdinalIgnoreCase) != 0) select queue.PropertyName @@ -140,6 +142,7 @@ from queue in queues where allQueues.Any(p => string.Equals(p.ConnectionString, queue.ConnectionString, StringComparison.OrdinalIgnoreCase) && string.Equals(p.QueueName, queue.QueueName, StringComparison.OrdinalIgnoreCase) && + //HINT: we need to filter out `!disable` as the user can still have old instances with this value string.Compare("!disable", queue.QueueName, StringComparison.OrdinalIgnoreCase) != 0 && string.Compare("!disable.log", queue.QueueName, StringComparison.OrdinalIgnoreCase) != 0) select queue.PropertyName