Skip to content

Commit

Permalink
Determine app health status for plugin architecture (#5454)
Browse files Browse the repository at this point in the history
* Determine app health status for plugin architecture

Signed-off-by: Yoshiki Fujikane <[email protected]>

* Determine UI for Unhealthy

Signed-off-by: Yoshiki Fujikane <[email protected]>

* Prioritize unhealthy over unknown

Signed-off-by: Yoshiki Fujikane <[email protected]>

---------

Signed-off-by: Yoshiki Fujikane <[email protected]>
  • Loading branch information
ffjlabo authored Dec 27, 2024
1 parent fd90cf5 commit ab37feb
Show file tree
Hide file tree
Showing 9 changed files with 348 additions and 226 deletions.
3 changes: 1 addition & 2 deletions pkg/app/pipedv1/livestatereporter/livestatereporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,8 +142,7 @@ func (pr *pluginReporter) flushSnapshots(ctx context.Context) {
Kind: app.Kind,
ApplicationLiveState: res.GetApplicationLiveState(),
}
// TODO: Implement DetermineAppHealthStatus for the case of plugin architecture.
snapshot.DetermineAppHealthStatus()
snapshot.DetermineApplicationHealthStatus()

if _, err := pr.apiClient.ReportApplicationLiveState(ctx, &pipedservice.ReportApplicationLiveStateRequest{
Snapshot: snapshot,
Expand Down
35 changes: 35 additions & 0 deletions pkg/model/application_live_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,3 +144,38 @@ 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 {
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN
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

// prioritize unhealthy over unknown when these two statuses are both set.
if unhealthy {
s.HealthStatus = ApplicationLiveStateSnapshot_UNHEALTHY
return
}

if unknown {
s.HealthStatus = ApplicationLiveStateSnapshot_UNKNOWN
return
}
}
450 changes: 227 additions & 223 deletions pkg/model/application_live_state.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions pkg/model/application_live_state.proto
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ message ApplicationLiveStateSnapshot {
UNKNOWN = 0;
HEALTHY = 1;
OTHER = 2;
UNHEALTHY = 3;
}
string application_id = 1 [(validate.rules).string.min_len = 1];
string piped_id = 3 [(validate.rules).string.min_len = 1];
Expand Down
75 changes: 75 additions & 0 deletions pkg/model/application_live_state_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -168,3 +168,78 @@ 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,
},
{
name: "unhealthy: one of the resources is unhealthy",
snapshot: &ApplicationLiveStateSnapshot{
ApplicationLiveState: &ApplicationLiveState{
Resources: []*ResourceState{
{HealthStatus: ResourceState_HEALTHY},
{HealthStatus: ResourceState_UNHEALTHY},
},
},
},
want: ApplicationLiveStateSnapshot_UNHEALTHY,
},
{
name: "unhealthy: prioritize unhealthy over unknown",
snapshot: &ApplicationLiveStateSnapshot{
ApplicationLiveState: &ApplicationLiveState{
Resources: []*ResourceState{
{HealthStatus: ResourceState_UNKNOWN},
{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)
})
}
}
1 change: 1 addition & 0 deletions web/model/application_live_state_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ export namespace ApplicationLiveStateSnapshot {
UNKNOWN = 0,
HEALTHY = 1,
OTHER = 2,
UNHEALTHY = 3,
}
}

Expand Down
3 changes: 2 additions & 1 deletion web/model/application_live_state_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@ const useStyles = makeStyles((theme) => ({
other: {
color: theme.palette.info.main,
},
unhealthy: {
color: theme.palette.info.main,
},
}));

export interface ApplicationHealthStatusIconProps {
Expand All @@ -31,6 +34,8 @@ export const ApplicationHealthStatusIcon: FC<ApplicationHealthStatusIconProps> =
return <FavoriteIcon className={classes.healthy} />;
case ApplicationLiveStateSnapshot.Status.OTHER:
return <OtherIcon className={classes.other} />;
case ApplicationLiveStateSnapshot.Status.UNHEALTHY:
return <OtherIcon className={classes.unhealthy} />;
}
}
);
1 change: 1 addition & 0 deletions web/src/constants/health-status-text.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,5 @@ export const APPLICATION_HEALTH_STATUS_TEXT: Record<
[ApplicationLiveStateSnapshot.Status.UNKNOWN]: "Unknown",
[ApplicationLiveStateSnapshot.Status.HEALTHY]: "Healthy",
[ApplicationLiveStateSnapshot.Status.OTHER]: "Other",
[ApplicationLiveStateSnapshot.Status.UNHEALTHY]: "Unhealthy",
};

0 comments on commit ab37feb

Please sign in to comment.