diff options
author | Christopher Speller <crspeller@gmail.com> | 2016-12-19 10:16:22 -0500 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-12-19 10:16:22 -0500 |
commit | f96173528f08684092b89f903f0389fe2b607192 (patch) | |
tree | f34f9057417ad6758cd65dc246bc764530f2134c /store | |
parent | 6a5cdd5cdf09317ce259dd146fc4f1cb76d8b9b6 (diff) | |
download | chat-f96173528f08684092b89f903f0389fe2b607192.tar.gz chat-f96173528f08684092b89f903f0389fe2b607192.tar.bz2 chat-f96173528f08684092b89f903f0389fe2b607192.zip |
Adding metrics for caching mechanisms (#4828)
Diffstat (limited to 'store')
-rw-r--r-- | store/sql_channel_store.go | 33 | ||||
-rw-r--r-- | store/sql_post_store.go | 13 | ||||
-rw-r--r-- | store/sql_user_store.go | 13 |
3 files changed, 59 insertions, 0 deletions
diff --git a/store/sql_channel_store.go b/store/sql_channel_store.go index aed568b46..001eaaa26 100644 --- a/store/sql_channel_store.go +++ b/store/sql_channel_store.go @@ -10,6 +10,7 @@ import ( l4g "github.com/alecthomas/log4go" "github.com/go-gorp/gorp" + "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -684,13 +685,21 @@ func (us SqlChannelStore) InvalidateAllChannelMembersForUser(userId string) { } func (us SqlChannelStore) IsUserInChannelUseCache(userId string, channelId string) bool { + metrics := einterfaces.GetMetricsInterface() if cacheItem, ok := allChannelMembersForUserCache.Get(userId); ok { + if metrics != nil { + metrics.IncrementMemCacheHitCounter("All Channel Members for User") + } ids := cacheItem.(map[string]string) if _, ok := ids[channelId]; ok { return true } else { return false } + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("All Channel Members for User") + } } if result := <-us.GetAllChannelMembersForUser(userId, true); result.Err != nil { @@ -746,13 +755,25 @@ func (s SqlChannelStore) GetAllChannelMembersForUser(userId string, allowFromCac go func() { result := StoreResult{} + metrics := einterfaces.GetMetricsInterface() if allowFromCache { if cacheItem, ok := allChannelMembersForUserCache.Get(userId); ok { + if metrics != nil { + metrics.IncrementMemCacheHitCounter("All Channel Members for User") + } result.Data = cacheItem.(map[string]string) storeChannel <- result close(storeChannel) return + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("All Channel Members for User") + } + } + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("All Channel Members for User") } } @@ -788,16 +809,28 @@ func (us SqlChannelStore) InvalidateMemberCount(channelId string) { func (s SqlChannelStore) GetMemberCount(channelId string, allowFromCache bool) StoreChannel { storeChannel := make(StoreChannel, 1) + metrics := einterfaces.GetMetricsInterface() go func() { result := StoreResult{} if allowFromCache { if cacheItem, ok := channelMemberCountsCache.Get(channelId); ok { + if metrics != nil { + metrics.IncrementMemCacheHitCounter("Channel Member Counts") + } result.Data = cacheItem.(int64) storeChannel <- result close(storeChannel) return + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("Channel Member Counts") + } + } + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("Channel Member Counts") } } diff --git a/store/sql_post_store.go b/store/sql_post_store.go index 44ae58b32..befb38b6a 100644 --- a/store/sql_post_store.go +++ b/store/sql_post_store.go @@ -9,6 +9,7 @@ import ( "strconv" "strings" + "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -227,16 +228,28 @@ func (s SqlPostStore) InvalidatePostEtagCache(channelId string) { func (s SqlPostStore) GetEtag(channelId string, allowFromCache bool) StoreChannel { storeChannel := make(StoreChannel, 1) + metrics := einterfaces.GetMetricsInterface() go func() { result := StoreResult{} if allowFromCache { if cacheItem, ok := postEtagCache.Get(channelId); ok { + if metrics != nil { + metrics.IncrementMemCacheHitCounter("Post Etag") + } result.Data = cacheItem.(string) storeChannel <- result close(storeChannel) return + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("Post Etag") + } + } + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("Post Etag") } } diff --git a/store/sql_user_store.go b/store/sql_user_store.go index b71d8214c..8db0e9624 100644 --- a/store/sql_user_store.go +++ b/store/sql_user_store.go @@ -10,6 +10,7 @@ import ( "strconv" "strings" + "github.com/mattermost/platform/einterfaces" "github.com/mattermost/platform/model" "github.com/mattermost/platform/utils" ) @@ -601,13 +602,25 @@ func (us SqlUserStore) GetProfilesInChannel(channelId string, offset int, limit go func() { result := StoreResult{} + metrics := einterfaces.GetMetricsInterface() if allowFromCache && offset == -1 && limit == -1 { if cacheItem, ok := profilesInChannelCache.Get(channelId); ok { + if metrics != nil { + metrics.IncrementMemCacheHitCounter("Profiles in Channel") + } result.Data = cacheItem.(map[string]*model.User) storeChannel <- result close(storeChannel) return + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("Profiles in Channel") + } + } + } else { + if metrics != nil { + metrics.IncrementMemCacheMissCounter("Profiles in Channel") } } |