in src/Elastic.Extensions.Logging/ElasticsearchLoggerProvider.cs [99:142]
private static NodePool CreateNodePool(ElasticsearchLoggerOptions loggerOptions)
{
var shipTo = loggerOptions.ShipTo;
var connectionPool = loggerOptions.ShipTo.NodePoolType;
var nodeUris = loggerOptions.ShipTo.NodeUris?.ToArray() ?? Array.Empty<Uri>();
if (nodeUris.Length == 0 && connectionPool != NodePoolType.Cloud)
return new SingleNodePool(new Uri("http://localhost:9200"));
if (connectionPool == NodePoolType.SingleNode || connectionPool == NodePoolType.Unknown && nodeUris.Length == 1)
return new SingleNodePool(nodeUris[0]);
switch (connectionPool)
{
// TODO: Add option to randomize pool
case NodePoolType.Unknown:
case NodePoolType.Sniffing:
return new SniffingNodePool(nodeUris);
case NodePoolType.Static:
return new StaticNodePool(nodeUris);
case NodePoolType.Sticky:
return new StickyNodePool(nodeUris);
// case NodePoolType.StickySniffing:
case NodePoolType.Cloud:
if (shipTo.CloudId.IsNullOrEmpty())
throw new Exception($"Cloud {nameof(CloudNodePool)} requires '{nameof(ShipToOptions.CloudId)}' to be provided as well");
if (!shipTo.ApiKey.IsNullOrEmpty())
{
var apiKeyCredentials = new ApiKey(shipTo.ApiKey);
return new CloudNodePool(shipTo.CloudId, apiKeyCredentials);
}
if (!shipTo.Username.IsNullOrEmpty() && !shipTo.Password.IsNullOrEmpty())
{
var basicAuthCredentials = new BasicAuthentication(shipTo.Username, shipTo.Password);
return new CloudNodePool(shipTo.CloudId, basicAuthCredentials);
}
throw new Exception(
$"Cloud requires either '{nameof(ShipToOptions.ApiKey)}' or"
+ $"'{nameof(ShipToOptions.Username)}' and '{nameof(ShipToOptions.Password)}"
);
default:
throw new ArgumentException($"Unrecognised connection pool type '{connectionPool}' specified in the configuration.",
nameof(connectionPool));
}
}