Skip to content

Commit b7ef661

Browse files
authored
Port 1344 and 1398 to main (#1401)
1 parent 23e168d commit b7ef661

File tree

5 files changed

+41
-7
lines changed

5 files changed

+41
-7
lines changed

src/Aspire.Dashboard/Components/Pages/Resources.razor

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@
6565
<SourceColumnDisplay Resource="context" FilterText="@_filter" />
6666
</TemplateColumn>
6767
<TemplateColumn Title="@Loc[Dashboard.Resources.Resources.ResourcesEnvironmentVariablesGridEndpointsColumnHeader]">
68-
<EndpointsColumnDisplay Resource="context" />
68+
<EndpointsColumnDisplay Resource="context" HasMultipleReplicas="HasMultipleReplicas(context)" />
6969
</TemplateColumn>
7070
<TemplateColumn Title="@Loc[Dashboard.Resources.Resources.ResourcesEnvironmentVariablesGridEnvironmentColumnHeader]" Sortable="false">
7171
<FluentButton Appearance="Appearance.Lightweight"

src/Aspire.Dashboard/Components/Pages/Resources.razor.cs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,24 @@ private async Task OnResourceListChanged(ResourceChangeType changeType, Resource
165165

166166
private string GetResourceName(ResourceViewModel resource) => ResourceViewModel.GetResourceName(resource, _resourcesMap.Values);
167167

168+
private bool HasMultipleReplicas(ResourceViewModel resource)
169+
{
170+
var count = 0;
171+
foreach (var item in _resourcesMap.Values)
172+
{
173+
if (item.DisplayName == resource.DisplayName)
174+
{
175+
count++;
176+
if (count >= 2)
177+
{
178+
return true;
179+
}
180+
}
181+
}
182+
183+
return false;
184+
}
185+
168186
protected virtual void Dispose(bool disposing)
169187
{
170188
if (disposing)

src/Aspire.Dashboard/Components/ResourcesGridColumns/EndpointsColumnDisplay.razor

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,17 @@
1111
else
1212
{
1313
@* If we have any, regardless of the state, go ahead and display them *@
14-
foreach (var endpoint in Resource.Endpoints.OrderBy(e => e))
14+
foreach (var endpoint in Resource.Endpoints.OrderBy(e => e.ProxyUrl))
1515
{
16-
<a href="@endpoint" target="_blank" class="long-inner-content">@endpoint</a>
16+
if (HasMultipleReplicas)
17+
{
18+
<a href="@endpoint.ProxyUrl" target="_blank" class="long-inner-content">@endpoint.ProxyUrl</a>
19+
<span class="long-inner-content">(<a href="@endpoint.EndpointUrl" target="_blank">@endpoint.EndpointUrl</a>)</span>
20+
}
21+
else
22+
{
23+
<a href="@endpoint.ProxyUrl" target="_blank" class="long-inner-content">@endpoint.ProxyUrl</a>
24+
}
1725
}
1826
@* If we're expecting more, say Starting..., unless the app isn't running anymore *@
1927
if (Resource.State != FinishedState
@@ -32,4 +40,7 @@
3240

3341
[Parameter, EditorRequired]
3442
public required ResourceViewModel Resource { get; set; }
43+
44+
[Parameter, EditorRequired]
45+
public required bool HasMultipleReplicas { get; set; }
3546
}

src/Aspire.Dashboard/Model/ResourceViewModel.cs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public abstract class ResourceViewModel
1818
public required DateTime? CreationTimeStamp { get; init; }
1919
public required ImmutableArray<EnvironmentVariableViewModel> Environment { get; init; }
2020
public required ILogSource LogSource { get; init; }
21-
public required ImmutableArray<string> Endpoints { get; init; }
21+
public required ImmutableArray<EndpointViewModel> Endpoints { get; init; }
2222
public required ImmutableArray<ResourceServiceSnapshot> Services { get; init; }
2323
public required int? ExpectedEndpointsCount { get; init; }
2424

@@ -55,3 +55,5 @@ public sealed class ResourceServiceSnapshot(string name, string? allocatedAddres
5555
public int? AllocatedPort { get; } = allocatedPort;
5656
public string AddressAndPort { get; } = $"{allocatedAddress}:{allocatedPort}";
5757
}
58+
59+
public sealed record EndpointViewModel(string EndpointUrl, string ProxyUrl);

src/Aspire.Hosting/Dashboard/DcpDataSource.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -237,12 +237,12 @@ private ExecutableViewModel ToSnapshot(Executable executable)
237237
};
238238
}
239239

240-
private (ImmutableArray<string> Endpoints, ImmutableArray<ResourceServiceSnapshot> Services) GetEndpointsAndServices(
240+
private (ImmutableArray<EndpointViewModel> Endpoints, ImmutableArray<ResourceServiceSnapshot> Services) GetEndpointsAndServices(
241241
CustomResource resource,
242242
string resourceKind,
243243
string? projectPath = null)
244244
{
245-
var endpoints = ImmutableArray.CreateBuilder<string>();
245+
var endpoints = ImmutableArray.CreateBuilder<EndpointViewModel>();
246246
var services = ImmutableArray.CreateBuilder<ResourceServiceSnapshot>();
247247
var name = resource.Metadata.Name;
248248

@@ -258,6 +258,7 @@ private ExecutableViewModel ToSnapshot(Executable executable)
258258
&& service?.UsesHttpProtocol(out var uriScheme) == true)
259259
{
260260
var endpointString = $"{uriScheme}://{endpoint.Spec.Address}:{endpoint.Spec.Port}";
261+
var proxyUrlString = $"{uriScheme}://{service.AllocatedAddress}:{service.AllocatedPort}";
261262

262263
// For project look into launch profile to append launch url
263264
if (projectPath is not null
@@ -269,6 +270,7 @@ private ExecutableViewModel ToSnapshot(Executable executable)
269270
{
270271
// This is relative URL
271272
endpointString += $"/{launchUrl}";
273+
proxyUrlString += $"/{launchUrl}";
272274
}
273275
else
274276
{
@@ -277,13 +279,14 @@ private ExecutableViewModel ToSnapshot(Executable executable)
277279
&& launchUrl.StartsWith(applicationUrl))
278280
{
279281
endpointString = launchUrl.Replace(applicationUrl, endpointString);
282+
proxyUrlString = launchUrl;
280283
}
281284
}
282285

283286
// If we cannot process launchUrl then we just show endpoint string
284287
}
285288

286-
endpoints.Add(endpointString);
289+
endpoints.Add(new(endpointString, proxyUrlString));
287290
}
288291
}
289292

0 commit comments

Comments
 (0)