From cbb17eadfe1d60c1f3c51a144f58a5c22b832065 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 28 Mar 2025 09:14:40 +0700 Subject: [PATCH 1/3] Favor connection string over server URL when trying to connect to RavenDB to retrieve dirty memory details --- .../MemoryInformationRetriever.cs | 2 +- .../MemoryInformationRetriever.cs | 9 +++++---- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs index 452546521d..5e16f3249e 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -13,7 +13,7 @@ class MemoryInformationRetriever(DatabaseConfiguration databaseConfiguration) // string when running in external mode. However, the tricky part is that when tests are run they // behave like if it was external mode. If the connection string contain always only the server // URL, this code is safe, otherwise it need to be adjusted to extract the server URL. - readonly HttpClient client = new() { BaseAddress = new Uri(databaseConfiguration.ServerConfiguration.ServerUrl ?? databaseConfiguration.ServerConfiguration.ConnectionString) }; + readonly HttpClient client = new() { BaseAddress = new Uri(databaseConfiguration.ServerConfiguration.ConnectionString ?? databaseConfiguration.ServerConfiguration.ServerUrl) }; record ResponseDto { diff --git a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs index b44ba50bfc..eb2d7412dc 100644 --- a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -9,10 +9,11 @@ namespace ServiceControl.Persistence.RavenDB; class MemoryInformationRetriever(RavenPersisterSettings persisterSettings) { // What does a connection string look like? Is it only a URI or could it contain other stuff? - // The primary instance has only the concept of a connection string (vs the Audit instance having - // both a ServiceUrl and a ConnectionString). If the connection string contain always only the - // server URL, this code is safe, otherwise it need to be adjusted to extract the server URL. - readonly HttpClient client = new() { BaseAddress = new Uri(persisterSettings.ServerUrl ?? persisterSettings.ConnectionString) }; + // The ?? operator is needed because ServerUrl is populated when running embedded and connection + // string when running in external mode. However, the tricky part is that when tests are run they + // behave like if it was external mode. If the connection string contain always only the server + // URL, this code is safe, otherwise it need to be adjusted to extract the server URL. + readonly HttpClient client = new() { BaseAddress = new Uri(persisterSettings.ConnectionString ?? persisterSettings.ServerUrl) }; record ResponseDto { From 52926a94cc168dc79157ce670199cb3009aff161 Mon Sep 17 00:00:00 2001 From: Mauro Servienti Date: Fri, 28 Mar 2025 15:48:54 +0700 Subject: [PATCH 2/3] Update comment to reflect reality --- .../MemoryInformationRetriever.cs | 10 +++++----- .../MemoryInformationRetriever.cs | 10 +++++----- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs index 5e16f3249e..a0ed8f0acf 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -8,11 +8,11 @@ namespace ServiceControl.Audit.Persistence.RavenDB; class MemoryInformationRetriever(DatabaseConfiguration databaseConfiguration) { - // What does a connection string look like? Is it only a URI or could it contain other stuff? - // The ?? operator is needed because ServerUrl is populated when running embedded and connection - // string when running in external mode. However, the tricky part is that when tests are run they - // behave like if it was external mode. If the connection string contain always only the server - // URL, this code is safe, otherwise it need to be adjusted to extract the server URL. + // Connection string is composed of the server URL. The ?? operator is needed because ServerUrl + // is populated when running embedded and connection string when running in external mode. + // However, the tricky part is that when tests are run they behave like if it was external mode. + // ServerUrl is always populated by the persister settings, hence the code first checks for the + // presence of a connection string, and if null, falls back to ServerUrl readonly HttpClient client = new() { BaseAddress = new Uri(databaseConfiguration.ServerConfiguration.ConnectionString ?? databaseConfiguration.ServerConfiguration.ServerUrl) }; record ResponseDto diff --git a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs index eb2d7412dc..f7db4f2557 100644 --- a/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -8,11 +8,11 @@ namespace ServiceControl.Persistence.RavenDB; class MemoryInformationRetriever(RavenPersisterSettings persisterSettings) { - // What does a connection string look like? Is it only a URI or could it contain other stuff? - // The ?? operator is needed because ServerUrl is populated when running embedded and connection - // string when running in external mode. However, the tricky part is that when tests are run they - // behave like if it was external mode. If the connection string contain always only the server - // URL, this code is safe, otherwise it need to be adjusted to extract the server URL. + // Connection string is composed of the server URL. The ?? operator is needed because ServerUrl + // is populated when running embedded and connection string when running in external mode. + // However, the tricky part is that when tests are run they behave like if it was external mode. + // ServerUrl is always populated by the persister settings, hence the code first checks for the + // presence of a connection string, and if null, falls back to ServerUrl readonly HttpClient client = new() { BaseAddress = new Uri(persisterSettings.ConnectionString ?? persisterSettings.ServerUrl) }; record ResponseDto From 36ee3496a99dd8f717e558e771713c8dbd208124 Mon Sep 17 00:00:00 2001 From: Brandon Ording Date: Fri, 28 Mar 2025 14:05:10 -0400 Subject: [PATCH 3/3] Update audit comment --- .../MemoryInformationRetriever.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs index a0ed8f0acf..5aff8c0fb7 100644 --- a/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs +++ b/src/ServiceControl.Audit.Persistence.RavenDB/MemoryInformationRetriever.cs @@ -11,8 +11,8 @@ class MemoryInformationRetriever(DatabaseConfiguration databaseConfiguration) // Connection string is composed of the server URL. The ?? operator is needed because ServerUrl // is populated when running embedded and connection string when running in external mode. // However, the tricky part is that when tests are run they behave like if it was external mode. - // ServerUrl is always populated by the persister settings, hence the code first checks for the - // presence of a connection string, and if null, falls back to ServerUrl + // Only one of ConnectionString and ServerUrl will be non-null, so we'll check ConnectionString first + // to be consistent with the error instance implementation, where ServerUrl always has a value. readonly HttpClient client = new() { BaseAddress = new Uri(databaseConfiguration.ServerConfiguration.ConnectionString ?? databaseConfiguration.ServerConfiguration.ServerUrl) }; record ResponseDto