Skip to content

Commit

Permalink
Truncate logs
Browse files Browse the repository at this point in the history
  • Loading branch information
defensivedepth committed Apr 22, 2024
1 parent c4e31b8 commit 6ffbc7e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
4 changes: 2 additions & 2 deletions server/modules/elastalert/elastalert.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,7 +572,7 @@ func (e *ElastAlertEngine) startCommunityRuleImport() {
// there were errors, don't save the fingerprint.
// idempotency means we might fix it if we try again later.
log.WithFields(log.Fields{
"errors": errMap,
"errors": mutil.TruncateMap(errMap, 5),
}).Error("unable to sync all ElastAlert community detections")

if e.notify {
Expand Down Expand Up @@ -877,7 +877,7 @@ func (e *ElastAlertEngine) syncCommunityDetections(ctx context.Context, detectio
"updated": results.Updated,
"removed": results.Removed,
"unchanged": results.Unchanged,
"errors": errMap,
"errors": mutil.TruncateMap(errMap, 5),
}).Info("elastalert community diff")

return errMap, nil
Expand Down
17 changes: 17 additions & 0 deletions server/modules/util/detengine_helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,23 @@ func readStateFile(iom IOManager, path string) (lastImport *uint64, err error) {
return &unix, nil
}

func TruncateMap(originalMap map[string]error, limit int) map[string]error {
if len(originalMap) <= limit {
return originalMap // Return the original map if it's already within the limit
}

truncatedMap := make(map[string]error, limit)
count := 0
for key, value := range originalMap {
if count >= limit {
break
}
truncatedMap[key] = value
count++
}
return truncatedMap
}

func WriteStateFile(iom IOManager, path string) {
unix := time.Now().Unix()
sUnix := strconv.FormatInt(unix, 10)
Expand Down

0 comments on commit 6ffbc7e

Please sign in to comment.