Please, fill the following sections to help us fix the issue
Whenever multiple CosmosDB Health Checks used with the recommendation of implementing in a SingleTon it always uses the latest connectionString. IF a Singleton is not used it results in Memory Leaks, this is new problem.
Please see sample below:
What you expected to happen:
I expect the health check to health check on both instances of the implemented singleTon
How to reproduce it (as minimally and precisely as possible):
Just add multiple CosmsoDB endpoints to check
Source code sample:
SingleTon impelementation -> Latest Connection is always used.
services.AddSingleton(sp => new CosmosClient(Configuration["Data:AzureCosmosDBGremlinConnectionString"].ToString())).AddHealthChecks()
.AddAzureCosmosDB(optionsFactory: s => new AzureCosmosDbHealthCheckOptions
{
ContainerIds = [Configuration["Data:AzureCosmosDBGremlincollectionId"].ToString()],
DatabaseId = Configuration["Data:AzureCosmosDBGremlinDatabase"].ToString()
}, name: "Azure_Gremlin_CosmosDB", timeout: TimeSpan.FromSeconds(network_check_timeout));
*/
services.AddSingleton(sp => new CosmosClient(Configuration["Data:AzureCosmosDBConnectionString"].ToString())).AddHealthChecks()
.AddAzureCosmosDB(optionsFactory: s => new AzureCosmosDbHealthCheckOptions
{
ContainerIds = [Configuration["Data:AzureCosmosDBcollectionId"].ToString()],
DatabaseId = Configuration["Data:AzureCosmosDBDatabaseId"].ToString()
}, name: "Azure_CosmosDB", timeout: TimeSpan.FromSeconds(network_check_timeout));
Non-SingleTon Implementaiton > Results in Memory Leaks
.AddAzureCosmosDB(sp => new CosmosClient(Configuration["Data:AzureCosmosDBConnectionString"].ToString()), sp => new AzureCosmosDbHealthCheckOptions()
{
ContainerIds = [Configuration["Data:AzureCosmosDBcollectionId"].ToString()],
DatabaseId = Configuration["Data:AzureCosmosDBDatabaseId"].ToString()
}, "AzureCosmosDB")/
/
.AddAzureCosmosDB(sp => new CosmosClient(Configuration["Data:AzureCosmosDBGremlinConnectionString"].ToString()), sp => new AzureCosmosDbHealthCheckOptions()
{
ContainerIds = [Configuration["Data:AzureCosmosDBGremlincollectionId"].ToString()],
DatabaseId = Configuration["Data:AzureCosmosDBGremlinDatabase"].ToString()
}
Please, fill the following sections to help us fix the issue
Whenever multiple CosmosDB Health Checks used with the recommendation of implementing in a SingleTon it always uses the latest connectionString. IF a Singleton is not used it results in Memory Leaks, this is new problem.
Please see sample below:
What you expected to happen:
I expect the health check to health check on both instances of the implemented singleTon
How to reproduce it (as minimally and precisely as possible):
Just add multiple CosmsoDB endpoints to check
Source code sample:
SingleTon impelementation -> Latest Connection is always used.
services.AddSingleton(sp => new CosmosClient(Configuration["Data:AzureCosmosDBGremlinConnectionString"].ToString())).AddHealthChecks() .AddAzureCosmosDB(optionsFactory: s => new AzureCosmosDbHealthCheckOptions { ContainerIds = [Configuration["Data:AzureCosmosDBGremlincollectionId"].ToString()], DatabaseId = Configuration["Data:AzureCosmosDBGremlinDatabase"].ToString() }, name: "Azure_Gremlin_CosmosDB", timeout: TimeSpan.FromSeconds(network_check_timeout));
*/
services.AddSingleton(sp => new CosmosClient(Configuration["Data:AzureCosmosDBConnectionString"].ToString())).AddHealthChecks() .AddAzureCosmosDB(optionsFactory: s => new AzureCosmosDbHealthCheckOptions { ContainerIds = [Configuration["Data:AzureCosmosDBcollectionId"].ToString()], DatabaseId = Configuration["Data:AzureCosmosDBDatabaseId"].ToString() }, name: "Azure_CosmosDB", timeout: TimeSpan.FromSeconds(network_check_timeout));
Non-SingleTon Implementaiton > Results in Memory Leaks
.AddAzureCosmosDB(sp => new CosmosClient(Configuration["Data:AzureCosmosDBConnectionString"].ToString()), sp => new AzureCosmosDbHealthCheckOptions() { ContainerIds = [Configuration["Data:AzureCosmosDBcollectionId"].ToString()], DatabaseId = Configuration["Data:AzureCosmosDBDatabaseId"].ToString() }, "AzureCosmosDB")/ / .AddAzureCosmosDB(sp => new CosmosClient(Configuration["Data:AzureCosmosDBGremlinConnectionString"].ToString()), sp => new AzureCosmosDbHealthCheckOptions() { ContainerIds = [Configuration["Data:AzureCosmosDBGremlincollectionId"].ToString()], DatabaseId = Configuration["Data:AzureCosmosDBGremlinDatabase"].ToString() }
Environment: