Skip to content

Commit

Permalink
feat: health func for notification crd
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra authored and moshloop committed Dec 23, 2024
1 parent b0fc56d commit 8d213e5
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
15 changes: 8 additions & 7 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -403,13 +403,14 @@ func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unst
return getScrapeConfigHealth
// case "ScrapePlugin":
}
// case "mission-control.flanksource.com":
// switch gvk.Kind {
// case "Notification":
// case "Playbook":
// case "NotificationSilence":
// case "Connection":
// }
case "mission-control.flanksource.com":
switch gvk.Kind {
case "Notification":
return getNotificationHealth
// case "Playbook":
// case "NotificationSilence":
// case "Connection":
}
case "kustomize.toolkit.fluxcd.io", "helm.toolkit.fluxcd.io", "source.toolkit.fluxcd.io":
return GetDefaultHealth
case "cert-manager.io":
Expand Down
45 changes: 45 additions & 0 deletions pkg/health/health_flanksource.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,48 @@ func getScrapeConfigHealth(obj *unstructured.Unstructured) (*HealthStatus, error

return status, nil
}

func getNotificationHealth(obj *unstructured.Unstructured) (*HealthStatus, error) {
failedCount, _, err := unstructured.NestedInt64(obj.Object, "status", "failed")
if err != nil {
return nil, err
}

pendingCount, _, err := unstructured.NestedInt64(obj.Object, "status", "pending")
if err != nil {
return nil, err
}

errorMessage, _, err := unstructured.NestedString(obj.Object, "status", "error")
if err != nil {
return nil, err
}

sentCount, _, err := unstructured.NestedInt64(obj.Object, "status", "sent")
if err != nil {
return nil, err
}

var h Health = HealthUnknown
if sentCount > 0 {
h = HealthHealthy
if failedCount > 0 || pendingCount > 0 {
h = HealthWarning
}
} else {
if pendingCount > 0 {
h = HealthWarning
}
if failedCount > 0 {
h = HealthUnhealthy
}
}

status := &HealthStatus{Health: h}

if errorMessage != "" {
status.Message = errorMessage
}

return status, nil
}

0 comments on commit 8d213e5

Please sign in to comment.