Repository navigation
[Do Not Merge] Change default of external event publishing #6006
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
base: master
Are you sure you want to change the base?
Changes from all commits
0c99386
616f128
435d288
e9a08e5
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,68 @@ | ||
| namespace ServiceControl.UnitTests.Infrastructure.Settings; | ||
|
|
||
| using System; | ||
| using NUnit.Framework; | ||
| using ServiceBus.Management.Infrastructure.Settings; | ||
|
|
||
| [TestFixture] | ||
| [NonParallelizable] | ||
| class ExternalIntegrationsPublishingSettingsTests | ||
| { | ||
| const string Variable = "SERVICECONTROL_ENABLEEXTERNALINTEGRATIONSPUBLISHING"; | ||
| const string LegacyVariable = "SERVICECONTROL_DISABLEEXTERNALINTEGRATIONSPUBLISHING"; | ||
|
|
||
| string originalValue; | ||
| string originalLegacyValue; | ||
|
|
||
| [SetUp] | ||
| public void SetUp() | ||
| { | ||
| originalValue = Environment.GetEnvironmentVariable(Variable); | ||
| originalLegacyValue = Environment.GetEnvironmentVariable(LegacyVariable); | ||
| Environment.SetEnvironmentVariable(Variable, null); | ||
| Environment.SetEnvironmentVariable(LegacyVariable, null); | ||
| } | ||
|
|
||
| [TearDown] | ||
| public void TearDown() | ||
| { | ||
| Environment.SetEnvironmentVariable(Variable, originalValue); | ||
| Environment.SetEnvironmentVariable(LegacyVariable, originalLegacyValue); | ||
| } | ||
|
|
||
| [Test] | ||
| public void Is_disabled_when_neither_setting_is_configured() => | ||
| Assert.That(new Settings().EnableExternalIntegrationsPublishing, Is.False); | ||
|
|
||
| [TestCase("true", true)] | ||
| [TestCase("false", false)] | ||
| public void Reads_the_enable_setting(string value, bool expected) | ||
| { | ||
| Environment.SetEnvironmentVariable(Variable, value); | ||
|
|
||
| Assert.That(new Settings().EnableExternalIntegrationsPublishing, Is.EqualTo(expected)); | ||
| } | ||
|
|
||
| [TestCase("true", false)] | ||
| [TestCase("false", true)] | ||
| public void Treats_the_legacy_setting_as_the_inverse(string value, bool expected) | ||
| { | ||
| Environment.SetEnvironmentVariable(LegacyVariable, value); | ||
|
|
||
| Assert.That(new Settings().EnableExternalIntegrationsPublishing, Is.EqualTo(expected)); | ||
| } | ||
|
|
||
| [TestCase("true", "true")] | ||
| [TestCase("true", "false")] | ||
| [TestCase("false", "true")] | ||
| [TestCase("false", "false")] | ||
| public void Rejects_both_settings_being_configured(string enable, string disable) | ||
| { | ||
| Environment.SetEnvironmentVariable(Variable, enable); | ||
| Environment.SetEnvironmentVariable(LegacyVariable, disable); | ||
|
|
||
| var ex = Assert.Throws<Exception>(() => _ = new Settings()); | ||
|
|
||
| Assert.That(ex.Message, Does.Contain("cannot both be configured")); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -14,7 +14,7 @@ public override void Configure(Settings settings, ITransportCustomization transp | |
| var services = hostBuilder.Services; | ||
| services.AddEventLogMapping<ExternalIntegrationEventFailedToBePublishedDefinition>(); | ||
|
|
||
| if (!settings.DisableExternalIntegrationsPublishing) | ||
| if (settings.EnableExternalIntegrationsPublishing) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
With the default now false, enabling publishing on the primary instance only means |
||
| { | ||
| services.AddDomainEventHandler<IntegrationEventWriter>(); | ||
|
|
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -84,7 +84,7 @@ public Settings( | |
| ErrorIngestionBatchSize = IngestionSettingsReader.ReadBatchSize(SettingsRootNamespace, nameof(ErrorIngestionBatchSize), ValidateConfiguration); | ||
| ErrorIngestionMaxParallelWriters = IngestionSettingsReader.ReadMaxParallelWriters(SettingsRootNamespace, nameof(ErrorIngestionMaxParallelWriters), ValidateConfiguration); | ||
| ErrorIngestionBatchTimeout = IngestionSettingsReader.ReadBatchTimeout(SettingsRootNamespace, nameof(ErrorIngestionBatchTimeout), ValidateConfiguration); | ||
| DisableExternalIntegrationsPublishing = SettingsReader.Read(SettingsRootNamespace, "DisableExternalIntegrationsPublishing", false); | ||
| EnableExternalIntegrationsPublishing = ReadEnableExternalIntegrationsPublishing(); | ||
| TrackInstancesInitialValue = SettingsReader.Read(SettingsRootNamespace, "TrackInstancesInitialValue", true); | ||
| ShutdownTimeout = SettingsReader.Read(SettingsRootNamespace, ShutdownTimeoutKey, ShutdownTimeout); | ||
| AssemblyLoadContextResolver = static assemblyPath => new PluginAssemblyLoadContext(assemblyPath); | ||
|
|
@@ -132,7 +132,7 @@ public Settings( | |
|
|
||
| public int ExternalIntegrationsDispatchingBatchSize => SettingsReader.Read(SettingsRootNamespace, ExternalIntegrationsDispatchingBatchSizeKey, 100); | ||
|
|
||
| public bool DisableExternalIntegrationsPublishing { get; set; } | ||
| public bool EnableExternalIntegrationsPublishing { get; set; } | ||
|
|
||
| public bool RunCleanupBundle { get; set; } | ||
|
|
||
|
|
@@ -305,6 +305,21 @@ TimeSpan GetEventRetentionPeriod() | |
| return SettingsReader.Read(SettingsRootNamespace, "EventsRetentionPeriod", TimeSpan.FromDays(14)); | ||
| } | ||
|
|
||
| bool ReadEnableExternalIntegrationsPublishing() | ||
| { | ||
| var legacyConfigured = SettingsReader.TryRead<bool>(SettingsRootNamespace, "DisableExternalIntegrationsPublishing", out var disable); | ||
| var configured = SettingsReader.TryRead<bool>(SettingsRootNamespace, "EnableExternalIntegrationsPublishing", out var enable); | ||
|
|
||
| if (legacyConfigured && configured) | ||
| { | ||
| const string message = "EnableExternalIntegrationsPublishing and the legacy DisableExternalIntegrationsPublishing settings cannot both be configured, please remove DisableExternalIntegrationsPublishing"; | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would it be better to rather check if they disagree, and then throw? Is it really a critical if they are both added but agree? |
||
| logger.LogCritical(message); | ||
| throw new Exception(message); | ||
| } | ||
|
|
||
| return legacyConfigured ? !disable : enable; | ||
| } | ||
|
|
||
| TimeSpan GetErrorRetentionPeriod() | ||
| { | ||
| string message; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Has this change been made to the docs PR?