Skip to content

Commit cfc15ca

Browse files
authored
Lower the level of recurring logging to reduce noise in apps (#1608)
* Reduce the level of recurring logging to reduce noise in apps * Remove redundant ? * Log at Info level only the first time
1 parent 883f326 commit cfc15ca

File tree

5 files changed

+27
-18
lines changed

5 files changed

+27
-18
lines changed

src/Configuration/src/ConfigServer/ConfigServerConfigurationProvider.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -725,9 +725,7 @@ internal async Task RefreshVaultTokenAsync(CancellationToken cancellationToken)
725725
Uri uri = GetVaultRenewUri();
726726
HttpRequestMessage message = await GetVaultRenewRequestMessageAsync(uri, cancellationToken);
727727

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

733731
if (response.StatusCode != HttpStatusCode.OK)

src/Discovery/test/HttpClients.Test/LoadBalancers/RoundRobinLoadBalancerTest.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,8 @@ private sealed class TestServiceInstance(Uri uri) : IServiceInstance
246246
public int Port => throw new NotImplementedException();
247247
public bool IsSecure => throw new NotImplementedException();
248248
public Uri Uri { get; } = uri;
249-
public Uri? NonSecureUri => throw new NotImplementedException();
250-
public Uri? SecureUri => throw new NotImplementedException();
249+
public Uri NonSecureUri => throw new NotImplementedException();
250+
public Uri SecureUri => throw new NotImplementedException();
251251
public IReadOnlyDictionary<string, string?> Metadata => throw new NotImplementedException();
252252
}
253253

src/Management/src/Endpoint/SpringBootAdminClient/SpringBootAdminPeriodicRefresh.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,19 +40,22 @@ private async Task TimerLoopAsync(TimeSpan interval)
4040
try
4141
{
4242
_logger.LogDebug("Starting periodic refresh loop with interval {Interval}.", interval);
43+
bool isFirstTime = true;
4344

4445
do
4546
{
4647
_logger.LogDebug("Starting refresh cycle.");
4748

4849
try
4950
{
50-
await _runner.RunAsync(_timerTokenSource.Token);
51+
await _runner.RunAsync(isFirstTime, _timerTokenSource.Token);
5152
}
5253
catch (Exception exception) when (!exception.IsCancellation())
5354
{
5455
_logger.LogWarning(exception, "Refresh cycle failed.");
5556
}
57+
58+
isFirstTime = false;
5659
}
5760
while (await _periodicTimer.WaitForNextTickAsync(_timerTokenSource.Token));
5861
}

src/Management/src/Endpoint/SpringBootAdminClient/SpringBootAdminRefreshRunner.cs

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public SpringBootAdminRefreshRunner(AppUrlCalculator appUrlCalculator, SpringBoo
5454
_logger = logger;
5555
}
5656

57-
public async Task RunAsync(CancellationToken cancellationToken)
57+
public async Task RunAsync(bool isFirstTime, CancellationToken cancellationToken)
5858
{
5959
_logger.LogDebug("Validating options.");
6060
SpringBootAdminClientOptions clientOptions = _clientOptionsMonitor.CurrentValue;
@@ -66,7 +66,7 @@ public async Task RunAsync(CancellationToken cancellationToken)
6666
await SafeUnregisterAsync(_lastGoodOptions, cancellationToken);
6767
}
6868

69-
await RegisterAsync(clientOptions, cancellationToken);
69+
await RegisterAsync(clientOptions, isFirstTime, cancellationToken);
7070
}
7171

7272
private void ValidateAndSetOptions(SpringBootAdminClientOptions options)
@@ -124,11 +124,19 @@ private void ValidateAndSetOptions(SpringBootAdminClientOptions options)
124124
}
125125
}
126126

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

131-
_logger.LogInformation("Registering with Spring Boot Admin Server at {Url}.", clientOptions.Url);
131+
if (isFirstTime)
132+
{
133+
_logger.LogInformation("Registering with Spring Boot Admin Server at {Url}.", clientOptions.Url);
134+
}
135+
else
136+
{
137+
_logger.LogDebug("Registering with Spring Boot Admin Server at {Url}.", clientOptions.Url);
138+
}
139+
132140
_lastRegistrationId = await _springBootAdminApiClient.RegisterAsync(app, clientOptions, cancellationToken);
133141
_lastGoodOptions = clientOptions;
134142
}
@@ -175,7 +183,7 @@ private async Task SafeUnregisterAsync(SpringBootAdminClientOptions clientOption
175183
{
176184
try
177185
{
178-
_logger.LogInformation("Unregistering from Spring Boot Admin Server at {Url}.", clientOptions.Url);
186+
_logger.LogDebug("Unregistering from Spring Boot Admin Server at {Url}.", clientOptions.Url);
179187
await _springBootAdminApiClient.UnregisterAsync(_lastRegistrationId, clientOptions, cancellationToken);
180188
_lastRegistrationId = null;
181189
}

src/Management/test/Endpoint.Test/SpringBootAdminClient/SpringBootAdminRefreshRunnerTest.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ public async Task BindsConfiguration()
8383
app.Services.GetRequiredService<HttpClientHandlerFactory>().Using(handler);
8484
var runner = app.Services.GetRequiredService<SpringBootAdminRefreshRunner>();
8585

86-
await runner.RunAsync(TestContext.Current.CancellationToken);
86+
await runner.RunAsync(true, TestContext.Current.CancellationToken);
8787
SpringBootAdminClientOptions? options = runner.LastGoodOptions;
8888

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

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

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

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

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

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

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

205-
await runner.RunAsync(TestContext.Current.CancellationToken);
205+
await runner.RunAsync(true, TestContext.Current.CancellationToken);
206206
SpringBootAdminClientOptions? options = runner.LastGoodOptions;
207207

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

252-
await runner.RunAsync(TestContext.Current.CancellationToken);
252+
await runner.RunAsync(true, TestContext.Current.CancellationToken);
253253

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

304-
await runner.RunAsync(TestContext.Current.CancellationToken);
304+
await runner.RunAsync(true, TestContext.Current.CancellationToken);
305305

306306
runner.LastRegistrationId.Should().Be("1234567");
307307
runner.LastGoodOptions.Should().NotBeNull();

0 commit comments

Comments
 (0)