Use bytes for flows event id (#3439)

This commit is contained in:
Viktor Liu
2025-03-07 16:12:47 +01:00
committed by GitHub
parent cb16d0f45f
commit 86370a0e7b
6 changed files with 23 additions and 20 deletions
+2 -2
View File
@@ -74,7 +74,7 @@ func (l *Logger) startReceiver() {
log.Info("flow Memory store receiver stopped")
return
case eventFields := <-c:
id := uuid.NewString()
id := uuid.New()
event := types.Event{
ID: id,
EventFields: *eventFields,
@@ -109,7 +109,7 @@ func (l *Logger) GetEvents() []*types.Event {
return l.Store.GetEvents()
}
func (l *Logger) DeleteEvents(ids []string) {
func (l *Logger) DeleteEvents(ids []uuid.UUID) {
l.Store.DeleteEvents(ids)
}
+3 -2
View File
@@ -8,6 +8,7 @@ import (
"sync"
"time"
"github.com/google/uuid"
log "github.com/sirupsen/logrus"
"google.golang.org/protobuf/types/known/timestamppb"
@@ -169,7 +170,7 @@ func (m *Manager) startSender() {
func (m *Manager) receiveACKs(client *client.GRPCClient) {
err := client.Receive(m.ctx, m.flowConfig.Interval, func(ack *proto.FlowEventAck) error {
log.Tracef("received flow event ack: %s", ack.EventId)
m.logger.DeleteEvents([]string{ack.EventId})
m.logger.DeleteEvents([]uuid.UUID{uuid.UUID(ack.EventId)})
return nil
})
@@ -192,7 +193,7 @@ func (m *Manager) send(event *nftypes.Event) error {
func toProtoEvent(publicKey []byte, event *nftypes.Event) *proto.FlowEvent {
protoEvent := &proto.FlowEvent{
EventId: event.ID,
EventId: event.ID[:],
Timestamp: timestamppb.New(event.Timestamp),
PublicKey: publicKey,
FlowFields: &proto.FlowFields{
+5 -3
View File
@@ -5,18 +5,20 @@ import (
"golang.org/x/exp/maps"
"github.com/google/uuid"
"github.com/netbirdio/netbird/client/internal/netflow/types"
)
func NewMemoryStore() *Memory {
return &Memory{
events: make(map[string]*types.Event),
events: make(map[uuid.UUID]*types.Event),
}
}
type Memory struct {
mux sync.Mutex
events map[string]*types.Event
events map[uuid.UUID]*types.Event
}
func (m *Memory) StoreEvent(event *types.Event) {
@@ -41,7 +43,7 @@ func (m *Memory) GetEvents() []*types.Event {
return events
}
func (m *Memory) DeleteEvents(ids []string) {
func (m *Memory) DeleteEvents(ids []uuid.UUID) {
m.mux.Lock()
defer m.mux.Unlock()
for _, id := range ids {
+3 -3
View File
@@ -64,7 +64,7 @@ const (
)
type Event struct {
ID string
ID uuid.UUID
Timestamp time.Time
EventFields
}
@@ -111,7 +111,7 @@ type FlowLogger interface {
// GetEvents returns all stored events
GetEvents() []*Event
// DeleteEvents deletes events from the store
DeleteEvents([]string)
DeleteEvents([]uuid.UUID)
// Close closes the logger
Close()
// Enable enables the flow logger receiver
@@ -126,7 +126,7 @@ type Store interface {
// GetEvents returns all stored events
GetEvents() []*Event
// DeleteEvents deletes events from the store
DeleteEvents([]string)
DeleteEvents([]uuid.UUID)
// Close closes the store
Close()
}