mirror of
https://github.com/goharbor/harbor.git
synced 2024-12-27 02:58:05 +01:00
add pull update control env (#16051)
These variables are temporary solution for issue: https://github.com/goharbor/harbor/issues/16039 When user disable the pull count/time/audit log, it will decrease the database access, especially in large concurrency pull scenarios. 1, PULL_TIME_UPDATE_DISABLE : The flag to indicate if pull time is disable for pull request. 2, PULL_COUNT_UPDATE_DISABLE : The flag to indicate if pull count is disable for pull request. 3, pull audit log will not create on disabling pull time. Signed-off-by: Wang Yan <wangyan@vmware.com>
This commit is contained in:
parent
cad78f6af4
commit
7608df4b5c
@ -186,4 +186,14 @@ const (
|
||||
TraceOtelCompression = "trace_otel_compression"
|
||||
TraceOtelInsecure = "trace_otel_insecure"
|
||||
TraceOtelTimeout = "trace_otel_timeout"
|
||||
|
||||
// These variables are temporary solution for issue: https://github.com/goharbor/harbor/issues/16039
|
||||
// When user disable the pull count/time/audit log, it will decrease the database access, especially in large concurrency pull scenarios.
|
||||
// TODO: Once we have a complete solution, delete these variables.
|
||||
// PullCountUpdateDisable indicate if pull count is disable for pull request.
|
||||
PullCountUpdateDisable = "pull_count_update_disable"
|
||||
// PullTimeUpdateDisable indicate if pull time is disable for pull request.
|
||||
PullTimeUpdateDisable = "pull_time_update_disable"
|
||||
// PullAuditLogDisable indicate if pull audit log is disable for pull request.
|
||||
PullAuditLogDisable = "pull_audit_log_disable"
|
||||
)
|
||||
|
@ -17,6 +17,7 @@ package auditlog
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/controller/event"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"github.com/goharbor/harbor/src/lib/log"
|
||||
"github.com/goharbor/harbor/src/pkg/audit"
|
||||
am "github.com/goharbor/harbor/src/pkg/audit/model"
|
||||
@ -39,10 +40,19 @@ func (h *Handler) Name() string {
|
||||
// Handle ...
|
||||
func (h *Handler) Handle(ctx context.Context, value interface{}) error {
|
||||
var auditLog *am.AuditLog
|
||||
var addAuditLog bool
|
||||
switch v := value.(type) {
|
||||
case *event.PushArtifactEvent, *event.PullArtifactEvent, *event.DeleteArtifactEvent,
|
||||
case *event.PushArtifactEvent, *event.DeleteArtifactEvent,
|
||||
*event.DeleteRepositoryEvent, *event.CreateProjectEvent, *event.DeleteProjectEvent,
|
||||
*event.DeleteTagEvent, *event.CreateTagEvent:
|
||||
addAuditLog = true
|
||||
case *event.PullArtifactEvent:
|
||||
addAuditLog = !config.PullAuditLogDisable(ctx)
|
||||
default:
|
||||
log.Errorf("Can not handler this event type! %#v", v)
|
||||
}
|
||||
|
||||
if addAuditLog {
|
||||
resolver := value.(AuditResolver)
|
||||
al, err := resolver.ResolveToAuditLog()
|
||||
if err != nil {
|
||||
@ -50,13 +60,11 @@ func (h *Handler) Handle(ctx context.Context, value interface{}) error {
|
||||
return err
|
||||
}
|
||||
auditLog = al
|
||||
default:
|
||||
log.Errorf("Can not handler this event type! %#v", v)
|
||||
}
|
||||
if auditLog != nil {
|
||||
_, err := audit.Mgr.Create(ctx, auditLog)
|
||||
if err != nil {
|
||||
log.Debugf("add audit log err: %v", err)
|
||||
if auditLog != nil {
|
||||
_, err := audit.Mgr.Create(ctx, auditLog)
|
||||
if err != nil {
|
||||
log.Debugf("add audit log err: %v", err)
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
@ -16,6 +16,7 @@ package internal
|
||||
|
||||
import (
|
||||
"context"
|
||||
"github.com/goharbor/harbor/src/lib/config"
|
||||
"time"
|
||||
|
||||
"github.com/goharbor/harbor/src/controller/artifact"
|
||||
@ -54,8 +55,12 @@ func (a *Handler) IsStateful() bool {
|
||||
}
|
||||
|
||||
func (a *Handler) onPull(ctx context.Context, event *event.ArtifactEvent) error {
|
||||
go func() { a.updatePullTime(ctx, event) }()
|
||||
go func() { a.addPullCount(ctx, event) }()
|
||||
if !config.PullTimeUpdateDisable(ctx) {
|
||||
go func() { a.updatePullTime(ctx, event) }()
|
||||
}
|
||||
if !config.PullCountUpdateDisable(ctx) {
|
||||
go func() { a.addPullCount(ctx, event) }()
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
|
@ -179,5 +179,9 @@ var (
|
||||
{Name: common.TraceOtelCompression, Scope: SystemScope, Group: BasicGroup, EnvKey: "TRACE_OTEL_COMPRESSION", DefaultValue: "", ItemType: &BoolType{}, Editable: false, Description: `The compression of the Otel`},
|
||||
{Name: common.TraceOtelInsecure, Scope: SystemScope, Group: BasicGroup, EnvKey: "TRACE_OTEL_INSECURE", DefaultValue: "", ItemType: &BoolType{}, Editable: false, Description: `The insecure of the Otel`},
|
||||
{Name: common.TraceOtelTimeout, Scope: SystemScope, Group: BasicGroup, EnvKey: "TRACE_OTEL_TIMEOUT", DefaultValue: "", ItemType: &IntType{}, Editable: false, Description: `The timeout of the Otel`},
|
||||
|
||||
{Name: common.PullTimeUpdateDisable, Scope: UserScope, Group: BasicGroup, EnvKey: "PULL_TIME_UPDATE_DISABLE", DefaultValue: "false", ItemType: &BoolType{}, Editable: false, Description: `The flag to indicate if pull time is disable for pull request.`},
|
||||
{Name: common.PullCountUpdateDisable, Scope: UserScope, Group: BasicGroup, EnvKey: "PULL_COUNT_UPDATE_DISABLE", DefaultValue: "false", ItemType: &BoolType{}, Editable: false, Description: `The flag to indicate if pull count is disable for pull request.`},
|
||||
{Name: common.PullAuditLogDisable, Scope: UserScope, Group: BasicGroup, EnvKey: "PULL_AUDIT_LOG_DISABLE", DefaultValue: "false", ItemType: &BoolType{}, Editable: false, Description: `The flag to indicate if pull audit log is disable for pull request.`},
|
||||
}
|
||||
)
|
||||
|
@ -226,3 +226,18 @@ func SplitAndTrim(s, sep string) []string {
|
||||
}
|
||||
return res
|
||||
}
|
||||
|
||||
// PullCountUpdateDisable returns a bool to indicate if pull count is disable for pull request.
|
||||
func PullCountUpdateDisable(ctx context.Context) bool {
|
||||
return defaultMgr().Get(ctx, common.PullCountUpdateDisable).GetBool()
|
||||
}
|
||||
|
||||
// PullTimeUpdateDisable returns a bool to indicate if pull time is disable for pull request.
|
||||
func PullTimeUpdateDisable(ctx context.Context) bool {
|
||||
return defaultMgr().Get(ctx, common.PullTimeUpdateDisable).GetBool()
|
||||
}
|
||||
|
||||
// PullAuditLogDisable returns a bool to indicate if pull audit log is disable for pull request.
|
||||
func PullAuditLogDisable(ctx context.Context) bool {
|
||||
return defaultMgr().Get(ctx, common.PullAuditLogDisable).GetBool()
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user