Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flow dashboard logs through the app host's logger #3523

Merged
merged 1 commit into from
Apr 11, 2024

Conversation

davidfowl
Copy link
Member

@davidfowl davidfowl commented Apr 9, 2024

  • Subscribe to logs from the dashboard resources and print them to the console.

Fixes #2911

This pull request primarily focuses on enhancing the DashboardLifecycleHook class in the src/Aspire.Hosting/Dashboard/DashboardLifecycleHook.cs file. The changes include the addition of new dependencies, the implementation of the IAsyncDisposable interface, and the introduction of a method to watch and handle dashboard logs. Additionally, there are modifications to the DistributedApplicationBuilder class and updates to the unit tests to accommodate these changes.

Key changes include:

Addition of new dependencies:

  • src/Aspire.Hosting/Dashboard/DashboardLifecycleHook.cs: New dependencies were added to the DashboardLifecycleHook class, including ResourceNotificationService, ResourceLoggerService, and ILoggerFactory. This change allows the class to handle resource notifications and logs, and to create loggers.

Implementation of the IAsyncDisposable interface:

  • src/Aspire.Hosting/Dashboard/DashboardLifecycleHook.cs: The DashboardLifecycleHook class now implements the IAsyncDisposable interface, which provides a mechanism for releasing unmanaged resources asynchronously. A new DisposeAsync method was added to handle the disposal of resources.

Introduction of a method to watch and handle dashboard logs:

Updates to the DistributedApplicationBuilder class:

Updates to unit tests:

Microsoft Reviewers: Open in CodeFlow

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-codeflow for labeling automated codeflow. intentionally a different color! label Apr 9, 2024
@eerhardt
Copy link
Member

eerhardt commented Apr 9, 2024

Don't forgot to add tests.

@davidfowl davidfowl marked this pull request as ready for review April 11, 2024 00:57
@davidfowl davidfowl added the area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication label Apr 11, 2024
@@ -199,7 +199,7 @@ private async Task WatchDashboardLogsAsync()
try
{
// The dashboard resource isn't immediately available so watch for it.
// Wait 1 min for dashboard to startup and be reported before giving up.
// Wait for dashboard to startup and be reported before giving up.
using var cts = new CancellationTokenSource(TimeSpan.FromSeconds(30));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Get this timeout from options? 30 seconds isn't much time if you are trying to debug something.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Alternatively: increase for DEBUG builds, or detect if a debugger is attached (or both).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I made it a setting and also removed the timeout when debugging.

Copy link
Member

@mitchdenny mitchdenny left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. would be good to see the timeout put as an option we could change if necessary. Sometimes its helpful for debugging issues.

@davidfowl
Copy link
Member Author

This needs to show no logs by default. I'll make that change so that it's config enabled.

@dotnet-policy-service dotnet-policy-service bot added the needs-author-action An issue or pull request that requires more info or actions from the author. label Apr 11, 2024
@dotnet-policy-service dotnet-policy-service bot removed the needs-author-action An issue or pull request that requires more info or actions from the author. label Apr 11, 2024
@davidfowl davidfowl requested a review from JamesNK April 11, 2024 05:48
- Make the timeout waiting for dashboard logs configurable
- Disable all dashboard logging by default
- Allow config override for default logging categories
- Added tests
@davidfowl davidfowl enabled auto-merge (squash) April 11, 2024 06:28
@davidfowl davidfowl merged commit 34b84a9 into main Apr 11, 2024
8 checks passed
@davidfowl davidfowl deleted the davidfowl/dashboard-logs branch April 11, 2024 07:01
@davidfowl
Copy link
Member Author

/backport to release/8.0

Copy link
Contributor

Started backporting to release/8.0: https://github.com/dotnet/aspire/actions/runs/8642812237

@@ -76,11 +76,15 @@ public DistributedApplicationBuilder(DistributedApplicationOptions options)

_innerBuilder.Logging.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.Warning);
_innerBuilder.Logging.AddFilter("Microsoft.AspNetCore.Server.Kestrel", LogLevel.Error);
_innerBuilder.Logging.AddFilter("Aspire.Hosting.Dashboard", LogLevel.None);
Copy link
Member

@eerhardt eerhardt Apr 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the Dashboard crashes, the user doesn't get any indication of what happened, right? They just see a hang for a minute and then hopefully an error??

#3429

We should be at least logging errors by default.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can’t. I tried the playground samples and lots of other errors showed up.

I think it could be done if we filtered to the startup category by default, but it can’t be all errors.

@github-actions github-actions bot locked and limited conversation to collaborators May 12, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-app-model Issues pertaining to the APIs in Aspire.Hosting, e.g. DistributedApplication area-codeflow for labeling automated codeflow. intentionally a different color!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Option to write dashboard console logs in the host console
6 participants