RemoteCache: Refactor remote cache settings (#95672)

* refactor remote cache settings

* fix cache error getting treating as application error

* fix cache error getting treating as application error
This commit is contained in:
Jo
2024-11-04 17:35:31 +01:00
committed by GitHub
parent 85c696c4ad
commit ddf766567b
11 changed files with 37 additions and 33 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ type memcachedStorage struct {
c *memcache.Client
}
func newMemcachedStorage(opts *setting.RemoteCacheOptions) *memcachedStorage {
func newMemcachedStorage(opts *setting.RemoteCacheSettings) *memcachedStorage {
return &memcachedStorage{
c: memcache.New(opts.ConnStr),
}
@@ -17,7 +17,7 @@ func TestIntegrationMemcachedCacheStorage(t *testing.T) {
t.Skip("No Memcached hosts provided")
}
opts := &setting.RemoteCacheOptions{Name: memcachedCacheType, ConnStr: u}
opts := &setting.RemoteCacheSettings{Name: memcachedCacheType, ConnStr: u}
client := createTestClient(t, opts, nil)
runTestsForClient(t, client)
}
+1 -1
View File
@@ -78,7 +78,7 @@ func parseRedisConnStr(connStr string) (*redis.Options, error) {
return options, nil
}
func newRedisStorage(opts *setting.RemoteCacheOptions) (*redisStorage, error) {
func newRedisStorage(opts *setting.RemoteCacheSettings) (*redisStorage, error) {
opt, err := parseRedisConnStr(opts.ConnStr)
if err != nil {
return nil, err
@@ -34,7 +34,7 @@ func TestIntegrationRedisCacheStorage(t *testing.T) {
b.WriteString(fmt.Sprintf(",db=%d", db))
}
opts := &setting.RemoteCacheOptions{Name: redisCacheType, ConnStr: b.String()}
opts := &setting.RemoteCacheSettings{Name: redisCacheType, ConnStr: b.String()}
client := createTestClient(t, opts, nil)
runTestsForClient(t, client)
}
+1 -1
View File
@@ -109,7 +109,7 @@ func (ds *RemoteCache) Run(ctx context.Context) error {
return ctx.Err()
}
func createClient(opts *setting.RemoteCacheOptions, sqlstore db.DB, secretsService secrets.Service) (cache CacheStorage, err error) {
func createClient(opts *setting.RemoteCacheSettings, sqlstore db.DB, secretsService secrets.Service) (cache CacheStorage, err error) {
switch opts.Name {
case redisCacheType:
cache, err = newRedisStorage(opts)
+3 -3
View File
@@ -21,7 +21,7 @@ func TestMain(m *testing.M) {
testsuite.Run(m)
}
func createTestClient(t *testing.T, opts *setting.RemoteCacheOptions, sqlstore db.DB) CacheStorage {
func createTestClient(t *testing.T, opts *setting.RemoteCacheSettings, sqlstore db.DB) CacheStorage {
t.Helper()
cfg := &setting.Cfg{
@@ -45,7 +45,7 @@ func TestCachedBasedOnConfig(t *testing.T) {
}
func TestInvalidCacheTypeReturnsError(t *testing.T) {
_, err := createClient(&setting.RemoteCacheOptions{Name: "invalid"}, nil, nil)
_, err := createClient(&setting.RemoteCacheSettings{Name: "invalid"}, nil, nil)
assert.Equal(t, err, ErrInvalidCacheType)
}
@@ -94,7 +94,7 @@ func TestCollectUsageStats(t *testing.T) {
"stats.remote_cache.encrypt_enabled.count": 1,
}
cfg := setting.NewCfg()
cfg.RemoteCacheOptions = &setting.RemoteCacheOptions{Name: redisCacheType, Encryption: true}
cfg.RemoteCacheOptions = &setting.RemoteCacheSettings{Name: redisCacheType, Encryption: true}
remoteCache := &RemoteCache{
Cfg: cfg,
+1 -1
View File
@@ -15,7 +15,7 @@ import (
func NewFakeStore(t *testing.T) *RemoteCache {
t.Helper()
opts := &setting.RemoteCacheOptions{
opts := &setting.RemoteCacheSettings{
Name: "database",
ConnStr: "",
}
@@ -145,7 +145,7 @@ func TestCollectingUsageStats(t *testing.T) {
AuthProxy: setting.AuthProxySettings{Enabled: true},
Packaging: "deb",
ReportingDistributor: "hosted-grafana",
RemoteCacheOptions: &setting.RemoteCacheOptions{
RemoteCacheOptions: &setting.RemoteCacheSettings{
Name: "database",
},
}, sqlStore, statsService,