MM-62079: Using a cache prefix to isolate cache keys for each test (#30261)
```release-note A new config setting CacheSettings.RedisCachePrefix has been added which can be used to add a prefix to all Redis cache keys. ```
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
e5755c925a
Коммит
4e5cb16955
@@ -113,6 +113,7 @@ func setupTestHelper(dbStore store.Store, searchEngine *searchengine.Broker, ent
|
|||||||
*memoryConfig.CacheSettings.RedisAddress = redisHost + ":6379"
|
*memoryConfig.CacheSettings.RedisAddress = redisHost + ":6379"
|
||||||
*memoryConfig.CacheSettings.DisableClientCache = true
|
*memoryConfig.CacheSettings.DisableClientCache = true
|
||||||
*memoryConfig.CacheSettings.RedisDB = 0
|
*memoryConfig.CacheSettings.RedisDB = 0
|
||||||
|
*memoryConfig.CacheSettings.RedisCachePrefix = model.NewId()
|
||||||
options = append(options, app.ForceEnableRedis())
|
options = append(options, app.ForceEnableRedis())
|
||||||
}
|
}
|
||||||
if updateConfig != nil {
|
if updateConfig != nil {
|
||||||
|
|||||||
@@ -131,7 +131,6 @@ func TestCreatePost(t *testing.T) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
t.Run("Create posts without the USE_CHANNEL_MENTIONS Permission - returns ephemeral message with mentions and no ephemeral message without mentions", func(t *testing.T) {
|
t.Run("Create posts without the USE_CHANNEL_MENTIONS Permission - returns ephemeral message with mentions and no ephemeral message without mentions", func(t *testing.T) {
|
||||||
t.Skip("MM-62764")
|
|
||||||
wsClient := th.CreateConnectedWebSocketClient(t)
|
wsClient := th.CreateConnectedWebSocketClient(t)
|
||||||
|
|
||||||
defaultPerms := th.SaveDefaultRolePermissions()
|
defaultPerms := th.SaveDefaultRolePermissions()
|
||||||
@@ -188,7 +187,6 @@ func TestCreatePost(t *testing.T) {
|
|||||||
}
|
}
|
||||||
case <-timeout:
|
case <-timeout:
|
||||||
require.Fail(t, fmt.Sprintf("Got %d ephemeral messages, expected: %d", gotEvents, expectedEvents))
|
require.Fail(t, fmt.Sprintf("Got %d ephemeral messages, expected: %d", gotEvents, expectedEvents))
|
||||||
break
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -168,10 +168,11 @@ func New(sc ServiceConfig, options ...Option) (*PlatformService, error) {
|
|||||||
} else if *cacheConfig.CacheType == model.CacheTypeRedis {
|
} else if *cacheConfig.CacheType == model.CacheTypeRedis {
|
||||||
ps.cacheProvider, err = cache.NewRedisProvider(
|
ps.cacheProvider, err = cache.NewRedisProvider(
|
||||||
&cache.RedisOptions{
|
&cache.RedisOptions{
|
||||||
RedisAddr: *cacheConfig.RedisAddress,
|
RedisAddr: *cacheConfig.RedisAddress,
|
||||||
RedisPassword: *cacheConfig.RedisPassword,
|
RedisPassword: *cacheConfig.RedisPassword,
|
||||||
RedisDB: *cacheConfig.RedisDB,
|
RedisDB: *cacheConfig.RedisDB,
|
||||||
DisableCache: *cacheConfig.DisableClientCache,
|
RedisCachePrefix: *cacheConfig.RedisCachePrefix,
|
||||||
|
DisableCache: *cacheConfig.DisableClientCache,
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
19
server/platform/services/cache/provider.go
поставляемый
19
server/platform/services/cache/provider.go
поставляемый
@@ -74,15 +74,17 @@ func (c *cacheProvider) Type() string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
type redisProvider struct {
|
type redisProvider struct {
|
||||||
client rueidis.Client
|
client rueidis.Client
|
||||||
metrics einterfaces.MetricsInterface
|
cachePrefix string
|
||||||
|
metrics einterfaces.MetricsInterface
|
||||||
}
|
}
|
||||||
|
|
||||||
type RedisOptions struct {
|
type RedisOptions struct {
|
||||||
RedisAddr string
|
RedisAddr string
|
||||||
RedisPassword string
|
RedisPassword string
|
||||||
RedisDB int
|
RedisDB int
|
||||||
DisableCache bool
|
RedisCachePrefix string
|
||||||
|
DisableCache bool
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewProvider creates a new CacheProvider
|
// NewProvider creates a new CacheProvider
|
||||||
@@ -107,11 +109,14 @@ func NewRedisProvider(opts *RedisOptions) (Provider, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
return &redisProvider{client: client}, nil
|
return &redisProvider{client: client, cachePrefix: opts.RedisCachePrefix}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
// NewCache creates a new cache with given opts
|
// NewCache creates a new cache with given opts
|
||||||
func (r *redisProvider) NewCache(opts *CacheOptions) (Cache, error) {
|
func (r *redisProvider) NewCache(opts *CacheOptions) (Cache, error) {
|
||||||
|
if r.cachePrefix != "" {
|
||||||
|
opts.Name = r.cachePrefix + ":" + opts.Name
|
||||||
|
}
|
||||||
rr, err := NewRedis(opts, r.client)
|
rr, err := NewRedis(opts, r.client)
|
||||||
rr.metrics = r.metrics
|
rr.metrics = r.metrics
|
||||||
return rr, err
|
return rr, err
|
||||||
|
|||||||
@@ -974,6 +974,7 @@ type CacheSettings struct {
|
|||||||
RedisAddress *string `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
RedisAddress *string `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
||||||
RedisPassword *string `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
RedisPassword *string `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
||||||
RedisDB *int `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
RedisDB *int `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
||||||
|
RedisCachePrefix *string `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
||||||
DisableClientCache *bool `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
DisableClientCache *bool `access:",write_restrictable,cloud_restrictable"` // telemetry: none
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -994,6 +995,10 @@ func (s *CacheSettings) SetDefaults() {
|
|||||||
s.RedisDB = NewPointer(-1)
|
s.RedisDB = NewPointer(-1)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if s.RedisCachePrefix == nil {
|
||||||
|
s.RedisCachePrefix = NewPointer("")
|
||||||
|
}
|
||||||
|
|
||||||
if s.DisableClientCache == nil {
|
if s.DisableClientCache == nil {
|
||||||
s.DisableClientCache = NewPointer(false)
|
s.DisableClientCache = NewPointer(false)
|
||||||
}
|
}
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user