Skip to content

Commit

Permalink
fix(logs): add logs about cache and lock strategy
Browse files Browse the repository at this point in the history
  • Loading branch information
aldor007 committed Mar 16, 2022
1 parent 4602e26 commit 59e7965
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
5 changes: 5 additions & 0 deletions pkg/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package cache

import (
"github.com/aldor007/mort/pkg/config"
"github.com/aldor007/mort/pkg/monitoring"
"github.com/aldor007/mort/pkg/object"
"github.com/aldor007/mort/pkg/response"
"go.uber.org/zap"
)

// ResponseCache is interface for caching of mort responses
Expand All @@ -17,10 +19,13 @@ type ResponseCache interface {
func Create(cacheCfg config.CacheCfg) ResponseCache {
switch cacheCfg.Type {
case "redis":
monitoring.Log().Info("Creating redis cache", zap.Strings("addr", cacheCfg.Address))
return NewRedis(cacheCfg.Address, cacheCfg.ClientConfig)
case "redis-cluster":
monitoring.Log().Info("Creating redis-cluster cache", zap.Strings("addr", cacheCfg.Address))
return NewRedisCluster(cacheCfg.Address, cacheCfg.ClientConfig)
default:
monitoring.Log().Info("Creating memory cache")
return NewMemoryCache(cacheCfg.CacheSize)
}
}
5 changes: 5 additions & 0 deletions pkg/lock/lock.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,9 @@ import (
"context"

"github.com/aldor007/mort/pkg/config"
"github.com/aldor007/mort/pkg/monitoring"
"github.com/aldor007/mort/pkg/response"
"go.uber.org/zap"
)

// Lock is responding for collapsing request for same object
Expand Down Expand Up @@ -64,14 +66,17 @@ func (l *NopLock) NotifyAndRelease(_ context.Context, _ string, _ *response.Resp

func Create(lockCfg *config.LockCfg, lockTimeout int) Lock {
if lockCfg == nil {
monitoring.Log().Info("Creating memory lock")
return NewMemoryLock()
}
switch lockCfg.Type {
case "redis":
monitoring.Log().Info("Creating redis lock", zap.Strings("addr", lockCfg.Address), zap.Int("lockTimeout", lockTimeout))
r := NewRedisLock(lockCfg.Address, lockCfg.ClientConfig)
r.LockTimeout = lockTimeout
return r
case "redis-cluster":
monitoring.Log().Info("Creating redis-cluster lock", zap.Strings("addr", lockCfg.Address), zap.Int("lockTimeout", lockTimeout))
r := NewRedisCluster(lockCfg.Address, lockCfg.ClientConfig)
r.LockTimeout = lockTimeout
return r
Expand Down

0 comments on commit 59e7965

Please # to comment.