Skip to content

Commit

Permalink
Use nanos to avoid problems with really close events
Browse files Browse the repository at this point in the history
  • Loading branch information
Juan Font committed Dec 12, 2024
1 parent f89b337 commit 5c3bba6
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ func (s *GitLabLogStreamer) preloadDBRecentData() error {
}

for _, event := range auditEvents {
s.latestAuditLogEvents.Store(fmt.Sprintf("%s,%s", event.CorrelationID, event.Time.Format(time.RFC3339)), *event)
s.latestAuditLogEvents.Store(fmt.Sprintf("%s,%d", event.CorrelationID, event.Time.UnixNano()), *event)
}

// load the auth log events from the last preloadEventsPeriodDays from s.db
Expand All @@ -113,7 +113,7 @@ func (s *GitLabLogStreamer) preloadDBRecentData() error {
}

for _, event := range authEvent {
s.latestAuthEvents.Store(fmt.Sprintf("%s,%s", event.CorrelationID, event.Time.Format(time.RFC3339)), *event)
s.latestAuthEvents.Store(fmt.Sprintf("%s,%d", event.CorrelationID, event.Time.UnixNano()), *event)
}

return nil
Expand Down
4 changes: 2 additions & 2 deletions audit_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ func (s *GitLabLogStreamer) processNewAuditLogEvents(auditEvents []*AuditEvent)
// if it does, we skip it
// if it doesn't, we insert it

_, ok := s.latestAuditLogEvents.Load(fmt.Sprintf("%s,%s", auditEvent.CorrelationID, auditEvent.Time.Format(time.RFC3339)))
_, ok := s.latestAuditLogEvents.Load(fmt.Sprintf("%s,%d", auditEvent.CorrelationID, auditEvent.Time.UnixNano()))
if ok {
log.Debug().Msgf("Audit event with correlation ID %s at %s already exists. Skipping", auditEvent.CorrelationID, auditEvent.Time.Format(time.RFC3339))
continue
Expand All @@ -96,7 +96,7 @@ func (s *GitLabLogStreamer) processNewAuditLogEvents(auditEvents []*AuditEvent)
return newEvents, err
}

s.latestAuditLogEvents.Store(fmt.Sprintf("%s,%s", auditEvent.CorrelationID, auditEvent.Time.Format(time.RFC3339)), *auditEvent)
s.latestAuditLogEvents.Store(fmt.Sprintf("%s,%d", auditEvent.CorrelationID, auditEvent.Time.UnixNano()), *auditEvent)
newEvents = append(newEvents, auditEvent)
log.Info().Msgf("Inserted audit event with correlation ID %s", auditEvent.CorrelationID)
}
Expand Down
4 changes: 2 additions & 2 deletions auth_log.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ func (s *GitLabLogStreamer) processNewAuthEvents(authEvents []*AuthEvent) ([]*Au
// if it does, we skip it
// if it doesn't, we insert it

_, ok := s.latestAuthEvents.Load(fmt.Sprintf("%s,%s", authEvent.CorrelationID, authEvent.Time.Format(time.RFC3339)))
_, ok := s.latestAuthEvents.Load(fmt.Sprintf("%s,%d", authEvent.CorrelationID, authEvent.Time.UnixNano()))
if ok {
log.Debug().Msgf("Auth event with correlation ID %s at %s already exists. Skipping", authEvent.CorrelationID, authEvent.Time.Format(time.RFC3339))
continue
Expand All @@ -101,7 +101,7 @@ func (s *GitLabLogStreamer) processNewAuthEvents(authEvents []*AuthEvent) ([]*Au
return newEvents, err
}

s.latestAuthEvents.Store(fmt.Sprintf("%s,%s", authEvent.CorrelationID, authEvent.Time.Format(time.RFC3339)), *authEvent)
s.latestAuthEvents.Store(fmt.Sprintf("%s,%d", authEvent.CorrelationID, authEvent.Time.UnixNano()), *authEvent)
newEvents = append(newEvents, authEvent)
log.Info().Msgf("Inserted auth event with correlation ID %s", authEvent.CorrelationID)
}
Expand Down

0 comments on commit 5c3bba6

Please sign in to comment.