MM-21331: Add aggregate cache metrics for channelByNameCache (#13440)

The `channelByNameCache` in the `GetByNames` query checks each teamId+channelName
combination in the cache and if any of the keys is not present, it queries the DB.

In this case, this is effectively a cache miss from the point of view of user.
But since the cache is at a teamId+channelName level, there may be several hits and some misses.
This is misleading as it does not generate proper metrics and might lead to a
false assumption of how effective the cache is.

We create separate metrics which account for all or none cache hits/misses.
This removes the old metrics which are used by other queries. So they are now separated,
and it will improve both the old and new metric. Because the old metric is not contaminated,
and the new metric is also separate.
Этот коммит содержится в:
Agniva De Sarker
2019-12-20 17:04:19 +05:30
коммит произвёл GitHub
родитель e4481aae21
Коммит c9cd14b50b

Просмотреть файл

@@ -1107,14 +1107,8 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
}
visited[name] = struct{}{}
if cacheItem, ok := channelByNameCache.Get(teamId + name); ok {
if s.metrics != nil {
s.metrics.IncrementMemCacheHitCounter("Channel By Name")
}
channels = append(channels, cacheItem.(*model.Channel))
} else {
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Channel By Name")
}
misses = append(misses, name)
}
}
@@ -1146,6 +1140,15 @@ func (s SqlChannelStore) GetByNames(teamId string, names []string, allowFromCach
channelByNameCache.AddWithExpiresInSecs(teamId+channel.Name, channel, CHANNEL_CACHE_SEC)
channels = append(channels, channel)
}
// Not all channels are in cache. Increment aggregate miss counter.
if s.metrics != nil {
s.metrics.IncrementMemCacheMissCounter("Channel By Name - Aggregate")
}
} else {
// All of the channel names are in cache. Increment aggregate hit counter.
if s.metrics != nil {
s.metrics.IncrementMemCacheHitCounter("Channel By Name - Aggregate")
}
}
return channels, nil