Skip to content
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 @@ -725,9 +725,7 @@ internal async Task RefreshVaultTokenAsync(CancellationToken cancellationToken)
Uri uri = GetVaultRenewUri();
HttpRequestMessage message = await GetVaultRenewRequestMessageAsync(uri, cancellationToken);

_logger.LogInformation("Renewing Vault token {Token} for {Ttl} milliseconds at Uri {Uri}", obscuredToken, ClientOptions.TokenTtl,
uri.ToMaskedString());

_logger.LogDebug("Renewing Vault token {Token} for {Ttl} milliseconds at Uri {Uri}", obscuredToken, ClientOptions.TokenTtl, uri.ToMaskedString());
using HttpResponseMessage response = await httpClient.SendAsync(message, cancellationToken);

if (response.StatusCode != HttpStatusCode.OK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -246,8 +246,8 @@ private sealed class TestServiceInstance(Uri uri) : IServiceInstance
public int Port => throw new NotImplementedException();
public bool IsSecure => throw new NotImplementedException();
public Uri Uri { get; } = uri;
public Uri? NonSecureUri => throw new NotImplementedException();
public Uri? SecureUri => throw new NotImplementedException();
public Uri NonSecureUri => throw new NotImplementedException();
public Uri SecureUri => throw new NotImplementedException();
public IReadOnlyDictionary<string, string?> Metadata => throw new NotImplementedException();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,19 +40,22 @@ private async Task TimerLoopAsync(TimeSpan interval)
try
{
_logger.LogDebug("Starting periodic refresh loop with interval {Interval}.", interval);
bool isFirstTime = true;

do
{
_logger.LogDebug("Starting refresh cycle.");

try
{
await _runner.RunAsync(_timerTokenSource.Token);
await _runner.RunAsync(isFirstTime, _timerTokenSource.Token);
}
catch (Exception exception) when (!exception.IsCancellation())
{
_logger.LogWarning(exception, "Refresh cycle failed.");
}

isFirstTime = false;
}
while (await _periodicTimer.WaitForNextTickAsync(_timerTokenSource.Token));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ public SpringBootAdminRefreshRunner(AppUrlCalculator appUrlCalculator, SpringBoo
_logger = logger;
}

public async Task RunAsync(CancellationToken cancellationToken)
public async Task RunAsync(bool isFirstTime, CancellationToken cancellationToken)
{
_logger.LogDebug("Validating options.");
SpringBootAdminClientOptions clientOptions = _clientOptionsMonitor.CurrentValue;
Expand All @@ -66,7 +66,7 @@ public async Task RunAsync(CancellationToken cancellationToken)
await SafeUnregisterAsync(_lastGoodOptions, cancellationToken);
}

await RegisterAsync(clientOptions, cancellationToken);
await RegisterAsync(clientOptions, isFirstTime, cancellationToken);
}

private void ValidateAndSetOptions(SpringBootAdminClientOptions options)
Expand Down Expand Up @@ -124,11 +124,19 @@ private void ValidateAndSetOptions(SpringBootAdminClientOptions options)
}
}

private async Task RegisterAsync(SpringBootAdminClientOptions clientOptions, CancellationToken cancellationToken)
private async Task RegisterAsync(SpringBootAdminClientOptions clientOptions, bool isFirstTime, CancellationToken cancellationToken)
{
Application app = CreateApplication(new Uri(clientOptions.BaseUrl!), clientOptions);

_logger.LogInformation("Registering with Spring Boot Admin Server at {Url}.", clientOptions.Url);
if (isFirstTime)
{
_logger.LogInformation("Registering with Spring Boot Admin Server at {Url}.", clientOptions.Url);
}
else
{
_logger.LogDebug("Registering with Spring Boot Admin Server at {Url}.", clientOptions.Url);
}

_lastRegistrationId = await _springBootAdminApiClient.RegisterAsync(app, clientOptions, cancellationToken);
_lastGoodOptions = clientOptions;
}
Expand Down Expand Up @@ -175,7 +183,7 @@ private async Task SafeUnregisterAsync(SpringBootAdminClientOptions clientOption
{
try
{
_logger.LogInformation("Unregistering from Spring Boot Admin Server at {Url}.", clientOptions.Url);
_logger.LogDebug("Unregistering from Spring Boot Admin Server at {Url}.", clientOptions.Url);
await _springBootAdminApiClient.UnregisterAsync(_lastRegistrationId, clientOptions, cancellationToken);
_lastRegistrationId = null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public async Task BindsConfiguration()
app.Services.GetRequiredService<HttpClientHandlerFactory>().Using(handler);
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

await runner.RunAsync(TestContext.Current.CancellationToken);
await runner.RunAsync(true, TestContext.Current.CancellationToken);
SpringBootAdminClientOptions? options = runner.LastGoodOptions;

options.Should().NotBeNull();
Expand Down Expand Up @@ -116,7 +116,7 @@ public async Task FailsOnMissingConfiguration()
await using WebApplication app = builder.Build();
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

Func<Task> action = async () => await runner.RunAsync(TestContext.Current.CancellationToken);
Func<Task> action = async () => await runner.RunAsync(true, TestContext.Current.CancellationToken);

string[] errorsExpected =
[
Expand Down Expand Up @@ -145,7 +145,7 @@ public async Task FailsOnInvalidConfiguration()
await using WebApplication app = builder.Build();
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

Func<Task> action = async () => await runner.RunAsync(TestContext.Current.CancellationToken);
Func<Task> action = async () => await runner.RunAsync(true, TestContext.Current.CancellationToken);

string[] errorsExpected =
[
Expand Down Expand Up @@ -175,7 +175,7 @@ public async Task FailsWhenConfigurationForBasePathIsUrl()
await using WebApplication app = builder.Build();
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

Func<Task> action = async () => await runner.RunAsync(TestContext.Current.CancellationToken);
Func<Task> action = async () => await runner.RunAsync(true, TestContext.Current.CancellationToken);

await action.Should().ThrowExactlyAsync<OptionsValidationException>()
.WithMessage("Use BaseUrl instead of BasePath to configure the absolute URL to register with");
Expand All @@ -202,7 +202,7 @@ public async Task BindsApplicationNameFromSpringConfiguration()
app.Services.GetRequiredService<HttpClientHandlerFactory>().Using(handler);
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

await runner.RunAsync(TestContext.Current.CancellationToken);
await runner.RunAsync(true, TestContext.Current.CancellationToken);
SpringBootAdminClientOptions? options = runner.LastGoodOptions;

options.Should().NotBeNull();
Expand Down Expand Up @@ -249,7 +249,7 @@ public async Task SendsRegisterRequestForDefaultConfiguration()
app.Services.GetRequiredService<HttpClientHandlerFactory>().Using(handler);
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

await runner.RunAsync(TestContext.Current.CancellationToken);
await runner.RunAsync(true, TestContext.Current.CancellationToken);

runner.LastRegistrationId.Should().Be("1234567");
runner.LastGoodOptions.Should().NotBeNull();
Expand Down Expand Up @@ -301,7 +301,7 @@ public async Task SendsRegisterRequestForCustomConfiguration()
app.Services.GetRequiredService<HttpClientHandlerFactory>().Using(handler);
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();

await runner.RunAsync(TestContext.Current.CancellationToken);
await runner.RunAsync(true, TestContext.Current.CancellationToken);

runner.LastRegistrationId.Should().Be("1234567");
runner.LastGoodOptions.Should().NotBeNull();
Expand Down