From 5c3bba678c4485a1f27a31dd9bfb5000c8821cfe Mon Sep 17 00:00:00 2001 From: Juan Font Date: Thu, 12 Dec 2024 15:14:26 +0000 Subject: [PATCH] Use nanos to avoid problems with really close events --- app.go | 4 ++-- audit_log.go | 4 ++-- auth_log.go | 4 ++-- 3 files changed, 6 insertions(+), 6 deletions(-) diff --git a/app.go b/app.go index 17b8760..8205c5a 100644 --- a/app.go +++ b/app.go @@ -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 @@ -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 diff --git a/audit_log.go b/audit_log.go index 2c26ee0..5fe48bc 100644 --- a/audit_log.go +++ b/audit_log.go @@ -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 @@ -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) } diff --git a/auth_log.go b/auth_log.go index 179cb5c..e98c419 100644 --- a/auth_log.go +++ b/auth_log.go @@ -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 @@ -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) }