diff --git a/lib/orm/orm.go b/lib/orm/orm.go index e98b0cdd..6c3b7a05 100644 --- a/lib/orm/orm.go +++ b/lib/orm/orm.go @@ -33,25 +33,41 @@ import ( // MySQL ... type MySQL struct { - Host string `json:"host"` - Port int `json:"port"` - Username string `json:"username"` - Password string `json:"password,omitempty"` - Database string `json:"database"` - PrometheusEnabled bool `json:"prometheusEnabled"` + Host string `json:"host"` + Port int `json:"port"` + Username string `json:"username"` + Password string `json:"password,omitempty"` + Database string `json:"database"` + PrometheusEnabled bool `json:"prometheusEnabled"` + SlowThreshold time.Duration `json:"slowThreshold"` + MaxIdleConns int `json:"maxIdleConns"` + MaxOpenConns int `json:"maxOpenConns"` } func NewMySQLDB(db *MySQL) (*gorm.DB, error) { conn := fmt.Sprintf("%s:%s@tcp(%s:%d)/%s?charset=utf8mb4&parseTime=True&loc=Local", db.Username, db.Password, db.Host, db.Port, db.Database) + // Set default value for SlowThreshold if not provided + if db.SlowThreshold == 0 { + db.SlowThreshold = 200 * time.Millisecond + } + // Set default value for MaxIdleConns if not provided + if db.MaxIdleConns == 0 { + db.MaxIdleConns = 10 + } + // Set default value for MaxOpenConns if not provided + if db.MaxOpenConns == 0 { + db.MaxOpenConns = 100 + } + sqlDB, err := sql.Open("mysql", conn) if err != nil { return nil, err } - sqlDB.SetMaxIdleConns(10) - sqlDB.SetMaxOpenConns(100) + sqlDB.SetMaxIdleConns(db.MaxIdleConns) + sqlDB.SetMaxOpenConns(db.MaxOpenConns) sqlDB.SetConnMaxLifetime(time.Hour) sqlDB.SetConnMaxIdleTime(time.Hour) @@ -62,6 +78,13 @@ func NewMySQLDB(db *MySQL) (*gorm.DB, error) { TablePrefix: "tb_", SingularTable: true, }, + Logger: logger.New(log.New(os.Stdout, "\r\n", log.LstdFlags), + logger.Config{ + SlowThreshold: db.SlowThreshold, + LogLevel: logger.Warn, + IgnoreRecordNotFoundError: false, + Colorful: true, + }), }) if db.PrometheusEnabled { diff --git a/pkg/eventhandler/wlgenerator/wlgenerator.go b/pkg/eventhandler/wlgenerator/wlgenerator.go index 9ca31679..74e53394 100644 --- a/pkg/eventhandler/wlgenerator/wlgenerator.go +++ b/pkg/eventhandler/wlgenerator/wlgenerator.go @@ -87,6 +87,7 @@ type PipelinerunInfo struct { ResourceCommonInfo ClusterID uint `json:"clusterID,omitempty"` ClusterName string `json:"clusterName,omitempty"` + ClusterEnv string `json:"clusterEnv,omitempty"` Action string `json:"action,omitempty"` Title string `json:"title,omitempty"` Description string `json:"description,omitempty"` @@ -329,6 +330,7 @@ func (w *WebhookLogGenerator) makeRequestBody(ctx context.Context, dep *messageD } return "" }(), + ClusterEnv: dep.cluster.EnvironmentName, Action: dep.pipelinerun.Action, Title: dep.pipelinerun.Title, Description: dep.pipelinerun.Description,