Skip to content

Commit

Permalink
Service Discovery API refactoring (#3114)
Browse files Browse the repository at this point in the history
* API review feedback & general cleanup including removal of currently unused features

* Align namespaces

* Hide more of the API, rename for consistency

* Hide more, rename more

* ResolutionStatus does not need to be equatable

* Make ServiceEndPointQuery public to break InternalsVisibleTo with Dns provider

* Break InternalsVisibleTo from ServiceDiscovery package to YARP by adding a middleware factory

* Remove ResolutionStatus, simplifying Service Discovery interfaces

* Clean up ServiceEndPointImpl

* Mark ServiceEndPointResolverResult as internal

* Remove unnecessary members from ServiceEndPointCollection/Source

* Seal service discovery types

* Remove IServiceEndPointSelectorFactory and use DI instead

* Remove unused endpoint selectors

* Remove unused PendingStatusRefreshPeriod option

* Rename UseServiceDiscovery to AddServiceDiscovery

* Remove possible ambiguity in AddConfigurationServiceEndPointResolver signature

* Add configuration delegate overloads to AddServiceDiscovery methods

* Clean up logging in configuration-based service endpoint provider

* API review: rename ServiceEndPointCollectionSource to IServiceEndPointBuilder

* Rename IServiceDiscoveryDelegatingHttpMessageHandlerFactory

* Rename IServiceEndPointProvider.ResolveAsync to PopulateAsync

* Hide IServiceEndPointSelector

* Remove allowedSchemes from ServiceEndPointQuery.TryParse

* Rename ServiceEndPointQuery.Host to .ServiceName

* Fix build

* Review feedback

* nit param rename

* Improve ServiceEndPointQuery.ToString output

* fixup
  • Loading branch information
ReubenBond authored Mar 26, 2024
1 parent ac2b068 commit 23104ee
Show file tree
Hide file tree
Showing 74 changed files with 695 additions and 1,291 deletions.
2 changes: 1 addition & 1 deletion playground/AWS/AWS.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.UseServiceDiscovery();
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
Expand Down
2 changes: 1 addition & 1 deletion playground/Playground.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.UseServiceDiscovery();
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
Expand Down
2 changes: 1 addition & 1 deletion playground/TestShop/ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.UseServiceDiscovery();
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
Expand Down
2 changes: 1 addition & 1 deletion playground/orleans/OrleansServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.UseServiceDiscovery();
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
Expand Down
2 changes: 1 addition & 1 deletion playground/seq/Seq.ServiceDefaults/Extensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public static IHostApplicationBuilder AddServiceDefaults(this IHostApplicationBu
http.AddStandardResilienceHandler();

// Turn on service discovery by default
http.UseServiceDiscovery();
http.AddServiceDiscovery();
});

// Uncomment the following to restrict the allowed schemes for service discovery.
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.Extensions.ServiceDiscovery.Abstractions;
namespace Microsoft.Extensions.ServiceDiscovery;

/// <summary>
/// Exposes the host name of the end point.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.Primitives;

namespace Microsoft.Extensions.ServiceDiscovery;

/// <summary>
/// Builder to create a <see cref="ServiceEndPointSource"/> instances.
/// </summary>
public interface IServiceEndPointBuilder
{
/// <summary>
/// Gets the endpoints.
/// </summary>
IList<ServiceEndPoint> EndPoints { get; }

/// <summary>
/// Gets the feature collection.
/// </summary>
IFeatureCollection Features { get; }

/// <summary>
/// Adds a change token to the resulting <see cref="ServiceEndPointSource"/>.
/// </summary>
/// <param name="changeToken">The change token.</param>
void AddChangeToken(IChangeToken changeToken);
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.

namespace Microsoft.Extensions.ServiceDiscovery.Abstractions;
namespace Microsoft.Extensions.ServiceDiscovery;

/// <summary>
/// Provides details about a service's endpoints.
Expand All @@ -14,5 +14,5 @@ public interface IServiceEndPointProvider : IAsyncDisposable
/// <param name="endPoints">The endpoint collection, which resolved endpoints will be added to.</param>
/// <param name="cancellationToken">The token to monitor for cancellation requests.</param>
/// <returns>The resolution status.</returns>
ValueTask<ResolutionStatus> ResolveAsync(ServiceEndPointCollectionSource endPoints, CancellationToken cancellationToken);
ValueTask PopulateAsync(IServiceEndPointBuilder endPoints, CancellationToken cancellationToken);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@

using System.Diagnostics.CodeAnalysis;

namespace Microsoft.Extensions.ServiceDiscovery.Abstractions;
namespace Microsoft.Extensions.ServiceDiscovery;

/// <summary>
/// Creates <see cref="IServiceEndPointProvider"/> instances.
/// </summary>
public interface IServiceEndPointResolverProvider
public interface IServiceEndPointProviderFactory
{
/// <summary>
/// Tries to create an <see cref="IServiceEndPointProvider"/> instance for the specified <paramref name="serviceName"/>.
/// Tries to create an <see cref="IServiceEndPointProvider"/> instance for the specified <paramref name="query"/>.
/// </summary>
/// <param name="serviceName">The service to create the resolver for.</param>
/// <param name="query">The service to create the resolver for.</param>
/// <param name="resolver">The resolver.</param>
/// <returns><see langword="true"/> if the resolver was created, <see langword="false"/> otherwise.</returns>
bool TryCreateResolver(string serviceName, [NotNullWhen(true)] out IServiceEndPointProvider? resolver);
bool TryCreateProvider(ServiceEndPointQuery query, [NotNullWhen(true)] out IServiceEndPointProvider? resolver);
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,11 @@
using System.Net;
using Microsoft.AspNetCore.Http.Features;

namespace Microsoft.Extensions.ServiceDiscovery.Abstractions;
namespace Microsoft.Extensions.ServiceDiscovery.Internal;

internal sealed class ServiceEndPointImpl : ServiceEndPoint
internal sealed class ServiceEndPointImpl(EndPoint endPoint, IFeatureCollection? features = null) : ServiceEndPoint
{
private readonly IFeatureCollection _features;
private readonly EndPoint _endPoint;

public ServiceEndPointImpl(EndPoint endPoint, IFeatureCollection? features = null)
{
_endPoint = endPoint;
_features = features ?? new FeatureCollection();
}

public override EndPoint EndPoint => _endPoint;
public override IFeatureCollection Features => _features;

public override EndPoint EndPoint { get; } = endPoint;
public override IFeatureCollection Features { get; } = features ?? new FeatureCollection();
public override string? ToString() => GetEndPointString();
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@
using System.Diagnostics;
using System.Net;
using Microsoft.AspNetCore.Http.Features;
using Microsoft.Extensions.ServiceDiscovery.Internal;

namespace Microsoft.Extensions.ServiceDiscovery.Abstractions;
namespace Microsoft.Extensions.ServiceDiscovery;

/// <summary>
/// Represents an endpoint for a service.
Expand Down
Loading

0 comments on commit 23104ee

Please sign in to comment.