Commit 7e742763 by bergquist

renames distcache -> remotecache

parent 66e71b66
...@@ -107,7 +107,7 @@ path = grafana.db ...@@ -107,7 +107,7 @@ path = grafana.db
cache_mode = private cache_mode = private
#################################### Cache server ############################# #################################### Cache server #############################
[cache_server] [remote_cache]
# Either "redis", "memcached" or "database" default is "database" # Either "redis", "memcached" or "database" default is "database"
type = database type = database
......
...@@ -102,6 +102,17 @@ log_queries = ...@@ -102,6 +102,17 @@ log_queries =
# For "sqlite3" only. cache mode setting used for connecting to the database. (private, shared) # For "sqlite3" only. cache mode setting used for connecting to the database. (private, shared)
;cache_mode = private ;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 ####################################
[session] [session]
# Either "memory", "file", "redis", "mysql", "postgres", default is "file" # Either "memory", "file", "redis", "mysql", "postgres", default is "file"
......
...@@ -28,8 +28,8 @@ import ( ...@@ -28,8 +28,8 @@ import (
// self registering services // self registering services
_ "github.com/grafana/grafana/pkg/extensions" _ "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/metrics"
_ "github.com/grafana/grafana/pkg/infra/remotecache"
_ "github.com/grafana/grafana/pkg/infra/serverlock" _ "github.com/grafana/grafana/pkg/infra/serverlock"
_ "github.com/grafana/grafana/pkg/infra/tracing" _ "github.com/grafana/grafana/pkg/infra/tracing"
_ "github.com/grafana/grafana/pkg/infra/usagestats" _ "github.com/grafana/grafana/pkg/infra/usagestats"
......
package distcache package remotecache
import ( import (
"context" "context"
......
package distcache package remotecache
import ( import (
"testing" "testing"
......
package distcache package remotecache
import ( import (
"time" "time"
...@@ -11,7 +11,7 @@ type memcachedStorage struct { ...@@ -11,7 +11,7 @@ type memcachedStorage struct {
c *memcache.Client c *memcache.Client
} }
func newMemcachedStorage(opts *setting.CacheOpts) *memcachedStorage { func newMemcachedStorage(opts *setting.RemoteCacheOptions) *memcachedStorage {
return &memcachedStorage{ return &memcachedStorage{
c: memcache.New(opts.ConnStr), c: memcache.New(opts.ConnStr),
} }
......
// +build memcached // +build memcached
package distcache package remotecache
import ( import (
"testing" "testing"
...@@ -9,6 +9,6 @@ import ( ...@@ -9,6 +9,6 @@ import (
) )
func TestMemcachedCacheStorage(t *testing.T) { 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)) runTestsForClient(t, createTestClient(t, opts, nil))
} }
package distcache package remotecache
import ( import (
"time" "time"
...@@ -11,7 +11,7 @@ type redisStorage struct { ...@@ -11,7 +11,7 @@ type redisStorage struct {
c *redis.Client c *redis.Client
} }
func newRedisStorage(opts *setting.CacheOpts) *redisStorage { func newRedisStorage(opts *setting.RemoteCacheOptions) *redisStorage {
opt := &redis.Options{ opt := &redis.Options{
Network: "tcp", Network: "tcp",
Addr: opts.ConnStr, Addr: opts.ConnStr,
......
// +build redis // +build redis
package distcache package remotecache
import ( import (
"testing" "testing"
...@@ -10,6 +10,6 @@ import ( ...@@ -10,6 +10,6 @@ import (
func TestRedisCacheStorage(t *testing.T) { 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)) runTestsForClient(t, createTestClient(t, opts, nil))
} }
package distcache package remotecache
import ( import (
"bytes" "bytes"
...@@ -20,7 +20,7 @@ var ( ...@@ -20,7 +20,7 @@ var (
) )
func init() { func init() {
registry.RegisterService(&DistributedCache{}) registry.RegisterService(&RemoteCache{})
} }
// CacheStorage allows the caller to set, get and delete items in the cache. // CacheStorage allows the caller to set, get and delete items in the cache.
...@@ -38,8 +38,8 @@ type CacheStorage interface { ...@@ -38,8 +38,8 @@ type CacheStorage interface {
Delete(key string) error Delete(key string) error
} }
// DistributedCache allows Grafana to cache data outside its own process // RemoteCache allows Grafana to cache data outside its own process
type DistributedCache struct { type RemoteCache struct {
log log.Logger log log.Logger
Client CacheStorage Client CacheStorage
SQLStore *sqlstore.SqlStore `inject:""` SQLStore *sqlstore.SqlStore `inject:""`
...@@ -47,15 +47,17 @@ type DistributedCache struct { ...@@ -47,15 +47,17 @@ type DistributedCache struct {
} }
// Init initializes the service // Init initializes the service
func (ds *DistributedCache) Init() error { func (ds *RemoteCache) Init() error {
ds.log = log.New("distributed.cache") ds.log = log.New("cache.remote")
ds.Client = createClient(ds.Cfg.CacheOptions, ds.SQLStore) ds.Client = createClient(ds.Cfg.RemoteCacheOptions, ds.SQLStore)
return nil 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) backgroundjob, ok := ds.Client.(registry.BackgroundService)
if ok { if ok {
return backgroundjob.Run(ctx) return backgroundjob.Run(ctx)
...@@ -65,7 +67,7 @@ func (ds *DistributedCache) Run(ctx context.Context) error { ...@@ -65,7 +67,7 @@ func (ds *DistributedCache) Run(ctx context.Context) error {
return ctx.Err() 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" { if opts.Name == "redis" {
return newRedisStorage(opts) return newRedisStorage(opts)
} }
......
package distcache package remotecache
import ( import (
"testing" "testing"
...@@ -19,13 +19,13 @@ func init() { ...@@ -19,13 +19,13 @@ func init() {
Register(CacheableStruct{}) 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() t.Helper()
dc := &DistributedCache{ dc := &RemoteCache{
SQLStore: sqlstore, SQLStore: sqlstore,
Cfg: &setting.Cfg{ Cfg: &setting.Cfg{
CacheOptions: opts, RemoteCacheOptions: opts,
}, },
} }
...@@ -44,7 +44,7 @@ func TestCachedBasedOnConfig(t *testing.T) { ...@@ -44,7 +44,7 @@ func TestCachedBasedOnConfig(t *testing.T) {
HomePath: "../../../", HomePath: "../../../",
}) })
client := createTestClient(t, cfg.CacheOptions, sqlstore.InitTestDB(t)) client := createTestClient(t, cfg.RemoteCacheOptions, sqlstore.InitTestDB(t))
runTestsForClient(t, client) runTestsForClient(t, client)
} }
......
...@@ -242,7 +242,7 @@ type Cfg struct { ...@@ -242,7 +242,7 @@ type Cfg struct {
EditorsCanOwn bool EditorsCanOwn bool
// DistributedCache // DistributedCache
CacheOptions *CacheOpts RemoteCacheOptions *RemoteCacheOptions
} }
type CommandLineArgs struct { type CommandLineArgs struct {
...@@ -782,8 +782,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { ...@@ -782,8 +782,8 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
enterprise := iniFile.Section("enterprise") enterprise := iniFile.Section("enterprise")
cfg.EnterpriseLicensePath = enterprise.Key("license_path").MustString(filepath.Join(cfg.DataPath, "license.jwt")) cfg.EnterpriseLicensePath = enterprise.Key("license_path").MustString(filepath.Join(cfg.DataPath, "license.jwt"))
cacheServer := iniFile.Section("cache_server") cacheServer := iniFile.Section("remote_cache")
cfg.CacheOptions = &CacheOpts{ cfg.RemoteCacheOptions = &RemoteCacheOptions{
Name: cacheServer.Key("type").MustString("database"), Name: cacheServer.Key("type").MustString("database"),
ConnStr: cacheServer.Key("connstr").MustString(""), ConnStr: cacheServer.Key("connstr").MustString(""),
} }
...@@ -791,7 +791,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error { ...@@ -791,7 +791,7 @@ func (cfg *Cfg) Load(args *CommandLineArgs) error {
return nil return nil
} }
type CacheOpts struct { type RemoteCacheOptions struct {
Name string Name string
ConnStr string ConnStr string
} }
......
...@@ -13,6 +13,6 @@ function exit_if_fail { ...@@ -13,6 +13,6 @@ function exit_if_fail {
echo "running redis and memcache tests" echo "running redis and memcache tests"
#set -e #set -e
#time for d in $(go list ./pkg/...); do #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=redis ./pkg/infra/remotecache/...
time exit_if_fail go test -tags=memcached ./pkg/infra/distcache/... time exit_if_fail go test -tags=memcached ./pkg/infra/remotecache/...
#done #done
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment