File tree 3 files changed +33
-3
lines changed
src/Aspire.Dashboard/Configuration
tests/Aspire.Dashboard.Tests/Integration
3 files changed +33
-3
lines changed Original file line number Diff line number Diff line change 2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using Aspire . Hosting ;
5
+ using Microsoft . Extensions . Logging . Abstractions ;
5
6
using Microsoft . Extensions . Options ;
6
7
7
8
namespace Aspire . Dashboard . Configuration ;
8
9
9
10
public sealed class PostConfigureDashboardOptions : IPostConfigureOptions < DashboardOptions >
10
11
{
11
12
private readonly IConfiguration _configuration ;
13
+ private readonly ILogger _logger ;
12
14
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 )
14
20
{
15
21
_configuration = configuration ;
22
+ _logger = logger ;
16
23
}
17
24
18
25
public void PostConfigure ( string ? name , DashboardOptions options )
19
26
{
27
+ _logger . LogDebug ( $ "PostConfigure { nameof ( DashboardOptions ) } with name '{ name } '.") ;
28
+
20
29
// Copy aliased config values to the strongly typed options.
21
30
if ( _configuration [ DashboardConfigNames . DashboardOtlpGrpcUrlName . ConfigKey ] is { Length : > 0 } otlpGrpcUrl )
22
31
{
Original file line number Diff line number Diff line change 2
2
// The .NET Foundation licenses this file to you under the MIT license.
3
3
4
4
using Aspire . Hosting ;
5
+ using Microsoft . Extensions . Logging . Abstractions ;
5
6
using Microsoft . Extensions . Options ;
6
7
7
8
namespace Aspire . Dashboard . Configuration ;
8
9
9
10
public sealed class ValidateDashboardOptions : IValidateOptions < DashboardOptions >
10
11
{
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
+
11
23
public ValidateOptionsResult Validate ( string ? name , DashboardOptions options )
12
24
{
25
+ _logger . LogDebug ( $ "Validating { nameof ( DashboardOptions ) } .") ;
26
+
13
27
var errorMessages = new List < string > ( ) ;
14
28
15
29
if ( ! options . Frontend . TryParseOptions ( out var frontendParseErrorMessage ) )
Original file line number Diff line number Diff line change @@ -166,7 +166,8 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi
166
166
}
167
167
}
168
168
} ;
169
- File . WriteAllText ( configPath , configJson . ToString ( ) ) ;
169
+ _testOutputHelper . WriteLine ( "Writing original JSON file." ) ;
170
+ await File . WriteAllTextAsync ( configPath , configJson . ToString ( ) ) ;
170
171
171
172
var testSink = new TestSink ( ) ;
172
173
await using var app = IntegrationTestHelpers . CreateDashboardWebApplication ( _testOutputHelper , config =>
@@ -178,6 +179,7 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi
178
179
var tcs = new TaskCompletionSource ( TaskCreationOptions . RunContinuationsAsynchronously ) ;
179
180
using var monitorRegistration = app . DashboardOptionsMonitor . OnChange ( ( o , n ) =>
180
181
{
182
+ _testOutputHelper . WriteLine ( "Options changed." ) ;
181
183
tcs . TrySetResult ( ) ;
182
184
} ) ;
183
185
@@ -207,10 +209,15 @@ public async Task CallService_OtlpGrpcEndPoint_ExternalFile_FileChanged_UseConfi
207
209
}
208
210
}
209
211
} ;
210
- File . WriteAllText ( configPath , configJson . ToString ( ) ) ;
211
212
213
+ _testOutputHelper . WriteLine ( "Writing new JSON file." ) ;
214
+ await File . WriteAllTextAsync ( configPath , configJson . ToString ( ) ) ;
215
+
216
+ _testOutputHelper . WriteLine ( "Waiting for options change." ) ;
212
217
await tcs . Task ;
213
218
219
+ Assert . Equal ( "Different" , app . DashboardOptionsMonitor . CurrentValue . Otlp . PrimaryApiKey ) ;
220
+
214
221
// Act 2
215
222
var ex = await Assert . ThrowsAsync < RpcException > ( ( ) => client . ExportAsync ( new ExportLogsServiceRequest ( ) , metadata ) . ResponseAsync ) ;
216
223
You can’t perform that action at this time.
0 commit comments