Loading main.go +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ func main() { tracker.SetMatchLeaveListener(matchRegistry.Leave) streamManager := server.NewLocalStreamManager(config, sessionRegistry, tracker) storageIndex, err := server.NewLocalStorageIndex(logger, db, config.GetStorage()) storageIndex, err := server.NewLocalStorageIndex(logger, db, config.GetStorage(), metrics) if err != nil { logger.Fatal("Failed to initialize storage index", zap.Error(err)) } Loading server/metrics.go +5 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ type Metrics interface { CountWebsocketClosed(delta int64) GaugeSessions(value float64) GaugePresences(value float64) GaugeStorageIndexEntries(indexName string, value float64) Matchmaker(tickets, activeTickets float64, processTime time.Duration) Loading Loading @@ -417,6 +418,10 @@ func (m *LocalMetrics) GaugePresences(value float64) { m.PrometheusScope.Gauge("presences").Update(value) } func (m *LocalMetrics) GaugeStorageIndexEntries(indexName string, value float64) { m.PrometheusScope.Tagged(map[string]string{"index_name": indexName}).Gauge("storage_index_entry_count").Update(value) } // Record a set of matchmaker metrics. func (m *LocalMetrics) Matchmaker(tickets, activeTickets float64, processTime time.Duration) { m.PrometheusScope.Gauge("matchmaker_tickets").Update(tickets) Loading server/storage_index.go +5 −1 Original line number Diff line number Diff line Loading @@ -54,16 +54,18 @@ type storageIndex struct { type LocalStorageIndex struct { logger *zap.Logger db *sql.DB metrics Metrics indexByName map[string]*storageIndex indicesByCollection map[string][]*storageIndex customFilterFunctions map[string]RuntimeStorageIndexFilterFunction config *StorageConfig } func NewLocalStorageIndex(logger *zap.Logger, db *sql.DB, config *StorageConfig) (StorageIndex, error) { func NewLocalStorageIndex(logger *zap.Logger, db *sql.DB, config *StorageConfig, metrics Metrics) (StorageIndex, error) { si := &LocalStorageIndex{ logger: logger, db: db, metrics: metrics, indexByName: make(map[string]*storageIndex), indicesByCollection: make(map[string][]*storageIndex), customFilterFunctions: make(map[string]RuntimeStorageIndexFilterFunction), Loading Loading @@ -149,6 +151,8 @@ func (si *LocalStorageIndex) Write(ctx context.Context, objects []*api.StorageOb } count, _ := reader.Count() // cannot return err si.metrics.GaugeStorageIndexEntries(idx.Name, float64(count)) // Apply eviction strategy if size of index is +10% than max size if count > uint64(float32(idx.MaxEntries)*(1.1)) { deleteCount := int(count - uint64(idx.MaxEntries)) Loading Loading
main.go +1 −1 Original line number Diff line number Diff line Loading @@ -147,7 +147,7 @@ func main() { tracker.SetMatchLeaveListener(matchRegistry.Leave) streamManager := server.NewLocalStreamManager(config, sessionRegistry, tracker) storageIndex, err := server.NewLocalStorageIndex(logger, db, config.GetStorage()) storageIndex, err := server.NewLocalStorageIndex(logger, db, config.GetStorage(), metrics) if err != nil { logger.Fatal("Failed to initialize storage index", zap.Error(err)) } Loading
server/metrics.go +5 −0 Original line number Diff line number Diff line Loading @@ -55,6 +55,7 @@ type Metrics interface { CountWebsocketClosed(delta int64) GaugeSessions(value float64) GaugePresences(value float64) GaugeStorageIndexEntries(indexName string, value float64) Matchmaker(tickets, activeTickets float64, processTime time.Duration) Loading Loading @@ -417,6 +418,10 @@ func (m *LocalMetrics) GaugePresences(value float64) { m.PrometheusScope.Gauge("presences").Update(value) } func (m *LocalMetrics) GaugeStorageIndexEntries(indexName string, value float64) { m.PrometheusScope.Tagged(map[string]string{"index_name": indexName}).Gauge("storage_index_entry_count").Update(value) } // Record a set of matchmaker metrics. func (m *LocalMetrics) Matchmaker(tickets, activeTickets float64, processTime time.Duration) { m.PrometheusScope.Gauge("matchmaker_tickets").Update(tickets) Loading
server/storage_index.go +5 −1 Original line number Diff line number Diff line Loading @@ -54,16 +54,18 @@ type storageIndex struct { type LocalStorageIndex struct { logger *zap.Logger db *sql.DB metrics Metrics indexByName map[string]*storageIndex indicesByCollection map[string][]*storageIndex customFilterFunctions map[string]RuntimeStorageIndexFilterFunction config *StorageConfig } func NewLocalStorageIndex(logger *zap.Logger, db *sql.DB, config *StorageConfig) (StorageIndex, error) { func NewLocalStorageIndex(logger *zap.Logger, db *sql.DB, config *StorageConfig, metrics Metrics) (StorageIndex, error) { si := &LocalStorageIndex{ logger: logger, db: db, metrics: metrics, indexByName: make(map[string]*storageIndex), indicesByCollection: make(map[string][]*storageIndex), customFilterFunctions: make(map[string]RuntimeStorageIndexFilterFunction), Loading Loading @@ -149,6 +151,8 @@ func (si *LocalStorageIndex) Write(ctx context.Context, objects []*api.StorageOb } count, _ := reader.Count() // cannot return err si.metrics.GaugeStorageIndexEntries(idx.Name, float64(count)) // Apply eviction strategy if size of index is +10% than max size if count > uint64(float32(idx.MaxEntries)*(1.1)) { deleteCount := int(count - uint64(idx.MaxEntries)) Loading