Skip to content
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

Added QueueLimit parameter and passing to base PeriodicBatchingSink #134

Merged
merged 1 commit into from
Oct 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ namespace Serilog.Sinks.Splunk
/// </summary>
public class EventCollectorSink : PeriodicBatchingSink
{
private const int NoQueueLimit = -1;

private readonly string _splunkHost;
private readonly string _uriPath;
private readonly ITextFormatter _jsonFormatter;
Expand All @@ -56,11 +58,13 @@ public class EventCollectorSink : PeriodicBatchingSink
/// <param name="formatProvider">The format provider used when rendering the message</param>
/// <param name="renderTemplate">Whether to render the message template</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
public EventCollectorSink(
string splunkHost,
string eventCollectorToken,
int batchIntervalInSeconds = 5,
int batchSizeLimit = 100,
int? queueLimit = null,
IFormatProvider formatProvider = null,
bool renderTemplate = true)
: this(
Expand All @@ -69,6 +73,7 @@ public EventCollectorSink(
null, null, null, null, null,
batchIntervalInSeconds,
batchSizeLimit,
queueLimit,
formatProvider,
renderTemplate)
{
Expand All @@ -84,6 +89,7 @@ public EventCollectorSink(
/// <param name="formatProvider">The format provider used when rendering the message</param>
/// <param name="renderTemplate">Whether to render the message template</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
/// <param name="index">The Splunk index to log to</param>
/// <param name="source">The source of the event</param>
/// <param name="sourceType">The source type of the event</param>
Expand All @@ -99,6 +105,7 @@ public EventCollectorSink(
string index,
int batchIntervalInSeconds,
int batchSizeLimit,
int? queueLimit,
IFormatProvider formatProvider = null,
bool renderTemplate = true,
HttpMessageHandler messageHandler = null)
Expand All @@ -108,6 +115,7 @@ public EventCollectorSink(
uriPath,
batchIntervalInSeconds,
batchSizeLimit,
queueLimit,
new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index),
messageHandler)
{
Expand All @@ -120,6 +128,7 @@ public EventCollectorSink(
/// <param name="eventCollectorToken">The token to use when authenticating with the event collector</param>
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
/// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
/// <param name="formatProvider">The format provider used when rendering the message</param>
/// <param name="renderTemplate">Whether to render the message template</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
Expand All @@ -140,6 +149,7 @@ public EventCollectorSink(
CustomFields fields,
int batchIntervalInSeconds,
int batchSizeLimit,
int? queueLimit,
IFormatProvider formatProvider = null,
bool renderTemplate = true,
HttpMessageHandler messageHandler = null)
Expand All @@ -150,6 +160,7 @@ public EventCollectorSink(
uriPath,
batchIntervalInSeconds,
batchSizeLimit,
queueLimit,
new SplunkJsonFormatter(renderTemplate, formatProvider, source, sourceType, host, index, fields),
messageHandler)
{
Expand All @@ -163,6 +174,7 @@ public EventCollectorSink(
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
/// <param name="batchSizeLimit">The size of the batch when sending to the event collector</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that batching should occur</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
public EventCollectorSink(
Expand All @@ -171,9 +183,10 @@ public EventCollectorSink(
string uriPath,
int batchIntervalInSeconds,
int batchSizeLimit,
int? queueLimit,
ITextFormatter jsonFormatter,
HttpMessageHandler messageHandler = null)
: base(batchSizeLimit, TimeSpan.FromSeconds(batchIntervalInSeconds))
: base(batchSizeLimit, TimeSpan.FromSeconds(batchIntervalInSeconds), queueLimit ?? NoQueueLimit)
{
_uriPath = uriPath;
_splunkHost = splunkHost;
Expand Down
11 changes: 10 additions & 1 deletion src/Serilog.Sinks.Splunk/SplunkLoggingConfigurationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public static class SplunkLoggingConfigurationExtensions
/// <param name="renderTemplate">If true, the message template will be rendered</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
/// <param name="batchSizeLimit">The size of the batch</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
/// <returns></returns>
Expand All @@ -66,6 +67,7 @@ public static LoggerConfiguration EventCollector(
bool renderTemplate = true,
int batchIntervalInSeconds = 2,
int batchSizeLimit = 100,
int? queueLimit = null,
HttpMessageHandler messageHandler = null,
LoggingLevelSwitch levelSwitch = null)
{
Expand All @@ -81,6 +83,7 @@ public static LoggerConfiguration EventCollector(
index,
batchIntervalInSeconds,
batchSizeLimit,
queueLimit,
formatProvider,
renderTemplate,
messageHandler);
Expand All @@ -97,9 +100,10 @@ public static LoggerConfiguration EventCollector(
/// <param name="jsonFormatter">The text formatter used to render log events into a JSON format for consumption by Splunk</param>
/// <param name="uriPath">Change the default endpoint of the Event Collector e.g. services/collector/event</param>
/// <param name="restrictedToMinimumLevel">The minimum log event level required in order to write an event to the sink.</param>

/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
/// <param name="batchSizeLimit">The size of the batch</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
/// <returns></returns>
Expand All @@ -112,6 +116,7 @@ public static LoggerConfiguration EventCollector(
LogEventLevel restrictedToMinimumLevel = LevelAlias.Minimum,
int batchIntervalInSeconds = 2,
int batchSizeLimit = 100,
int? queueLimit = null,
HttpMessageHandler messageHandler = null,
LoggingLevelSwitch levelSwitch = null)
{
Expand All @@ -124,6 +129,7 @@ public static LoggerConfiguration EventCollector(
uriPath,
batchIntervalInSeconds,
batchSizeLimit,
queueLimit,
jsonFormatter,
messageHandler);

Expand All @@ -147,6 +153,7 @@ public static LoggerConfiguration EventCollector(
/// <param name="renderTemplate">If ture, the message template will be rendered</param>
/// <param name="batchIntervalInSeconds">The interval in seconds that the queue should be instpected for batching</param>
/// <param name="batchSizeLimit">The size of the batch</param>
/// <param name="queueLimit">Maximum number of events in the queue</param>
/// <param name="messageHandler">The handler used to send HTTP requests</param>
/// <param name="levelSwitch">A switch allowing the pass-through minimum level to be changed at runtime.</param>
/// <param name="fields">Customfields that will be indexed in splunk with this event</param>
Expand All @@ -166,6 +173,7 @@ public static LoggerConfiguration EventCollector(
bool renderTemplate = true,
int batchIntervalInSeconds = 2,
int batchSizeLimit = 100,
int? queueLimit = null,
HttpMessageHandler messageHandler = null,
LoggingLevelSwitch levelSwitch = null)
{
Expand All @@ -182,6 +190,7 @@ public static LoggerConfiguration EventCollector(
fields,
batchIntervalInSeconds,
batchSizeLimit,
queueLimit,
formatProvider,
renderTemplate,
messageHandler
Expand Down