Skip to content

Commit

Permalink
Add Seq integration
Browse files Browse the repository at this point in the history
  • Loading branch information
bartelink committed Oct 18, 2018
1 parent c587928 commit 43edbe4
Show file tree
Hide file tree
Showing 16 changed files with 248 additions and 28 deletions.
1 change: 1 addition & 0 deletions Samples/Store/Integration/Infrastructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,5 @@ module SerilogHelpers =
let createLogger sink =
LoggerConfiguration()
.WriteTo.Sink(sink)
.WriteTo.Seq("http://localhost:5341")
.CreateLogger()
50 changes: 50 additions & 0 deletions Samples/Store/Integration/Integration.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,56 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Formatting.Compact">
<HintPath>..\..\..\packages\Serilog.Formatting.Compact\lib\net45\Serilog.Formatting.Compact.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Microsoft.CSharp">
<Paket>True</Paket>
</Reference>
<Reference Include="Serilog.Sinks.File">
<HintPath>..\..\..\packages\Serilog.Sinks.File\lib\net45\Serilog.Sinks.File.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Sinks.PeriodicBatching">
<HintPath>..\..\..\packages\Serilog.Sinks.PeriodicBatching\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="System.Net.Http">
<Paket>True</Paket>
</Reference>
<Reference Include="Serilog.Sinks.Seq">
<HintPath>..\..\..\packages\Serilog.Sinks.Seq\lib\net45\Serilog.Sinks.Seq.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions Samples/Store/Integration/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ nuget FsCheck.Xunit
nuget FSharp.Core
nuget Newtonsoft.Json
nuget Serilog
nuget Serilog.Sinks.Seq
nuget TypeShape
nuget unquote
nuget xunit.runner.visualstudio
1 change: 1 addition & 0 deletions paket.dependencies
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ nuget TypeShape
nuget MathNet.Numerics
nuget Serilog.Sinks.Console
nuget Serilog.Sinks.File
nuget Serilog.Sinks.Seq
nuget Unquote
nuget xunit.core redirects: force
nuget xunit.runner.visualstudio
Expand Down
9 changes: 9 additions & 0 deletions paket.lock
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,19 @@ NUGET
MathNet.Numerics (4.4.1)
Newtonsoft.Json (11.0.2)
Serilog (2.6)
Serilog.Formatting.Compact (1.0)
Serilog (>= 2.0)
Serilog.Sinks.Console (3.1.1)
Serilog (>= 2.5)
Serilog.Sinks.File (4.0)
Serilog (>= 2.5)
Serilog.Sinks.PeriodicBatching (2.1.1)
Serilog (>= 2.0)
Serilog.Sinks.Seq (4.0)
Serilog (>= 2.5)
Serilog.Formatting.Compact (>= 1.0)
Serilog.Sinks.File (>= 4.0)
Serilog.Sinks.PeriodicBatching (>= 2.1.1)
System.Reactive (3.1.1)
System.Reactive.PlatformServices (>= 3.1.1)
System.Reactive.Windows.Threading (>= 3.1.1)
Expand Down
2 changes: 2 additions & 0 deletions tests/Foldunk.EventStore.Integration/EventStoreIntegration.fs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
module Foldunk.EventStore.Integration.EventStoreIntegration

open Foldunk.EventStore
open Serilog
open Swensen.Unquote
open System.Threading
open System
Expand Down Expand Up @@ -60,6 +61,7 @@ type Tests(testOutputHelper) =
let capture = LogCaptureBuffer()
let logger =
Serilog.LoggerConfiguration()
.WriteTo.Seq("http://localhost:5341")
.WriteTo.Sink(testOutput)
.WriteTo.Sink(capture)
.CreateLogger()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,56 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Formatting.Compact">
<HintPath>..\..\packages\Serilog.Formatting.Compact\lib\net45\Serilog.Formatting.Compact.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Microsoft.CSharp">
<Paket>True</Paket>
</Reference>
<Reference Include="Serilog.Sinks.File">
<HintPath>..\..\packages\Serilog.Sinks.File\lib\net45\Serilog.Sinks.File.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Sinks.PeriodicBatching">
<HintPath>..\..\packages\Serilog.Sinks.PeriodicBatching\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="System.Net.Http">
<Paket>True</Paket>
</Reference>
<Reference Include="Serilog.Sinks.Seq">
<HintPath>..\..\packages\Serilog.Sinks.Seq\lib\net45\Serilog.Sinks.Seq.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
Expand Down
1 change: 1 addition & 0 deletions tests/Foldunk.EventStore.Integration/Infrastructure.fs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ module SerilogHelpers =
let createLogger sink =
LoggerConfiguration()
.WriteTo.Sink(sink)
.WriteTo.Seq("http://localhost:5341")
.CreateLogger()

let (|SerilogScalar|_|) : Serilog.Events.LogEventPropertyValue -> obj option = function
Expand Down
1 change: 1 addition & 0 deletions tests/Foldunk.EventStore.Integration/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ nuget FsCheck.Xunit
nuget FSharp.Core
nuget Newtonsoft.Json
nuget Serilog
nuget Serilog.Sinks.Seq
nuget TypeShape
nuget unquote
nuget xunit.runner.visualstudio
16 changes: 8 additions & 8 deletions tests/Foldunk.LoadTests/App.config
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@
</startup>
<runtime>
<gcServer enabled="true" />
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.4.3.0" />
</dependentAssembly>
</assemblyBinding>
</runtime>

<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<dependentAssembly>
<Paket>True</Paket>
<assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" />
<bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.4.3.0" />
</dependentAssembly>
</assemblyBinding></runtime>
</configuration>
35 changes: 34 additions & 1 deletion tests/Foldunk.LoadTests/Foldunk.LoadTests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
<WarningLevel>5</WarningLevel>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<OtherFlags>--warnon:1182</OtherFlags>
<StartArguments>-f 2000 -o 3 -e 3000</StartArguments>
<StartArguments>-f 2 -o 3 -e 3000 -S -vd -ve</StartArguments>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
Expand Down Expand Up @@ -215,6 +215,17 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Formatting.Compact">
<HintPath>..\..\packages\Serilog.Formatting.Compact\lib\net45\Serilog.Formatting.Compact.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
Expand All @@ -240,6 +251,28 @@
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Sinks.PeriodicBatching">
<HintPath>..\..\packages\Serilog.Sinks.PeriodicBatching\lib\net45\Serilog.Sinks.PeriodicBatching.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And ($(TargetFrameworkVersion) == 'v4.5.2' Or $(TargetFrameworkVersion) == 'v4.6.1')">
<ItemGroup>
<Reference Include="Serilog.Sinks.Seq">
<HintPath>..\..\packages\Serilog.Sinks.Seq\lib\net45\Serilog.Sinks.Seq.dll</HintPath>
<Private>True</Private>
<Paket>True</Paket>
</Reference>
</ItemGroup>
</When>
</Choose>
<Choose>
<When Condition="$(TargetFrameworkIdentifier) == '.NETFramework' And $(TargetFrameworkVersion) == 'v4.5.2'">
<ItemGroup>
Expand Down
53 changes: 34 additions & 19 deletions tests/Foldunk.LoadTests/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,19 @@ open Domain
open System.Threading
open Serilog.Events
open System.IO
open System.Net
open Serilog.Context

type Arguments =
| [<AltCommandLine("-g")>] Host of string
| [<AltCommandLine("-u")>] Username of string
| [<AltCommandLine("-p")>] Password of string

| [<AltCommandLine("-l")>] LogFile of string
| [<AltCommandLine("-v")>] Verbose
| [<AltCommandLine("-ve")>] VerboseEs
| [<AltCommandLine("-vd")>] VerboseDomain
| [<AltCommandLine("-vc")>] VerboseConsole
| [<AltCommandLine("-S")>] LocalSeq

| [<AltCommandLine("-f")>] TestsPerSecond of int
| [<AltCommandLine("-c")>] ConcurrentOperationsLimit of int
Expand All @@ -34,7 +39,10 @@ type Arguments =
| Username _ -> "specify a username (default: admin)."
| Password _ -> "specify a Password (default: changeit)."
| LogFile _ -> "specify a log file to write the result breakdown."
| Verbose -> "Include low level logging in screen output."
| VerboseEs -> "Include low level ES logging."
| VerboseDomain -> "Include low level Domain logging."
| VerboseConsole -> "Include low level Domain and ES logging in screen output."
| LocalSeq -> "Configures writing to a local Seq endpoint at http://localhost:5341, see https://getseq.net"
| TestsPerSecond _ -> "specify a target number of requests per second (default: 1000)."
| ConcurrentOperationsLimit _ -> "max concurrent operations in flight (default: 5000)."
| DurationM _ -> "specify a run duration in minutes (default: 1)."
Expand All @@ -55,9 +63,9 @@ let run log testsPerSecond duration errorCutoff reportingIntervals (clients : Cl
/// To establish a local node to run the tests against:
/// 1. cinst eventstore-oss -y # where cinst is an invocation of the Chocolatey Package Installer on Windows
/// 2. & $env:ProgramData\chocolatey\bin\EventStore.ClusterNode.exe --gossip-on-single-node --discover-via-dns 0 --ext-http-port=30778
let connectToEventStoreNode log (dnsQuery, heartbeatTimeout, col) (username, password) (operationTimeout, operationRetries) =
let connectToEventStoreNode (log: ILogger) (dnsQuery, heartbeatTimeout, col) (username, password) (operationTimeout, operationRetries) =
GesConnector(username, password, reqTimeout=operationTimeout, reqRetries=operationRetries,
heartbeatTimeout=heartbeatTimeout, concurrentOperationsLimit = col, log=Logger.SerilogVerbose log)
heartbeatTimeout=heartbeatTimeout, concurrentOperationsLimit = col, log=if log.IsEnabled(LogEventLevel.Debug) then Logger.SerilogVerbose log else Logger.SerilogNormal log)
.Establish("Foldunk-loadtests", Discovery.GossipDns dnsQuery, ConnectionStrategy.ClusterTwinPreferSlaveReads)

let defaultBatchSize = 500
Expand All @@ -82,16 +90,19 @@ let runFavoriteTest log _clientId conn = async {
let! items = service.Read log clientId
if items |> Array.exists (fun x -> x.skuId = sku) |> not then invalidOp "Added item not found" }

let log =
LoggerConfiguration()
.Destructure.FSharpTypes()
.WriteTo.Console(LogEventLevel.Debug, theme = Sinks.SystemConsole.Themes.AnsiConsoleTheme.Code)
.CreateLogger()
let domainLog verbose =
LoggerConfiguration()
.Destructure.FSharpTypes()
.WriteTo.Console((if verbose then LogEventLevel.Debug else LogEventLevel.Warning), theme = Sinks.SystemConsole.Themes.AnsiConsoleTheme.Code)
.CreateLogger()
let createEsLog verboseEs verboseConsole maybeSeqEndpoint =
let c = LoggerConfiguration().Destructure.FSharpTypes()
let c = if verboseEs then c.MinimumLevel.Debug() else c
let c = c.WriteTo.Console((if verboseConsole then LogEventLevel.Debug else LogEventLevel.Information), theme = Sinks.SystemConsole.Themes.AnsiConsoleTheme.Code)
let c = match maybeSeqEndpoint with None -> c | Some endpoint -> c.WriteTo.Seq(endpoint)
c.CreateLogger()
let domainLog verboseDomain verboseConsole maybeSeqEndpoint =
let c = LoggerConfiguration().Destructure.FSharpTypes().Enrich.FromLogContext()
let c = if verboseDomain then c.MinimumLevel.Debug() else c
let c = c.WriteTo.Console((if verboseConsole then LogEventLevel.Debug else LogEventLevel.Warning), theme = Sinks.SystemConsole.Themes.AnsiConsoleTheme.Code)
let c = match maybeSeqEndpoint with None -> c | Some endpoint -> c.WriteTo.Seq(endpoint)
c.CreateLogger()

let createResultLog fileName =
LoggerConfiguration()
.Destructure.FSharpTypes()
Expand All @@ -117,14 +128,18 @@ let main argv =
let heartbeatTimeout = args.GetResult(HeartbeatTimeout,1.5) |> float |> TimeSpan.FromSeconds
let concurrentOperationsLimit = args.GetResult(ConcurrentOperationsLimit,5000)
let report = args.GetResult(LogFile,"log.txt") |> fun n -> FileInfo(n).FullName
let verboseEs = args.Contains(VerboseEs)
let verboseConsole = args.Contains(VerboseConsole)
let maybeSeq = if args.Contains LocalSeq then Some "http://localhost:5341" else None
let log = createEsLog verboseEs verboseConsole maybeSeq
let conn = connectToEventStoreNode log (host, heartbeatTimeout, concurrentOperationsLimit) creds operationThrottling |> Async.RunSynchronously

let clients = Array.init (testsPerSecond * 2) (fun _ -> Guid.NewGuid () |> ClientId)
let verbose = args.Contains(Verbose)
let domainLog = domainLog verbose
let runSingleTest clientId =
if verbose then domainLog.Information("Using session {sessionId}", ([|clientId|] : obj []))
runFavoriteTest domainLog clientId conn
let verboseDomain = args.Contains(VerboseDomain)
let domainLog = domainLog verboseDomain verboseConsole maybeSeq
let runSingleTest clientId = async {
use _ = LogContext.PushProperty("clientId", clientId)
return! runFavoriteTest domainLog clientId conn }
log.Information(
"Running for {duration}, targeting {host} with heartbeat: {heartbeat}, max concurrent requests: {concurrency}\n" +
"Test freq {tps} hits/s; Operation timeout: {timeout} and {retries} retries; max errors: {errorCutOff}\n" +
Expand Down
1 change: 1 addition & 0 deletions tests/Foldunk.LoadTests/paket.references
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ Newtonsoft.Json
Serilog
Serilog.Sinks.Console
Serilog.Sinks.File
Serilog.Sinks.Seq
System.Reactive
TypeShape
Loading

0 comments on commit 43edbe4

Please sign in to comment.