Skip to content

Commit

Permalink
Merge pull request #117 from AnthonySteele/buffer-on-by-default
Browse files Browse the repository at this point in the history
Remove the "PreferBufferedTransport" flag
  • Loading branch information
martincostello authored Oct 7, 2018
2 parents 188b405 + 1ca8883 commit 4822cb3
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 39 deletions.
9 changes: 3 additions & 6 deletions src/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,7 @@ public void BufferBasedTransportShouldBeChosenIfAvailableAndAskedFor()
var config = new StatsDConfiguration
{
Prefix = "test",
Host = "127.0.0.1",
PreferBufferedTransport = true
Host = "127.0.0.1"
};

var transport = new BothVersionsTransportMock();
Expand All @@ -99,8 +98,7 @@ public void BufferBasedTransportShouldBeChosenByDefault()
var config = new StatsDConfiguration
{
Prefix = "test",
Host = "127.0.0.1",
PreferBufferedTransport = true
Host = "127.0.0.1"
};

var transport = new BothVersionsTransportMock();
Expand All @@ -120,8 +118,7 @@ public void StringBasedTransportShouldBeUsedIfBufferedIsNotAvailable()
var config = new StatsDConfiguration
{
Prefix = "test",
Host = "127.0.0.1",
PreferBufferedTransport = false
Host = "127.0.0.1"
};

var transport = new Mock<IStatsDTransport>(MockBehavior.Loose);
Expand Down
9 changes: 0 additions & 9 deletions src/JustEat.StatsD.Tests/WhenTheTransportThrows.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,19 +151,10 @@ public void ThrownExceptionCanBeCaptured(string name, Func<StatsDConfiguration,
"StringBasedStatsDPublisher",
config => new StringBasedStatsDPublisher(config, new ThrowingTransport())
},
{
"StatsDPublisher",
config =>
{
config.PreferBufferedTransport = false;
return new StatsDPublisher(config, new ThrowingTransport());
}
},
{
"StatsDPublisherBuffered",
config =>
{
config.PreferBufferedTransport = true;
return new StatsDPublisher(config, new ThrowingTransport());
}
}
Expand Down
20 changes: 6 additions & 14 deletions src/JustEat.StatsD/StatsDConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,12 @@ public class StatsDConfiguration
/// </summary>
public TimeSpan? DnsLookupInterval { get; set; } = DefaultDnsLookupInterval;

/// <summary>
/// Configure to use either UDP or IP sockets to transport stats.
/// Default is UDP.
/// </summary>
public SocketProtocol SocketProtocol { get; set; } = SocketProtocol.Udp;

/// <summary>
/// Prepend a prefix to all stats.
/// Default is empty.
Expand All @@ -40,19 +46,5 @@ public class StatsDConfiguration
/// The default behaviour is to ignore the error
/// </summary>
public Func<Exception, bool> OnError { get; set; }

/// <summary>
/// If true will prefer to use <see cref="IStatsDBufferedTransport"/> interface implementation
/// if transport implementation provides both
/// <see cref="IStatsDBufferedTransport"/> and <see cref="IStatsDTransport"/> interfaces.
/// Default is true.
/// </summary>
public bool PreferBufferedTransport { get; set; } = true;

/// <summary>
/// Configure to use either UDP or IP sockets to transport stats.
/// Default is Udp.
/// </summary>
public SocketProtocol SocketProtocol { get; set; } = SocketProtocol.Udp;
}
}
13 changes: 3 additions & 10 deletions src/JustEat.StatsD/StatsDPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public StatsDPublisher(StatsDConfiguration configuration, IStatsDTransport trans

switch (transport)
{
case IStatsDBufferedTransport bufferedTransport when configuration.PreferBufferedTransport:
case IStatsDBufferedTransport bufferedTransport:
_inner = new BufferBasedStatsDPublisher(configuration, bufferedTransport);
break;
default:
Expand Down Expand Up @@ -77,18 +77,11 @@ public StatsDPublisher(StatsDConfiguration configuration)
configuration.Host, configuration.Port, configuration.DnsLookupInterval);

var transport = new SocketTransport(endpointSource, configuration.SocketProtocol);

_transport = transport;
_disposeTransport = true;

if (configuration.PreferBufferedTransport)
{
_inner = new BufferBasedStatsDPublisher(configuration, transport);
}
else
{
_inner = new StringBasedStatsDPublisher(configuration, transport);
}
_inner = new BufferBasedStatsDPublisher(configuration, transport);
}

/// <inheritdoc />
Expand Down

0 comments on commit 4822cb3

Please sign in to comment.