Skip to content

Commit 0f5debe

Browse files
authored
Add more logging to CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfiguredKey (dotnet#4638)
1 parent 7860984 commit 0f5debe

File tree

3 files changed

+33
-3
lines changed

3 files changed

+33
-3
lines changed

src/Aspire.Dashboard/Configuration/PostConfigureDashboardOptions.cs

+10-1
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,30 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Aspire.Hosting;
5+
using Microsoft.Extensions.Logging.Abstractions;
56
using Microsoft.Extensions.Options;
67

78
namespace Aspire.Dashboard.Configuration;
89

910
public sealed class PostConfigureDashboardOptions : IPostConfigureOptions<DashboardOptions>
1011
{
1112
private readonly IConfiguration _configuration;
13+
private readonly ILogger _logger;
1214

13-
public PostConfigureDashboardOptions(IConfiguration configuration)
15+
public PostConfigureDashboardOptions(IConfiguration configuration) : this(configuration, NullLogger<PostConfigureDashboardOptions>.Instance)
16+
{
17+
}
18+
19+
public PostConfigureDashboardOptions(IConfiguration configuration, ILogger<PostConfigureDashboardOptions> logger)
1420
{
1521
_configuration = configuration;
22+
_logger = logger;
1623
}
1724

1825
public void PostConfigure(string? name, DashboardOptions options)
1926
{
27+
_logger.LogDebug($"PostConfigure {nameof(DashboardOptions)} with name '{name}'.");
28+
2029
// Copy aliased config values to the strongly typed options.
2130
if (_configuration[DashboardConfigNames.DashboardOtlpGrpcUrlName.ConfigKey] is { Length: > 0 } otlpGrpcUrl)
2231
{

src/Aspire.Dashboard/Configuration/ValidateDashboardOptions.cs

+14
Original file line numberDiff line numberDiff line change
@@ -2,14 +2,28 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using Aspire.Hosting;
5+
using Microsoft.Extensions.Logging.Abstractions;
56
using Microsoft.Extensions.Options;
67

78
namespace Aspire.Dashboard.Configuration;
89

910
public sealed class ValidateDashboardOptions : IValidateOptions<DashboardOptions>
1011
{
12+
private readonly ILogger _logger;
13+
14+
public ValidateDashboardOptions() : this(NullLogger<ValidateDashboardOptions>.Instance)
15+
{
16+
}
17+
18+
public ValidateDashboardOptions(ILogger<ValidateDashboardOptions> logger)
19+
{
20+
_logger = logger;
21+
}
22+
1123
public ValidateOptionsResult Validate(string? name, DashboardOptions options)
1224
{
25+
_logger.LogDebug($"Validating {nameof(DashboardOptions)}.");
26+
1327
var errorMessages = new List<string>();
1428

1529
if (!options.Frontend.TryParseOptions(out var frontendParseErrorMessage))

tests/Aspire.Dashboard.Tests/Integration/OtlpGrpcServiceTests.cs

+9-2
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,8 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi
166166
}
167167
}
168168
};
169-
File.WriteAllText(configPath, configJson.ToString());
169+
_testOutputHelper.WriteLine("Writing original JSON file.");
170+
await File.WriteAllTextAsync(configPath, configJson.ToString());
170171

171172
var testSink = new TestSink();
172173
await using var app = IntegrationTestHelpers.CreateDashboardWebApplication(_testOutputHelper, config =>
@@ -178,6 +179,7 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi
178179
var tcs = new TaskCompletionSource(TaskCreationOptions.RunContinuationsAsynchronously);
179180
using var monitorRegistration = app.DashboardOptionsMonitor.OnChange((o, n) =>
180181
{
182+
_testOutputHelper.WriteLine("Options changed.");
181183
tcs.TrySetResult();
182184
});
183185

@@ -207,10 +209,15 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi
207209
}
208210
}
209211
};
210-
File.WriteAllText(configPath, configJson.ToString());
211212

213+
_testOutputHelper.WriteLine("Writing new JSON file.");
214+
await File.WriteAllTextAsync(configPath, configJson.ToString());
215+
216+
_testOutputHelper.WriteLine("Waiting for options change.");
212217
await tcs.Task;
213218

219+
Assert.Equal("Different", app.DashboardOptionsMonitor.CurrentValue.Otlp.PrimaryApiKey);
220+
214221
// Act 2
215222
var ex = await Assert.ThrowsAsync<RpcException>(() => client.ExportAsync(new ExportLogsServiceRequest(), metadata).ResponseAsync);
216223

0 commit comments

Comments
 (0)