Browse Source

renames distcache -> remotecache

bergquist 6 năm trước cách đây
mục cha
commit
7e7427637c

+ 1 - 1
conf/defaults.ini

@@ -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
 
 

+ 11 - 0
conf/sample.ini

@@ -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"

+ 1 - 1
pkg/cmd/grafana-server/server.go

@@ -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"

+ 1 - 1
pkg/infra/distcache/database_storage.go → pkg/infra/remotecache/database_storage.go

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

+ 1 - 1
pkg/infra/distcache/database_storage_test.go → pkg/infra/remotecache/database_storage_test.go

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

+ 2 - 2
pkg/infra/distcache/memcached_storage.go → pkg/infra/remotecache/memcached_storage.go

@@ -1,4 +1,4 @@
-package distcache
+package remotecache
 
 
 import (
 import (
 	"time"
 	"time"
@@ -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),
 	}
 	}

+ 2 - 2
pkg/infra/distcache/memcached_storage_integration_test.go → pkg/infra/remotecache/memcached_storage_integration_test.go

@@ -1,6 +1,6 @@
 // +build memcached
 // +build memcached
 
 
-package distcache
+package remotecache
 
 
 import (
 import (
 	"testing"
 	"testing"
@@ -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))
 }
 }

+ 2 - 2
pkg/infra/distcache/redis_storage.go → pkg/infra/remotecache/redis_storage.go

@@ -1,4 +1,4 @@
-package distcache
+package remotecache
 
 
 import (
 import (
 	"time"
 	"time"
@@ -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,

+ 2 - 2
pkg/infra/distcache/redis_storage_integration_test.go → pkg/infra/remotecache/redis_storage_integration_test.go

@@ -1,6 +1,6 @@
 // +build redis
 // +build redis
 
 
-package distcache
+package remotecache
 
 
 import (
 import (
 	"testing"
 	"testing"
@@ -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))
 }
 }

+ 11 - 9
pkg/infra/distcache/distcache.go → pkg/infra/remotecache/remotecache.go

@@ -1,4 +1,4 @@
-package distcache
+package remotecache
 
 
 import (
 import (
 	"bytes"
 	"bytes"
@@ -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 {
 	Delete(key string) error
 	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
 	log      log.Logger
 	Client   CacheStorage
 	Client   CacheStorage
 	SQLStore *sqlstore.SqlStore `inject:""`
 	SQLStore *sqlstore.SqlStore `inject:""`
@@ -47,15 +47,17 @@ type DistributedCache struct {
 }
 }
 
 
 // Init initializes the service
 // 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
 	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 {
 	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)
 	}
 	}

+ 5 - 5
pkg/infra/distcache/distcache_test.go → pkg/infra/remotecache/remotecache_test.go

@@ -1,4 +1,4 @@
-package distcache
+package remotecache
 
 
 import (
 import (
 	"testing"
 	"testing"
@@ -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) {
 		HomePath: "../../../",
 		HomePath: "../../../",
 	})
 	})
 
 
-	client := createTestClient(t, cfg.CacheOptions, sqlstore.InitTestDB(t))
+	client := createTestClient(t, cfg.RemoteCacheOptions, sqlstore.InitTestDB(t))
 
 
 	runTestsForClient(t, client)
 	runTestsForClient(t, client)
 }
 }

+ 4 - 4
pkg/setting/setting.go

@@ -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 {
 	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")
-	cfg.CacheOptions = &CacheOpts{
+	cacheServer := iniFile.Section("remote_cache")
+	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 {
 	return nil
 	return nil
 }
 }
 
 
-type CacheOpts struct {
+type RemoteCacheOptions struct {
 	Name    string
 	Name    string
 	ConnStr string
 	ConnStr string
 }
 }

+ 2 - 2
scripts/circle-test-cache-servers.sh

@@ -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=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
 #done