-
Notifications
You must be signed in to change notification settings - Fork 30
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
Add queue inspector facility #29
Merged
Merged
Changes from 3 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
579a0cf
Add monitor facility
bartelink dcd24ac
Add IQueueState inspector
bartelink d3b5309
Surface dropped events count. Resolves #13
bartelink 510db8d
Address nblumhardt review comments
bartelink 6546958
Add IAsyncLogEventSinkMonitor
bartelink 17e0779
Complete IAsyncLogEventSinkMonitor impl
bartelink File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -51,5 +51,62 @@ public static LoggerConfiguration Async( | |
configure); | ||
} | ||
|
||
/// <summary> | ||
/// Configure a sink to be invoked asynchronously, on a background worker thread. | ||
/// Provides an <paramref name="inspector"/> that can be used to check the live state of the buffer for health monitoring purposes. | ||
/// </summary> | ||
/// <param name="loggerSinkConfiguration">The <see cref="LoggerSinkConfiguration"/> being configured.</param> | ||
/// <param name="configure">An action that configures the wrapped sink.</param> | ||
/// <param name="bufferSize">The size of the concurrent queue used to feed the background worker thread. If | ||
/// the thread is unable to process events quickly enough and the queue is filled, depending on | ||
/// <paramref name="blockWhenFull"/> the queue will block or subsequent events will be dropped until | ||
/// room is made in the queue.</param> | ||
/// <param name="blockWhenFull">Block when the queue is full, instead of dropping events.</param> | ||
/// <param name="inspector">Provides a way to inspect the state of the queue for health monitoring purposes.</param> | ||
/// <returns>A <see cref="LoggerConfiguration"/> allowing configuration to continue.</returns> | ||
public static LoggerConfiguration Async( | ||
this LoggerSinkConfiguration loggerSinkConfiguration, | ||
Action<LoggerSinkConfiguration> configure, | ||
out IQueueState inspector, | ||
int bufferSize = 10000, | ||
bool blockWhenFull = false) | ||
{ | ||
// Cannot assign directly to the out param from within the lambda, so we need a temp | ||
IQueueState stateLens = null; | ||
var result = LoggerSinkConfiguration.Wrap( | ||
loggerSinkConfiguration, | ||
wrappedSink => | ||
{ | ||
var sink = new BackgroundWorkerSink(wrappedSink, bufferSize, blockWhenFull); | ||
stateLens = sink; | ||
return sink; | ||
}, | ||
configure); | ||
inspector = stateLens; | ||
return result; | ||
} | ||
} | ||
|
||
/// <summary> | ||
/// Provides a way to inspect the current state of Async wrapper's ingestion queue. | ||
/// </summary> | ||
public interface IQueueState | ||
{ | ||
/// <summary> | ||
/// Count of items currently awaiting ingestion. | ||
/// </summary> | ||
/// <exception cref="T:System.ObjectDisposedException">The Sink has been disposed.</exception> | ||
int Count { get; } | ||
|
||
/// <summary> | ||
/// Accumulated number of messages dropped due to attempted submission having breached <see cref="BufferSize"/> limit. | ||
/// </summary> | ||
long DroppedMessagesCount { get; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Any advance on this name? |
||
|
||
/// <summary> | ||
/// Maximum number of items permitted to be held in the buffer awaiting ingestion. | ||
/// </summary> | ||
/// <exception cref="T:System.ObjectDisposedException">The Sink has been disposed.</exception> | ||
int BufferSize { get; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Nit- would be preferable to have this in its own file.
Another nit :-) ... it's closer to being the sink state than the queue state, since the dropped count isn't logically a property of the queue..?
Just looking at namespacing etc., could we tuck this away under
Serilog.Sinks.Async.IAsyncLogEventSinkState
or something along those lines, so that it's less likely to conflict with other types? I can't imagine there are too manyIQueueState
interfaces out there, but since it's not something a user will type regularly, a more descriptive name might not hurt.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.
In my language of choice it should not be a separate file ;) Agree and will do.
The specific name is way better (the original was a speculative generality land grab) - dropped events are not a thing one wants as a universal 'feature'