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: 2 additions & 0 deletions playground/Stress/Stress.AppHost/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@
}
}

builder.AddParameter("testParameterResource", () => "value", secret: true);

// TODO: OTEL env var can be removed when OTEL libraries are updated to 1.9.0
// See https://github.com/open-telemetry/opentelemetry-dotnet/blob/main/RELEASENOTES.md#1100
var serviceBuilder = builder.AddProject<Projects.Stress_ApiService>("stress-apiservice", launchProfileName: null)
Expand Down
2 changes: 1 addition & 1 deletion src/Aspire.Dashboard/Components/Pages/ConsoleLogs.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ internal static ImmutableList<SelectViewModel<ResourceTypeDetails>> GetConsoleLo
var builder = ImmutableList.CreateBuilder<SelectViewModel<ResourceTypeDetails>>();

foreach (var grouping in resourcesByName
.Where(r => !r.Value.IsHiddenState())
.Where(r => !r.Value.IsResourceHidden())
.OrderBy(c => c.Value, ResourceViewModelNameComparer.Instance)
.GroupBy(r => r.Value.DisplayName, StringComparers.ResourceName))
{
Expand Down
8 changes: 4 additions & 4 deletions src/Aspire.Dashboard/Components/Pages/Resources.razor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ private bool Filter(ResourceViewModel resource)
&& IsKeyValueTrue(resource.State ?? string.Empty, PageViewModel.ResourceStatesToVisibility)
&& IsKeyValueTrue(resource.HealthStatus?.Humanize() ?? string.Empty, PageViewModel.ResourceHealthStatusesToVisibility)
&& (_filter.Length == 0 || resource.MatchesFilter(_filter))
&& !resource.IsHiddenState();
&& !resource.IsResourceHidden();

static bool IsKeyValueTrue(string key, IDictionary<string, bool> dictionary) => dictionary.TryGetValue(key, out var value) && value;
}
Expand Down Expand Up @@ -451,7 +451,7 @@ private void UpdateMenuButtons()

private bool HasCollapsedResources()
{
return _resourceByName.Any(r => !r.Value.IsHiddenState() && _collapsedResourceNames.Contains(r.Key));
return _resourceByName.Any(r => !r.Value.IsResourceHidden() && _collapsedResourceNames.Contains(r.Key));
}

private void UpdateMaxHighlightedCount()
Expand Down Expand Up @@ -619,7 +619,7 @@ private bool HasMultipleReplicas(ResourceViewModel resource)
var count = 0;
foreach (var (_, item) in _resourceByName)
{
if (item.IsHiddenState())
if (item.IsResourceHidden())
{
continue;
}
Expand Down Expand Up @@ -693,7 +693,7 @@ private async Task OnToggleCollapse(ResourceGridViewModel viewModel)
private async Task OnToggleCollapseAll()
{
var resourcesWithChildren = _resourceByName.Values
.Where(r => !r.IsHiddenState())
.Where(r => !r.IsResourceHidden())
.Where(r => _resourceByName.Values.Any(nested => nested.GetResourcePropertyValue(KnownProperties.Resource.ParentName) == r.Name))
.ToList();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@ namespace Aspire.Dashboard.Extensions;

internal static class ResourceViewModelExtensions
{
public static bool IsHiddenState(this ResourceViewModel resource)
{
return resource.KnownState is KnownResourceState.Hidden;
}

public static bool IsRunningState(this ResourceViewModel resource)
{
return resource.KnownState is KnownResourceState.Running;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public static ResourceDto MapResource(ResourceViewModel r, IDictionary<string, R
{
var matches = resourcesByName.Values
.Where(r => string.Equals(r.DisplayName, resourceRelationships.Key, StringComparisons.ResourceName))
.Where(r => r.KnownState != KnownResourceState.Hidden)
.Where(r => !r.IsResourceHidden())
.ToList();

foreach (var match in matches)
Expand Down
9 changes: 7 additions & 2 deletions src/Aspire.Dashboard/Model/ResourceViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using Aspire.Dashboard.Components.Controls;
using Aspire.Dashboard.Extensions;
using Aspire.Dashboard.Utils;
using Google.Protobuf.WellKnownTypes;
using Humanizer;
Expand Down Expand Up @@ -39,6 +38,7 @@ public sealed class ResourceViewModel
public required ImmutableArray<CommandViewModel> Commands { get; init; }
/// <summary>The health status of the resource. <see langword="null"/> indicates that health status is expected but not yet available.</summary>
public HealthStatus? HealthStatus { get; private set; }
public bool IsHidden { private get; init; }

public required ImmutableArray<HealthReportViewModel> HealthReports
{
Expand Down Expand Up @@ -79,6 +79,11 @@ internal bool MatchesFilter(string filter)
return null;
}

public bool IsResourceHidden()
{
return IsHidden || KnownState is KnownResourceState.Hidden;
}

internal static HealthStatus? ComputeHealthStatus(ImmutableArray<HealthReportViewModel> healthReports, KnownResourceState? state)
{
if (state != KnownResourceState.Running)
Expand All @@ -100,7 +105,7 @@ public static string GetResourceName(ResourceViewModel resource, IDictionary<str
var count = 0;
foreach (var (_, item) in allResources)
{
if (item.IsHiddenState())
if (item.IsResourceHidden())
{
continue;
}
Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Dashboard/ResourceService/Partials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ public ResourceViewModel ToViewModel(IKnownPropertyLookup knownPropertyLookup, I
StateStyle = HasStateStyle ? StateStyle : null,
Commands = GetCommands(),
HealthReports = HealthReports.Select(ToHealthReportViewModel).OrderBy(vm => vm.Name).ToImmutableArray(),
IsHidden = IsHidden
};
}
catch (Exception ex)
Expand Down
6 changes: 6 additions & 0 deletions src/Aspire.Hosting/ApplicationModel/CustomResourceSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,11 @@ internal init
/// </summary>
public ImmutableArray<RelationshipSnapshot> Relationships { get; init; } = [];

/// <summary>
/// Whether this resource should be hidden in UI.
/// </summary>
public bool IsHidden { get; init; }

internal static HealthStatus? ComputeHealthStatus(ImmutableArray<HealthReportSnapshot> healthReports, string? state)
{
if (state != KnownResourceStates.Running)
Expand Down Expand Up @@ -337,6 +342,7 @@ public static class KnownResourceStates
/// <summary>
/// The hidden state. Useful for hiding the resource.
/// </summary>
[Obsolete("Use CustomResourceSnapshot.Hidden instead.")]
public static readonly string Hidden = nameof(Hidden);

/// <summary>
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/ConnectionStringBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,9 @@ public static IResourceBuilder<ConnectionStringResource> AddConnectionString(thi
{
ResourceType = "ConnectionString",
// TODO: We'll hide this until we come up with a sane representation of these in the dashboard
#pragma warning disable CS0618 // Type or member is obsolete
State = KnownResourceStates.Hidden,
#pragma warning restore CS0618 // Type or member is obsolete
Properties = []
});
}
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/Dashboard/DashboardLifecycleHook.cs
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,9 @@ private void ConfigureAspireDashboardResource(IResource dashboardResource)
},
State = configuration.GetBool(KnownConfigNames.ShowDashboardResources, KnownConfigNames.Legacy.ShowDashboardResources) is true
? null
#pragma warning disable CS0618 // Type or member is obsolete
: KnownResourceStates.Hidden
#pragma warning restore CS0618 // Type or member is obsolete
};

dashboardResource.Annotations.Add(new ResourceSnapshotAnnotation(snapshot));
Expand Down
3 changes: 2 additions & 1 deletion src/Aspire.Hosting/Dashboard/DashboardServiceData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ static GenericResourceSnapshot CreateResourceSnapshot(IResource resource, string
State = snapshot.State?.Text,
StateStyle = snapshot.State?.Style,
HealthReports = snapshot.HealthReports,
Commands = snapshot.Commands
Commands = snapshot.Commands,
IsHidden = snapshot.IsHidden,
};
}

Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/Dashboard/ResourceSnapshot.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ internal abstract class ResourceSnapshot
public required ImmutableArray<RelationshipSnapshot> Relationships { get; init; }
public required ImmutableArray<HealthReportSnapshot> HealthReports { get; init; }
public required ImmutableArray<ResourceCommandSnapshot> Commands { get; init; }
public required bool IsHidden { get; init; }

protected abstract IEnumerable<(string Key, Value Value, bool IsSensitive)> GetProperties();

Expand Down
1 change: 1 addition & 0 deletions src/Aspire.Hosting/Dashboard/proto/Partials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ public static Resource FromSnapshot(ResourceSnapshot snapshot)
Uid = snapshot.Uid,
State = snapshot.State ?? "",
StateStyle = snapshot.StateStyle ?? "",
IsHidden = snapshot.IsHidden
};

if (snapshot.CreationTimeStamp.HasValue)
Expand Down
3 changes: 3 additions & 0 deletions src/Aspire.Hosting/Dashboard/proto/resource_service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,9 @@ message Resource {

// The list of relationships for this resource.
repeated ResourceRelationship relationships = 20;

// Whether the resource should be visually hidden in the dashboard.
bool is_hidden = 21;
}

////////////////////////////////////////////
Expand Down
2 changes: 2 additions & 0 deletions src/Aspire.Hosting/Dcp/ResourceSnapshotBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,9 @@ public CustomResourceSnapshot ToSnapshot(Container container, CustomResourceSnap
var volumes = GetVolumes(container);

var environment = GetEnvironmentVariables(container.Status?.EffectiveEnv ?? container.Spec.Env, container.Spec.Env);
#pragma warning disable CS0618 // Type or member is obsolete
var state = container.AppModelInitialState == KnownResourceStates.Hidden ? KnownResourceStates.Hidden : container.Status?.State;
#pragma warning restore CS0618 // Type or member is obsolete

var relationships = ImmutableArray<RelationshipSnapshot>.Empty;

Expand Down
6 changes: 4 additions & 2 deletions src/Aspire.Hosting/ParameterResourceBuilderExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,17 +152,19 @@ private static string GetParameterValue(ConfigurationManager configuration, stri
configurationKey ??= $"Parameters:{name}";
return configuration[configurationKey]
?? parameterDefault?.GetDefaultValue()
?? throw new DistributedApplicationException($"Parameter resource could not be used because configuration key '{configurationKey}' is missing and the Parameter has no default value."); ;
?? throw new DistributedApplicationException($"Parameter resource could not be used because configuration key '{configurationKey}' is missing and the Parameter has no default value.");
}

internal static IResourceBuilder<T> AddParameter<T>(this IDistributedApplicationBuilder builder, T resource)
where T : ParameterResource
{
var state = new CustomResourceSnapshot()
var state = new CustomResourceSnapshot
{
ResourceType = "Parameter",
// hide parameters by default
#pragma warning disable CS0618 // Type or member is obsolete
State = KnownResourceStates.Hidden,
#pragma warning restore CS0618 // Type or member is obsolete
Properties = [
new("parameter.secret", resource.Secret.ToString()),
new(CustomResourceKnownProperties.Source, resource.ConfigurationKey)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -328,6 +328,7 @@ private static ResourceViewModel CreateResource(string name, string type, string
Relationships = default,
Properties = ImmutableDictionary<string, ResourcePropertyViewModel>.Empty,
Commands = [],
IsHidden = false,
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,8 @@ private static GenericResourceSnapshot CreateResourceSnapshot(string name)
Environment = [],
HealthReports = [],
Commands = [],
Relationships = []
Relationships = [],
IsHidden = false
};
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ public static Task WaitForResource(this DistributedApplication app, string resou
return app.ResourceNotifications.WaitForResourceAsync(resourceName, targetState, cancellationToken);
}

#pragma warning disable CS0618 // Type or member is obsolete
Copy link
Member

Choose a reason for hiding this comment

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

nit: can you place these just around KnownResourceStates.Hidden in the method instead of the entire method

/// <summary>
/// Waits for all resources in the application to reach one of the specified states.
/// </summary>
Expand All @@ -102,6 +103,7 @@ public static Task WaitForResources(this DistributedApplication app, IEnumerable

return Task.WhenAll(applicationModel.Resources.Select(r => app.ResourceNotifications.WaitForResourceAsync(r.Name, targetStates, cancellationToken)));
}
#pragma warning restore CS0618 // Type or member is obsolete

/// <summary>
/// Gets the app host and resource logs from the application.
Expand Down
4 changes: 3 additions & 1 deletion tests/Shared/DashboardModel/ModelTestHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public static ResourceViewModel CreateResource(
HealthStatus? reportHealthStatus = null,
bool createNullHealthReport = false,
ImmutableArray<CommandViewModel>? commands = null,
ImmutableArray<RelationshipViewModel>? relationships = null)
ImmutableArray<RelationshipViewModel>? relationships = null,
bool hidden = false)
{
return new ResourceViewModel
{
Expand All @@ -42,6 +43,7 @@ public static ResourceViewModel CreateResource(
HealthReports = reportHealthStatus is null && !createNullHealthReport ? [] : [new HealthReportViewModel("healthcheck", reportHealthStatus, null, null)],
Commands = commands ?? [],
Relationships = relationships ?? [],
IsHidden = hidden
};
}
}