From 08f0c7086d8f8edbf394a4f8cbcf39fb122ecafd Mon Sep 17 00:00:00 2001 From: oleksandr-codefresh Date: Sun, 8 Sep 2024 20:42:26 +0300 Subject: [PATCH] feat: event-reporter: report resource health status errors with parent application event (+ under app-sets) --- .../reporter/application_errors_parser.go | 17 +++++++++++++++++ .../reporter/application_event_reporter.go | 3 ++- event_reporter/reporter/event_payload.go | 17 ++++++++--------- 3 files changed, 27 insertions(+), 10 deletions(-) diff --git a/event_reporter/reporter/application_errors_parser.go b/event_reporter/reporter/application_errors_parser.go index c450abed30a4b..ba678c949385b 100644 --- a/event_reporter/reporter/application_errors_parser.go +++ b/event_reporter/reporter/application_errors_parser.go @@ -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) diff --git a/event_reporter/reporter/application_event_reporter.go b/event_reporter/reporter/application_event_reporter.go index d62ae13cf52da..730c4260ccfee 100644 --- a/event_reporter/reporter/application_event_reporter.go +++ b/event_reporter/reporter/application_event_reporter.go @@ -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) diff --git a/event_reporter/reporter/event_payload.go b/event_reporter/reporter/event_payload.go index bac87acadeff5..ecaa2f45c3e39 100644 --- a/event_reporter/reporter/event_payload.go +++ b/event_reporter/reporter/event_payload.go @@ -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 { @@ -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, @@ -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{} @@ -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, }