MM-53058: Move cache layer out of timer layer (#23660)

Having cache layer as part of the store call
Prometheus metrics can be somewhat misleading
because cache-backed methods can have very high
volume and yet not cause any load on the DB at all.

However, if the admin is not aware which calls
are cache-backed and which are not, then
it can be hard to understand why a store call
of high volume isn't causing any stress on the DB at all.

Therefore, for simplicity we reorder the layers
such that cache layer is handled outside the timer layer.

We already have cache related metrics like hit/miss
which can be used to monitor cache usage.

https://mattermost.atlassian.net/browse/MM-53058

```release-note
NONE
```

Co-authored-by: Mattermost Build <build@mattermost.com>
Этот коммит содержится в:
Agniva De Sarker
2023-06-15 21:08:14 +05:30
коммит произвёл GitHub
родитель 75a0e61de7
Коммит 747b4cf26c

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

@@ -193,20 +193,20 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
// Depends on Step 0 (config), 1 (cacheProvider), 3 (search engine), 5 (metrics) and cluster.
if ps.newStore == nil {
ps.newStore = func() (store.Store, error) {
// The layer cake is as follows: (From bottom to top)
// SQL layer
// |
// Retry layer
// |
// Search layer
// |
// Timer layer
// |
// Cache layer
ps.sqlStore = sqlstore.New(ps.Config().SqlSettings, ps.metricsIFace)
lcl, err2 := localcachelayer.NewLocalCacheLayer(
retrylayer.New(ps.sqlStore),
ps.metricsIFace,
ps.clusterIFace,
ps.cacheProvider,
)
if err2 != nil {
return nil, fmt.Errorf("cannot create local cache layer: %w", err2)
}
searchStore := searchlayer.NewSearchLayer(
lcl,
retrylayer.New(ps.sqlStore),
ps.SearchEngine,
ps.Config(),
)
@@ -215,16 +215,23 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
searchStore.UpdateConfig(cfg)
})
lcl, err2 := localcachelayer.NewLocalCacheLayer(
timerlayer.New(searchStore, ps.metricsIFace),
ps.metricsIFace,
ps.clusterIFace,
ps.cacheProvider,
)
if err2 != nil {
return nil, fmt.Errorf("cannot create local cache layer: %w", err2)
}
license := ps.License()
ps.sqlStore.UpdateLicense(license)
ps.AddLicenseListener(func(oldLicense, newLicense *model.License) {
ps.sqlStore.UpdateLicense(newLicense)
})
return timerlayer.New(
searchStore,
ps.metricsIFace,
), nil
return lcl, nil
}
}