Closed pederwagner closed 1 year ago
We are working on this healtcheck on some PR, we can take a look on this, thanks!
Hi @pederwagner
The CosmosDb health check allow to set the cosmos client from the service collection, you can register it using your connection mode.
void Configure(IHealthChecksBuilder builder)
{
builder.Services.AddSingleton(sp => new CosmosClient(
"endpoint-from-portal",
new DefaultAzureCredential()));
builder.AddHealthChecks().AddAzureCosmosDB();
}
What would you like to be added: The ability to specify connection type for CosmosDbHealthCheck so that either Direct or Gateway can be selected when creating the CosmosClient. https://learn.microsoft.com/en-us/azure/cosmos-db/nosql/sdk-connection-modes
Example of how implementation could be made:
string connectionString = "";
CosmosClient client = new CosmosClient(connectionString,
new CosmosClientOptions
{
ConnectionMode = ConnectionMode.Gateway
});
Why is this needed: The different connection modes use different protocols (Direct: TCP, Gateway: HTTPS) and different ports. Therefore the connection to Cosmos could behave vastly different based on network and firewall configurations.
In our implementation, we use gateway mode (port 443) for our application, but the healthcheck is not able to connect over TCP and only shows Cosmos DB as unhealthy with a 503 Service unavailable.