Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(event-reporter): added app warning conditions reporting #346

Merged
merged 4 commits into from
Oct 23, 2024
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 level := getConditionLevel(cnd); level != "" {
errs = append(errs, &events.ObjectError{
Type: "sync",
Level: "error",
Level: level,
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.IsError() {
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
49 changes: 47 additions & 2 deletions event_reporter/reporter/applications_errors_parser_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,41 @@ func TestParseResourceSyncResultErrors(t *testing.T) {
})
}

func TestGetConditionLevel(t *testing.T) {
errorsTypes := []v1alpha1.ApplicationCondition{
{Type: v1alpha1.ApplicationConditionDeletionError},
{Type: v1alpha1.ApplicationConditionInvalidSpecError},
{Type: v1alpha1.ApplicationConditionComparisonError},
{Type: v1alpha1.ApplicationConditionSyncError},
{Type: v1alpha1.ApplicationConditionUnknownError},
}
for _, errorAppCondition := range errorsTypes {
t.Run("parses as error "+errorAppCondition.Type, func(t *testing.T) {
level := getConditionLevel(errorAppCondition)
assert.Equal(t, "error", level)
})
}

warningTypes := []v1alpha1.ApplicationCondition{
{Type: v1alpha1.ApplicationConditionSharedResourceWarning},
{Type: v1alpha1.ApplicationConditionRepeatedResourceWarning},
{Type: v1alpha1.ApplicationConditionExcludedResourceWarning},
{Type: v1alpha1.ApplicationConditionOrphanedResourceWarning},
}
for _, warningAppCondition := range warningTypes {
t.Run("parses as warning "+warningAppCondition.Type, func(t *testing.T) {
level := getConditionLevel(warningAppCondition)
assert.Equal(t, "warning", level)
})
}
}

func TestParseApplicationSyncResultErrorsFromConditions(t *testing.T) {
t.Run("conditions exists", func(t *testing.T) {
errors := parseApplicationSyncResultErrorsFromConditions(v1alpha1.ApplicationStatus{
Conditions: []v1alpha1.ApplicationCondition{
{
Type: "error",
Type: v1alpha1.ApplicationConditionSyncError,
Message: "error message",
},
},
Expand All @@ -154,11 +183,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
Loading
Loading