Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/ServiceClient/DashboardClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ namespace Aspire.Dashboard.ServiceClient;
/// lives until the stream is closed.
/// </para>
/// <para>
/// If the <c>DOTNET_RESOURCE_SERVICE_ENDPOINT_URL</c> environment variable is not specified, then there's
/// If the <c>ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL</c> environment variable is not specified, then there's
/// no known endpoint to connect to, and this dashboard client will be disabled. Calls to
Comment thread
JamesNK marked this conversation as resolved.
/// <see cref="IDashboardClient.SubscribeResourcesAsync"/> and <see cref="IDashboardClient.SubscribeConsoleLogs"/>
/// will throw if <see cref="IDashboardClient.IsEnabled"/> is <see langword="false"/>. Callers should
Expand Down
18 changes: 5 additions & 13 deletions src/Aspire.Hosting/Dashboard/DashboardServiceHost.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,16 +24,6 @@ namespace Aspire.Hosting.Dashboard;
/// </summary>
internal sealed class DashboardServiceHost : IHostedService
{
/// <summary>
/// Name of the environment variable that optionally specifies the resource service URL,
/// which the dashboard will connect to over gRPC.
/// </summary>
/// <remarks>
/// This is primarily intended for cases outside of the local developer environment.
/// If no value exists for this variable, a port is assigned dynamically.
/// </remarks>
private const string ResourceServiceUrlVariableName = "DOTNET_RESOURCE_SERVICE_ENDPOINT_URL";

/// <summary>
/// Provides access to the URI at which the resource service endpoint is hosted.
/// </summary>
Expand Down Expand Up @@ -135,7 +125,9 @@ public DashboardServiceHost(
void ConfigureKestrel(KestrelServerOptions kestrelOptions)
{
// Inspect environment for the address to listen on.
var uri = configuration.GetUri(ResourceServiceUrlVariableName);
// Prefer the new config name, falling back to the legacy name.
var uri = configuration.GetUri(KnownConfigNames.ResourceServiceEndpointUrl)
?? configuration.GetUri(KnownConfigNames.Legacy.ResourceServiceEndpointUrl);
var allowUnsecuredTransport = configuration.GetBool(KnownConfigNames.AllowUnsecuredTransport) ?? false;

var scheme = ResolveScheme(uri, allowUnsecuredTransport);
Expand All @@ -154,7 +146,7 @@ void ConfigureKestrel(KestrelServerOptions kestrelOptions)
}
else
{
throw new ArgumentException($"{ResourceServiceUrlVariableName} must contain a local loopback address.");
throw new ArgumentException($"{KnownConfigNames.ResourceServiceEndpointUrl} must contain a local loopback address.");
}
Comment thread
JamesNK marked this conversation as resolved.

void ConfigureListen(ListenOptions options)
Expand Down Expand Up @@ -191,7 +183,7 @@ internal static string ResolveScheme(Uri? configuredUri, bool allowUnsecuredTran
/// </summary>
/// <remarks>
/// Intended to be used by the app model when launching the dashboard process, populating its
/// <c>DOTNET_RESOURCE_SERVICE_ENDPOINT_URL</c> environment variable with a single URI.
/// <c>ASPIRE_RESOURCE_SERVICE_ENDPOINT_URL</c> environment variable with a single URI.
/// </remarks>
public async Task<string> GetResourceServiceUriAsync(CancellationToken cancellationToken = default)
{
Expand Down
28 changes: 28 additions & 0 deletions tests/Aspire.Hosting.Tests/DistributedApplicationTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
using System.Threading.Channels;
using Aspire.Dashboard.Model;
using Aspire.Hosting.Diagnostics;
using Aspire.Hosting.Dashboard;
using Aspire.TestUtilities;
using Aspire.Hosting.Dcp;
using Aspire.Hosting.Dcp.Model;
Expand Down Expand Up @@ -1433,6 +1434,33 @@ public async Task StartAsync_UnsecuredAllowAnonymous_PassedToDashboardProcess()
}
}

[Fact]
public async Task StartAsync_ResourceServiceEndpointUrl_PassedToDashboardServiceHost()
{
const string testName = "dashboard-resource-service-endpoint-url";
var resourceServicePort = await Network.GetAvailablePortAsync();
var configuredResourceServiceUrl = $"http://localhost:{resourceServicePort}";
var args = new string[] {
$"{KnownConfigNames.ResourceServiceEndpointUrl}={configuredResourceServiceUrl}"
};
using var testProgram = CreateTestProgram(testName, args: args, disableDashboard: false);

await using var app = testProgram.Build();

var dashboardServiceHost = app.Services.GetRequiredService<DashboardServiceHost>();
await ((IHostedService)dashboardServiceHost).StartAsync(CancellationToken.None);

try
{
var resourceServiceUri = await dashboardServiceHost.GetResourceServiceUriAsync();
Assert.Equal(configuredResourceServiceUrl, resourceServiceUri.TrimEnd('/'));
}
finally
{
await ((IHostedService)dashboardServiceHost).StopAsync(CancellationToken.None);
}
}

[Fact]
[RequiresFeature(TestFeature.Docker)]
public async Task VerifyDockerWithEntrypointWorks()
Expand Down
Loading