Skip to content

Commit

Permalink
chore: add scrape config health
Browse files Browse the repository at this point in the history
  • Loading branch information
yashmehrotra committed Dec 19, 2024
1 parent 2a2023d commit 309c993
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 5 deletions.
11 changes: 6 additions & 5 deletions pkg/health/health.go
Original file line number Diff line number Diff line change
Expand Up @@ -397,11 +397,12 @@ func GetHealthCheckFunc(gvk schema.GroupVersionKind) func(obj *unstructured.Unst
// case "Component":
// case "Topology":
}
// case "configs.flanksource.com":
// switch gvk.Kind {
// case "ScrapeConfig":
// case "ScrapePlugin":
// }
case "configs.flanksource.com":
switch gvk.Kind {
case "ScrapeConfig":
return getScrapeConfigHealth
// case "ScrapePlugin":
}
// case "mission-control.flanksource.com":
// switch gvk.Kind {
// case "Notification":
Expand Down
42 changes: 42 additions & 0 deletions pkg/health/health_flanksource.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package health
import (
"regexp"
"strconv"
"strings"

"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)
Expand Down Expand Up @@ -66,3 +67,44 @@ func parseCanaryUptime(uptime string) *float64 {

return &v
}

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

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

var h Health
switch {
case errorCount == 0 && successCount == 0:
h = HealthUnknown
case errorCount == 0 && successCount > 0:
h = HealthHealthy
case errorCount > 0 && successCount == 0:
h = HealthUnhealthy
case errorCount > 0 && successCount > 0:
h = HealthWarning
default:
h = HealthUnknown
}

status := &HealthStatus{Health: h}

if errorCount > 0 {
errorMsgs, _, err := unstructured.NestedStringSlice(obj.Object, "status", "lastRun", "errors")
if err != nil {
return nil, err
}

if len(errorMsgs) > 0 {
status.Message = strings.Join(errorMsgs, ",")
}
}

return status, nil
}

0 comments on commit 309c993

Please sign in to comment.