-
Notifications
You must be signed in to change notification settings - Fork 685
Remove HealthStatus defaulting to healthy when there is no value from a health check #6209
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
adamint
merged 28 commits into
dotnet:main
from
adamint:dev/adamint/remove-default-healthy-status
Oct 17, 2024
Merged
Changes from 4 commits
Commits
Show all changes
28 commits
Select commit
Hold shift + click to select a range
150ec05
Remove HealthStatus defaulting to healthy when there is no value from…
c26e8dd
Show unhealthy only if health status is not null
57f11be
Add null assert to status in ResourceNotificationTests
c66b778
Add test for StateColumnDisplay static functions
7fb3fa0
Merge branch 'main' into dev/adamint/remove-default-healthy-status
a2df9ed
Update with new expectations
049dcee
Create initial health reports if we have not received from server
951e1f9
update public api
19bb010
Plumb nullable health status / reports through, create fake snapshots…
613784c
Make resource healthy if it is running with no health checks
2e10709
Update comment
f138e46
Clean up
c726d5a
Add initial test, move health status update logic elsewhere in notifi…
54c32fd
Add two more tests
78178d8
Fix flaky test
65cd571
Simplify test
caf163e
Merge branch 'refs/heads/main' into dev/adamint/remove-default-health…
a28f89d
Apply PR suggestions
254b88d
Merge branch 'main' into dev/adamint/remove-default-healthy-status
6535aae
Add RuntimeUnhealthy state to known states, as it is affected in Stat…
c37db7d
Refactor state column display and its tests
JamesNK 749c0b6
Runtime unhealthy improvements
JamesNK e168dc9
Merge
JamesNK ac14849
Fix merge
JamesNK 0297102
Fix state not changing
JamesNK ead2b13
check at beginning of update health status if health status is not al…
3eacb74
Set state to running (unhealthy) on empty health status
3f23964
Update test expectations
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
4 changes: 2 additions & 2 deletions
4
src/Aspire.Dashboard/Components/ResourcesGridColumns/StateColumnDisplay.razor
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
112 changes: 112 additions & 0 deletions
112
tests/Aspire.Dashboard.Components.Tests/Controls/StateColumnDisplayTests.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,112 @@ | ||
// Licensed to the .NET Foundation under one or more agreements. | ||
// The .NET Foundation licenses this file to you under the MIT license. | ||
|
||
using System.Collections.Frozen; | ||
using Aspire.Dashboard.Components.ResourcesGridColumns; | ||
using Aspire.Dashboard.Model; | ||
using Google.Protobuf.WellKnownTypes; | ||
using Microsoft.Extensions.Diagnostics.HealthChecks; | ||
using Microsoft.Extensions.Logging.Abstractions; | ||
using Microsoft.FluentUI.AspNetCore.Components; | ||
using Xunit; | ||
using Enum = System.Enum; | ||
|
||
namespace Aspire.Dashboard.Components.Tests.Controls; | ||
|
||
public class StateColumnDisplayTests | ||
{ | ||
private const string ResourceType = "TestResourceType"; | ||
private const string ExitedUnexpectedlyTooltip = "Exited Unexpectedly {0} {1}"; | ||
private const string ExitedTooltip = "Exited {0}"; | ||
private const string RunningAndUnhealthyTooltip = "Running and Unhealthy"; | ||
private const string UnknownStateLabel = "Unknown"; | ||
|
||
[Theory] | ||
// Resource is no longer running | ||
[InlineData( | ||
/* state */ KnownResourceState.Exited, null, null,null, | ||
/* expected output */ "Exited TestResourceType", "Warning", Color.Warning, "Exited")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Exited, 3, null, null, | ||
/* expected output */ "Exited Unexpectedly TestResourceType 3", "ErrorCircle", Color.Error, "Exited")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Finished, 0, null, null, | ||
/* expected output */ "Exited TestResourceType", "CheckmarkUnderlineCircle", Color.Success, "Finished")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Unknown, null, null, null, | ||
/* expected output */ null, "CircleHint", Color.Info, "Unknown")] | ||
// Health checks | ||
[InlineData( | ||
/* state */ KnownResourceState.Running, null, "Healthy", null, | ||
/* expected output */ null, "CheckmarkCircle", Color.Success, "Running")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Running, null, null, null, | ||
/* expected output */ null, "CheckmarkCircle", Color.Success, "Running")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Running, null, "Unhealthy", null, | ||
/* expected output */ RunningAndUnhealthyTooltip, "CheckmarkCircleWarning", Color.Neutral, "Running (Unhealthy)")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Running, null, null, "warning", | ||
/* expected output */ null, "Warning", Color.Warning, "Running")] | ||
[InlineData( | ||
/* state */ KnownResourceState.Running, null, null, "NOT_A_VALID_STATE_STYLE", | ||
/* expected output */ null, "Circle", Color.Neutral, "Running")] | ||
public void ResourceViewModel_ReturnsCorrectIconAndTooltip( | ||
adamint marked this conversation as resolved.
Show resolved
Hide resolved
|
||
KnownResourceState state, | ||
int? exitCode, | ||
string? healthStatusString, | ||
string? stateStyle, | ||
string? expectedTooltip, | ||
string expectedIconName, | ||
Color expectedColor, | ||
string expectedText) | ||
{ | ||
// Arrange | ||
HealthStatus? healthStatus = healthStatusString is null ? null : Enum.Parse<HealthStatus>(healthStatusString); | ||
var propertiesDictionary = new Dictionary<string, ResourcePropertyViewModel>(); | ||
if (exitCode is not null) | ||
{ | ||
propertiesDictionary.TryAdd(KnownProperties.Resource.ExitCode, new ResourcePropertyViewModel(KnownProperties.Resource.ExitCode, Value.ForNumber((double)exitCode), false, null, 0, new BrowserTimeProvider(new NullLoggerFactory()))); | ||
} | ||
|
||
var resource = new ResourceViewModel | ||
{ | ||
// these are the properties that affect this column | ||
State = state.ToString(), | ||
KnownState = state, | ||
HealthStatus = healthStatus, | ||
StateStyle = stateStyle, | ||
Properties = propertiesDictionary.ToFrozenDictionary(), | ||
|
||
// these properties don't matter | ||
Name = string.Empty, | ||
ResourceType = ResourceType, | ||
DisplayName = string.Empty, | ||
Uid = string.Empty, | ||
CreationTimeStamp = null, | ||
StartTimeStamp = null, | ||
StopTimeStamp = null, | ||
Environment = default, | ||
Urls = default, | ||
Volumes = default, | ||
Commands = default, | ||
HealthReports = default | ||
}; | ||
|
||
if (exitCode is not null) | ||
{ | ||
resource.Properties.TryAdd(KnownProperties.Resource.ExitCode, new ResourcePropertyViewModel(KnownProperties.Resource.ExitCode, Value.ForNumber((double)exitCode), false, null, 0, new BrowserTimeProvider(new NullLoggerFactory()))); | ||
} | ||
|
||
// Act | ||
var tooltip = StateColumnDisplay.GetResourceStateTooltip(resource, ExitedUnexpectedlyTooltip, ExitedTooltip, RunningAndUnhealthyTooltip); | ||
var vm = StateColumnDisplay.GetStateViewModel(resource, UnknownStateLabel); | ||
|
||
// Assert | ||
Assert.Equal(expectedTooltip, tooltip); | ||
|
||
Assert.Equal(expectedIconName, vm.Icon.Name); | ||
Assert.Equal(expectedColor, vm.Color); | ||
Assert.Equal(expectedText, vm.Text); | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.