Skip to content

Commit

Permalink
feat: event-reporter: report resource health status errors with paren…
Browse files Browse the repository at this point in the history
…t application event (+ under app-sets)
  • Loading branch information
oleksandr-codefresh committed Sep 8, 2024
1 parent 9e78a78 commit 08f0c70
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 10 deletions.
17 changes: 17 additions & 0 deletions event_reporter/reporter/application_errors_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,23 @@ func parseResourceSyncResultErrors(rs *appv1.ResourceStatus, os *appv1.Operation
return errors
}

func parseAggregativeHealthErrorsOfApplication(a *appv1.Application, appTree *appv1.ApplicationTree) []*events.ObjectError {
var errors []*events.ObjectError
if a.Status.Resources == nil {
return errors
}

for _, rs := range a.Status.Resources {
if rs.Health != nil {
if rs.Health.Status != health.HealthStatusHealthy {
errors = append(errors, parseAggregativeHealthErrors(&rs, appTree, true)...)
}
}
}

return errors
}

func parseAggregativeHealthErrors(rs *appv1.ResourceStatus, apptree *appv1.ApplicationTree, addReference bool) []*events.ObjectError {
errs := make([]*events.ObjectError, 0)

Expand Down
3 changes: 2 additions & 1 deletion event_reporter/reporter/application_event_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,8 @@ func (s *applicationEventReporter) StreamApplicationEvents(
} else {
logCtx.Info("processing as root application")
// will get here only for root applications (not managed as a resource by another application)
appEvent, err := s.getApplicationEventPayload(ctx, a, ts, appInstanceLabelKey, trackingMethod, desiredManifests.ApplicationVersions)
appEvent, err := s.getApplicationEventPayload(ctx, a, appTree, ts, appInstanceLabelKey, trackingMethod, desiredManifests.ApplicationVersions)

if err != nil {
s.metricsServer.IncErroredEventsCounter(metrics.MetricParentAppEventType, metrics.MetricEventGetPayloadErrorType, a.Name)
return fmt.Errorf("failed to get application event: %w", err)
Expand Down
17 changes: 8 additions & 9 deletions event_reporter/reporter/event_payload.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,14 +128,8 @@ func getResourceEventPayload(
errors = append(errors, parseApplicationSyncResultErrorsFromConditions(originalApplication.Status)...)
}

if originalApplication != nil && originalApplication.Status.Resources != nil {
for _, rs := range originalApplication.Status.Resources {
if rs.Health != nil {
if rs.Health.Status != health.HealthStatusHealthy {
errors = append(errors, parseAggregativeHealthErrors(&rs, apptree, true)...)
}
}
}
if originalApplication != nil {
errors = append(errors, parseAggregativeHealthErrorsOfApplication(originalApplication, apptree)...)
}

if len(desiredState.RawManifest) == 0 && len(desiredState.CompiledManifest) != 0 {
Expand Down Expand Up @@ -207,6 +201,7 @@ func getResourceEventPayload(
func (s *applicationEventReporter) getApplicationEventPayload(
ctx context.Context,
a *appv1.Application,
appTree *appv1.ApplicationTree,
ts string,
appInstanceLabelKey string,
trackingMethod appv1.TrackingMethod,
Expand All @@ -216,6 +211,7 @@ func (s *applicationEventReporter) getApplicationEventPayload(
syncStarted = metav1.Now()
syncFinished *metav1.Time
logCtx = log.WithField("application", a.Name)
errors = []*events.ObjectError{}
)

obj := appv1.Application{}
Expand Down Expand Up @@ -291,11 +287,14 @@ func (s *applicationEventReporter) getApplicationEventPayload(
TrackingMethod: string(trackingMethod),
}

errors = append(errors, parseApplicationSyncResultErrorsFromConditions(a.Status)...)
errors = append(errors, parseAggregativeHealthErrorsOfApplication(a, appTree)...)

payload := events.EventPayload{
Timestamp: ts,
Object: object,
Source: source,
Errors: parseApplicationSyncResultErrorsFromConditions(a.Status),
Errors: errors,
AppVersions: applicationVersionsEvents,
}

Expand Down

0 comments on commit 08f0c70

Please sign in to comment.