-
Notifications
You must be signed in to change notification settings - Fork 50
Add configured and live audit instance counts to the usage report #5938
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
Changes from all commits
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 |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| namespace Particular.LicensingComponent.Contracts; | ||
|
|
||
| public record AuditServiceMetadata(Dictionary<string, int> Versions, Dictionary<string, int> Transports); | ||
| public record AuditServiceMetadata(Dictionary<string, int> Versions, Dictionary<string, int> Transports) | ||
| { | ||
| public int? ConfiguredInstances { get; init; } | ||
| public int? LiveInstances { get; init; } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -47,12 +47,12 @@ public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationT | |
|
|
||
| if (remotes.Any()) | ||
| { | ||
| List<string> queues = []; | ||
|
|
||
| foreach (var remote in remotes) | ||
|
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. Parse each remote in its own try catch, so a single bad remote doesnt discard the entire list.
Member
Author
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. I looked at this @warwickschroeder, and as far as I can tell, the code is already quite defensive, everywhere we are using
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. My concern is that |
||
| { | ||
| List<string> queues = []; | ||
| string? retention = null; | ||
| string? transportTypeUsed = null; | ||
| var respondedAsAuditInstance = false; | ||
| if (remote.Configuration != null) | ||
| { | ||
| retention = remote.Configuration.AsObject().TryGetPropertyValue("data_retention", out var dataRetention) && | ||
|
|
@@ -71,6 +71,7 @@ public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationT | |
| if (transport?.AsObject().TryGetPropertyValue("audit_queue", out var auditQueue) == true) | ||
| { | ||
| queues.Add(auditQueue!.GetValue<string>()); | ||
| respondedAsAuditInstance = true; | ||
| } | ||
| if (transport?.AsObject().TryGetPropertyValue("audit_log_queue", out var auditLogQueue) == true) | ||
| { | ||
|
|
@@ -90,7 +91,8 @@ public async Task<List<RemoteInstanceInformation>> GetAuditRemotes(CancellationT | |
| Status = remote.Status, | ||
| Retention = TimeSpan.TryParse(retention, out var ts) ? ts : TimeSpan.Zero, | ||
| Queues = queues, | ||
| Transport = transportTypeUsed ?? "" | ||
| Transport = transportTypeUsed ?? "", | ||
| RespondedAsAuditInstance = respondedAsAuditInstance | ||
| }; | ||
|
|
||
| remoteInstance.SemanticVersion = SemanticVersion.TryParse(remoteInstance.VersionString ?? string.Empty, out var v) ? v : null; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| namespace ServiceControl.Persistence.Tests.RavenDB.Throughput; | ||
|
|
||
| using System.Collections.Generic; | ||
| using System.Threading.Tasks; | ||
| using Microsoft.Extensions.DependencyInjection; | ||
| using NUnit.Framework; | ||
| using ServiceControl.Persistence.RavenDB.Throughput; | ||
|
|
||
| [TestFixture] | ||
| class AuditServiceMetadataCompatibilityTests : RavenPersistenceTestBase | ||
| { | ||
| [Test] | ||
| public async Task Audit_service_metadata_saved_before_the_instance_counts_existed_reads_back_without_them() | ||
| { | ||
| var throughputDatabase = ServiceProvider.GetRequiredService<ThroughputDatabaseConfiguration>().Name; | ||
|
|
||
| using (var session = DocumentStore.OpenAsyncSession(throughputDatabase)) | ||
| { | ||
| var metadataWithoutCounts = new AuditServiceMetadataBeforeInstanceCounts( | ||
| new Dictionary<string, int> { ["6.2.0"] = 2 }, | ||
| new Dictionary<string, int> { ["RabbitMQ.QuorumConventionalRouting"] = 2 }); | ||
|
|
||
| await session.StoreAsync(metadataWithoutCounts, "AuditServiceMetadata"); | ||
| await session.SaveChangesAsync(); | ||
| } | ||
|
|
||
| var auditServiceMetadata = await LicensingDataStore.GetAuditServiceMetadata(); | ||
|
|
||
| using (Assert.EnterMultipleScope()) | ||
| { | ||
| Assert.That(auditServiceMetadata.Versions, Is.EquivalentTo(new Dictionary<string, int> { ["6.2.0"] = 2 })); | ||
| Assert.That(auditServiceMetadata.ConfiguredInstances, Is.Null); | ||
| Assert.That(auditServiceMetadata.LiveInstances, Is.Null); | ||
| } | ||
| } | ||
|
|
||
| record AuditServiceMetadataBeforeInstanceCounts(Dictionary<string, int> Versions, Dictionary<string, int> Transports); | ||
| } |
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.
Some xml comments here would be handy explaining what these capture, and what null means.