@@ -6,15 +6,8 @@ namespace ServiceControl.Persistence.RavenDB;
66using System . Threading ;
77using System . Threading . Tasks ;
88
9- class MemoryInformationRetriever ( RavenPersisterSettings persisterSettings )
9+ class MemoryInformationRetriever ( IRavenDocumentStoreProvider documentStoreProvider )
1010{
11- // Connection string is composed of the server URL. The ?? operator is needed because ServerUrl
12- // is populated when running embedded and connection string when running in external mode.
13- // However, the tricky part is that when tests are run they behave like if it was external mode.
14- // ServerUrl is always populated by the persister settings, hence the code first checks for the
15- // presence of a connection string, and if null, falls back to ServerUrl
16- readonly HttpClient client = new ( ) { BaseAddress = new Uri ( persisterSettings . ConnectionString ?? persisterSettings . ServerUrl ) } ;
17-
1811 record ResponseDto
1912 {
2013 public MemoryInformation MemoryInformation { get ; set ; }
@@ -28,7 +21,10 @@ record MemoryInformation
2821
2922 public async Task < ( bool IsHighDirty , string DirtyMemory ) > GetMemoryInformation ( CancellationToken cancellationToken = default )
3023 {
31- var httpResponse = await client . GetAsync ( "/admin/debug/memory/stats?includeThreads=false&includeMappings=false" , cancellationToken ) ;
24+ var documentStore = await documentStoreProvider . GetDocumentStore ( cancellationToken ) ;
25+ var client = documentStore . GetRequestExecutor ( ) . HttpClient ;
26+ var requestUrl = documentStore . Urls [ 0 ] . TrimEnd ( '/' ) + "/admin/debug/memory/stats?includeThreads=false&includeMappings=false" ;
27+ var httpResponse = await client . GetAsync ( requestUrl , cancellationToken ) ;
3228 var responseDto = JsonSerializer . Deserialize < ResponseDto > ( await httpResponse . Content . ReadAsStringAsync ( cancellationToken ) ) ;
3329
3430 return responseDto . MemoryInformation is null
0 commit comments