-
Notifications
You must be signed in to change notification settings - Fork 54
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Several improvements to Elasticsearch.Ext.Logging #97
Conversation
- Add some basic integration tests to assert the logs make it in the right index - Rename `ElasticsearchDataProcessor` to `ElasticsearchDataShipper` - Move enrichtment of `LogEvent` out of the shipper and into static helper class. - Rely on elasticsearch to generate ids - Move to PostData.StreamHandler to serialize directly to the IO stream.
7f5d9da
to
5f49309
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've had a look through and left some general comments
{ | ||
_outputThread.Join(1500); // with timeout in case writer is locked | ||
} | ||
catch (ThreadStateException) { } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is there an internal logger to which this exception can be written?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I looked into fallback loggers in the Mic.Ext.Logging world but there is no such concept. The best we can do is expose callbacks to allow to user to log manually to fallback locations in their application configuration.
This is a carry over of #85 (introduced there not here) that is rewritten in #99 .
settings = new ConnectionConfiguration(nodes[0]); | ||
else | ||
{ | ||
settings = new ConnectionConfiguration(connectionPool); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like _options.ShipTo.CreateConnectionPool();
can return null
:
ecs-dotnet/src/Elasticsearch.Extensions.Logging/ShipTo.cs
Lines 61 to 86 in 249b86d
internal IConnectionPool? CreateConnectionPool() | |
{ | |
switch (ConnectionPoolType) | |
{ | |
// TODO: Add option to randomize pool | |
case Logging.ConnectionPoolType.Unknown: | |
case Logging.ConnectionPoolType.Sniffing: | |
return new SniffingConnectionPool(NodeUris); | |
case Logging.ConnectionPoolType.Static: | |
return new StaticConnectionPool(NodeUris); | |
case Logging.ConnectionPoolType.Sticky: | |
return new StickyConnectionPool(NodeUris); | |
// case ConnectionPoolType.StickySniffing: | |
case Logging.ConnectionPoolType.Cloud: | |
if (!string.IsNullOrEmpty(ApiKey)) | |
{ | |
var apiKeyCredentials = new ApiKeyAuthenticationCredentials(ApiKey); | |
return new CloudConnectionPool(CloudId, apiKeyCredentials); | |
} | |
var basicAuthCredentials = new BasicAuthenticationCredentials(Username, Password); | |
return new CloudConnectionPool(CloudId, basicAuthCredentials); | |
default: | |
return null; | |
} | |
} |
but ConnectionConfiguration
does not guard against null
:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
var lowlevelClient = new ElasticLowLevelClient(settings); | ||
|
||
_ = Interlocked.Exchange(ref _lowLevelClient, lowlevelClient); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm struggling to see what benefit this provides over assigning to the field directly in this case, as the original value is not used and field assignment is atomic on all .NET platforms AFAIK. Is there a benefit that I'm missing?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is not, carry over from #85 we can address that in a follow up PR.
try | ||
{ | ||
foreach (var logEvent in _messageQueue.GetConsumingEnumerable()) PostEvent(logEvent); | ||
} | ||
catch | ||
{ | ||
try | ||
{ | ||
_messageQueue.CompleteAdding(); | ||
} | ||
catch { } | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I understand this correctly, an exception in posting the event will mark the blocking collection as no longer accepting items, causing any subsequent items to be sent to PostEvent
directly in EnqueueMessage
. Would we want to distinguish the types of exceptions that should cause this behaviour vs. those that shouldn't e.g. are there exceptions the client could throw where this behaviour is undesirable?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var index = string.Format(_options.Index, indexTime); | ||
|
||
var localClient = _lowLevelClient; | ||
var response = localClient.Index<StringResponse>(index, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had a question about bulk, but see that this is addressed in #99 😄
logger.LogError("an error occured"); | ||
|
||
// TODO make sure we can await something here on ElasticsearchDataShipper | ||
await Task.Delay(TimeSpan.FromSeconds(5)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could the logger expose a property/event to ascertain that it has sent or is sending events?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That was my intend but I knew the shipper had to be rewritten so I left the TODO :)
Once #99 lands we can expose more callbacks and stats
ElasticsearchDataProcessor
toElasticsearchDataShipper
LogEvent
out of the shipper and into static helper class.relates: #95