From 686e51eca6b28497af26d072ab50e2ebeda6d529 Mon Sep 17 00:00:00 2001 From: Anthony Steele Date: Sat, 6 Oct 2018 11:21:28 +0100 Subject: [PATCH] Remove the "PreferBufferedTransport" flag The "PreferBufferedTransport" flag should always be true --- .../WhenCreatingStatsDPublisher.cs | 9 +++------ .../WhenTheTransportThrows.cs | 9 --------- src/JustEat.StatsD/StatsDConfiguration.cs | 20 ++++++------------- src/JustEat.StatsD/StatsDPublisher.cs | 11 ++-------- 4 files changed, 11 insertions(+), 38 deletions(-) diff --git a/src/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs b/src/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs index d653c370..ae7bf2a6 100644 --- a/src/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs +++ b/src/JustEat.StatsD.Tests/WhenCreatingStatsDPublisher.cs @@ -77,8 +77,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(); @@ -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(); @@ -117,8 +115,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(MockBehavior.Loose); diff --git a/src/JustEat.StatsD.Tests/WhenTheTransportThrows.cs b/src/JustEat.StatsD.Tests/WhenTheTransportThrows.cs index f1797db7..f4e880af 100644 --- a/src/JustEat.StatsD.Tests/WhenTheTransportThrows.cs +++ b/src/JustEat.StatsD.Tests/WhenTheTransportThrows.cs @@ -101,19 +101,10 @@ public void ThrownExceptionCanBeCaptured(string name, Func 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()); } } diff --git a/src/JustEat.StatsD/StatsDConfiguration.cs b/src/JustEat.StatsD/StatsDConfiguration.cs index e37def9a..463decf4 100644 --- a/src/JustEat.StatsD/StatsDConfiguration.cs +++ b/src/JustEat.StatsD/StatsDConfiguration.cs @@ -26,6 +26,12 @@ public class StatsDConfiguration /// public TimeSpan? DnsLookupInterval { get; set; } = DefaultDnsLookupInterval; + /// + /// Configure to use either UDP or IP sockets to transport stats. + /// Default is UDP. + /// + public SocketProtocol SocketProtocol { get; set; } = SocketProtocol.Udp; + /// /// Prepend a prefix to all stats. /// Default is empty. @@ -40,19 +46,5 @@ public class StatsDConfiguration /// The default behaviour is to ignore the error /// public Func OnError { get; set; } - - /// - /// If true will prefer to use interface implementation - /// if transport implementation provides both - /// and interfaces. - /// Default is true. - /// - public bool PreferBufferedTransport { get; set; } = true; - - /// - /// Configure to use either UDP or IP sockets to transport stats. - /// Default is Udp. - /// - public SocketProtocol SocketProtocol { get; set; } = SocketProtocol.Udp; } } diff --git a/src/JustEat.StatsD/StatsDPublisher.cs b/src/JustEat.StatsD/StatsDPublisher.cs index 481cd8af..c696493c 100644 --- a/src/JustEat.StatsD/StatsDPublisher.cs +++ b/src/JustEat.StatsD/StatsDPublisher.cs @@ -27,7 +27,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: @@ -48,14 +48,7 @@ public StatsDPublisher(StatsDConfiguration configuration) var transport = new SocketTransport(endpointSource, configuration.SocketProtocol); - if (configuration.PreferBufferedTransport) - { - _inner = new BufferBasedStatsDPublisher(configuration, transport); - } - else - { - _inner = new StringBasedStatsDPublisher(configuration, transport); - } + _inner = new BufferBasedStatsDPublisher(configuration, transport); } public void MarkEvent(string name)