Skip to content

Commit

Permalink
More logging and fix
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNK committed Sep 14, 2024
1 parent fcd29a0 commit 2b5ab7c
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
11 changes: 9 additions & 2 deletions src/Aspire.Dashboard/Components/Controls/LogViewer.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,13 @@ public sealed partial class LogViewer
public required BrowserTimeProvider TimeProvider { get; init; }

[Inject]
public required DimensionManager DimensionManager { get; set; }
public required DimensionManager DimensionManager { get; init; }

[Inject]
public required IOptions<DashboardOptions> Options { get; set; }
public required ILogger<LogViewer> Logger { get; init; }

[Inject]
public required IOptions<DashboardOptions> Options { get; init; }

internal LogEntries LogEntries { get; set; } = null!;

Expand Down Expand Up @@ -66,6 +69,8 @@ private void OnBrowserResize(object? o, EventArgs args)

internal async Task SetLogSourceAsync(string resourceName, IAsyncEnumerable<IReadOnlyList<ResourceLogLine>> batches, bool convertTimestampsFromUtc = true)
{
Logger.LogDebug("Setting log source to {ResourceName}.", resourceName);

ResourceName = resourceName;

System.Diagnostics.Debug.Assert(LogEntries.GetEntries().Count == 0, "Expecting zero log entries");
Expand Down Expand Up @@ -108,6 +113,8 @@ private string GetDisplayTimestamp(DateTimeOffset timestamp)

internal async Task ClearLogsAsync()
{
Logger.LogDebug("Clearing logs for {ResourceName}.", ResourceName);

await _cancellationSeries.ClearAsync();

_applicationChanged = true;
Expand Down
3 changes: 3 additions & 0 deletions src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -290,6 +290,7 @@ private async ValueTask LoadLogsAsync()
{
try
{
Logger.LogDebug("Waiting for console logs subscription {ResourceName} to finished.", resourceSubscriptionName);
await task;
}
finally
Expand All @@ -298,6 +299,8 @@ private async ValueTask LoadLogsAsync()
_subscriptionResourceName = null;
PageViewModel.Status = Loc[nameof(Dashboard.Resources.ConsoleLogs.ConsoleLogsFinishedWatchingLogs)];
await InvokeAsync(StateHasChanged);
}
});
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ public void ResourceName_MultiRender_SubscribeConsoleLogsOnce()

var instance = cut.Instance;
var logger = Services.GetRequiredService<ILogger<ConsoleLogsTests>>();
var loc = Services.GetRequiredService<IStringLocalizer<Resources.ConsoleLogs>>();

logger.LogInformation("Console log page is waiting for resource.");
cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsLoadingResources)]);

var testResource = CreateResourceViewModel("test-resource", KnownResourceState.Running);
resourceChannel.Writer.TryWrite([
Expand All @@ -70,6 +74,7 @@ public void ResourceName_MultiRender_SubscribeConsoleLogsOnce()
// Assert
logger.LogInformation("Waiting for selected resource.");
cut.WaitForState(() => instance.PageViewModel.SelectedResource == testResource);
cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsWatchingLogs)]);

// Ensure component is rendered again.
cut.SetParametersAndRender(builder => { });
Expand All @@ -78,7 +83,6 @@ public void ResourceName_MultiRender_SubscribeConsoleLogsOnce()
consoleLogsChannel.Writer.Complete();

logger.LogInformation("Waiting for finish message.");
var loc = Services.GetRequiredService<IStringLocalizer<Resources.ConsoleLogs>>();
cut.WaitForState(() => instance.PageViewModel.Status == loc[nameof(Resources.ConsoleLogs.ConsoleLogsFinishedWatchingLogs)]);

Assert.Equal("test-resource", Assert.Single(subscribedResourceNames));
Expand Down

0 comments on commit 2b5ab7c

Please sign in to comment.