Skip to content

Commit

Permalink
Merge branch 'release/8.0' into mtomka/fix-AddResilienceEnrichment-be…
Browse files Browse the repository at this point in the history
…havior
  • Loading branch information
martintmk committed Sep 29, 2023
2 parents eeda9bc + baeb3cd commit 9a4788a
Show file tree
Hide file tree
Showing 16 changed files with 91 additions and 90 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,15 +83,15 @@ private static void AddHedging(this IServiceCollection services, HedgingClientTy
{
options.Groups = Enumerable.Repeat(0, routes).Select(_ =>
{
return new EndpointGroup
return new UriEndpointGroup
{
Endpoints = new[]
{
new WeightedEndpoint
new WeightedUriEndpoint
{
Uri = new Uri(PrimaryEndpoint)
},
new WeightedEndpoint
new WeightedUriEndpoint
{
Uri = new Uri(SecondaryEndpoint)
}
Expand All @@ -106,15 +106,15 @@ private static void AddHedging(this IServiceCollection services, HedgingClientTy
{
options.Groups = Enumerable.Repeat(0, routes).Select(_ =>
{
return new WeightedEndpointGroup
return new WeightedUriEndpointGroup
{
Endpoints = new[]
{
new WeightedEndpoint
new WeightedUriEndpoint
{
Uri = new Uri(PrimaryEndpoint)
},
new WeightedEndpoint
new WeightedUriEndpoint
{
Uri = new Uri(SecondaryEndpoint)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,38 +11,6 @@
}
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.Endpoint",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Http.Resilience.Endpoint.Endpoint();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "System.Uri? Microsoft.Extensions.Http.Resilience.Endpoint.Uri { get; set; }",
"Stage": "Stable"
}
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.EndpointGroup",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Http.Resilience.EndpointGroup.EndpointGroup();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.Http.Resilience.WeightedEndpoint> Microsoft.Extensions.Http.Resilience.EndpointGroup.Endpoints { get; set; }",
"Stage": "Stable"
}
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.HedgingEndpointOptions",
"Stage": "Stable",
Expand Down Expand Up @@ -452,7 +420,7 @@
],
"Properties": [
{
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.Http.Resilience.EndpointGroup> Microsoft.Extensions.Http.Resilience.OrderedGroupsRoutingOptions.Groups { get; set; }",
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.Http.Resilience.UriEndpointGroup> Microsoft.Extensions.Http.Resilience.OrderedGroupsRoutingOptions.Groups { get; set; }",
"Stage": "Stable"
}
]
Expand Down Expand Up @@ -538,37 +506,33 @@
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.WeightedEndpoint",
"Type": "class Microsoft.Extensions.Http.Resilience.UriEndpoint",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Http.Resilience.WeightedEndpoint.WeightedEndpoint();",
"Member": "Microsoft.Extensions.Http.Resilience.UriEndpoint.UriEndpoint();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "System.Uri? Microsoft.Extensions.Http.Resilience.WeightedEndpoint.Uri { get; set; }",
"Stage": "Stable"
},
{
"Member": "int Microsoft.Extensions.Http.Resilience.WeightedEndpoint.Weight { get; set; }",
"Member": "System.Uri? Microsoft.Extensions.Http.Resilience.UriEndpoint.Uri { get; set; }",
"Stage": "Stable"
}
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.WeightedEndpointGroup : Microsoft.Extensions.Http.Resilience.EndpointGroup",
"Type": "class Microsoft.Extensions.Http.Resilience.UriEndpointGroup",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Http.Resilience.WeightedEndpointGroup.WeightedEndpointGroup();",
"Member": "Microsoft.Extensions.Http.Resilience.UriEndpointGroup.UriEndpointGroup();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "int Microsoft.Extensions.Http.Resilience.WeightedEndpointGroup.Weight { get; set; }",
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.Http.Resilience.WeightedUriEndpoint> Microsoft.Extensions.Http.Resilience.UriEndpointGroup.Endpoints { get; set; }",
"Stage": "Stable"
}
]
Expand Down Expand Up @@ -606,14 +570,50 @@
],
"Properties": [
{
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.Http.Resilience.WeightedEndpointGroup> Microsoft.Extensions.Http.Resilience.WeightedGroupsRoutingOptions.Groups { get; set; }",
"Member": "System.Collections.Generic.IList<Microsoft.Extensions.Http.Resilience.WeightedUriEndpointGroup> Microsoft.Extensions.Http.Resilience.WeightedGroupsRoutingOptions.Groups { get; set; }",
"Stage": "Stable"
},
{
"Member": "Microsoft.Extensions.Http.Resilience.WeightedGroupSelectionMode Microsoft.Extensions.Http.Resilience.WeightedGroupsRoutingOptions.SelectionMode { get; set; }",
"Stage": "Stable"
}
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.WeightedUriEndpoint",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Http.Resilience.WeightedUriEndpoint.WeightedUriEndpoint();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "System.Uri? Microsoft.Extensions.Http.Resilience.WeightedUriEndpoint.Uri { get; set; }",
"Stage": "Stable"
},
{
"Member": "int Microsoft.Extensions.Http.Resilience.WeightedUriEndpoint.Weight { get; set; }",
"Stage": "Stable"
}
]
},
{
"Type": "class Microsoft.Extensions.Http.Resilience.WeightedUriEndpointGroup : Microsoft.Extensions.Http.Resilience.UriEndpointGroup",
"Stage": "Stable",
"Methods": [
{
"Member": "Microsoft.Extensions.Http.Resilience.WeightedUriEndpointGroup.WeightedUriEndpointGroup();",
"Stage": "Stable"
}
],
"Properties": [
{
"Member": "int Microsoft.Extensions.Http.Resilience.WeightedUriEndpointGroup.Weight { get; set; }",
"Stage": "Stable"
}
]
}
]
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@ internal sealed class OrderedGroupsRoutingStrategy : RequestRoutingStrategy, IRe
{
private readonly ObjectPool<OrderedGroupsRoutingStrategy> _pool;
private int _lastUsedIndex;
private IList<EndpointGroup>? _groups;
private IList<UriEndpointGroup>? _groups;

public OrderedGroupsRoutingStrategy(Randomizer randomizer, ObjectPool<OrderedGroupsRoutingStrategy> pool)
: base(randomizer)
{
_pool = pool;
}

public void Initialize(IList<EndpointGroup> groups)
public void Initialize(IList<UriEndpointGroup> groups)
{
_ = TryReset();

Expand Down Expand Up @@ -55,7 +55,7 @@ public override bool TryReset()
return true;
}

private bool TryGetNextGroup(out EndpointGroup? nextGroup)
private bool TryGetNextGroup(out UriEndpointGroup? nextGroup)
{
if (_lastUsedIndex >= _groups!.Count)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace Microsoft.Extensions.Http.Resilience.Routing.Internal.WeightedGroups;

internal sealed class WeightedGroupsRoutingStrategy : RequestRoutingStrategy
{
private readonly List<WeightedEndpointGroup> _groups;
private readonly List<WeightedUriEndpointGroup> _groups;
private readonly ObjectPool<WeightedGroupsRoutingStrategy> _pool;
private bool _initialGroupPicked;
private WeightedGroupSelectionMode _mode;
Expand All @@ -25,7 +25,7 @@ public WeightedGroupsRoutingStrategy(Randomizer randomizer, ObjectPool<WeightedG
_pool = pool;
}

public void Initialize(IEnumerable<WeightedEndpointGroup> groups, WeightedGroupSelectionMode mode)
public void Initialize(IEnumerable<WeightedUriEndpointGroup> groups, WeightedGroupSelectionMode mode)
{
_ = TryReset();

Expand Down Expand Up @@ -62,7 +62,7 @@ public override bool TryGetNextRoute([NotNullWhen(true)] out Uri? nextRoute)
return false;
}

private bool TryGetNextGroup(out WeightedEndpointGroup? nextGroup)
private bool TryGetNextGroup(out WeightedUriEndpointGroup? nextGroup)
{
if (_groups.Count == 0)
{
Expand All @@ -75,7 +75,7 @@ private bool TryGetNextGroup(out WeightedEndpointGroup? nextGroup)
return true;
}

private WeightedEndpointGroup PickGroup()
private WeightedUriEndpointGroup PickGroup()
{
if (!_initialGroupPicked)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class OrderedGroupsRoutingOptions
[Microsoft.Shared.Data.Validation.Length(1)]
#endif
[ValidateEnumeratedItems]
public IList<EndpointGroup> Groups { get; set; } = new List<EndpointGroup>();
public IList<UriEndpointGroup> Groups { get; set; } = new List<UriEndpointGroup>();
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning restore CA2227 // Collection properties should be read only
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ namespace Microsoft.Extensions.Http.Resilience;
/// <summary>
/// Represents an URI based endpoint.
/// </summary>
public class Endpoint
public class UriEndpoint
{
private Uri? _uri;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@
namespace Microsoft.Extensions.Http.Resilience;

/// <summary>
/// Represents a collection of <see cref="WeightedEndpoint"/>.
/// Represents a collection of <see cref="WeightedUriEndpoint"/>.
/// </summary>
public class EndpointGroup
public class UriEndpointGroup
{
/// <summary>
/// Gets or sets the endpoints in this endpoint group.
Expand All @@ -27,7 +27,7 @@ public class EndpointGroup
[Microsoft.Shared.Data.Validation.Length(1)]
#endif
[ValidateEnumeratedItems]
public IList<WeightedEndpoint> Endpoints { get; set; } = new List<WeightedEndpoint>();
public IList<WeightedUriEndpoint> Endpoints { get; set; } = new List<WeightedUriEndpoint>();
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning restore CA2227 // Collection properties should be read only
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ namespace Microsoft.Extensions.Http.Resilience;
public enum WeightedGroupSelectionMode
{
/// <summary>
/// In this selection mode the weight is used for every pick of <see cref="WeightedEndpointGroup"/>.
/// In this selection mode the weight is used for every pick of <see cref="WeightedUriEndpointGroup"/>.
/// </summary>
EveryAttempt,

/// <summary>
/// In this selection mode the weight is only used to pick initial <see cref="WeightedEndpointGroup"/>.
/// In this selection mode the weight is only used to pick initial <see cref="WeightedUriEndpointGroup"/>.
/// Remaining groups are picked in order, starting from the first, finishing with last and skipping already picked group.
/// </summary>
InitialAttempt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class WeightedGroupsRoutingOptions
[Microsoft.Shared.Data.Validation.Length(1)]
#endif
[ValidateEnumeratedItems]
public IList<WeightedEndpointGroup> Groups { get; set; } = new List<WeightedEndpointGroup>();
public IList<WeightedUriEndpointGroup> Groups { get; set; } = new List<WeightedUriEndpointGroup>();
#pragma warning restore IL2026 // Members annotated with 'RequiresUnreferencedCodeAttribute' require dynamic access otherwise can break functionality when trimming application code
#pragma warning restore CA2227 // Collection properties should be read only
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ namespace Microsoft.Extensions.Http.Resilience;
/// <summary>
/// Represents an URI based endpoint with a weight assigned.
/// </summary>
public class WeightedEndpoint
public class WeightedUriEndpoint
{
private const int MinWeight = 1;
private const int MaxWeight = 64000;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
namespace Microsoft.Extensions.Http.Resilience;

/// <summary>
/// Represents a collection of <see cref="Endpoint"/> with a weight assigned.
/// Represents a collection of <see cref="UriEndpoint"/> with a weight assigned.
/// </summary>
public class WeightedEndpointGroup : EndpointGroup
public class WeightedUriEndpointGroup : UriEndpointGroup
{
private const int MinWeight = 1;
private const int MaxWeight = 64000;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<RootNamespace>Microsoft.Extensions.Resilience</RootNamespace>
<Description>Mechanisms to harden applications against transient failures.</Description>
Expand Down Expand Up @@ -26,7 +26,7 @@

<ItemGroup>
<ProjectReference Include="..\Microsoft.Extensions.Diagnostics.ExceptionSummarization\Microsoft.Extensions.Diagnostics.ExceptionSummarization.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Diagnostics.Extra\Microsoft.Extensions.Diagnostics.Extra.csproj" />
<ProjectReference Include="..\Microsoft.Extensions.Diagnostics.ExtraAbstractions\Microsoft.Extensions.Diagnostics.ExtraAbstractions.csproj" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Microsoft.Extensions.DependencyInjection.Extensions;
using Microsoft.Extensions.Diagnostics.ExceptionSummarization;
using Microsoft.Extensions.Http.Diagnostics;
using Microsoft.Extensions.Options;
Expand Down Expand Up @@ -51,9 +52,9 @@ public static IServiceCollection AddResilienceEnrichment(this IServiceCollection
return services;
}

services.AddExceptionSummarizer().TryAddSingleton<ResilienceMetricsEnricher>();

_ = services
.AddExceptionSummarizer()
.AddSingleton<ResilienceMetricsEnricher>()
.AddOptionsWithValidateOnStart<TelemetryOptions>()
.Configure<ResilienceMetricsEnricher>((options, enricher) => options.MeteringEnrichers.Add(enricher));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class EndpointTests
[Fact]
public void Uri_OK()
{
var endpoint = new Endpoint
var endpoint = new UriEndpoint
{
Uri = new Uri("https://localhost:5001")
};
Expand Down
Loading

0 comments on commit 9a4788a

Please sign in to comment.