diff --git a/src/Particular.LicensingComponent.UnitTests/AuditQuery_Tests.cs b/src/Particular.LicensingComponent.UnitTests/AuditQuery_Tests.cs index 082fe266ee..76692d5e00 100644 --- a/src/Particular.LicensingComponent.UnitTests/AuditQuery_Tests.cs +++ b/src/Particular.LicensingComponent.UnitTests/AuditQuery_Tests.cs @@ -100,6 +100,42 @@ public async Task Should_return_each_remote_with_only_its_own_queues() Assert.That(remotes.Select(remote => remote.Queues), Is.EqualTo(new[] { new[] { "audit.a", "audit.a.log" }, new[] { "audit.b", "audit.b.log" } })); } + /// + /// Tests that the backwards compatibility handling of the instance name property works for both formats of this response, in version 5.4 and earlier the field + /// was called service_name, and was renamed instance_name after that. + /// The version number is not used to determine the property name, but is included in the test to ensure that the correct property name is used for each version. + /// + [TestCase("6.21.0", "instance_name")] + [TestCase("5.4.0", "service_name")] + public async Task Should_include_the_input_queue_named_after_the_audit_instance(string version, string instanceNameProperty) + { + var configuration = $$""" + { + "host": { + "{{instanceNameProperty}}": "Contoso.Audit", + "logging": { "log_path": "/var/log/servicecontrol-audit", "logging_level": "debug" } + }, + "data_retention": { "audit_retention_period": "30.00:00:00" }, + "performance_tunning": { "max_body_size_to_store": 102400 }, + "transport": { + "transport_type": "LearningTransport", + "audit_log_queue": "audit.log", + "audit_queue": "audit", + "forward_audit_messages": false + }, + "persistence": { "persistence_type": "PostgreSQL" }, + "plugins": {} + } + """; + var configurationApi = new ConfigurationApi_ReturningRemotes( + new RemoteConfiguration { ApiUri = "http://audit:44444/api/", Status = "online", Version = version, Configuration = JsonNode.Parse(configuration) }); + var auditQuery = new AuditQuery(NullLogger.Instance, new FakeEndpointApi(), new FakeAuditCountApi(), configurationApi); + + var remotes = await auditQuery.GetAuditRemotes(); + + Assert.That(remotes.Single().Queues, Is.EquivalentTo(new[] { "Contoso.Audit", "audit", "audit.log" })); + } + [Test] public async Task Should_return_successful_audit_connection_if_instances_exist_and_are_online() { diff --git a/src/Particular.LicensingComponent/AuditThroughput/AuditQuery.cs b/src/Particular.LicensingComponent/AuditThroughput/AuditQuery.cs index e048619e34..8b173eecf5 100644 --- a/src/Particular.LicensingComponent/AuditThroughput/AuditQuery.cs +++ b/src/Particular.LicensingComponent/AuditThroughput/AuditQuery.cs @@ -61,9 +61,10 @@ public async Task> GetAuditRemotes(CancellationT : null; if (remote.Configuration.AsObject().TryGetPropertyValue("host", out var host) && - host?.AsObject().TryGetPropertyValue("service_name", out var serviceName) == true) + (host?.AsObject().TryGetPropertyValue("instance_name", out var instanceName) == true || + host?.AsObject().TryGetPropertyValue("service_name", out instanceName) == true)) { - queues.Add(serviceName!.GetValue()); + queues.Add(instanceName!.GetValue()); } if (remote.Configuration.AsObject().TryGetPropertyValue("transport", out var transport))