Skip to content
Draft
Show file tree
Hide file tree
Changes from 11 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions src/Aspire.Cli/Commands/ResourceCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,8 @@ private static async Task<CommandResult> LoadCommandArgumentsAsync(

private static async Task<ResourceSnapshotCommand?> GetCommandMetadataAsync(IAppHostAuxiliaryBackchannel connection, string resourceName, string commandName, bool includeHidden, CancellationToken cancellationToken)
{
var snapshots = await connection.GetResourceSnapshotsAsync(includeHidden, cancellationToken).ConfigureAwait(false);
var effectiveIncludeHidden = includeHidden || !string.IsNullOrEmpty(resourceName);
var snapshots = await connection.GetResourceSnapshotsAsync(effectiveIncludeHidden, cancellationToken).ConfigureAwait(false);
var resources = ResourceSnapshotMapper.ResolveResources(resourceName, snapshots);
var lookupCommandName = s_legacyCommandNameMap.GetValueOrDefault(commandName, commandName);

Expand All @@ -232,7 +233,8 @@ private static async Task<CommandResult> LoadCommandArgumentsAsync(

private static async Task<(string Name, string Description)[]> GetAvailableCommandMetadataAsync(IAppHostAuxiliaryBackchannel connection, string resourceName, bool includeHidden, CancellationToken cancellationToken)
{
var snapshots = await connection.GetResourceSnapshotsAsync(includeHidden, cancellationToken).ConfigureAwait(false);
var effectiveIncludeHidden = includeHidden || !string.IsNullOrEmpty(resourceName);
var snapshots = await connection.GetResourceSnapshotsAsync(effectiveIncludeHidden, cancellationToken).ConfigureAwait(false);
var resources = ResourceSnapshotMapper.ResolveResources(resourceName, snapshots);

return resources
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1826,7 +1826,8 @@ passed to the Aspire command line (arguments specified after '--'). Specifying t
app_host_file_path (str): The path to the AppHost source file. By default, this will use the ASPIRE_APPHOST_FILEPATH
environment variable if set.
container_registry_override (str): When containers are used, use this value to override the container registry.
disable_dashboard (bool): Determines whether the dashboard is disabled.
disable_dashboard (bool): Determines whether dashboard auto-start is disabled.
In run mode, the dashboard resource is still added and can be started explicitly later.
dashboard_application_name (str): The application name to display in the dashboard.
allow_unsecured_transport (bool): Allows the use of HTTP urls for the AppHost resource endpoint.
enable_resource_logging (bool): Enables resource logging.
Expand Down
3 changes: 2 additions & 1 deletion src/Aspire.Hosting/Ats/CreateBuilderOptions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,8 @@ internal sealed class CreateBuilderOptions
public string? ContainerRegistryOverride { get; set; }

/// <summary>
/// Determines whether the dashboard is disabled.
/// Determines whether dashboard auto-start should be disabled at app host startup.
/// In run mode, the dashboard resource is still added and can be started explicitly later.
/// </summary>
public bool DisableDashboard { get; set; }

Expand Down
8 changes: 0 additions & 8 deletions src/Aspire.Hosting/Backchannel/AppHostRpcTarget.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@ internal class AppHostRpcTarget(
ProfilingTelemetry profilingTelemetry,
PipelineActivityReporter activityReporter,
IHostApplicationLifetime lifetime,
DistributedApplicationOptions options,
AppHostStartupState startupState,
IFileUploadStore fileUploadStore,
IConfiguration configuration)
Expand Down Expand Up @@ -178,13 +177,6 @@ public void CancelInflightRpcCalls()
public async Task<DashboardUrlsState> GetDashboardUrlsAsync(CancellationToken cancellationToken)
{
using var activity = profilingTelemetry.StartJsonRpcServerCall(nameof(GetDashboardUrlsAsync), streaming: false);
if (!options.DashboardEnabled)
{
logger.LogDebug("Dashboard URL requested but dashboard is disabled.");
activity.SetDashboardHealthy(false);
return new DashboardUrlsState { DashboardHealthy = false };
}

try
{
var urls = await DashboardUrlsHelper.GetDashboardUrlsAsync(serviceProvider, logger, cancellationToken).ConfigureAwait(false);
Expand Down
25 changes: 22 additions & 3 deletions src/Aspire.Hosting/Backchannel/DashboardUrlsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,8 @@ public static async Task<DashboardConnectionInfo> GetDashboardConnectionInfoAsyn
ILogger logger,
CancellationToken cancellationToken = default)
{
// Check whether the dashboard resource is registered at all. If it isn't (e.g. the user
// called DisableDashboard()), return immediately rather than waiting forever for a resource
// event that will never arrive.
// Check whether the dashboard resource is registered at all. If it isn't, return
// immediately rather than waiting forever for a resource event that will never arrive.
var appModel = serviceProvider.GetService<DistributedApplicationModel>();
var dashboardResource = appModel?.Resources.SingleOrDefault(
r => string.Equals(r.Name, KnownResourceNames.AspireDashboard, StringComparisons.ResourceName)) as IResourceWithEndpoints;
Expand All @@ -48,6 +47,26 @@ public static async Task<DashboardConnectionInfo> GetDashboardConnectionInfoAsyn
using var activity = profilingTelemetry.StartDashboardGetConnectionInfo();
var resourceNotificationService = serviceProvider.GetRequiredService<ResourceNotificationService>();

if (dashboardResource.TryGetLastAnnotation<ExplicitStartupAnnotation>(out _))
{
if (!resourceNotificationService.TryGetCurrentState(KnownResourceNames.AspireDashboard, out var dashboardEvent))
{
logger.LogDebug("Dashboard resource is explicit-start and has no current state. Returning unavailable state.");
activity.SetDashboardHealthy(false);
return DashboardConnectionInfo.Unhealthy;
}

var state = dashboardEvent.Snapshot.State?.Text;
var isStarting = state == KnownResourceStates.Starting || state == KnownResourceStates.Building;
var isRunning = state == KnownResourceStates.Running;
if (!isStarting && !isRunning)
{
logger.LogDebug("Dashboard resource is explicit-start and in state '{State}'. Returning unavailable state.", state ?? "(null)");
activity.SetDashboardHealthy(false);
return DashboardConnectionInfo.Unhealthy;
}
}

// Wait for the dashboard to be healthy
using (var waitActivity = profilingTelemetry.StartDashboardWaitHealthy())
{
Expand Down
73 changes: 72 additions & 1 deletion src/Aspire.Hosting/Dashboard/DashboardEventHandlers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
using Aspire.Hosting.Devcontainers.Codespaces;
using Aspire.Hosting.Eventing;
using Aspire.Hosting.Lifecycle;
using Aspire.Hosting.Orchestrator;
using Aspire.Hosting.Resources;
using Aspire.Hosting.Utils;
using Aspire.Shared;
using Aspire.Shared.ConsoleLogs;
Expand All @@ -34,6 +36,7 @@ internal sealed class DashboardEventHandlers(IConfiguration configuration,
ILogger<DistributedApplication> distributedApplicationLogger,
IDashboardEndpointProvider dashboardEndpointProvider,
DistributedApplicationExecutionContext executionContext,
DistributedApplicationOptions distributedApplicationOptions,
ResourceNotificationService resourceNotificationService,
ResourceLoggerService resourceLoggerService,
ILoggerFactory loggerFactory,
Expand Down Expand Up @@ -320,7 +323,14 @@ private void AddDashboardResource(DistributedApplicationModel model)

if (!File.Exists(dashboardDll))
{
distributedApplicationLogger.LogError("Dashboard DLL not found: {Path}", dashboardDll);
if (distributedApplicationOptions.DisableDashboard)
{
distributedApplicationLogger.LogDebug("Dashboard DLL not found while dashboard auto-start is disabled: {Path}", dashboardDll);
}
else
{
distributedApplicationLogger.LogError("Dashboard DLL not found: {Path}", dashboardDll);
}
}

dashboardResource = new ExecutableResource(KnownResourceNames.AspireDashboard, "dotnet", dashboardWorkingDirectory ?? "");
Expand All @@ -343,9 +353,20 @@ private void AddDashboardResource(DistributedApplicationModel model)

private void ConfigureAspireDashboardResource(IResource dashboardResource)
{
var isDashboardExplicitStart = distributedApplicationOptions.DisableDashboard;
if (isDashboardExplicitStart &&
!dashboardResource.TryGetLastAnnotation<ExplicitStartupAnnotation>(out _))
{
dashboardResource.Annotations.Add(new ExplicitStartupAnnotation());
}

// The dashboard resource can be visible during development. We don't want people to be able to stop the dashboard from inside the dashboard.
// Exclude the lifecycle commands from the dashboard resource so they're not accidently clicked during development.
dashboardResource.Annotations.Add(new ExcludeLifecycleCommandsAnnotation());
if (isDashboardExplicitStart)
{
AddDisabledDashboardStartCommand(dashboardResource);
Comment thread
afscrome marked this conversation as resolved.
Resolved
}

// Add the ContentView icon to the dashboard resource
dashboardResource.Annotations.Add(new ResourceIconAnnotation("ContentView"));
Expand Down Expand Up @@ -500,6 +521,56 @@ private void ConfigureAspireDashboardResource(IResource dashboardResource)
eventing.Subscribe<ResourceReadyEvent>(dashboardResource, DashboardStarted);
}

private static void AddDisabledDashboardStartCommand(IResource dashboardResource)
{
if (dashboardResource.TryGetAnnotationsOfType<ResourceCommandAnnotation>(out var commands) &&
commands.Any(command => string.Equals(command.Name, KnownResourceCommands.StartCommand, StringComparison.Ordinal)))
{
return;
}

dashboardResource.Annotations.Add(new ResourceCommandAnnotation(
name: KnownResourceCommands.StartCommand,
displayName: CommandStrings.StartName,
executeCommand: async context =>
{
var orchestrator = context.Services.GetRequiredService<ApplicationOrchestrator>();
await orchestrator.StartResourceAsync(context.ResourceName, context.CancellationToken).ConfigureAwait(false);
Comment thread
afscrome marked this conversation as resolved.
Resolved
return new ExecuteCommandResult
{
Success = true,
Message = string.Format(CultureInfo.InvariantCulture, CommandStrings.ResourceStarted, dashboardResource.GetResolvedDisplayResourceName(context.ResourceName))
};
},
updateState: context =>
{
var state = context.ResourceSnapshot.State?.Text;
if (state == KnownResourceStates.Starting ||
state == KnownResourceStates.Building ||
state == KnownResourceStates.RuntimeUnhealthy ||
string.IsNullOrEmpty(state))
{
return ResourceCommandState.Disabled;
}

if (KnownResourceStates.TerminalStates.Contains(state) ||
state == KnownResourceStates.NotStarted ||
state == KnownResourceStates.Waiting ||
state == "Unknown")
{
return ResourceCommandState.Enabled;
}

return ResourceCommandState.Hidden;
},
displayDescription: CommandStrings.StartDescription,
arguments: null,
confirmationMessage: null,
iconName: "Play",
iconVariant: IconVariant.Filled,
isHighlighted: true));
}

private async Task DashboardStarted(ResourceReadyEvent @event, CancellationToken cancellationToken)
{
var options = dashboardOptions.Value;
Expand Down
7 changes: 3 additions & 4 deletions src/Aspire.Hosting/Dashboard/DashboardServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,12 @@ internal sealed class DashboardServiceHost : IHostedService
private readonly TaskCompletionSource<string> _resourceServiceUri = new();

/// <summary>
/// <see langword="null"/> if <see cref="DistributedApplicationOptions.DashboardEnabled"/> is <see langword="false"/>.
/// <see langword="null"/> in publish mode.
/// </summary>
private readonly WebApplication? _app;
private readonly ILogger<DashboardServiceHost> _logger;

public DashboardServiceHost(
DistributedApplicationOptions options,
DistributedApplicationModel applicationModel,
IConfiguration configuration,
DistributedApplicationExecutionContext executionContext,
Expand All @@ -54,9 +53,9 @@ public DashboardServiceHost(
{
_logger = loggerFactory.CreateLogger<DashboardServiceHost>();

if (!options.DashboardEnabled || executionContext.IsPublishMode)
if (executionContext.IsPublishMode)
{
_logger.LogDebug("Dashboard is not enabled so skipping hosting the resource service.");
_logger.LogDebug("Skipping hosting the resource service in publish mode.");
_resourceServiceUri.SetCanceled();
return;
Comment thread
afscrome marked this conversation as resolved.
Resolved
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ internal class TransportOptionsValidator(IConfiguration configuration, Distribut
{
public ValidateOptionsResult Validate(string? name, TransportOptions transportOptions)
{
var effectiveAllowUnsecureTransport = transportOptions.AllowUnsecureTransport || distributedApplicationOptions.DisableDashboard || distributedApplicationOptions.AllowUnsecuredTransport;
var effectiveAllowUnsecureTransport = transportOptions.AllowUnsecureTransport || distributedApplicationOptions.AllowUnsecuredTransport;
Comment thread
afscrome marked this conversation as resolved.
Resolved
Comment thread
afscrome marked this conversation as resolved.
Resolved

if (executionContext.IsPublishMode || effectiveAllowUnsecureTransport)
{
Expand Down
4 changes: 2 additions & 2 deletions src/Aspire.Hosting/DistributedApplication.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace Aspire.Hosting;
/// </para>
/// <para>
/// The <see cref="CreateBuilder(Aspire.Hosting.DistributedApplicationOptions)"/> method provides additional options for
/// constructing the <see cref="IDistributedApplicationBuilder"/> including disabling the Aspire dashboard (see <see cref="DistributedApplicationOptions.DisableDashboard"/>) or
/// constructing the <see cref="IDistributedApplicationBuilder"/> including disabling Aspire dashboard auto-start in run mode (see <see cref="DistributedApplicationOptions.DisableDashboard"/>) or
/// allowing unsecured communication between the browser and dashboard, and dashboard and app host (see <see cref="DistributedApplicationOptions.AllowUnsecuredTransport"/>.
/// </para>
/// <example>
Expand Down Expand Up @@ -178,7 +178,7 @@ public static IDistributedApplicationBuilder CreateBuilder(string[] args)
/// greater control over the behavior of the distributed application at runtime. For example providing
/// an <paramref name="options"/> argument allows developers to force all container images to be loaded
/// from a specified container registry by using the <see cref="DistributedApplicationOptions.ContainerRegistryOverride"/>
/// property, or disabling the dashboard by using the <see cref="DistributedApplicationOptions.DisableDashboard"/>
/// property, or disabling dashboard auto-start in run mode by using the <see cref="DistributedApplicationOptions.DisableDashboard"/>
/// property. Refer to the <see cref="DistributedApplicationOptions"/> class for more details on
/// each option that may be provided.
/// </para>
Expand Down
Loading
Loading