renames distcache -> remotecache

This commit is contained in:
bergquist 2019-03-08 20:49:16 +01:00
parent 66e71b66dd
commit 7e7427637c
13 changed files with 45 additions and 32 deletions

View File

@ -107,7 +107,7 @@ path = grafana.db
cache_mode = private
#################################### Cache server #############################
[cache_server]
[remote_cache]
# Either "redis", "memcached" or "database" default is "database"
type = database

View File

@ -102,6 +102,17 @@ log_queries =
# For "sqlite3" only. cache mode setting used for connecting to the database. (private, shared)
;cache_mode = private
#################################### Cache server #############################
[remote_cache]
# Either "redis", "memcached" or "database" default is "database"
;type = database
# cache connectionstring options
# database: will use Grafana primary database.
# redis: config like redis server e.g. `addr=127.0.0.1:6379,pool_size=100,db=grafana`
# memcache: 127.0.0.1:11211
;connstr =
#################################### Session ####################################
[session]
# Either "memory", "file", "redis", "mysql", "postgres", default is "file"

View File

@ -28,8 +28,8 @@ import (
// self registering services
_ "github.com/grafana/grafana/pkg/extensions"
_ "github.com/grafana/grafana/pkg/infra/distcache"
_ "github.com/grafana/grafana/pkg/infra/metrics"
_ "github.com/grafana/grafana/pkg/infra/remotecache"
_ "github.com/grafana/grafana/pkg/infra/serverlock"
_ "github.com/grafana/grafana/pkg/infra/tracing"
_ "github.com/grafana/grafana/pkg/infra/usagestats"

View File

@ -1,4 +1,4 @@
package distcache
package remotecache
import (
"context"

View File

@ -1,4 +1,4 @@
package distcache
package remotecache
import (
"testing"

View File

@ -1,4 +1,4 @@
package distcache
package remotecache
import (
"time"
@ -11,7 +11,7 @@ type memcachedStorage struct {
c *memcache.Client
}
func newMemcachedStorage(opts *setting.CacheOpts) *memcachedStorage {
func newMemcachedStorage(opts *setting.RemoteCacheOptions) *memcachedStorage {
return &memcachedStorage{
c: memcache.New(opts.ConnStr),
}

View File

@ -1,6 +1,6 @@
// +build memcached
package distcache
package remotecache
import (
"testing"
@ -9,6 +9,6 @@ import (
)
func TestMemcachedCacheStorage(t *testing.T) {
opts := &setting.CacheOpts{Name: "memcached", ConnStr: "localhost:11211"}
opts := &setting.RemoteCacheOptions{Name: "memcached", ConnStr: "localhost:11211"}
runTestsForClient(t, createTestClient(t, opts, nil))
}

View File

@ -1,4 +1,4 @@
package distcache
package remotecache
import (
"time"
@ -11,7 +11,7 @@ type redisStorage struct {
c *redis.Client
}
func newRedisStorage(opts *setting.CacheOpts) *redisStorage {
func newRedisStorage(opts *setting.RemoteCacheOptions) *redisStorage {
opt := &redis.Options{
Network: "tcp",
Addr: opts.ConnStr,

View File

@ -1,6 +1,6 @@
// +build redis
package distcache
package remotecache
import (
"testing"
@ -10,6 +10,6 @@ import (
func TestRedisCacheStorage(t *testing.T) {
opts := &setting.CacheOpts{Name: "redis", ConnStr: "localhost:6379"}
opts := &setting.RemoteCacheOptions{Name: "redis", ConnStr: "localhost:6379"}
runTestsForClient(t, createTestClient(t, opts, nil))
}

View File

@ -1,4 +1,4 @@
package distcache
package remotecache
import (
"bytes"
@ -20,7 +20,7 @@ var (
)
func init() {
registry.RegisterService(&DistributedCache{})
registry.RegisterService(&RemoteCache{})
}
// CacheStorage allows the caller to set, get and delete items in the cache.
@ -38,8 +38,8 @@ type CacheStorage interface {
Delete(key string) error
}
// DistributedCache allows Grafana to cache data outside its own process
type DistributedCache struct {
// RemoteCache allows Grafana to cache data outside its own process
type RemoteCache struct {
log log.Logger
Client CacheStorage
SQLStore *sqlstore.SqlStore `inject:""`
@ -47,15 +47,17 @@ type DistributedCache struct {
}
// Init initializes the service
func (ds *DistributedCache) Init() error {
ds.log = log.New("distributed.cache")
func (ds *RemoteCache) Init() error {
ds.log = log.New("cache.remote")
ds.Client = createClient(ds.Cfg.CacheOptions, ds.SQLStore)
ds.Client = createClient(ds.Cfg.RemoteCacheOptions, ds.SQLStore)
return nil
}
func (ds *DistributedCache) Run(ctx context.Context) error {
// Run start the backend processes for cache clients
func (ds *RemoteCache) Run(ctx context.Context) error {
//create new interface if more clients need GC jobs
backgroundjob, ok := ds.Client.(registry.BackgroundService)
if ok {
return backgroundjob.Run(ctx)
@ -65,7 +67,7 @@ func (ds *DistributedCache) Run(ctx context.Context) error {
return ctx.Err()
}
func createClient(opts *setting.CacheOpts, sqlstore *sqlstore.SqlStore) CacheStorage {
func createClient(opts *setting.RemoteCacheOptions, sqlstore *sqlstore.SqlStore) CacheStorage {
if opts.Name == "redis" {
return newRedisStorage(opts)
}

View File

@ -1,4 +1,4 @@
package distcache
package remotecache
import (
"testing"
@ -19,13 +19,13 @@ func init() {
Register(CacheableStruct{})
}
func createTestClient(t *testing.T, opts *setting.CacheOpts, sqlstore *sqlstore.SqlStore) CacheStorage {
func createTestClient(t *testing.T, opts *setting.RemoteCacheOptions, sqlstore *sqlstore.SqlStore) CacheStorage {
t.Helper()
dc := &DistributedCache{
dc := &RemoteCache{
SQLStore: sqlstore,
Cfg: &setting.Cfg{
CacheOptions: opts,
RemoteCacheOptions: opts,
},
}
@ -44,7 +44,7 @@ func TestCachedBasedOnConfig(t *testing.T) {
HomePath: "../../../",
})
client := createTestClient(t, cfg.CacheOptions, sqlstore.InitTestDB(t))
client := createTestClient(t, cfg.RemoteCacheOptions, sqlstore.InitTestDB(t))
runTestsForClient(t, client)
}

View File

@ -242,7 +242,7 @@ type Cfg struct {
EditorsCanOwn bool
// DistributedCache
CacheOptions *CacheOpts
RemoteCacheOptions *RemoteCacheOptions
}
type CommandLineArgs struct {
@ -782,8 +782,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
enterprise := iniFile.Section("enterprise")
cfg.EnterpriseLicensePath = enterprise.Key("license_path").MustString(filepath.Join(cfg.DataPath, "license.jwt"))
cacheServer := iniFile.Section("cache_server")
cfg.CacheOptions = &CacheOpts{
cacheServer := iniFile.Section("remote_cache")
cfg.RemoteCacheOptions = &RemoteCacheOptions{
Name: cacheServer.Key("type").MustString("database"),
ConnStr: cacheServer.Key("connstr").MustString(""),
}
@ -791,7 +791,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
return nil
}
type CacheOpts struct {
type RemoteCacheOptions struct {
Name string
ConnStr string
}

View File

@ -13,6 +13,6 @@ function exit_if_fail {
echo "running redis and memcache tests"
#set -e
#time for d in $(go list ./pkg/...); do
time exit_if_fail go test -tags=redis ./pkg/infra/distcache/...
time exit_if_fail go test -tags=memcached ./pkg/infra/distcache/...
time exit_if_fail go test -tags=redis ./pkg/infra/remotecache/...
time exit_if_fail go test -tags=memcached ./pkg/infra/remotecache/...
#done