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

Remove the "PreferBufferedTransport" flag #117

Merged
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
9 changes: 3 additions & 6 deletions src/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,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 @@ -97,8 +96,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 @@ -118,8 +116,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