Skip to content

Allow dashboard to run without resource service - #1815

Merged
Drew Noakes (drewnoakes) merged 9 commits into
microsoft:mainfrom
drewnoakes:disconnected-client-2
Jan 25, 2024
Merged

Drew Noakes (drewnoakes) merged 9 commits into
microsoft:mainfrom
drewnoakes:disconnected-client-2

Conversation

@drewnoakes

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

Copy link
Copy Markdown
Member

(Replaces #1795 which closed when we merged the feature branch.)

Relates to #1556

With the dashboard running OOP, it is configured with the resource server endpoint via the DOTNET_DASHBOARD_GRPC_ENDPOINT_URL environment variable.

The dashboard can actually perform useful work even without this connection, however it requires some code changes to support this.

In this PR, if the environment variable is not defined, then IDashboardClient.IsEnabled will be false, and some code paths become inactive based off the flag.

To get tests passing, we introduce an abstraction for environment variables so we can inject the values we need.

The navigation tree will not display the "Resources" or "Console logs" items when no resource service endpoint is available:

image


Pending work:

  • On load the page currently routes to / which shows an empty Resources list. Route somewhere else.
  • Update dashboard's README
Microsoft Reviewers: Open in CodeFlow

With the dashboard running OOP, it is configured with the resource server endpoint via an environment variable.

The dashboard can actually perform useful work even without this connection, however it requires some code changes to support this.

In this change, if the environment variable is not defined, then `IDashboardClient.IsEnabled` will be false, and some code paths become inactive based off the flag.

To get tests passing, we introduce an abstraction for environment variables so we can inject the values we need.

The navigation tree will not display the "Resources" or "Console logs" items when no resource service endpoint is available.

---

Squashed from several other commits:

Add singular overload of EnvironmentUtil.GetAddressUris

And tidy up some code that parsed `DOTNET_DASHBOARD_GRPC_ENDPOINT_URL`. Change that code to only support a single URI for that purpose, as it only makes one connection.

DashboardClient is disabled when no dashboard endpoint

When the `DOTNET_DASHBOARD_GRPC_ENDPOINT_URL` variable is not in the dashboard's environment, the `DashboardClient` disables itself. In this state, it will throw when invoked, though you may query the `IsEnabled` property safely before making other calls.

Add IEnvironmentVariables abstraction for unit testing

Makes it possible to unit test environment variables.

Make init properties

Remove redundant null suppression

Hide navigation items when resource service unavailable

Hides the "Resources" and "Console logs" navigation menu items whenever the `DashboardClient` is not enabled (due to `DOTNET_DASHBOARD_GRPC_ENDPOINT_URL` not being available).

Check if IDashboardClient is enabled before calling it
@JamesNK

Copy link
Copy Markdown
Member

The title should have a value when there is no resource server. "Aspire dashboard"?

An option to set it via argument/env var would be useful, but no one has asked for that yet.

@drewnoakes

Copy link
Copy Markdown
Member Author

The title should have a value when there is no resource server. "Aspire dashboard"?

An option to set it via argument/env var would be useful, but no one has asked for that yet.

I like this idea! Added:

    string IDashboardClient.ApplicationName
    {
        get => _applicationName
            ?? _environmentVariables.GetString("DOTNET_DASHBOARD_APPLICATION_NAME")
            ?? "Aspire";
    }

@drewnoakes

Copy link
Copy Markdown
Member Author

James Newton-King (@JamesNK) PTAL. I'd like to get this merged in so there's more chance it's included in the next round of testing.

@drewnoakes
Drew Noakes (drewnoakes) enabled auto-merge (squash) January 25, 2024 02:42
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.

3 participants