-
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
Changes from 1 commit
6734011
8e16586
b723484
5aec9a7
f3bbedd
400e581
a236221
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -144,3 +144,24 @@ func (s *ApplicationLiveStateSnapshot) determineLambdaAppHealthStatus() { | |||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
// DetermineApplicationHealthStatus updates the health status of the application based on the health status of its resources. | ||||||||||||||||||||||||||||||||||||||||||||||||||
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 | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||||||||||||
if r.HealthStatus == ResourceState_UNKNOWN { | ||||||||||||||||||||||||||||||||||||||||||||||||||
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN | ||||||||||||||||||||||||||||||||||||||||||||||||||
return | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. In the following code,
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||||||||||||||||||||||||||||||||||||||||||||||||||
s.HealthStatus = ApplicationLiveStateSnapshot_HEALTHY | ||||||||||||||||||||||||||||||||||||||||||||||||||
khanhtc1202 marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||||||||||||||||||||||||||||
} |
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. We decided to use |
||
} | ||
string application_id = 1 [(validate.rules).string.min_len = 1]; | ||
string piped_id = 3 [(validate.rules).string.min_len = 1]; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -168,3 +168,65 @@ func TestApplicationLiveStateSnapshot_DetermineAppHealthStatus(t *testing.T) { | |
}) | ||
} | ||
} | ||
func TestApplicationLiveStateSnapshot_DetermineApplicationHealthStatus(t *testing.T) { | ||
testcases := []struct { | ||
name string | ||
snapshot *ApplicationLiveStateSnapshot | ||
want ApplicationLiveStateSnapshot_Status | ||
}{ | ||
{ | ||
name: "healthy: all resources are healthy", | ||
snapshot: &ApplicationLiveStateSnapshot{ | ||
ApplicationLiveState: &ApplicationLiveState{ | ||
Resources: []*ResourceState{ | ||
{HealthStatus: ResourceState_HEALTHY}, | ||
{HealthStatus: ResourceState_HEALTHY}, | ||
}, | ||
}, | ||
}, | ||
want: ApplicationLiveStateSnapshot_HEALTHY, | ||
}, | ||
{ | ||
name: "healthy: no resources", | ||
snapshot: &ApplicationLiveStateSnapshot{ | ||
ApplicationLiveState: &ApplicationLiveState{}, | ||
}, | ||
want: ApplicationLiveStateSnapshot_HEALTHY, | ||
Comment on lines
+191
to
+195
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 commentThe reason will be displayed to describe this comment to others. Learn more. @khanhtc1202 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 |
||
}, | ||
{ | ||
name: "unhealthy: one of the resources is unhealthy", | ||
snapshot: &ApplicationLiveStateSnapshot{ | ||
ApplicationLiveState: &ApplicationLiveState{ | ||
Resources: []*ResourceState{ | ||
{HealthStatus: ResourceState_HEALTHY}, | ||
{HealthStatus: ResourceState_UNHEALTHY}, | ||
}, | ||
}, | ||
}, | ||
want: ApplicationLiveStateSnapshot_UNHEALTHY, | ||
}, | ||
{ | ||
name: "unknown: one of the resources is unknown", | ||
snapshot: &ApplicationLiveStateSnapshot{ | ||
ApplicationLiveState: &ApplicationLiveState{ | ||
Resources: []*ResourceState{ | ||
{HealthStatus: ResourceState_HEALTHY}, | ||
{HealthStatus: ResourceState_UNKNOWN}, | ||
}, | ||
}, | ||
}, | ||
want: ApplicationLiveStateSnapshot_UNKNOWN, | ||
}, | ||
{ | ||
name: "unknown: nil application live state", | ||
snapshot: &ApplicationLiveStateSnapshot{}, | ||
want: ApplicationLiveStateSnapshot_UNKNOWN, | ||
}, | ||
} | ||
for _, tc := range testcases { | ||
t.Run(tc.name, func(t *testing.T) { | ||
tc.snapshot.DetermineApplicationHealthStatus() | ||
assert.Equal(t, tc.want, tc.snapshot.HealthStatus) | ||
}) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 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