Skip to content

Run dashboard out-of-process - #1667

Merged
Drew Noakes (drewnoakes) merged 3 commits into
microsoft:feature/dashboard-oopfrom
drewnoakes:dashboard-oop
Jan 19, 2024
Merged

Drew Noakes (drewnoakes) merged 3 commits into
microsoft:feature/dashboard-oopfrom
drewnoakes:dashboard-oop

Conversation

@drewnoakes

@drewnoakes Drew Noakes (drewnoakes) commented Jan 16, 2024 •

Copy link
Copy Markdown
Member

Fixes #1003
Fixes #851

This change causes the dashboard to be run as an orchestrated project, just like any other Aspire resource.

To achieve this, we:

  • Break the project dependency from AppHost upon Dashboard.
    • Until we have support for dotnet tool resources, having the sample projects depend upon the dashboard directly, and register them with the DAB.
    • Copy TimestampParser.DisplayFormat into Aspire.Hosting.Dashboard.ConsoleLogsConfigurationExtensions where it was used, and add comments to keep them in sync.
  • Have the dashboard wire up its own web application.
    • Remove DashboardWebApplicationHost.
    • Remove dashboard-specific code from DistributedApplicationBuilder.
    • Update URLs to resources defined in the dashboard. They no longer need (or work with) the _content/Aspire.Dashboard/ prefix.
    • Remove workarounds/configuration to support static web assets, as the new structure supports this automatically.
    • Link KnownProperties and KnownResourceTypes into the hosting project, so both projects can share the definition without needing an assembly reference.
  • Change the MSBuild SDK for the dashboard from Razor Class Library to Web project.
    • Remove explicit framework reference.
    • Remove redundant using directives (the new SDK has different implicit usings).
    • Make the dashboard an executable.
    • Update the CSS bundle file name (from Aspire.Dashboard.bundle.scp.css to Aspire.Dashboard.styles.css)

This work is incomplete for a few reasons:

  1. Aspire users won't be able to create a project reference to the dashboard. That only works in this solution. We need support for resources defined via dotnet tool packages before we can fix that.
  2. We don't launch a browser to the dashboard any more. You have to find the URL in the logs and launch it.

We will need to address those issues before the changes here can be merged.


To test this locally, run any of the sample applications. To find the dashboard's URL, navigate to %TEMP% and find the relevant log files. For example, %TEMP%\aspire.oweozx1d.bmh\dashboard-5buv5so_out_eedbad51-0294-4ff8-9add-001f27499206 (your IDs will be different). The first log message should read Now listening on: https://localhost:49337 or similar. Open that URL in a browser.


Open questions before this can be marked as ready for review:

  • We need DAM to support dotnet tool-based resources. When will that be available, and what APIs do we want?
  • How do we preserve the development experience in this repo once we integrate dotnet tools? We want to be able to change the dashboard and hit F5.
  • How to open a browser at the dashboard during launch in this model?
  • Do we have to ensure the dashboard is running before other orchestrated processes start? We don't want to lose any OTEL data. See comments below about retry logic.

We should also consider to:

  • Improve the experience when the resource service is unavailable.

Screenshots

image

image

Microsoft Reviewers: Open in CodeFlow

This change causes the dashboard to be run as an orchestrated project, just like any other Aspire resource.

To achieve this, we:

- Break the project dependency from AppHost upon Dashboard.
  - Until we have support for dotnet tool resources, having the sample projects depend upon the dashboard directly, and register them with the DAB.
  - Copy `TimestampParser.DisplayFormat` into `Aspire.Hosting.Dashboard.ConsoleLogsConfigurationExtensions` where it was used, and add comments to keep them in sync.
- Have the dashboard wire up its own web application.
  - Remove `DashboardWebApplicationHost`.
  - Remove dashboard-specific code from `DistributedApplicationBuilder`.
  - Update URLs to resources defined in the dashboard. They no longer need (or work with) the `_content/Aspire.Dashboard/` prefix.
  - Remove workarounds/configuration to support static web assets, as the new structure supports this automatically.
  - Link `KnownProperties` and `KnownResourceTypes` into the hosting project, so both projects can share the definition without needing an assembly reference.
- Change the MSBuild SDK for the dashboard from Razor Class Library to Web project.
  - Remove explicit framework reference.
  - Remove redundant using directives (the new SDK has different implicit usings).
  - Make the dashboard an executable.
  - Update the CSS bundle file name (from `Aspire.Dashboard.bundle.scp.css` to `Aspire.Dashboard.styles.css`)

This work is incomplete for a few reasons:

1. Aspire users won't be able to create a project reference to the dashboard. That only works in this solution. We need support for resources defined via `dotnet tool` packages before we can fix that.
2. We don't launch a browser to the dashboard any more. You have to find the URL in the logs and launch it.

We will need to address those issues before the changes here can be merged.

---

To test this locally, run any of the sample applications. To find the dashboard's URL, navigate to `%TEMP%` and find the relevant log files. For example, `%TEMP%\aspire.oweozx1d.bmh\dashboard-5buv5so_out_eedbad51-0294-4ff8-9add-001f27499206` (your IDs will be different). The first log message should read _Now listening on: https://localhost:49337_ or similar. Open that URL in a browser.
@JamesNK

James Newton-King (JamesNK) commented Jan 16, 2024 •

Copy link
Copy Markdown
Member

This change causes the dashboard to be run as an orchestrated project, just like any other Aspire resource.

A problem that occurs to me with treating the dashboard as a resource is the order things are loaded. Today the dashboard starts up at the same time other services are initialized. It has a head start on resources. By the time orchestrated resources are loaded and OTLP data is sent to the dashboard, the dashboard is ready to receive it.

If the dashboard is loaded alongside other resources, then other resources could send OTLP data to the dashboard that isn't ready yet. Data could be lost.

The OTLP spec says SDKs should support retries. Unfortunately the .NET OTEL SDK has infrastructure for retries, but nothing uses it yet: open-telemetry/opentelemetry-dotnet#4616.

Testing is needed to figure out whether this is an actual problem.

@adamint

Adam Ratzman (adamint) commented Jan 16, 2024 •

Copy link
Copy Markdown
Member

The problem of startup order might be solved by introducing the concept of ordered initialization, similar to Kubernetes’ native sidecar containers.

Ordered initialization might also be useful to have in other cases, such as user-launched logging resources or tasks the user wants completed before some resources start.

@JamesNK

Copy link
Copy Markdown
Member

Waiting until the dashboard is ready could solve the data loss problem, but if other resources must wait for the dashboard resource to startup, then it would increase total startup time of Aspire apps during development. Less would be happening in parallel and we would end up with:

Aspire host starts -> orchestration starts -> dashboard loads and is ready -> others projects start loading.

Do we care about the time between pressing F5 and seeing the dashboard UI? cc Damian Edwards (@DamianEdwards) David Fowler (@davidfowl)

@kvenkatrajan

kvenkatrajan commented Jan 16, 2024 •

Copy link
Copy Markdown

We need DAM to support dotnet tool-based resources. When will that be available, and what APIs do we want?

Mitch Denny (@mitchdenny) would you be able to assist with this please?

@davidfowl

Copy link
Copy Markdown
Collaborator

We made some big decisions around how this will work today:

  1. We're going to make the dashboard part of the workload instead of making it a .NET tool
  2. We're going to teach the aspire host how to locate the executable at runtime (much like it does with finding DCP in the workload).
  3. Aspire.Hosting will spin up the dashboard resource before other resources.
  4. There will be no observable public API change to enable the dashboard outside of what exists for preview 2.

@JamesNK

Copy link
Copy Markdown
Member

Aspire.Hosting will spin up the dashboard resource before other resources.

From a user perspective it looks like the DCP starts everything at the same time today. What does being first mean from a timing perspective?

If it is the first resource in a loop that starts all resources, won't that only offer a small difference (milliseconds) in start-up time?

@JamesNK

Copy link
Copy Markdown
Member

I created an issue with OTEL folks to enable retries - open-telemetry/opentelemetry-dotnet#5226. I think that in the long term it is the best way to ensure OTEL data doesn't get lost.

Also adds a readme explaining dashboard configuration, and sets some metadata on the package for the icon, readme, etc.
@drewnoakes

Drew Noakes (drewnoakes) commented Jan 17, 2024 •

Copy link
Copy Markdown
Member Author

From a user perspective it looks like the DCP starts everything at the same time today. What does being first mean from a timing perspective?

If it is the first resource in a loop that starts all resources, won't that only offer a small difference (milliseconds) in start-up time?

The idea was that the dashboard would be started and actual readiness would be awaited before other resources were started. Readiness would be determined by probing OTEL somehow.

I created an issue with OTEL folks to enable retries - open-telemetry/opentelemetry-dotnet#5226. I think that in the long term it is the best way to ensure OTEL data doesn't get lost.

Thanks. Agree that's the best approach overall.

We're going to make the dashboard part of the workload instead of making it a .NET tool

As far as I know, ACA will still want a dotnet tool for their container image. I've pushed an update to this PR that enables that.


var builder = WebApplication.CreateBuilder();

builder.Logging.AddFilter("Microsoft.Hosting.Lifetime", LogLevel.None);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We may not need these filters anymore since the dashboard isn't running in proc we don't need to worry about the noise it generates.


## As a dotnet tool

The dashboard can be packaged and executed as a `dotnet tool`.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

This reads more like documentation for ourselves, but I think this README.md will end up being used as the README for the package, so perhaps we need to review the content in that context?

/// </summary>
public static class DashboardExtensions
{
public static IResourceBuilder<ExecutableResource> AddDashboard(this IDistributedApplicationBuilder builder)

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We probably don't need this now (TODO below is out of date :P)

@danegsta

Copy link
Copy Markdown
Member

Drew Noakes (@drewnoakes) do you want me to make the build targets changes required to integrate the dashboard into the workload in this branch? They shouldn't conflict with any of the current changes you've made.

@mitchdenny

Copy link
Copy Markdown
Member

David Negstad (@danegsta) Drew Noakes (@drewnoakes) why don't we get this PR merged onto another branch in the upstream so we can more easily collaborate there? Then we can merge the finalized branch in one go?

@danegsta

Copy link
Copy Markdown
Member

Mitch Denny (@mitchdenny) Drew Noakes (@drewnoakes) yeah, getting a feature branch going in the upstream makes sense.

@davidfowl

David Fowler (davidfowl) commented Jan 18, 2024 •

Copy link
Copy Markdown
Collaborator

I dont think we should merge anything that breaks the workload into main. Why can't we commit on top of this branch? I see this isn't a branch

@joperezr

Copy link
Copy Markdown
Member

I just created https://github.com/dotnet/aspire/tree/feature/dashboard-oop off from main. We can now retarget this PR to go against that branch, and I'll setup PR validation against that branch too.

@joperezr
Jose Perez Rodriguez (joperezr) changed the base branch from main to feature/dashboard-oop January 18, 2024 23:50
@joperezr

Copy link
Copy Markdown
Member

Hey Drew Noakes (@drewnoakes), I took the liberty of retargeting your PR against a feature branch instead, this way we can hopefully get it in without disrupting main, and we can parallelize the rest of the dashboard-related work. I hope that's okay.

@drewnoakes

Copy link
Copy Markdown
Member Author

/azp run

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 1 pipeline(s).

@drewnoakes
Drew Noakes (drewnoakes) marked this pull request as ready for review January 19, 2024 03:43
@drewnoakes
Drew Noakes (drewnoakes) merged commit b5b8c12 into microsoft:feature/dashboard-oop Jan 19, 2024
@drewnoakes
Drew Noakes (drewnoakes) deleted the dashboard-oop branch January 19, 2024 03:48
Drew Noakes (drewnoakes) added a commit that referenced this pull request Jan 24, 2024
* Add PR validation for feature branches.

* Run dashboard out-of-process (#1667)

* Run dashboard out-of-process

This change causes the dashboard to be run as an orchestrated project, just like any other Aspire resource.

To achieve this, we:

- Break the project dependency from AppHost upon Dashboard.
  - Until we have support for dotnet tool resources, having the sample projects depend upon the dashboard directly, and register them with the DAB.
  - Copy `TimestampParser.DisplayFormat` into `Aspire.Hosting.Dashboard.ConsoleLogsConfigurationExtensions` where it was used, and add comments to keep them in sync.
- Have the dashboard wire up its own web application.
  - Remove `DashboardWebApplicationHost`.
  - Remove dashboard-specific code from `DistributedApplicationBuilder`.
  - Update URLs to resources defined in the dashboard. They no longer need (or work with) the `_content/Aspire.Dashboard/` prefix.
  - Remove workarounds/configuration to support static web assets, as the new structure supports this automatically.
  - Link `KnownProperties` and `KnownResourceTypes` into the hosting project, so both projects can share the definition without needing an assembly reference.
- Change the MSBuild SDK for the dashboard from Razor Class Library to Web project.
  - Remove explicit framework reference.
  - Remove redundant using directives (the new SDK has different implicit usings).
  - Make the dashboard an executable.
  - Update the CSS bundle file name (from `Aspire.Dashboard.bundle.scp.css` to `Aspire.Dashboard.styles.css`)

This work is incomplete for a few reasons:

1. Aspire users won't be able to create a project reference to the dashboard. That only works in this solution. We need support for resources defined via `dotnet tool` packages before we can fix that.
2. We don't launch a browser to the dashboard any more. You have to find the URL in the logs and launch it.

We will need to address those issues before the changes here can be merged.

---

To test this locally, run any of the sample applications. To find the dashboard's URL, navigate to `%TEMP%` and find the relevant log files. For example, `%TEMP%\aspire.oweozx1d.bmh\dashboard-5buv5so_out_eedbad51-0294-4ff8-9add-001f27499206` (your IDs will be different). The first log message should read _Now listening on: https://localhost:49337_ or similar. Open that URL in a browser.

* Make dashboard packable as a dotnet tool

Also adds a readme explaining dashboard configuration, and sets some metadata on the package for the icon, readme, etc.

* [feature/dashboard-oop] Add initial workload targets and manifest entry for dashboard (#1705)

* Add initial workload targets and manifest entry for dashboard

* Do a better job handling trailing slashes for workload tool paths

* Update based on PR feedback

* Publishing as a tool by default breaks the workload build

* Remove extra parenthesis from import condition

* Updated workload package name

* [dashboard-oop] Dynamic dashboard port (#1750)

* Expose resource service URIs on DashboardServiceHost

The resource service will no longer bind to a default, hardcoded port. This encourages port collisions. Instead, when no URL is set in the environment, a port is chosen dynamically.

When the app model launches the dashboard, it must pass the URIs exposed via `DashboardServiceHost.GetUrisAsync` via the `DOTNET_DASHBOARD_GRPC_ENDPOINT_URL` environment variable to the spawned instance. That work is happening concurrently, and will use this API is a subsequent change.

* Resource service listens on a single URI which must be loopback

* Require parsed URI to be absolute

* [feature/dashboard-oop] Ensure the dashboard builds as a package for the workload (#1767)

* Ensure the dashboard actually builds as a package for the workload

* Publish then pack the dashboard as part of workload build

* [dashboard-oop] Launch dashboard as exe (#1717)

* Run dashboard out-of-process

This change causes the dashboard to be run as an orchestrated project, just like any other Aspire resource.

To achieve this, we:

- Break the project dependency from AppHost upon Dashboard.
  - Until we have support for dotnet tool resources, having the sample projects depend upon the dashboard directly, and register them with the DAB.
  - Copy `TimestampParser.DisplayFormat` into `Aspire.Hosting.Dashboard.ConsoleLogsConfigurationExtensions` where it was used, and add comments to keep them in sync.
- Have the dashboard wire up its own web application.
  - Remove `DashboardWebApplicationHost`.
  - Remove dashboard-specific code from `DistributedApplicationBuilder`.
  - Update URLs to resources defined in the dashboard. They no longer need (or work with) the `_content/Aspire.Dashboard/` prefix.
  - Remove workarounds/configuration to support static web assets, as the new structure supports this automatically.
  - Link `KnownProperties` and `KnownResourceTypes` into the hosting project, so both projects can share the definition without needing an assembly reference.
- Change the MSBuild SDK for the dashboard from Razor Class Library to Web project.
  - Remove explicit framework reference.
  - Remove redundant using directives (the new SDK has different implicit usings).
  - Make the dashboard an executable.
  - Update the CSS bundle file name (from `Aspire.Dashboard.bundle.scp.css` to `Aspire.Dashboard.styles.css`)

This work is incomplete for a few reasons:

1. Aspire users won't be able to create a project reference to the dashboard. That only works in this solution. We need support for resources defined via `dotnet tool` packages before we can fix that.
2. We don't launch a browser to the dashboard any more. You have to find the URL in the logs and launch it.

We will need to address those issues before the changes here can be merged.

---

To test this locally, run any of the sample applications. To find the dashboard's URL, navigate to `%TEMP%` and find the relevant log files. For example, `%TEMP%\aspire.oweozx1d.bmh\dashboard-5buv5so_out_eedbad51-0294-4ff8-9add-001f27499206` (your IDs will be different). The first log message should read _Now listening on: https://localhost:49337_ or similar. Open that URL in a browser.

* Make dashboard packable as a dotnet tool

Also adds a readme explaining dashboard configuration, and sets some metadata on the package for the icon, readme, etc.

* Launching dashboard via DCP executable.

* Work in progress checkin.

* Remove unnecessary environment sets.

* Move dashboard path resolution to dcp options.

* PR feedback.

* Read ASPNETCORE_ENVIRONMENT ... from environment.

* Update src/Aspire.Hosting/Dashboard/DashboardServiceHost.cs

Co-authored-by: Drew Noakes <[email protected]>

* Update src/Aspire.Hosting/Dashboard/DashboardServiceHost.cs

Co-authored-by: Drew Noakes <[email protected]>

* Exclude dashboard resources from being watched.

* Filtering dashboard resources from view.

* Revert dashboard servicehost to parent branch state.

* Changes after integrating feature branch.

* Fix unit tests

---------

Co-authored-by: Drew Noakes <[email protected]>

* Rename and format (#1776)

* Formatting

Addresses diagnostics shown by the IDE. If we don't want these changes, we should reconfigure or disable those diagnostics.

* Rename method and log if delays are observed

* Replace `Trace.WriteLine` with `_logger.LogWarning`

* Start dashboard first for playground scenario (#1775)

* Add KnownResourceNames

* Ensure dashboard is started first

When F5'ing one of the playground solutions in the dotnet/aspire repo, the dashboard is added as the last resource. This means it starts after all other resources, which is not what we want. This change ensures it is always started first.

* Wait for dashboard to be online before starting other resources. (#1778)

* Add wait for dashboard start.

* WIP to merge with parent branch.

* Wait for dashboard if it is a Aspire resource.

* Add dashboard setup across playground.

* Update src/Aspire.Hosting/Dcp/ApplicationExecutor.cs

Co-authored-by: Drew Noakes <[email protected]>

* Add short delay in polling loop.

* Fix up get request.

---------

Co-authored-by: Drew Noakes <[email protected]>

* Add API docs to DcpOptions (#1777)

* [feature/dashboard-oop] Publish dashboard for specific RIDs before packing (#1771)

* Publish dashboard for specific RIDs before packing

* Add comments explaining the need to keep runtime lists in sync

* Remove unused item for icon

* Ensure it is clear the runtimes list matches the supported runtimes from DCP

* Allow parallel publishing

* Fix build of OrleansAppHost (#1794)

* [dashboard-oop] Update dashboard attribute config for playground projects (#1799)

* Update attribute handling for playground projects

* Update comments on default path to dashboard

* [dashboard-oop] Support starting dashboard as DLL or executable (#1798)

* Support starting dashboard as DLL or executable

The workload ships an executable, but `ApplicationExecutor` was written to run a DLL via `dotnet <dll>`.

This change checks whether the dashboard is a DLL or not, and configures the executable spec accordingly.

* Fix compile error

Co-authored-by: David Negstad <[email protected]>

---------

Co-authored-by: David Negstad <[email protected]>

* Fix dashboard startup ordering. (#1804)

* Fix dashboard startup ordering.

* Workaround pathing bug.

* Fix up AspireDashboardDir (keep it in Directory.Build.props in repo root).

* [dashboard-oop] PR feedback (#1805)

* Rename environment variable

This hasn't shipped anywhere yet, so it's fine to rename it now.

* Remove unused DashboardExtensions

* Update exception message

* DashboardServiceHost logs when skipping hosting resource service

---------

Co-authored-by: Jose Perez Rodriguez <[email protected]>
Co-authored-by: Mitch Denny <[email protected]>
Co-authored-by: David Negstad <[email protected]>
Co-authored-by: James Newton-King <[email protected]>
@github-actions github-actions Bot locked and limited conversation to collaborators Apr 25, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Decouple the dashboard from the Aspire.Hosting during development Can't add multiple Blazor Web Apps to Aspire

8 participants