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

Remove IServiceEndPointResolver.DisplayName property and use ToString() instead #1761

Merged
merged 1 commit into from
Jan 23, 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
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,6 @@ namespace Microsoft.Extensions.ServiceDiscovery.Abstractions;
/// </summary>
public interface IServiceEndPointResolver : IAsyncDisposable
{
/// <summary>
/// Gets the diagnostic display name for this resolver.
/// </summary>
string DisplayName { get; }

/// <summary>
/// Attempts to resolve the endpoints for the service which this instance is configured to resolve endpoints for.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ internal sealed partial class DnsServiceEndPointResolver(
string IHostNameFeature.HostName => hostName;

/// <inheritdoc/>
public override string DisplayName => "DNS";
public override string ToString() => "DNS";

protected override async Task ResolveAsyncCore()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,18 @@ protected DnsServiceEndPointResolverBase(
_lastChangeToken = new CancellationChangeToken(cancellation.Token);
}

public abstract string DisplayName { get; }

private TimeSpan ElapsedSinceRefresh => _timeProvider.GetElapsedTime(_lastRefreshTimeStamp);

protected string ServiceName { get; }

protected abstract double RetryBackOffFactor { get; }

protected abstract TimeSpan MinRetryPeriod { get; }

protected abstract TimeSpan MaxRetryPeriod { get; }

protected abstract TimeSpan DefaultRefreshPeriod { get; }

protected CancellationToken ShutdownToken => _disposeCancellation.Token;

/// <inheritdoc/>
Expand Down Expand Up @@ -116,7 +118,9 @@ private async Task ResolveAsyncInternal()
}

protected void SetException(Exception exception) => SetResult(endPoints: null, exception, validityPeriod: TimeSpan.Zero);

protected void SetResult(List<ServiceEndPoint> endPoints, TimeSpan validityPeriod) => SetResult(endPoints, exception: null, validityPeriod);

private void SetResult(List<ServiceEndPoint>? endPoints, Exception? exception, TimeSpan validityPeriod)
{
lock (_lock)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,14 @@ internal sealed partial class DnsSrvServiceEndPointResolver(
TimeProvider timeProvider) : DnsServiceEndPointResolverBase(serviceName, logger, timeProvider), IHostNameFeature
{
protected override double RetryBackOffFactor => options.CurrentValue.RetryBackOffFactor;

protected override TimeSpan MinRetryPeriod => options.CurrentValue.MinRetryPeriod;

protected override TimeSpan MaxRetryPeriod => options.CurrentValue.MaxRetryPeriod;

protected override TimeSpan DefaultRefreshPeriod => options.CurrentValue.DefaultRefreshPeriod;

public override string DisplayName => "DNS SRV";
public override string ToString() => "DNS SRV";

string IHostNameFeature.HostName => hostName;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,6 @@ public ConfigurationServiceEndPointResolver(
_options = options;
}

/// <inheritdoc/>
public string DisplayName => "Configuration";

/// <inheritdoc/>
public ValueTask DisposeAsync() => default;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,6 @@ namespace Microsoft.Extensions.ServiceDiscovery.PassThrough;
/// </summary>
internal sealed partial class PassThroughServiceEndPointResolver(ILogger logger, string serviceName, EndPoint endPoint) : IServiceEndPointResolver
{
public string DisplayName => "Pass-through";

public ValueTask<ResolutionStatus> ResolveAsync(ServiceEndPointCollectionSource endPoints, CancellationToken cancellationToken)
{
if (endPoints.EndPoints.Count != 0)
Expand All @@ -29,4 +27,6 @@ public ValueTask<ResolutionStatus> ResolveAsync(ServiceEndPointCollectionSource
}

public ValueTask DisposeAsync() => default;

public override string ToString() => "Pass-through";
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ static string GetEndPointString(ServiceEndPoint ep)
{
if (ep.Features.Get<IServiceEndPointResolver>() is { } resolver)
{
return $"{ep.GetEndPointString()} ({resolver.DisplayName})";
return $"{ep.GetEndPointString()} ({resolver})";
}

return ep.GetEndPointString();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static void CreatingResolver(ILogger logger, string serviceName, List<ISe
{
if (logger.IsEnabled(LogLevel.Debug))
{
ServiceEndPointResolverListCore(logger, serviceName, resolvers.Count, string.Join(", ", resolvers.Select(static r => r.DisplayName)));
ServiceEndPointResolverListCore(logger, serviceName, resolvers.Count, string.Join(", ", resolvers.Select(static r => r.ToString())));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,6 @@ public bool TryCreateResolver(string serviceName, [NotNullWhen(true)] out IServi

private sealed class FakeEndPointResolver(Func<ServiceEndPointCollectionSource, CancellationToken, ValueTask<ResolutionStatus>> resolveAsync, Func<ValueTask> disposeAsync) : IServiceEndPointResolver
{
public string DisplayName => "Fake";

public ValueTask<ResolutionStatus> ResolveAsync(ServiceEndPointCollectionSource endPoints, CancellationToken cancellationToken) => resolveAsync(endPoints, cancellationToken);
public ValueTask DisposeAsync() => disposeAsync();
}
Expand Down
Loading