Skip to content
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
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,9 @@
<Compile Include="..\Serilog.Sinks.Splunk\LoggerConfigurationSplunkPCLExtensions.cs">
<Link>LoggerConfigurationSplunkPCLExtensions.cs</Link>
</Compile>
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\Epoch.cs">
<Link>Sinks\Splunk\Epoch.cs</Link>
</Compile>
<Compile Include="..\Serilog.Sinks.Splunk\Sinks\Splunk\EventCollectorClient.cs">
<Link>Sinks\Splunk\EventCollectorClient.cs</Link>
</Compile>
Expand Down
1 change: 1 addition & 0 deletions src/Serilog.Sinks.Splunk/Serilog.Sinks.Splunk.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
<Compile Include="..\..\assets\CommonAssemblyInfo.cs">
<Link>Properties\CommonAssemblyInfo.cs</Link>
</Compile>
<Compile Include="Sinks\Splunk\Epoch.cs" />
<Compile Include="Sinks\Splunk\EventCollectorClient.cs" />
<Compile Include="Sinks\Splunk\EventCollectorRequest.cs" />
<Compile Include="Sinks\Splunk\RepeatAction.cs" />
Expand Down
20 changes: 20 additions & 0 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/Epoch.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
namespace Serilog.Sinks.Splunk
{
using System;

internal static class EpochExtensions
{
private static DateTimeOffset Epoch = new DateTimeOffset(1970,1,1,0,0,0,TimeSpan.Zero);

public static double ToEpoch(this DateTimeOffset value)
{
// From Splunk HTTP Collector Protocol
// The default time format is epoch time format, in the format <sec>.<ms>.
// For example, 1433188255.500 indicates 1433188255 seconds and 500 milliseconds after epoch,
// or Monday, June 1, 2015, at 7:50:55 PM GMT.
// See: http://dev.splunk.com/view/SP-CAAAE6P

return Math.Round((value - Epoch).TotalSeconds, 3, MidpointRounding.AwayFromZero);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ internal class SplunkEvent
{
private string _payload;

internal SplunkEvent(string logEvent, string source, string sourceType, string host, string index)
internal SplunkEvent(string logEvent, string source, string sourceType, string host, string index, double time)
{
_payload = string.Empty;

Expand All @@ -32,6 +32,11 @@ internal SplunkEvent(string logEvent, string source, string sourceType, string h
jsonPayLoad = jsonPayLoad + @",""index"":""" + index + @"""";
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might want to use StringBuilder here

Copy link
Copy Markdown

@glennblock glennblock May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another thing to consider is adding support for batching i.e. sending multiple events in a single request for efficiency. That would require having some sort of Flush() method. See here under Examples for how batching works.

Our logging library handles a lot of this natively (including retries, batching/flush, async), but it does't support DotNet core.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, also it takes a dependency on Newtonsoft.Json

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also we have this, could be improved however we do batch if needed. Needs to be revisited with the epoch time allocated to each event.

https://github.com/serilog/serilog-sinks-splunk/blob/dev/src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs#L183

Copy link
Copy Markdown

@glennblock glennblock May 25, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point on Newtonsoft, my main point for linking to the code was showing how we do it. We basically have an in-memory queue where events are written to which allows us to process things (like batching) very efficiently in an async manner

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We are using ConcurrentQueue. I understand it has a some overhead. @glennblock, any chance you guys are going to port to dotnet core?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A chance at some point but there will have to be SIGNIFICANT demand in our
customer base, and well there is not currently ;-)
On Tue, May 24, 2016 at 10:32 PM Matthew Erbs notifications@github.com
wrote:

In src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorRequest.cs
#15 (comment)
:

@@ -32,6 +32,11 @@ internal SplunkEvent(string logEvent, string source, string sourceType, string h
jsonPayLoad = jsonPayLoad + @",""index"":""" + index + @"""";

We are using ConcurrentQueue. I understand it has a some overhead.
@glennblock https://github.com/glennblock, any chance you guys are
going to port to dotnet core?


You are receiving this because you were mentioned.
Reply to this email directly or view it on GitHub
https://github.com/serilog/serilog-sinks-splunk/pull/15/files/c965fe65ed3789486169001735cf5b68fa135c6d#r64517345

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We will try to fill the void 😀

}

if (time > 0)
{
jsonPayLoad = jsonPayLoad + @",""time"":" + time;
}

jsonPayLoad = jsonPayLoad + "}";
_payload = jsonPayLoad;
}
Expand Down
4 changes: 2 additions & 2 deletions src/Serilog.Sinks.Splunk/Sinks/Splunk/EventCollectorSink.cs
Original file line number Diff line number Diff line change
Expand Up @@ -176,8 +176,8 @@ private async Task Send(IEnumerable<LogEvent> events)
_jsonFormatter.Format(logEvent, sw);

var serialisedEvent = sw.ToString();

var splunkEvent = new SplunkEvent(serialisedEvent, _source, _sourceType, _host, _index);
var splunkEvent = new SplunkEvent(serialisedEvent, _source, _sourceType, _host, _index, logEvent.Timestamp.ToEpoch());

allEvents = $"{allEvents}{splunkEvent.Payload}";
}
Expand Down