-
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
Bulk support for extensions logging integration. #99
Conversation
2588f3e
to
aaa9d6f
Compare
examples/Elasticsearch.Extensions.Logging.Example/HighVolumeWorkSimulation.cs
Outdated
Show resolved
Hide resolved
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 gone through and left some comments
examples/Elasticsearch.Extensions.Logging.Example/HighVolumeWorkSimulation.cs
Outdated
Show resolved
Hide resolved
examples/Elasticsearch.Extensions.Logging.Example/HighVolumeWorkSimulation.cs
Outdated
Show resolved
Hide resolved
if (_options.IndexOffset.HasValue) indexTime = indexTime.ToOffset(_options.IndexOffset.Value); | ||
|
||
var index = string.Format(_options.Index, indexTime); | ||
var indexHeader = new { index = new { _index = 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.
would there be some benefit to introducing a type for this?
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 would! Was holding off on dedicated types when following this up with retries, backoff and response failure callbacks.
I'm in two minds to spin off ElasticsearchDataShipper
as its own package which would benefit from some more typing and control for the end user as well.
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 think as these integrations continue to develop, a separate shipper package would probably be a good idea, to share across integrations, and allow users to use the shipper for their own integrations.
src/Elasticsearch.Extensions.Logging/ElasticsearchDataShipper.cs
Outdated
Show resolved
Hide resolved
src/Elasticsearch.Extensions.Logging/ElasticsearchLoggerOptions.cs
Outdated
Show resolved
Hide resolved
src/Elasticsearch.Extensions.Logging/ElasticsearchLoggerOptions.cs
Outdated
Show resolved
Hide resolved
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 left a few more comments
src/Elasticsearch.Extensions.Logging/ElasticsearchLoggerOptions.cs
Outdated
Show resolved
Hide resolved
/// If <see cref="MaxInFlightMessages"/> is reached, <see cref="LogEvent"/>'s will fail to be published to the channel. You can be notified of dropped | ||
/// events with this callback | ||
/// </summary> | ||
public Action<LogEvent> PublishRejectionCallback { get; set; } = e => { }; |
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.
public Action<LogEvent> PublishRejectionCallback { get; set; } = e => { }; | |
public Action<LogEvent> WriteFailedCallback { get; set; } = e => { }; |
Maybe could use an event
for this?
if (_options.IndexOffset.HasValue) indexTime = indexTime.ToOffset(_options.IndexOffset.Value); | ||
|
||
var index = string.Format(_options.Index, indexTime); | ||
var indexHeader = new { index = new { _index = 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 think as these integrations continue to develop, a separate shipper package would probably be a good idea, to share across integrations, and allow users to use the shipper for their own integrations.
// DropWrite will make `TryWrite` always return true, which is not what we want. | ||
FullMode = BoundedChannelFullMode.Wait | ||
}); | ||
async Task ConsumeMessages() => |
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 was thinking along the lines of
private readonly List<Task> _backgroundTasks = new List<Task>();
for (var i = 0; i < maxConsumers; i++)
_backgroundTasks.Add(Task.Factory.StartNew(() => Consume(options), TaskCreationOptions.LongRunning));
with Consume
taking ElasticsearchLoggerOptions
so that changes to options will affect consumers (might be unexpected if changes to options.Throttles
don't affect existing consumers).
- 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.
Co-authored-by: Russ Cam <russ.cam@elastic.co>
735c888
to
d474514
Compare
@russcam I think this is ready for another round. Your comment about I don't want to support scaling consumers and buffer sizes just yet, most likely worth their own PR 😄 |
Continuation of #97
Introduces batching of log events before indexing into Elasticsearch. Powered by
System.Threading.Channels
. It supports sending every N items or every M interval after the first item was added.This also introduces the ability to have multiple consumers drain the channel concurrently.
A callback now exists when items are being dropped because the channel is full and when a
_bulk
request has occurred.We still need to add
LogEvent
Since this PR and #97 are big enough already will tackle the remained when we pull in the flight PR's.
This also includes a modified version of the example project from @sgryphon 's PR: #69
It also includes a high volume worker that can be started with
dotnet run -- high
.