Skip to content

Commit

Permalink
event-reporter: added app warning conditions reporting
Browse files Browse the repository at this point in the history
  • Loading branch information
oleksandr-codefresh committed Oct 23, 2024
1 parent e7664de commit a31d298
Show file tree
Hide file tree
Showing 6 changed files with 134 additions and 98 deletions.
2 changes: 1 addition & 1 deletion changelog/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
### Features
- feat: manage clusters via proxy
- feat(event-reporter): added warning conditions reporting
23 changes: 16 additions & 7 deletions event_reporter/reporter/application_errors_parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ func parseApplicationSyncResultErrorsFromConditions(status appv1.ApplicationStat
return errs
}
for _, cnd := range status.Conditions {
if !strings.Contains(strings.ToLower(cnd.Type), "error") {
continue
}

lastSeen := metav1.Now()
if cnd.LastTransitionTime != nil {
lastSeen = *cnd.LastTransitionTime
Expand All @@ -52,10 +48,13 @@ func parseApplicationSyncResultErrorsFromConditions(status appv1.ApplicationStat
resourcesSyncErrors := parseAggregativeResourcesSyncErrors(status.OperationState.SyncResult.Resources)

errs = append(errs, resourcesSyncErrors...)
} else {
continue
}

if cnd.IsError() || cnd.IsWarning() {
errs = append(errs, &events.ObjectError{
Type: "sync",
Level: "error",
Level: getConditionLevel(cnd),
Message: cnd.Message,
LastSeen: lastSeen,
})
Expand All @@ -64,6 +63,16 @@ func parseApplicationSyncResultErrorsFromConditions(status appv1.ApplicationStat
return errs
}

func getConditionLevel(cnd appv1.ApplicationCondition) string {
if cnd.IsWarning() {
return "warning"
}
if cnd.IsWarning() {
return "error"
}
return ""
}

func parseResourceSyncResultErrors(rs *appv1.ResourceStatus, os *appv1.OperationState) []*events.ObjectError {
errors := []*events.ObjectError{}
if os.SyncResult == nil {
Expand Down Expand Up @@ -133,7 +142,7 @@ func parseAggregativeHealthErrors(rs *appv1.ResourceStatus, apptree *appv1.Appli
}

if addReference {
newErr.SourceReference = events.ErrorSourceReference{
newErr.SourceReference = &events.ErrorSourceReference{
Group: rs.Group,
Version: rs.Version,
Kind: rs.Kind,
Expand Down
20 changes: 18 additions & 2 deletions event_reporter/reporter/applications_errors_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ func TestParseApplicationSyncResultErrorsFromConditions(t *testing.T) {
errors := parseApplicationSyncResultErrorsFromConditions(v1alpha1.ApplicationStatus{
Conditions: []v1alpha1.ApplicationCondition{
{
Type: "error",
Type: v1alpha1.ApplicationConditionSyncError,
Message: "error message",
},
},
Expand All @@ -154,11 +154,27 @@ func TestParseApplicationSyncResultErrorsFromConditions(t *testing.T) {
assert.Equal(t, "error", errors[0].Level)
})

t.Run("warning exists", func(t *testing.T) {
errors := parseApplicationSyncResultErrorsFromConditions(v1alpha1.ApplicationStatus{
Conditions: []v1alpha1.ApplicationCondition{
{
Type: v1alpha1.ApplicationConditionOrphanedResourceWarning,
Message: "Application has 8 orphaned resources",
},
},
})

assert.Len(t, errors, 1)
assert.Equal(t, "Application has 8 orphaned resources", errors[0].Message)
assert.Equal(t, "sync", errors[0].Type)
assert.Equal(t, "warning", errors[0].Level)
})

t.Run("conditions erorr replaced with sync result errors", func(t *testing.T) {
errors := parseApplicationSyncResultErrorsFromConditions(v1alpha1.ApplicationStatus{
Conditions: []v1alpha1.ApplicationCondition{
{
Type: "error",
Type: v1alpha1.ApplicationConditionSyncError,
Message: syncTaskUnsuccessfullErrorMessage,
},
},
Expand Down
180 changes: 93 additions & 87 deletions pkg/apiclient/events/events.pb.go

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

5 changes: 5 additions & 0 deletions pkg/apis/application/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2869,6 +2869,11 @@ func (condition *ApplicationCondition) IsError() bool {
return strings.HasSuffix(condition.Type, "Error")
}

// IsWarning returns true if a condition indicates an warning condition
func (condition *ApplicationCondition) IsWarning() bool {
return strings.HasSuffix(condition.Type, "Warning")
}

// Equals compares two instances of ApplicationSource and return true if instances are equal.
func (source *ApplicationSource) Equals(other *ApplicationSource) bool {
if source == nil && other == nil {
Expand Down
Loading

0 comments on commit a31d298

Please sign in to comment.