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

[cherry-pick] fix: increase beego max memory and upload size (#19578) #19670

Merged
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
10 changes: 10 additions & 0 deletions src/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -226,4 +226,14 @@ const (
UIMaxLengthLimitedOfNumber = 10
// ExecutionStatusRefreshIntervalSeconds is the interval seconds for refreshing execution status
ExecutionStatusRefreshIntervalSeconds = "execution_status_refresh_interval_seconds"

// Beego web config
// BeegoMaxMemoryBytes is the max memory(bytes) of the beego web config
BeegoMaxMemoryBytes = "beego_max_memory_bytes"
// DefaultBeegoMaxMemoryBytes sets default max memory to 128GB
DefaultBeegoMaxMemoryBytes = 1 << 37
// BeegoMaxUploadSizeBytes is the max upload size(bytes) of the beego web config
BeegoMaxUploadSizeBytes = "beego_max_upload_size_bytes"
// DefaultBeegoMaxUploadSizeBytes sets default max upload size to 128GB
DefaultBeegoMaxUploadSizeBytes = 1 << 37
)
8 changes: 6 additions & 2 deletions src/core/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,6 @@ func main() {

web.BConfig.WebConfig.Session.SessionOn = true
web.BConfig.WebConfig.Session.SessionName = config.SessionCookieName
web.BConfig.MaxMemory = 1 << 35 // (32GB)
web.BConfig.MaxUploadSize = 1 << 35 // (32GB)
// the core db used for beego session
redisCoreURL := os.Getenv("_REDIS_URL_CORE")
if len(redisCoreURL) > 0 {
Expand Down Expand Up @@ -161,6 +159,12 @@ func main() {
log.Info("initializing configurations...")
config.Init()
log.Info("configurations initialization completed")

// default beego max memory and max upload size is 128GB, consider from some AI related image would be large,
// also support customize it from the environment variables if the default value cannot satisfy some scenarios.
web.BConfig.MaxMemory = config.GetBeegoMaxMemoryBytes()
web.BConfig.MaxUploadSize = config.GetBeegoMaxUploadSizeBytes()

metricCfg := config.Metric()
if metricCfg.Enabled {
metric.RegisterCollectors()
Expand Down
9 changes: 8 additions & 1 deletion src/lib/config/metadata/metadatalist.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,11 @@

package metadata

import "github.com/goharbor/harbor/src/common"
import (
"fmt"

"github.com/goharbor/harbor/src/common"
)

// Item - Configure item include default value, type, env name
type Item struct {
Expand Down Expand Up @@ -191,5 +195,8 @@ var (
{Name: common.SessionTimeout, Scope: UserScope, Group: BasicGroup, EnvKey: "SESSION_TIMEOUT", DefaultValue: "60", ItemType: &Int64Type{}, Editable: true, Description: `The session timeout in minutes`},

{Name: common.ExecutionStatusRefreshIntervalSeconds, Scope: SystemScope, Group: BasicGroup, EnvKey: "EXECUTION_STATUS_REFRESH_INTERVAL_SECONDS", DefaultValue: "30", ItemType: &Int64Type{}, Editable: false, Description: `The interval seconds to refresh the execution status`},

{Name: common.BeegoMaxMemoryBytes, Scope: SystemScope, Group: BasicGroup, EnvKey: "BEEGO_MAX_MEMORY_BYTES", DefaultValue: fmt.Sprintf("%d", common.DefaultBeegoMaxMemoryBytes), ItemType: &Int64Type{}, Editable: false, Description: `The bytes for limiting the beego max memory, default is 128GB`},
{Name: common.BeegoMaxUploadSizeBytes, Scope: SystemScope, Group: BasicGroup, EnvKey: "BEEGO_MAX_UPLOAD_SIZE_BYTES", DefaultValue: fmt.Sprintf("%d", common.DefaultBeegoMaxUploadSizeBytes), ItemType: &Int64Type{}, Editable: false, Description: `The bytes for limiting the beego max upload size, default it 128GB`},
}
)
10 changes: 10 additions & 0 deletions src/lib/config/systemconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,16 @@
return DefaultMgr().Get(backgroundCtx, common.WithNotary).GetBool()
}

// GetBeegoMaxMemoryBytes returns the max memory bytes of beego config
func GetBeegoMaxMemoryBytes() int64 {
return DefaultMgr().Get(backgroundCtx, common.BeegoMaxMemoryBytes).GetInt64()

Check warning on line 156 in src/lib/config/systemconfig.go

View check run for this annotation

Codecov / codecov/patch

src/lib/config/systemconfig.go#L155-L156

Added lines #L155 - L156 were not covered by tests
}

// GetBeegoMaxUploadSizeBytes returns the max upload size bytes of beego config
func GetBeegoMaxUploadSizeBytes() int64 {
return DefaultMgr().Get(backgroundCtx, common.BeegoMaxUploadSizeBytes).GetInt64()

Check warning on line 161 in src/lib/config/systemconfig.go

View check run for this annotation

Codecov / codecov/patch

src/lib/config/systemconfig.go#L160-L161

Added lines #L160 - L161 were not covered by tests
}

// WithTrivy returns a bool value to indicate if Harbor's deployed with Trivy.
func WithTrivy() bool {
return DefaultMgr().Get(backgroundCtx, common.WithTrivy).GetBool()
Expand Down
Loading