diff --git a/server/channels/app/platform/service.go b/server/channels/app/platform/service.go index aa58cb2a76..0d8721d1c9 100644 --- a/server/channels/app/platform/service.go +++ b/server/channels/app/platform/service.go @@ -275,6 +275,7 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) { // Needed before loading license ps.statusCache, err = ps.cacheProvider.NewCache(&cache.CacheOptions{ + Name: "Status", Size: model.StatusCacheSize, Striped: true, StripedBuckets: maxInt(runtime.NumCPU()-1, 1), diff --git a/server/channels/app/platform/status.go b/server/channels/app/platform/status.go index 94c11e26f2..e3a7d34848 100644 --- a/server/channels/app/platform/status.go +++ b/server/channels/app/platform/status.go @@ -65,12 +65,12 @@ func (ps *PlatformService) GetStatusesByIds(userIDs []string) (map[string]any, * if err := ps.statusCache.Get(userID, &status); err == nil { statusMap[userID] = status.Status if metrics != nil { - metrics.IncrementMemCacheHitCounter("Status") + metrics.IncrementMemCacheHitCounter(ps.statusCache.Name()) } } else { missingUserIds = append(missingUserIds, userID) if metrics != nil { - metrics.IncrementMemCacheMissCounter("Status") + metrics.IncrementMemCacheMissCounter(ps.statusCache.Name()) } } } @@ -112,12 +112,12 @@ func (ps *PlatformService) GetUserStatusesByIds(userIDs []string) ([]*model.Stat if err := ps.statusCache.Get(userID, &status); err == nil { statusMap = append(statusMap, status) if metrics != nil { - metrics.IncrementMemCacheHitCounter("Status") + metrics.IncrementMemCacheHitCounter(ps.statusCache.Name()) } } else { missingUserIds = append(missingUserIds, userID) if metrics != nil { - metrics.IncrementMemCacheMissCounter("Status") + metrics.IncrementMemCacheMissCounter(ps.statusCache.Name()) } } } diff --git a/server/channels/store/localcachelayer/channel_layer.go b/server/channels/store/localcachelayer/channel_layer.go index da1b18ee28..e708a4826c 100644 --- a/server/channels/store/localcachelayer/channel_layer.go +++ b/server/channels/store/localcachelayer/channel_layer.go @@ -112,14 +112,14 @@ func (s LocalCacheChannelStore) InvalidateMemberCount(channelId string) { func (s LocalCacheChannelStore) InvalidateGuestCount(channelId string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.channelGuestCountCache, channelId, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel Guests Count - Remove by channelId") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.channelGuestCountCache.Name()) } } func (s LocalCacheChannelStore) InvalidateChannel(channelId string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.channelByIdCache, channelId, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Channel - Remove by ChannelId") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.channelByIdCache.Name()) } } diff --git a/server/channels/store/localcachelayer/file_info_layer.go b/server/channels/store/localcachelayer/file_info_layer.go index ee73e44629..9081cb6663 100644 --- a/server/channels/store/localcachelayer/file_info_layer.go +++ b/server/channels/store/localcachelayer/file_info_layer.go @@ -53,7 +53,7 @@ func (s LocalCacheFileInfoStore) GetForPost(postId string, readFromMaster, inclu func (s LocalCacheFileInfoStore) ClearCaches() { s.rootStore.fileInfoCache.Purge() if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("File Info Cache - Purge") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.fileInfoCache.Name()) } } @@ -64,7 +64,7 @@ func (s LocalCacheFileInfoStore) InvalidateFileInfosForPostCache(postId string, } s.rootStore.doInvalidateCacheCluster(s.rootStore.fileInfoCache, cacheKey, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("File Info Cache - Remove by PostId") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.fileInfoCache.Name()) } } diff --git a/server/channels/store/localcachelayer/post_layer.go b/server/channels/store/localcachelayer/post_layer.go index ad5f4a41fc..16ad8460e1 100644 --- a/server/channels/store/localcachelayer/post_layer.go +++ b/server/channels/store/localcachelayer/post_layer.go @@ -49,9 +49,9 @@ func (s LocalCachePostStore) ClearCaches() { s.PostStore.ClearCaches() if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Purge") - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Last Posts Cache - Purge") - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Posts Usage Cache - Purge") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.lastPostTimeCache.Name()) + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.postLastPostsCache.Name()) + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.postsUsageCache.Name()) } } @@ -65,8 +65,8 @@ func (s LocalCachePostStore) InvalidateLastPostTimeCache(channelId string) { s.PostStore.InvalidateLastPostTimeCache(channelId) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Last Post Time - Remove by Channel Id") - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Last Posts Cache - Remove by Channel Id") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.lastPostTimeCache.Name()) + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.postLastPostsCache.Name()) } } diff --git a/server/channels/store/localcachelayer/team_layer.go b/server/channels/store/localcachelayer/team_layer.go index 0e2b8aa3e5..f13c11e620 100644 --- a/server/channels/store/localcachelayer/team_layer.go +++ b/server/channels/store/localcachelayer/team_layer.go @@ -26,14 +26,14 @@ func (s *LocalCacheTeamStore) handleClusterInvalidateTeam(msg *model.ClusterMess func (s LocalCacheTeamStore) ClearCaches() { s.rootStore.teamAllTeamIdsForUserCache.Purge() if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("All Team Ids for User - Purge") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.teamAllTeamIdsForUserCache.Name()) } } func (s LocalCacheTeamStore) InvalidateAllTeamIdsForUser(userId string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.teamAllTeamIdsForUserCache, userId, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("All Team Ids for User - Remove by UserId") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.teamAllTeamIdsForUserCache.Name()) } } diff --git a/server/channels/store/localcachelayer/terms_of_service_layer.go b/server/channels/store/localcachelayer/terms_of_service_layer.go index f31664c48d..ad8d836d63 100644 --- a/server/channels/store/localcachelayer/terms_of_service_layer.go +++ b/server/channels/store/localcachelayer/terms_of_service_layer.go @@ -31,7 +31,7 @@ func (s LocalCacheTermsOfServiceStore) ClearCaches() { s.rootStore.doClearCacheCluster(s.rootStore.termsOfServiceCache) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Terms Of Service - Purge") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.termsOfServiceCache.Name()) } } diff --git a/server/channels/store/localcachelayer/user_layer.go b/server/channels/store/localcachelayer/user_layer.go index 2a851778cd..ae1b5a5eeb 100644 --- a/server/channels/store/localcachelayer/user_layer.go +++ b/server/channels/store/localcachelayer/user_layer.go @@ -56,8 +56,8 @@ func (s *LocalCacheUserStore) ClearCaches() { s.rootStore.profilesInChannelCache.Purge() if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profile By Ids - Purge") - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Purge") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.userProfileByIdsCache.Name()) + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.profilesInChannelCache.Name()) } } @@ -69,7 +69,7 @@ func (s *LocalCacheUserStore) InvalidateProfileCacheForUser(userId string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.allUserCache, allUserKey, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profile By Ids - Remove") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.userProfileByIdsCache.Name()) } } @@ -82,7 +82,7 @@ func (s *LocalCacheUserStore) InvalidateProfilesInChannelCacheByUser(userId stri if _, userInCache := userMap[userId]; userInCache { s.rootStore.doInvalidateCacheCluster(s.rootStore.profilesInChannelCache, key, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Remove by User") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.profilesInChannelCache.Name()) } } } @@ -93,7 +93,7 @@ func (s *LocalCacheUserStore) InvalidateProfilesInChannelCacheByUser(userId stri func (s *LocalCacheUserStore) InvalidateProfilesInChannelCache(channelID string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.profilesInChannelCache, channelID, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Profiles in Channel - Remove by Channel") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.profilesInChannelCache.Name()) } } @@ -197,14 +197,8 @@ func (s *LocalCacheUserStore) GetProfileByIds(ctx context.Context, userIds []str func (s *LocalCacheUserStore) Get(ctx context.Context, id string) (*model.User, error) { var cacheItem *model.User if err := s.rootStore.doStandardReadCache(s.rootStore.userProfileByIdsCache, id, &cacheItem); err == nil { - if s.rootStore.metrics != nil { - s.rootStore.metrics.AddMemCacheHitCounter("Profile By Id", float64(1)) - } return cacheItem, nil } - if s.rootStore.metrics != nil { - s.rootStore.metrics.AddMemCacheMissCounter("Profile By Id", float64(1)) - } // If it was invalidated, then we need to query master. s.userProfileByIdsMut.Lock() @@ -238,14 +232,8 @@ func (s *LocalCacheUserStore) GetMany(ctx context.Context, ids []string) ([]*mod for _, id := range uniqIDs { var cachedUser *model.User if err := s.rootStore.doStandardReadCache(s.rootStore.userProfileByIdsCache, id, &cachedUser); err == nil { - if s.rootStore.metrics != nil { - s.rootStore.metrics.AddMemCacheHitCounter("Profile By Id", float64(1)) - } cachedUsers = append(cachedUsers, cachedUser) } else { - if s.rootStore.metrics != nil { - s.rootStore.metrics.AddMemCacheMissCounter("Profile By Id", float64(1)) - } // If it was invalidated, then we need to query master. s.userProfileByIdsMut.Lock() if s.userProfileByIdsInvalidations[id] { diff --git a/server/channels/store/localcachelayer/webhook_layer.go b/server/channels/store/localcachelayer/webhook_layer.go index 9cbd6fe1bf..9a753b4b4f 100644 --- a/server/channels/store/localcachelayer/webhook_layer.go +++ b/server/channels/store/localcachelayer/webhook_layer.go @@ -27,14 +27,14 @@ func (s LocalCacheWebhookStore) ClearCaches() { s.rootStore.doClearCacheCluster(s.rootStore.webhookCache) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Webhook - Purge") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.webhookCache.Name()) } } func (s LocalCacheWebhookStore) InvalidateWebhookCache(webhookId string) { s.rootStore.doInvalidateCacheCluster(s.rootStore.webhookCache, webhookId, nil) if s.rootStore.metrics != nil { - s.rootStore.metrics.IncrementMemCacheInvalidationCounter("Webhook - Remove by WebhookId") + s.rootStore.metrics.IncrementMemCacheInvalidationCounter(s.rootStore.webhookCache.Name()) } }