Skip to content

Commit

Permalink
Merge pull request #14 from hudl/OSS
Browse files Browse the repository at this point in the history
Open up the bits
  • Loading branch information
robhruska committed Jun 17, 2014
2 parents dae8d92 + 44b56b3 commit 63db242
Show file tree
Hide file tree
Showing 91 changed files with 932 additions and 3,088 deletions.
20 changes: 2 additions & 18 deletions Hudl.Mjolnir.SystemTests/Hudl.Mjolnir.SystemTests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,21 +41,9 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Castle.Core.2.5.1\lib\NET35\Castle.Core.dll</HintPath>
</Reference>
<Reference Include="Hudl.Common, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Hudl.Common.1.2.0.0\lib\net35\Hudl.Common.dll</HintPath>
</Reference>
<Reference Include="Hudl.Config, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Hudl.Config.1.4.1.0\lib\net40\Hudl.Config.dll</HintPath>
</Reference>
<Reference Include="Hudl.Riemann, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Hudl.Riemann.1.2.6.0\lib\net45\Hudl.Riemann.dll</HintPath>
</Reference>
<Reference Include="Hudl.RiemannClient, Version=1.0.0.0, Culture=neutral, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Hudl.RiemannClient.1.1.0.0\lib\net45\Hudl.RiemannClient.dll</HintPath>
<HintPath>..\packages\Hudl.Config.1.5.0\lib\net40\Hudl.Config.dll</HintPath>
</Reference>
<Reference Include="log4net, Version=1.2.11.0, Culture=neutral, PublicKeyToken=669e0ddf0bb1aa2a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
Expand All @@ -65,10 +53,6 @@
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\Newtonsoft.Json.6.0.2\lib\net45\Newtonsoft.Json.dll</HintPath>
</Reference>
<Reference Include="protobuf-net, Version=2.0.0.622, Culture=neutral, PublicKeyToken=257b51d87d2e4d67, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>..\packages\protobuf-net.2.0.0.622\lib\net40\protobuf-net.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Net.Http" />
<Reference Include="xunit">
Expand All @@ -93,7 +77,7 @@
<Compile Include="HttpClientCommand.cs" />
<Compile Include="IHttpClientService.cs" />
<Compile Include="HttpServer.cs" />
<Compile Include="MemoryStoreRiemann.cs" />
<Compile Include="MemoryStoreStats.cs" />
<Compile Include="Metric.cs" />
<Compile Include="ServerBehavior.cs" />
<Compile Include="SystemTestConfigProvider.cs" />
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
using System;
using System.Collections.Generic;
using Hudl.Riemann;
using Hudl.Mjolnir.External;

namespace Hudl.Mjolnir.SystemTests
{
internal class MemoryStoreRiemann : IRiemann
internal class MemoryStoreStats : IStats
{
// Normally you'll want to .Stop() before accessing this.
public List<Metric> Metrics
Expand Down Expand Up @@ -51,34 +51,19 @@ private void Store(string service, string state, object metric)
}
}

public void Event(string service, string state, long? metric = null, ISet<string> tags = null, string description = null, int? ttl = null)
public void Event(string service, string state, long? metric = null)
{
Store(service, state, metric);
}

public void Event(string service, string state, float? metric = null, ISet<string> tags = null, string description = null, int? ttl = null)
{
Store(service, state, metric);
}

public void Event(string service, string state, double? metric = null, ISet<string> tags = null, string description = null, int? ttl = null)
{
Store(service, state, metric);
}

public void Elapsed(string service, string state, TimeSpan elapsed, ISet<string> tags = null, string description = null, int? ttl = null)
public void Elapsed(string service, string state, TimeSpan elapsed)
{
Store(service, state, elapsed.TotalMilliseconds);
}

public void Gauge(string service, string state, long? metric = null, ISet<string> tags = null, string description = null, int? ttl = null)
public void Gauge(string service, string state, long? metric = null)
{
Store(service, state, metric);
}

public void ConfigGauge(string service, long metric)
{
Store(service, null, metric);
}
}
}
53 changes: 27 additions & 26 deletions Hudl.Mjolnir.SystemTests/Tests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,15 @@ public class Tests
private static readonly ILog Log = LogManager.GetLogger(typeof (Tests));

private readonly IConfigurationProvider _testConfigProvider = new SystemTestConfigProvider();
private readonly MemoryStoreRiemann _testRiemann = new MemoryStoreRiemann();
private readonly MemoryStoreStats _testStats = new MemoryStoreStats();

// This is a long-running test. Uncomment [Fact] to run it.
//[Fact]
public async Task RunAllScenarios()
{
ConfigProvider.UseProvider(_testConfigProvider);
InitializeLogging();
CommandContext.Riemann = _testRiemann;
CommandContext.Stats = _testStats;

File.Delete(ReportFile);

Expand Down Expand Up @@ -125,7 +126,7 @@ private async Task<ChartSet> IdealInheritedCommand(string key)
server.Start(ServerPort);
server.ProcessRequest += ServerBehavior.Immediate200();

_testRiemann.ClearAndStart();
_testStats.ClearAndStart();

await Task.WhenAll(Repeat(10, 30, () =>
{
Expand All @@ -136,15 +137,15 @@ await Task.WhenAll(Repeat(10, 30, () =>
server.Stop();
}

_testRiemann.Stop();
_testStats.Stop();

File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testRiemann.Metrics.Select(m => m.ToCsvLine()));
File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testStats.Metrics.Select(m => m.ToCsvLine()));

return new ChartSet
{
Name = "Ideal (Inherited Command)",
Description = "30s @ 5/sec.<br/>Command: Inherited<br/>Timeout: 10000<br/>Server: Immediate 200<br/>Breaker: 50% / 10sec, min 5 ops, 5s tripped",
Charts = GatherChartData(_testRiemann.Metrics, key, key + ".HttpClient"),
Charts = GatherChartData(_testStats.Metrics, key, key + ".HttpClient"),
};
}

Expand All @@ -166,22 +167,22 @@ private async Task<ChartSet> IdealCommandAttribute(string key)
server.Start(ServerPort);
server.ProcessRequest += ServerBehavior.Immediate200();

_testRiemann.ClearAndStart();
_testStats.ClearAndStart();

await Task.WhenAll(Repeat(10, 30, () => proxy.MakeRequest(url, CancellationToken.None)));

server.Stop();
}

_testRiemann.Stop();
_testStats.Stop();

File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testRiemann.Metrics.Select(m => m.ToCsvLine()));
File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testStats.Metrics.Select(m => m.ToCsvLine()));

return new ChartSet
{
Name = "Ideal (Command Attribute)",
Description = "30s @ 5/sec.<br/>Command: Inherited<br/>Timeout: 10000<br/>Server: Immediate 200<br/>Breaker: 50% / 10sec, min 5 ops, 5s tripped",
Charts = GatherChartData(_testRiemann.Metrics, key, key + ".IHttpClientService-MakeRequest"),
Charts = GatherChartData(_testStats.Metrics, key, key + ".IHttpClientService-MakeRequest"),
};
}

Expand All @@ -199,7 +200,7 @@ private async Task<ChartSet> DelayedSuccess(string key)
server.Start(ServerPort);
server.ProcessRequest += ServerBehavior.Delayed200(TimeSpan.FromMilliseconds(15000));

_testRiemann.ClearAndStart();
_testStats.ClearAndStart();

await Task.WhenAll(Repeat(1, 30, () =>
{
Expand All @@ -210,15 +211,15 @@ await Task.WhenAll(Repeat(1, 30, () =>
server.Stop();
}

_testRiemann.Stop();
_testStats.Stop();

File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testRiemann.Metrics.Select(m => m.ToCsvLine()));
File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testStats.Metrics.Select(m => m.ToCsvLine()));

return new ChartSet
{
Name = "Slow Success",
Description = "30s @ 5/sec.<br/>Command: Inherited<br/>Timeout: 30000<br/>Server: Delayed (15s) 200<br/>Breaker: 50% / 10sec, min 5 ops, 5s tripped",
Charts = GatherChartData(_testRiemann.Metrics, key, key + ".HttpClient"),
Charts = GatherChartData(_testStats.Metrics, key, key + ".HttpClient"),
};
}

Expand All @@ -236,7 +237,7 @@ private async Task<ChartSet> FastFailures(string key)
server.Start(ServerPort);
server.ProcessRequest += ServerBehavior.Immediate500();

_testRiemann.ClearAndStart();
_testStats.ClearAndStart();

await Task.WhenAll(Repeat(5, 30, async () =>
{
Expand All @@ -255,15 +256,15 @@ await Task.WhenAll(Repeat(5, 30, async () =>
server.Stop();
}

_testRiemann.Stop();
_testStats.Stop();

File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testRiemann.Metrics.Select(m => m.ToCsvLine()));
File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testStats.Metrics.Select(m => m.ToCsvLine()));

return new ChartSet
{
Name = "Fast Failures",
Description = "30s @ 5/sec.<br/>Command: Inherited<br/>Timeout: 30000<br/>Server: Immediate 500<br/>Breaker: 50% / 10sec, min 5 ops, 5s tripped",
Charts = GatherChartData(_testRiemann.Metrics, key, key + ".HttpClient"),
Charts = GatherChartData(_testStats.Metrics, key, key + ".HttpClient"),
};
}

Expand All @@ -284,7 +285,7 @@ private async Task<ChartSet> FastTimeouts(string key)
server.Start(ServerPort);
server.ProcessRequest += ServerBehavior.Delayed200(TimeSpan.FromMilliseconds(200));

_testRiemann.ClearAndStart();
_testStats.ClearAndStart();

await Task.WhenAll(Repeat(5, 30, async () =>
{
Expand All @@ -302,15 +303,15 @@ await Task.WhenAll(Repeat(5, 30, async () =>
server.Stop();
}

_testRiemann.Stop();
_testStats.Stop();

File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testRiemann.Metrics.Select(m => m.ToCsvLine()));
File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testStats.Metrics.Select(m => m.ToCsvLine()));

return new ChartSet
{
Name = "Fast Timeouts",
Description = "30s @ 5/sec.<br/>Command: Inherited<br/>Timeout: 100<br/>Server: Delayed (200ms) 200<br/>Breaker: 50% / 10sec, min 5 ops, 5s tripped",
Charts = GatherChartData(_testRiemann.Metrics, key, key + ".HttpClient"),
Charts = GatherChartData(_testStats.Metrics, key, key + ".HttpClient"),
};
}

Expand All @@ -335,7 +336,7 @@ private async Task<ChartSet> ErrorsInTheMiddle(string key)

server.ProcessRequest += okayBehavior;

_testRiemann.ClearAndStart();
_testStats.ClearAndStart();

await Task.WhenAll(Repeat(5, 5, () => new HttpClientCommand(key, url, TimeSpan.FromMilliseconds(10000)).InvokeAsync()));

Expand Down Expand Up @@ -374,15 +375,15 @@ await Task.WhenAll(Repeat(5, 20, async () =>
server.Stop();
}

_testRiemann.Stop();
_testStats.Stop();

File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testRiemann.Metrics.Select(m => m.ToCsvLine()));
File.WriteAllLines(string.Format(@"c:\hudl\logs\mjolnir-metrics-{0}-{1}.txt", key, DateTime.Now.ToString("yyyy-MM-dd-HH-mm-ss")), _testStats.Metrics.Select(m => m.ToCsvLine()));

return new ChartSet
{
Name = "Error for 5s",
Description = "30s @ 5/sec.<br/>Command: Inherited<br/>Timeout: 10000<br/>Server: 500 for 5 seconds in the middle<br/>Breaker: 50% / 10sec, min 5 ops, 5s tripped",
Charts = GatherChartData(_testRiemann.Metrics, key, key + ".HttpClient"),
Charts = GatherChartData(_testStats.Metrics, key, key + ".HttpClient"),
};
}

Expand Down
6 changes: 1 addition & 5 deletions Hudl.Mjolnir.SystemTests/packages.config
Original file line number Diff line number Diff line change
@@ -1,12 +1,8 @@
<?xml version="1.0" encoding="utf-8"?>
<packages>
<package id="Castle.Core" version="2.5.1" targetFramework="net45" />
<package id="Hudl.Common" version="1.2.0.0" targetFramework="net45" />
<package id="Hudl.Config" version="1.4.1.0" targetFramework="net45" />
<package id="Hudl.Riemann" version="1.2.6.0" targetFramework="net45" />
<package id="Hudl.RiemannClient" version="1.1.0.0" targetFramework="net45" />
<package id="Hudl.Config" version="1.5.0" targetFramework="net45" />
<package id="log4net" version="2.0.0" targetFramework="net45" />
<package id="Newtonsoft.Json" version="6.0.2" targetFramework="net45" />
<package id="protobuf-net" version="2.0.0.622" targetFramework="net45" />
<package id="xunit" version="1.9.2" targetFramework="net45" />
</packages>
Loading

0 comments on commit 63db242

Please sign in to comment.