mirror of
https://github.com/goharbor/harbor.git
synced 2025-01-21 07:01:25 +01:00
log: change log level to reduce the noise logs (#19165)
1. Change some logs level to reduce the noise. 2. Wrap the go-redis.Nil error as ErrNotFound to avoid confusing Signed-off-by: chlins <chenyuzh@vmware.com>
This commit is contained in:
parent
fbdc03bcab
commit
8ad19e785b
@ -36,16 +36,7 @@ func main() {
|
|||||||
viper.SetEnvPrefix("harbor")
|
viper.SetEnvPrefix("harbor")
|
||||||
viper.AutomaticEnv()
|
viper.AutomaticEnv()
|
||||||
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
viper.SetEnvKeyReplacer(strings.NewReplacer(".", "_"))
|
||||||
connMaxLifetime, err := time.ParseDuration(viper.GetString("database.conn_max_lifetime"))
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to parse database.conn_max_lifetime: %v", err)
|
|
||||||
connMaxLifetime = 5 * time.Minute
|
|
||||||
}
|
|
||||||
connMaxIdleTime, err := time.ParseDuration(viper.GetString("database.conn_max_idle_time"))
|
|
||||||
if err != nil {
|
|
||||||
log.Errorf("Failed to parse database.conn_max_idle_time: %v", err)
|
|
||||||
connMaxIdleTime = 0
|
|
||||||
}
|
|
||||||
dbCfg := &models.Database{
|
dbCfg := &models.Database{
|
||||||
Type: "postgresql",
|
Type: "postgresql",
|
||||||
PostGreSQL: &models.PostGreSQL{
|
PostGreSQL: &models.PostGreSQL{
|
||||||
@ -57,8 +48,8 @@ func main() {
|
|||||||
SSLMode: viper.GetString("database.sslmode"),
|
SSLMode: viper.GetString("database.sslmode"),
|
||||||
MaxIdleConns: viper.GetInt("database.max_idle_conns"),
|
MaxIdleConns: viper.GetInt("database.max_idle_conns"),
|
||||||
MaxOpenConns: viper.GetInt("database.max_open_conns"),
|
MaxOpenConns: viper.GetInt("database.max_open_conns"),
|
||||||
ConnMaxLifetime: connMaxLifetime,
|
ConnMaxLifetime: getConnMaxLifetime(viper.GetString("database.conn_max_lifetime")),
|
||||||
ConnMaxIdleTime: connMaxIdleTime,
|
ConnMaxIdleTime: getConnMaxIdleTime(viper.GetString("database.conn_max_idle_time")),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if err := dao.InitDatabase(dbCfg); err != nil {
|
if err := dao.InitDatabase(dbCfg); err != nil {
|
||||||
@ -109,3 +100,33 @@ func main() {
|
|||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func getConnMaxLifetime(duration string) time.Duration {
|
||||||
|
// set conn max life time, 5m by default
|
||||||
|
connMaxLifetime := 5 * time.Minute
|
||||||
|
if duration != "" {
|
||||||
|
maxLifetime, err := time.ParseDuration(duration)
|
||||||
|
if err == nil {
|
||||||
|
connMaxLifetime = maxLifetime
|
||||||
|
} else {
|
||||||
|
log.Warningf("Failed to parse database.conn_max_lifetime, use default value: %s, err: %v", connMaxLifetime, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return connMaxLifetime
|
||||||
|
}
|
||||||
|
|
||||||
|
func getConnMaxIdleTime(duration string) time.Duration {
|
||||||
|
// set conn max idle time, 0 by default
|
||||||
|
connMaxIdleTime := time.Duration(0)
|
||||||
|
if duration != "" {
|
||||||
|
maxIdleTime, err := time.ParseDuration(duration)
|
||||||
|
if err == nil {
|
||||||
|
connMaxIdleTime = maxIdleTime
|
||||||
|
} else {
|
||||||
|
log.Warningf("Failed to parse database.conn_max_idle_time, use default value: %s, err: %v", connMaxIdleTime, err)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return connMaxIdleTime
|
||||||
|
}
|
||||||
|
@ -16,13 +16,12 @@ package session
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"errors"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"github.com/beego/beego/v2/server/web/session"
|
"github.com/beego/beego/v2/server/web/session"
|
||||||
goredis "github.com/go-redis/redis/v8"
|
|
||||||
|
|
||||||
"github.com/goharbor/harbor/src/lib/cache"
|
"github.com/goharbor/harbor/src/lib/cache"
|
||||||
"github.com/goharbor/harbor/src/lib/cache/redis"
|
"github.com/goharbor/harbor/src/lib/cache/redis"
|
||||||
@ -131,7 +130,7 @@ func (rp *Provider) SessionRead(ctx context.Context, sid string) (session.Store,
|
|||||||
ctx = context.TODO()
|
ctx = context.TODO()
|
||||||
}
|
}
|
||||||
err := rp.c.Fetch(ctx, sid, &kv)
|
err := rp.c.Fetch(ctx, sid, &kv)
|
||||||
if err != nil && !strings.Contains(err.Error(), goredis.Nil.Error()) {
|
if err != nil && !errors.Is(err, cache.ErrNotFound) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -166,7 +165,7 @@ func (rp *Provider) SessionRegenerate(ctx context.Context, oldsid, sid string) (
|
|||||||
} else {
|
} else {
|
||||||
kv := make(map[interface{}]interface{})
|
kv := make(map[interface{}]interface{})
|
||||||
err := rp.c.Fetch(ctx, sid, &kv)
|
err := rp.c.Fetch(ctx, sid, &kv)
|
||||||
if err != nil && !strings.Contains(err.Error(), goredis.Nil.Error()) {
|
if err != nil && !errors.Is(err, cache.ErrNotFound) {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
|
4
src/lib/cache/redis/redis.go
vendored
4
src/lib/cache/redis/redis.go
vendored
@ -58,6 +58,10 @@ func (c *Cache) Fetch(ctx context.Context, key string, value interface{}) error
|
|||||||
// convert internal or Timeout error to be ErrNotFound
|
// convert internal or Timeout error to be ErrNotFound
|
||||||
// so that the caller can continue working without breaking
|
// so that the caller can continue working without breaking
|
||||||
// return cache.ErrNotFound
|
// return cache.ErrNotFound
|
||||||
|
if err == redis.Nil {
|
||||||
|
return cache.ErrNotFound
|
||||||
|
}
|
||||||
|
|
||||||
return fmt.Errorf("%w:%v", cache.ErrNotFound, err)
|
return fmt.Errorf("%w:%v", cache.ErrNotFound, err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -217,7 +217,7 @@ func (nw *NotificationWatcher) Notify(ctx context.Context, notification Notifica
|
|||||||
// Currently, we just log the error
|
// Currently, we just log the error
|
||||||
log.Errorf("Error occurred when triggering handler %s of topic %s: %s\n", reflect.TypeOf(hd).String(), notification.Topic, err.Error())
|
log.Errorf("Error occurred when triggering handler %s of topic %s: %s\n", reflect.TypeOf(hd).String(), notification.Topic, err.Error())
|
||||||
} else {
|
} else {
|
||||||
log.Infof("Handle notification with Handler '%s' on topic '%s': %+v\n", hd.Name(), notification.Topic, notification.Value)
|
log.Debugf("Handle notification with Handler '%s' on topic '%s': %+v\n", hd.Name(), notification.Topic, notification.Value)
|
||||||
}
|
}
|
||||||
}()
|
}()
|
||||||
}(h, handlerChan)
|
}(h, handlerChan)
|
||||||
|
@ -93,7 +93,7 @@ func getManifest(w http.ResponseWriter, req *http.Request) {
|
|||||||
_, _ = buffer.Write(manifest)
|
_, _ = buffer.Write(manifest)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
log.Warningf("failed to get manifest from cache, error: %v", err)
|
log.Debugf("failed to get manifest from cache, will fallback to registry, error: %v", err)
|
||||||
// only write cache when request is GET because HEAD request resp
|
// only write cache when request is GET because HEAD request resp
|
||||||
// body is empty.
|
// body is empty.
|
||||||
if req.Method == http.MethodGet {
|
if req.Method == http.MethodGet {
|
||||||
|
Loading…
Reference in New Issue
Block a user