Determine app health status for plugin architecture#5454
Conversation
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
| UNKNOWN = 0; | ||
| HEALTHY = 1; | ||
| OTHER = 2; | ||
| UNHEALTHY = 3; |
There was a problem hiding this comment.
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.14% +0.05%
==========================================
Files 457 457
Lines 49081 49107 +26
==========================================
+ Hits 12808 12841 +33
+ Misses 35251 35244 -7
Partials 1022 1022 ☔ View full report in Codecov by Sentry. |
|
lint/web is failed, so will fix it. |
| 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.
[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 | |
| } | |
| } |
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
| case ApplicationLiveStateSnapshot.Status.UNHEALTHY: | ||
| return <OtherIcon className={classes.unhealthy} />; |
There was a problem hiding this comment.
Use OtherIcon similar to OTHER's one as the UNHEALTHY icon for now.
This is a fix for lint/web.
| 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.
| 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.
| 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.
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.
What happen if ApplicationLiveState = nil, not a dummy pointer?
There was a problem hiding this comment.
@khanhtc1202
The case is ApplicationLiveStateSnapshot_UNKNOWN as the last of the testcases, similar to the current implementation.
There was a problem hiding this comment.
Thanks for clarify, commented in https://github.com/pipe-cd/pipecd/pull/5454/files#r1898201564
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
07acfbc to
5aec9a7
Compare
| if app == nil { | ||
| return | ||
| } |
There was a problem hiding this comment.
| if app == nil { | |
| return | |
| } | |
| if app == nil { | |
| s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | |
| return | |
| } |
We should trickly assign the UNKNOWN stage here. The current logic looks like if this live state is nill, then the state will be kept "as is", which is unclearly UNKNOWN since UNKOWN is 0 in the enum. We should make it clear to avoid misunderstanding.
pkg/model/application_live_state.go
Outdated
| return | ||
| } | ||
|
|
||
| s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY |
There was a problem hiding this comment.
Move this to L169, to make reading scope smaller.
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
|
@khanhtc1202 I fixed them 🙏 |
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
|
@t-kikuc Sorry, plz re-approve 🙏 |
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?: