-
Notifications
You must be signed in to change notification settings - Fork 154
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
Determine app health status for plugin architecture #5454
base: master
Are you sure you want to change the base?
Determine app health status for plugin architecture #5454
Conversation
Signed-off-by: Yoshiki Fujikane <[email protected]>
@@ -29,6 +29,7 @@ message ApplicationLiveStateSnapshot { | |||
UNKNOWN = 0; | |||
HEALTHY = 1; | |||
OTHER = 2; | |||
UNHEALTHY = 3; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We decided to use UNHEALTHY
instead of OTHER
in pipedv1
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5454 +/- ##
==========================================
+ Coverage 26.09% 26.13% +0.03%
==========================================
Files 457 457
Lines 49081 49105 +24
==========================================
+ Hits 12808 12833 +25
+ Misses 35251 35250 -1
Partials 1022 1022 ☔ View full report in Codecov by Sentry. |
lint/web is failed, so will fix it. |
pkg/model/application_live_state.go
Outdated
for _, r := range app.Resources { | ||
if r.HealthStatus == ResourceState_UNHEALTHY { | ||
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | ||
return | ||
} | ||
|
||
if r.HealthStatus == ResourceState_UNKNOWN { | ||
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | ||
return | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[IMO] How about prioritizing UNHEALTHY?
In your code, the app's health status depends on resource order.
(e.g. If an Unknown resource is found earlier than an Unhealthy resource, then it's Unknown)
In the following code,
1. If any Unhealthy is found, then the app is Unhealthy.
2. If no Unhealthy was found and any Unknown is found, then the app is Unknown
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNHEALTHY { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | |
return | |
} | |
if r.HealthStatus == ResourceState_UNKNOWN { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
return | |
} | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNHEALTHY { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | |
return | |
} | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNKNOWN { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
return | |
} | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Signed-off-by: Yoshiki Fujikane <[email protected]>
Signed-off-by: Yoshiki Fujikane <[email protected]>
case ApplicationLiveStateSnapshot.Status.UNHEALTHY: | ||
return <OtherIcon className={classes.unhealthy} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use OtherIcon similar to OTHER
's one as the UNHEALTHY
icon for now.
This is a fix for lint/web.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!!
pkg/model/application_live_state.go
Outdated
func (s *ApplicationLiveStateSnapshot) DetermineApplicationHealthStatus() { | ||
app := s.ApplicationLiveState | ||
if app == nil { | ||
return | ||
} | ||
|
||
for _, r := range app.Resources { | ||
if r.HealthStatus == ResourceState_UNHEALTHY { | ||
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | ||
return | ||
} | ||
} | ||
|
||
for _, r := range app.Resources { | ||
if r.HealthStatus == ResourceState_UNKNOWN { | ||
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | ||
return | ||
} | ||
} | ||
|
||
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (s *ApplicationLiveStateSnapshot) DetermineApplicationHealthStatus() { | |
app := s.ApplicationLiveState | |
if app == nil { | |
return | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNHEALTHY { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | |
return | |
} | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNKNOWN { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
return | |
} | |
} | |
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | |
} | |
func (s *ApplicationLiveStateSnapshot) DetermineApplicationHealthStatus() { | |
app := s.ApplicationLiveState | |
if app == nil { | |
return | |
} | |
unhealthy := false | |
unknown := false | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNHEALTHY { | |
unhealthy = true | |
} | |
if r.HealthStatus == ResourceState_UNKNOWN { | |
unknown = true | |
} | |
} | |
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | |
if unhealthy { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | |
} | |
if unknown { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
} | |
} |
@ffjlabo @t-kikuc ok, let's me suggest a clear version of what you both trying to do 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
func (s *ApplicationLiveStateSnapshot) DetermineApplicationHealthStatus() { | |
app := s.ApplicationLiveState | |
if app == nil { | |
return | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNHEALTHY { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | |
return | |
} | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNKNOWN { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
return | |
} | |
} | |
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | |
} | |
func (s *ApplicationLiveStateSnapshot) DetermineApplicationHealthStatus() { | |
app := s.ApplicationLiveState | |
if app == nil { | |
return | |
} | |
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNHEALTHY { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY | |
return | |
} | |
} | |
for _, r := range app.Resources { | |
if r.HealthStatus == ResourceState_UNKNOWN { | |
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
return | |
} | |
} | |
} |
Or another version at least could be this to avoid miss set health status.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks both @khanhtc1202 @t-kikuc
I fixed it to reduce one for statement.
5aec9a7
name: "healthy: no resources", | ||
snapshot: &ApplicationLiveStateSnapshot{ | ||
ApplicationLiveState: &ApplicationLiveState{}, | ||
}, | ||
want: ApplicationLiveStateSnapshot_HEALTHY, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What happen if ApplicationLiveState = nil, not a dummy pointer?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@khanhtc1202
The case is ApplicationLiveStateSnapshot_UNKNOWN
as the last of the testcases, similar to the current implementation.
Signed-off-by: Yoshiki Fujikane <[email protected]>
07acfbc
to
5aec9a7
Compare
What this PR does:
Added a method to determine application health state.
Why we need it:
In the pipedv0, there is a similar method called
DetermineAppHealthStatus
, but I don't want to use it to avoid implementation logic based on the kind.pipecd/pkg/model/application_live_state.go
Lines 62 to 74 in 6734011
Which issue(s) this PR fixes:
Part of #5363
Does this PR introduce a user-facing change?: