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

Support for .NET Core 3.0 #182

Merged
merged 19 commits into from
Oct 11, 2019
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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -276,6 +276,9 @@ _TeamCity*
*.coverage
*.coveragexml

# Coverlet
coverage.*

# NCrunch
_NCrunch_*
.*crunch*.local.xml
Expand Down
8 changes: 4 additions & 4 deletions Build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ else {
}

function DotNetBuild {
param([string]$Project, [string]$Configuration, [string]$Framework)
& $dotnet build $Project --output (Join-Path $OutputPath $Framework) --framework $Framework --configuration $Configuration
param([string]$Project, [string]$Configuration)
& $dotnet build $Project --output $OutputPath --configuration $Configuration
if ($LASTEXITCODE -ne 0) {
throw "dotnet build failed with exit code $LASTEXITCODE"
}
Expand Down Expand Up @@ -131,8 +131,8 @@ $packageProjects = @(

Write-Host "Building $($projects.Count) projects..." -ForegroundColor Green
ForEach ($project in $projects) {
DotNetBuild $project $Configuration "netstandard2.0"
DotNetBuild $project $Configuration "net451"
DotNetBuild $project $Configuration
DotNetBuild $project $Configuration
}

if ($SkipTests -eq $false) {
Expand Down
12 changes: 7 additions & 5 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,18 @@
<Import Project="version.props" />
<PropertyGroup>
<AnalyzersVersion>2.9.6</AnalyzersVersion>
<MicrosoftNETFrameworkReferenceAssembliesVersion>1.0.0-preview.2</MicrosoftNETFrameworkReferenceAssembliesVersion>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="2.7.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-beta2-19367-01" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.FxCopAnalyzers" Version="$(AnalyzersVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(AnalyzersVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.NetCore.Analyzers" Version="$(AnalyzersVersion)" PrivateAssets="All" />
<PackageReference Include="ReportGenerator" Version="4.3.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net451' ">
<PackageReference Include="Microsoft.CodeAnalysis.PublicApiAnalyzers" Version="$(AnalyzersVersion)" PrivateAssets="All" />
<ItemGroup>
<None Include="$(MSBuildThisFileDirectory)package-icon.png" Pack="True" PackagePath="" />
</ItemGroup>
<PropertyGroup>
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
Expand All @@ -24,9 +26,9 @@
<GenerateDocumentationFile>false</GenerateDocumentationFile>
<GenerateRuntimeConfigurationFiles>true</GenerateRuntimeConfigurationFiles>
<LangVersion>latest</LangVersion>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
<NeutralLanguage>en-US</NeutralLanguage>
<PackageIconUrl>https://avatars3.githubusercontent.com/u/1516790?s=64</PackageIconUrl>
<Nullable>enable</Nullable>
<PackageIcon>package-icon.png</PackageIcon>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<PackageProjectUrl>https://github.com/justeat/JustEat.StatsD</PackageProjectUrl>
<PackageReleaseNotes>$(PackageProjectUrl)/releases</PackageReleaseNotes>
Expand All @@ -44,7 +46,7 @@
<CollectCoverage>true</CollectCoverage>
<CoverletOutput Condition=" '$(OutputPath)' != '' ">$(OutputPath)\</CoverletOutput>
<CoverletOutputFormat>cobertura,json</CoverletOutputFormat>
<Exclude>[*.Benchmark]*,[*.Tests]*,[xunit.*]*</Exclude>
<Exclude>[Benchmark]*,[*.Tests]*,[xunit.*]*</Exclude>
<ExcludeByAttribute>System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverageAttribute</ExcludeByAttribute>
<Threshold>90</Threshold>
</PropertyGroup>
Expand Down
5 changes: 1 addition & 4 deletions Directory.Build.targets
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
<Project>
<PropertyGroup>
<MSBuildAllProjects>$(MSBuildAllProjects);$(MSBuildThisFileFullPath)</MSBuildAllProjects>
</PropertyGroup>
<!-- disable sourcelink on mono, to workaround https://github.com/dotnet/sourcelink/issues/155 -->
<!-- Disable sourcelink on mono, to workaround https://github.com/dotnet/sourcelink/issues/155 -->
<Target Name="_RemoveMSSourceLinkGitHub" AfterTargets="CollectPackageReferences" Condition=" '$(OS)' != 'Windows_NT' AND '$(MSBuildRuntimeType)' != 'Core' ">
<ItemGroup>
<PackageReference Remove="Microsoft.SourceLink.GitHub" />
Expand Down
1 change: 0 additions & 1 deletion JustEat.StatsD.sln
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Assets", "Assets", "{06BE4D
JustEat.StatsD.ruleset = JustEat.StatsD.ruleset
LICENSE = LICENSE
README.md = README.md
ReferenceAssemblies.props = ReferenceAssemblies.props
version.props = version.props
EndProjectSection
EndProject
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ We use this library within our components to publish [StatsD](http://github.com/

### Supported platforms

`JustEat.Statsd` version 4 is built for these target frameworks:
`JustEat.StatsD` version 4.1.0 is built for these target frameworks:

* `net451`
* `net461`
* `netstandard2.0`
* `netstandard2.1`
* `netcoreapp2.1`
* `netcoreapp2.2`

Expand Down
4 changes: 2 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
os: Visual Studio 2017
version: 4.0.1.{build}
os: Visual Studio 2019
version: 4.1.0.{build}
configuration: Release
environment:
DOTNET_SKIP_FIRST_TIME_EXPERIENCE: true
Expand Down
5 changes: 3 additions & 2 deletions build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,9 @@ if [ "$dotnet_version" != "$CLI_VERSION" ]; then
curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --version "$CLI_VERSION" --install-dir "$DOTNET_INSTALL_DIR"
fi

dotnet build src/JustEat.StatsD/JustEat.StatsD.csproj --output $artifacts --configuration $configuration || exit 1
dotnet build ./JustEat.StatsD.sln --output $artifacts --configuration $configuration || exit 1
dotnet pack ./src/JustEat.StatsD/JustEat.StatsD.csproj --output $artifacts --configuration $configuration || exit 1

if [ $skipTests == 0 ]; then
dotnet test tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj --output $artifacts --configuration $configuration --framework "netcoreapp2.2" || exit 1
dotnet test ./tests/JustEat.StatsD.Tests/JustEat.StatsD.Tests.csproj --output $artifacts --configuration $configuration || exit 1
fi
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.2.401"
"version": "3.0.100"
}
}
Binary file added package-icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
13 changes: 9 additions & 4 deletions src/JustEat.StatsD/Buffered/BufferBasedStatsDPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,24 @@ internal sealed class BufferBasedStatsDPublisher : IStatsDPublisher
private const int SafeUdpPacketSize = 512;

[ThreadStatic]
private static byte[] _buffer;
private static byte[]? _buffer;
private static byte[] Buffer => _buffer ?? (_buffer = new byte[SafeUdpPacketSize]);

[ThreadStatic]
private static Random _random;
private static Random? _random;
private static Random Random => _random ?? (_random = new Random());

private readonly StatsDUtf8Formatter _formatter;
private readonly IStatsDTransport _transport;
private readonly Func<Exception, bool> _onError;
private readonly Func<Exception, bool>? _onError;

public BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
internal BufferBasedStatsDPublisher(StatsDConfiguration configuration, IStatsDTransport transport)
{
if (configuration == null)
{
throw new ArgumentNullException(nameof(configuration));
}

_onError = configuration.OnError;
_transport = transport;
_formatter = new StatsDUtf8Formatter(configuration.Prefix);
Expand Down
10 changes: 6 additions & 4 deletions src/JustEat.StatsD/Buffered/BufferExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,25 @@ public static bool TryWriteBytes(this ref Buffer src, Span<byte> destination)

public static bool TryWriteUtf8String(this ref Buffer src, string str)
{
#if NETCOREAPP2_1 || NETCOREAPP2_2
#if NETSTANDARD2_0 || NET461
var bucketBytes = Encoding.UTF8.GetBytes(str);
return src.TryWriteBytes(bucketBytes);
#else
int written = 0;
try
{
written = Encoding.UTF8.GetBytes(str, src.Tail);
}
#pragma warning disable CA1031
catch (ArgumentException)
#pragma warning restore CA1031
{
return false;
}

src.Tail = src.Tail.Slice(written);
src.Written += written;
return true;
#else
var bucketBytes = Encoding.UTF8.GetBytes(str);
return src.TryWriteBytes(bucketBytes);
#endif
}

Expand Down
4 changes: 0 additions & 4 deletions src/JustEat.StatsD/Buffered/StatsDUtf8Formatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,7 @@ internal sealed class StatsDUtf8Formatter
public StatsDUtf8Formatter(string prefix)
{
_utf8Prefix = string.IsNullOrWhiteSpace(prefix) ?
#if NET451
new byte[0] :
#else
Array.Empty<byte>() :
#endif
Encoding.UTF8.GetBytes(prefix + ".");
}

Expand Down
2 changes: 1 addition & 1 deletion src/JustEat.StatsD/ConnectedSocketPool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ private Socket CreateSocket()
/// <summary>Retrieves an object from the pool if one is available.
/// return null if the pool is empty</summary>
/// <returns>An object from the pool. </returns>
private Socket Pop()
private Socket? Pop()
{
if (_pool.TryTake(out Socket result))
{
Expand Down
9 changes: 3 additions & 6 deletions src/JustEat.StatsD/DisposableTimer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ namespace JustEat.StatsD
{
internal sealed class DisposableTimer : IDisposableTimer
{
private bool _disposed;
private readonly IStatsDPublisher _publisher;
private readonly Stopwatch _stopwatch;

private IStatsDPublisher _publisher;
private Stopwatch _stopwatch;
private bool _disposed;

public string Bucket { get; set; }

Expand Down Expand Up @@ -38,9 +38,6 @@ public void Dispose()
}

_publisher.Timing(_stopwatch.Elapsed, Bucket);

_stopwatch = null;
_publisher = null;
}
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/JustEat.StatsD/EndpointLookups/CachedEndpointSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class CachedEndpointSource : IEndPointSource
{
private readonly IEndPointSource _inner;
private readonly TimeSpan _cacheDuration;
private EndPoint _cachedValue;
private EndPoint? _cachedValue;
private DateTime _expiry;

/// <summary>
Expand Down Expand Up @@ -46,7 +46,8 @@ public EndPoint GetEndpoint()
_cachedValue = _inner.GetEndpoint();
_expiry = DateTime.UtcNow.Add(_cacheDuration);
}
return _cachedValue;

return _cachedValue!;
}

private bool NeedsRead()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ private static IPAddress GetIpAddressOfHost(string hostName)
throw new Exception($"Failed to resolve any IP addresses for StatsD host '${hostName}' using DNS.");
}

IPAddress result = null;
IPAddress? result = null;

if (endpoints.Length > 1)
{
Expand Down
17 changes: 6 additions & 11 deletions src/JustEat.StatsD/JustEat.StatsD.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(MSBuildThisFileDirectory)/../../ReferenceAssemblies.props" />
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<Description>A .NET library for publishing metrics to StatsD.</Description>
<GenerateDocumentationFile>true</GenerateDocumentationFile>
Expand All @@ -8,20 +7,16 @@
<PackageId>JustEat.StatsD</PackageId>
<RootNamespace>JustEat.StatsD</RootNamespace>
<Summary>A .NET library for publishing metrics to StatsD.</Summary>
<TargetFrameworks>net451;netstandard2.0;netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
<TargetFrameworks>net461;netstandard2.0;netstandard2.1;netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
</PropertyGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' ">
<Reference Include="System" />
<Reference Include="System.Runtime" />
<Reference Include="Microsoft.CSharp" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net451' ">
<ItemGroup>
<PackageReference Include="Microsoft.NETFramework.ReferenceAssemblies" Version="$(MicrosoftNETFrameworkReferenceAssembliesVersion)" PrivateAssets="All" />
<PackageReference Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="2.0.0" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' == 'net451' or '$(TargetFramework)' == 'netstandard2.0' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'net461' or '$(TargetFramework)' == 'netstandard2.0' ">
<PackageReference Include="System.Memory" Version="4.5.1" />
</ItemGroup>
<ItemGroup Condition=" '$(TargetFramework)' != 'net451' ">
<ItemGroup>
<AdditionalFiles Include="PublicAPI.Shipped.txt" />
<AdditionalFiles Include="PublicAPI.Unshipped.txt" />
</ItemGroup>
Expand Down
17 changes: 5 additions & 12 deletions src/JustEat.StatsD/SocketFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,32 +8,25 @@ internal static class SocketFactory
{
internal static Socket For(SocketProtocol socketProtocol)
{
switch (socketProtocol)
return socketProtocol switch
{
case SocketProtocol.IP:
return ForIp();
SocketProtocol.IP => ForIp(),

case SocketProtocol.Udp:
return ForUdp();
SocketProtocol.Udp => ForUdp(),

default:
throw new InvalidOperationException($"Unknown {nameof(SocketProtocol)} value {socketProtocol} specified.");
}
_ => throw new InvalidOperationException($"Unknown {nameof(SocketProtocol)} value {socketProtocol} specified."),
};
}

internal static Socket ForUdp()
{
var socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

#if !NET451
// See https://github.com/dotnet/corefx/pull/17853#issuecomment-291371266
if (!RuntimeInformation.IsOSPlatform(OSPlatform.OSX))
{
socket.SendBufferSize = 0;
}
#else
socket.SendBufferSize = 0;
#endif

return socket;
}
Expand Down
4 changes: 2 additions & 2 deletions src/JustEat.StatsD/SocketTransport.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@ namespace JustEat.StatsD
/// </summary>
public sealed class SocketTransport : IStatsDTransport, IDisposable
{
private ConnectedSocketPool _pool;
private readonly IEndPointSource _endpointSource;
private readonly SocketProtocol _socketProtocol;
private ConnectedSocketPool? _pool;

/// <summary>
/// Initializes a new instance of the <see cref="SocketTransport"/> class.
Expand Down Expand Up @@ -96,7 +96,7 @@ private ConnectedSocketPool GetPool(EndPoint endPoint)
else
{
newPool.Dispose();
return _pool;
return _pool!;
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/JustEat.StatsD/StatsDConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public class StatsDConfiguration
/// <remarks>
/// A value must be provided for this property.
/// </remarks>
public string Host { get; set; }
public string? Host { get; set; }

/// <summary>
/// Gets or sets the port on the StatsD server to use.
Expand Down Expand Up @@ -62,6 +62,6 @@ public class StatsDConfiguration
/// <para/>
/// The default behaviour is to ignore the exception.
/// </remarks>
public Func<Exception, bool> OnError { get; set; }
public Func<Exception, bool>? OnError { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/JustEat.StatsD/StatsDPublisher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public StatsDPublisher(StatsDConfiguration configuration)
}

var endpointSource = EndPointFactory.MakeEndPointSource(
configuration.Host, configuration.Port, configuration.DnsLookupInterval);
configuration.Host!, configuration.Port, configuration.DnsLookupInterval);

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

Expand Down
Loading