Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

log: change log level to reduce the noise logs #19146

Merged
merged 1 commit into from
Aug 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 33 additions & 12 deletions src/cmd/exporter/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,16 +36,7 @@ func main() {
viper.SetEnvPrefix("harbor")
viper.AutomaticEnv()
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{
Type: "postgresql",
PostGreSQL: &models.PostGreSQL{
Expand All @@ -57,8 +48,8 @@ func main() {
SSLMode: viper.GetString("database.sslmode"),
MaxIdleConns: viper.GetInt("database.max_idle_conns"),
MaxOpenConns: viper.GetInt("database.max_open_conns"),
ConnMaxLifetime: connMaxLifetime,
ConnMaxIdleTime: connMaxIdleTime,
ConnMaxLifetime: getConnMaxLifetime(viper.GetString("database.conn_max_lifetime")),
ConnMaxIdleTime: getConnMaxIdleTime(viper.GetString("database.conn_max_idle_time")),
},
}
if err := dao.InitDatabase(dbCfg); err != nil {
Expand Down Expand Up @@ -109,3 +100,33 @@ func main() {
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
}
7 changes: 3 additions & 4 deletions src/core/session/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,12 @@

import (
"context"
"errors"
"net/http"
"strings"
"sync"
"time"

"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/redis"
Expand Down Expand Up @@ -131,7 +130,7 @@
ctx = context.TODO()
}
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
}

Expand Down Expand Up @@ -166,7 +165,7 @@
} else {
kv := make(map[interface{}]interface{})
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) {

Check warning on line 168 in src/core/session/session.go

View check run for this annotation

Codecov / codecov/patch

src/core/session/session.go#L168

Added line #L168 was not covered by tests
return nil, err
}

Expand Down
4 changes: 4 additions & 0 deletions src/lib/cache/redis/redis.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ func (c *Cache) Fetch(ctx context.Context, key string, value interface{}) error
// convert internal or Timeout error to be ErrNotFound
// so that the caller can continue working without breaking
// return cache.ErrNotFound
if err == redis.Nil {
return cache.ErrNotFound
}

return fmt.Errorf("%w:%v", cache.ErrNotFound, err)
}

Expand Down
2 changes: 1 addition & 1 deletion src/pkg/notifier/notifier.go
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ func (nw *NotificationWatcher) Notify(ctx context.Context, notification Notifica
// 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())
} 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)
Expand Down
2 changes: 1 addition & 1 deletion src/server/registry/manifest.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@
_, _ = buffer.Write(manifest)
}
} 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)

Check warning on line 96 in src/server/registry/manifest.go

View check run for this annotation

Codecov / codecov/patch

src/server/registry/manifest.go#L96

Added line #L96 was not covered by tests
// only write cache when request is GET because HEAD request resp
// body is empty.
if req.Method == http.MethodGet {
Expand Down
Loading