-
Notifications
You must be signed in to change notification settings - Fork 50
[Spike] Run audit ingestion in the primary instance #5892
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
Closed
Closed
Changes from all commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
aa1818c
Add plan for host audit ingestion in the primary instance
johnsimons d2c6525
Add primary audit persistence contracts and capability model
johnsimons 959ecd7
Copy the audit ingestion runtime into the primary instance
johnsimons c33fea6
Add the audit ingestion only command and its startup checks
johnsimons d3cc627
Serve audit counts and saga history from local storage
johnsimons 399c823
Restore platform connection details and licensing for local audit
johnsimons 0a1eb01
Compose the audit ingestion only host
johnsimons a6c89bf
Document the audit hosting modes and pin the project boundary
johnsimons a84673d
Introduce AddServiceControlInstance and report host.name and process.…
johnsimons 497cfbb
Add plan for EF audit persistence in the primary instance
johnsimons 694bd89
Add the audit schema to the primary EF persisters
johnsimons 457f986
Make audit partitioning SQL schema-aware when a custom schema is conf…
johnsimons f96c6af
Add code layout rules to the EF audit plan
johnsimons 84fba2d
Move the shared ingestion helpers out of the error pipeline folder
johnsimons ffaaa67
Add the EF audit ingestion write path
johnsimons 7711eb5
Add audit retention, partition lifecycle and the retention lock
johnsimons 6ead227
Serve the message views, audit counts and saga history from EF
johnsimons c0b48ca
Store failed audit imports in EF
johnsimons 623acf0
Advertise audit support on the SQL Server and PostgreSQL persisters
johnsimons f78e6cb
Add the audit instance host for a dedicated audit database
johnsimons 3279a7e
Document the audit topologies of the relational persisters
johnsimons a30f623
Revise the audit ingestion document for clarity and completeness
johnsimons File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 15 additions & 0 deletions
15
src/Particular.LicensingComponent/AuditThroughput/ILocalAuditSource.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| namespace Particular.LicensingComponent.AuditThroughput; | ||
|
|
||
| using Particular.LicensingComponent.Contracts; | ||
|
|
||
| /// <summary> | ||
| /// Audit throughput collection is driven entirely by audit remotes. A primary that holds audit data | ||
| /// itself has no remote to describe it, so without this its own audit queues are counted as customer | ||
| /// endpoints and the audit service metadata in the licensing report is blank. | ||
| /// </summary> | ||
| public interface ILocalAuditSource | ||
| { | ||
| bool Enabled { get; } | ||
|
|
||
| RemoteInstanceInformation Describe(); | ||
| } |
2 changes: 1 addition & 1 deletion
2
src/Particular.LicensingComponent/LicensingComponentHostBuilderExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
162 changes: 162 additions & 0 deletions
162
src/ServiceControl.AcceptanceTests/Auditing/When_composing_audit_ingestion_in_the_primary.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,162 @@ | ||
| namespace ServiceControl.AcceptanceTests.Auditing | ||
| { | ||
| using System; | ||
| using System.IO; | ||
| using System.Linq; | ||
| using System.Runtime.Loader; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.AspNetCore.Builder; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using Microsoft.Extensions.Hosting; | ||
| using Microsoft.Extensions.Logging; | ||
| using NServiceBus; | ||
| using NUnit.Framework; | ||
| using Particular.LicensingComponent.AuditThroughput; | ||
| using Particular.ServiceControl; | ||
| using ServiceBus.Management.Infrastructure.Settings; | ||
| using ServiceControl.Auditing; | ||
| using ServiceControl.Connection; | ||
| using ServiceControl.Infrastructure; | ||
| using ServiceControl.Infrastructure.WebApi; | ||
| using ServiceControl.Persistence; | ||
| using ServiceControl.SagaAudit; | ||
|
|
||
| class When_composing_audit_ingestion_in_the_primary : AcceptanceTest | ||
| { | ||
| [Test] | ||
| public async Task Should_host_the_audit_runtime() | ||
| { | ||
| var (app, services) = await BuildHost(); | ||
|
|
||
| try | ||
| { | ||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(HostsAuditIngestion(services), Is.True); | ||
| Assert.That(app.Services.GetService<AuditIngestor>(), Is.Not.Null); | ||
| Assert.That(app.Services.GetService<ImportFailedAudits>(), Is.Not.Null); | ||
| Assert.That(app.Services.GetService<IFailedAuditImportDataStore>(), Is.Not.Null); | ||
| Assert.That(app.Services.GetService<IAuditCountsDataStore>(), Is.Not.Null); | ||
| Assert.That(app.Services.GetService<ISagaHistoryDataStore>(), Is.Not.Null); | ||
|
|
||
| Assert.That(app.Services.GetService<ILocalAuditSource>(), Is.Not.Null, | ||
| "without it the local audit queues are counted as customer endpoints in the licensing report"); | ||
| Assert.That(services.Any(descriptor => | ||
| descriptor.ServiceType == typeof(IProvidePlatformConnectionDetails) | ||
| && descriptor.ImplementationType == typeof(AuditPlatformConnectionDetailsProvider)), | ||
| Is.True, | ||
| "/api/connection must still tell endpoints where to send audit and saga data"); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| await app.DisposeAsync(); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_keep_every_audit_capability_but_the_receiver_when_ingestion_is_disabled() | ||
| { | ||
| var (app, services) = await BuildHost(settings => settings.IngestAuditMessages = false); | ||
|
|
||
| try | ||
| { | ||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(HostsAuditIngestion(services), Is.False, | ||
| "the receiver is the only thing the setting turns off, because other processes may still be ingesting"); | ||
| Assert.That(app.Services.GetService<AuditIngestor>(), Is.Not.Null); | ||
| Assert.That(app.Services.GetService<IAuditCountsDataStore>(), Is.Not.Null); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| await app.DisposeAsync(); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_stand_aside_from_audit_entirely_when_the_audit_data_is_remote() | ||
| { | ||
| var (app, services) = await BuildHost(settings => | ||
| { | ||
| settings.AuditDataLocation = AuditDataLocation.Remote; | ||
| settings.RemoteInstances = [new RemoteInstanceSetting("http://localhost:44444/api")]; | ||
| }); | ||
|
|
||
| try | ||
| { | ||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(HostsAuditIngestion(services), Is.False, "the audit host ingests, not this primary"); | ||
| Assert.That(app.Services.GetService<AuditIngestor>(), Is.Null); | ||
| Assert.That(app.Services.GetService<ILocalAuditSource>(), Is.Null, "licensing learns about audit from the remote"); | ||
| Assert.That(app.Services.GetRequiredService<IAuditCountsDataStore>(), Is.TypeOf<EmptyAuditCountsDataStore>(), | ||
| "the local source stands aside so the scatter gather treats this instance as a non-participant"); | ||
| Assert.That(app.Services.GetRequiredService<ISagaHistoryDataStore>(), Is.TypeOf<EmptySagaHistoryDataStore>()); | ||
| Assert.That(app.Services.GetService<GetSagaByIdApi>(), Is.Not.Null, "the audit routes still answer, from the remote"); | ||
| } | ||
| } | ||
| finally | ||
| { | ||
| await app.DisposeAsync(); | ||
| } | ||
| } | ||
|
|
||
| [Test] | ||
| public async Task Should_refuse_local_audit_ingestion_alongside_remote_instances() | ||
| { | ||
| var exception = Assert.ThrowsAsync<Exception>(() => BuildHost(settings => | ||
| settings.RemoteInstances = [new RemoteInstanceSetting("http://localhost:44444/api")])); | ||
|
|
||
| Assert.That(exception.Message, Does.Contain("AuditDataLocation")); | ||
| } | ||
|
|
||
| // The registrations are inspected rather than resolved. A normal primary hosts an NServiceBus | ||
| // endpoint, and constructing every hosted service without starting it fails inside the | ||
| // transport's receive component. | ||
| static bool HostsAuditIngestion(IServiceCollection services) => | ||
| services.Any(descriptor => | ||
| descriptor.ServiceType == typeof(IHostedService) && descriptor.ImplementationType == typeof(AuditIngestion)); | ||
|
|
||
| async Task<(WebApplication App, IServiceCollection Services)> BuildHost(Action<Settings> customize = null) | ||
| { | ||
| var settings = await CreateSettings(); | ||
|
|
||
| customize?.Invoke(settings); | ||
|
|
||
| var endpointConfiguration = new EndpointConfiguration(settings.InstanceName); | ||
| endpointConfiguration.AssemblyScanner().Disable = true; | ||
|
|
||
| var hostBuilder = WebApplication.CreateBuilder(); | ||
| hostBuilder.AddServiceControl(settings, endpointConfiguration); | ||
| hostBuilder.AddServiceControlApi(settings.CorsSettings); | ||
|
|
||
| return (hostBuilder.Build(), hostBuilder.Services); | ||
| } | ||
|
|
||
| async Task<Settings> CreateSettings() | ||
| { | ||
| var settings = new Settings(TransportIntegration.TypeName, StorageConfiguration.PersistenceType, | ||
| CreateLoggingSettings(), forwardErrorMessages: false, errorRetentionPeriod: TimeSpan.FromDays(10)) | ||
| { | ||
| InstanceName = $"AuditComposition.{Guid.NewGuid():n}", | ||
| TransportConnectionString = TransportIntegration.ConnectionString, | ||
| MaximumConcurrencyLevel = 2, | ||
| DisableHealthChecks = true, | ||
| AssemblyLoadContextResolver = static _ => AssemblyLoadContext.Default | ||
| }; | ||
|
|
||
| await StorageConfiguration.CustomizeSettings(settings); | ||
|
|
||
| return settings; | ||
| } | ||
|
|
||
| static LoggingSettings CreateLoggingSettings() | ||
| { | ||
| var logPath = Path.Combine(Path.GetTempPath(), Path.GetRandomFileName()); | ||
| Directory.CreateDirectory(logPath); | ||
| return new LoggingSettings(Settings.SettingsRootNamespace, defaultLevel: LogLevel.Debug, logPath: logPath); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
should this be a wildcard exclude since raven will never support primary audit ingestion?