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

Cleanup Http.Resilience dependencies #5217

Merged
merged 1 commit into from
Jun 13, 2024
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
1 change: 0 additions & 1 deletion eng/packages/General.props
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@
<PackageVersion Include="Microsoft.Extensions.Configuration" Version="$(MicrosoftExtensionsConfigurationVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection.Abstractions" Version="$(MicrosoftExtensionsDependencyInjectionAbstractionsVersion)" />
<PackageVersion Include="Microsoft.Extensions.DependencyInjection" Version="$(MicrosoftExtensionsDependencyInjectionVersion)" />
<PackageVersion Include="Microsoft.Extensions.DiagnosticAdapter" Version="3.1.32" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics" Version="$(MicrosoftExtensionsDiagnosticsVersion)" />
<PackageVersion Include="Microsoft.Extensions.Diagnostics.HealthChecks" Version="$(MicrosoftExtensionsDiagnosticsHealthChecksVersion)" />
<PackageVersion Include="Microsoft.Extensions.Hosting.Abstractions" Version="$(MicrosoftExtensionsHostingAbstractionsVersion)" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Configuration" />
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,8 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
<PackageReference Include="System.Collections.Immutable" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Include="System.IO.Hashing" Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Bcl.HashCode" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net6.0'))" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" />
<PackageReference Include="Microsoft.Extensions.Options" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Logging" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" />
<PackageReference Include="System.Diagnostics.DiagnosticSource" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.Telemetry.Abstractions\Microsoft.Extensions.Telemetry.Abstractions.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Diagnostics.Testing\Microsoft.Extensions.Diagnostics.Testing.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Compliance.Testing\Microsoft.Extensions.Compliance.Testing.csproj" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,9 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" />
<PackageReference Include="Microsoft.IO.RecyclableMemoryStream" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="Microsoft.Extensions.Http" />
<PackageReference Include="System.Collections.Immutable" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using System.Threading;

namespace Microsoft.Extensions.Http.Resilience.Internal;

Expand All @@ -11,9 +10,15 @@ namespace Microsoft.Extensions.Http.Resilience.Internal;

internal class Randomizer
{
private static readonly ThreadLocal<Random> _randomInstance = new(() => new Random());
#if NET6_0_OR_GREATER
public virtual double NextDouble(double maxValue) => Random.Shared.NextDouble() * maxValue;

public virtual int NextInt(int maxValue) => Random.Shared.Next(maxValue);
#else
private static readonly System.Threading.ThreadLocal<Random> _randomInstance = new(() => new Random());

public virtual double NextDouble(double maxValue) => _randomInstance.Value!.NextDouble() * maxValue;

public virtual int NextInt(int maxValue) => _randomInstance.Value!.Next(maxValue);
#endif
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,7 @@ internal static bool IsTransientHttpException(Exception exception)

internal static bool IsHttpConnectionTimeout(in Outcome<HttpResponseMessage> outcome, in CancellationToken cancellationToken)
=> !cancellationToken.IsCancellationRequested
&& outcome.Exception is OperationCanceledException { Source: "System.Private.CoreLib" }
&& outcome.Exception.InnerException is TimeoutException;
&& outcome.Exception is OperationCanceledException { Source: "System.Private.CoreLib", InnerException: TimeoutException };

/// <summary>
/// Determines whether a response contains a transient failure.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public bool ShouldRetryAfterHeader
DelayGenerator = args => args.Outcome.Result switch
{
HttpResponseMessage response when RetryAfterHelper.TryParse(response, TimeProvider.System, out var retryAfter) => new ValueTask<TimeSpan?>(retryAfter),
_ => new ValueTask<TimeSpan?>((TimeSpan?)null)
_ => default
};
}
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ private static OptionsBuilder<OrderedGroupsRoutingOptions> ConfigureOrderedGroup
{
var optionsCache = new NamedOptionsCache<OrderedGroupsRoutingOptions>(builder.Name, serviceProvider.GetRequiredService<IOptionsMonitor<OrderedGroupsRoutingOptions>>());
var factory = new OrderedGroupsRoutingStrategyFactory(serviceProvider.GetRequiredService<Randomizer>(), optionsCache);
return () => factory.Get();
return factory.Get;
});

return builder.Services.AddOptionsWithValidateOnStart<OrderedGroupsRoutingOptions, OrderedGroupsRoutingOptionsValidator>(builder.Name);
Expand All @@ -141,7 +141,7 @@ private static OptionsBuilder<WeightedGroupsRoutingOptions> ConfigureWeightedGro
{
var optionsCache = new NamedOptionsCache<WeightedGroupsRoutingOptions>(builder.Name, serviceProvider.GetRequiredService<IOptionsMonitor<WeightedGroupsRoutingOptions>>());
var factory = new WeightedGroupsRoutingStrategyFactory(serviceProvider.GetRequiredService<Randomizer>(), optionsCache);
return () => factory.Get();
return factory.Get;
});

return builder.Services.AddOptionsWithValidateOnStart<WeightedGroupsRoutingOptions, WeightedGroupsRoutingOptionsValidator>(builder.Name);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,8 @@
</PropertyGroup>

<PropertyGroup>
<UseLoggingGenerator>true</UseLoggingGenerator>
<UseMetricsGenerator>true</UseMetricsGenerator>
<UseOptionsValidationGenerator>true</UseOptionsValidationGenerator>
<InjectTrimAttributesOnLegacy>true</InjectTrimAttributesOnLegacy>
<InjectGetOrAddOnLegacy>true</InjectGetOrAddOnLegacy>
<InjectTrimAttributesOnLegacy>true</InjectTrimAttributesOnLegacy>
<InjectSharedDataValidation>true</InjectSharedDataValidation>
<InjectSharedDiagnosticIds>true</InjectSharedDiagnosticIds>
</PropertyGroup>

Expand All @@ -28,12 +23,10 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Polly.Core" />
<PackageReference Include="Polly.Extensions" />
<PackageReference Include="Polly.RateLimiting" />
<PackageReference Include="Microsoft.Extensions.Diagnostics" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" />
<PackageReference Include="System.Runtime.CompilerServices.Unsafe" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net7.0'))" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public static IServiceCollection AddServiceLogEnricher(this IServiceCollection s

return services
.AddStaticLogEnricher<ApplicationLogEnricher>()
.AddLogEnricherOptions(configure);
.Configure(configure);
}

/// <summary>
Expand All @@ -58,21 +58,6 @@ public static IServiceCollection AddServiceLogEnricher(this IServiceCollection s

return services
.AddStaticLogEnricher<ApplicationLogEnricher>()
.AddLogEnricherOptions(_ => { }, section);
}

private static IServiceCollection AddLogEnricherOptions(
this IServiceCollection services,
Action<ApplicationLogEnricherOptions> configure,
IConfigurationSection? section = null)
{
_ = services.Configure(configure);

if (section is not null)
{
_ = services.Configure<ApplicationLogEnricherOptions>(section);
}

return services;
.Configure<ApplicationLogEnricherOptions>(section);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public static IServiceCollection AddProcessLogEnricher(this IServiceCollection s
return services
.AddLogEnricher<ProcessLogEnricher>()
.AddStaticLogEnricher<StaticProcessLogEnricher>()
.AddLogEnricherOptions(configure);
.Configure(configure);
}

/// <summary>
Expand All @@ -60,21 +60,6 @@ public static IServiceCollection AddProcessLogEnricher(this IServiceCollection s
return services
.AddLogEnricher<ProcessLogEnricher>()
.AddStaticLogEnricher<StaticProcessLogEnricher>()
.AddLogEnricherOptions(_ => { }, section);
}

private static IServiceCollection AddLogEnricherOptions(
this IServiceCollection services,
Action<ProcessLogEnricherOptions> configure,
IConfigurationSection? section = null)
{
_ = services.Configure(configure);

if (section is not null)
{
_ = services.Configure<ProcessLogEnricherOptions>(section);
}

return services;
.Configure<ProcessLogEnricherOptions>(section);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,10 @@
<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.DependencyInjection.AutoActivation\Microsoft.Extensions.DependencyInjection.AutoActivation.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.AmbientMetadata.Application\Microsoft.Extensions.AmbientMetadata.Application.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Compliance.Abstractions\Microsoft.Extensions.Compliance.Abstractions.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Telemetry.Abstractions\Microsoft.Extensions.Telemetry.Abstractions.csproj" />
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration.Binder" />
<PackageReference Include="Microsoft.Extensions.Options" />
<PackageReference Include="Microsoft.Bcl.TimeProvider" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
<PackageReference Include="Microsoft.Extensions.Logging.Configuration" />
<PackageReference Include="System.Collections.Immutable" Condition="!$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0'))" />
Expand Down
2 changes: 1 addition & 1 deletion src/Shared/RentedSpan/RentedSpan.cs
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ public void Dispose()
/// When a buffer isn't rented by this type, it's a cue to you to allocate buffer from the stack instead
/// using stackalloc.
/// </remarks>
public Span<T> Span => _rentedBuffer != null ? _rentedBuffer.AsSpan(0, _length) : Array.Empty<T>().AsSpan();
public Span<T> Span => _rentedBuffer != null ? _rentedBuffer.AsSpan(0, _length) : default;

/// <summary>
/// Gets a value indicating whether a buffer has been rented.
Expand Down