-
Notifications
You must be signed in to change notification settings - Fork 156
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
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.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. |
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.
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 for clarify, commented in https://github.com/pipe-cd/pipecd/pull/5454/files#r1898201564
Signed-off-by: Yoshiki Fujikane <[email protected]>
07acfbc
to
5aec9a7
Compare
pkg/model/application_live_state.go
Outdated
if app == nil { | ||
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.
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.
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.
FIxed at f3bbedd
pkg/model/application_live_state.go
Outdated
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.
Move this to L169, to make reading scope smaller.
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]>
@khanhtc1202 I fixed them 🙏 |
Signed-off-by: Yoshiki Fujikane <[email protected]>
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 👍
@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?: