mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-11-25 11:21:02 +00:00
Add options to controll the database connections (open,idle,timeout) (#4212)
This commit is contained in:
parent
4270eca597
commit
6e38a950cd
6 changed files with 72 additions and 20 deletions
|
@ -27,14 +27,34 @@ import (
|
|||
|
||||
var flags = append([]cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_LOG_XORM"),
|
||||
Name: "log-xorm",
|
||||
Usage: "enable xorm logging",
|
||||
Sources: cli.EnvVars("WOODPECKER_DATABASE_LOG", "WOODPECKER_LOG_XORM"),
|
||||
Name: "db-log",
|
||||
Aliases: []string{"log-xorm"}, // TODO: remove in v4.0.0
|
||||
Usage: "enable logging in database engine (currently xorm)",
|
||||
},
|
||||
&cli.BoolFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_LOG_XORM_SQL"),
|
||||
Name: "log-xorm-sql",
|
||||
Usage: "enable xorm sql command logging",
|
||||
Sources: cli.EnvVars("WOODPECKER_DATABASE_LOG_SQL", "WOODPECKER_LOG_XORM_SQL"),
|
||||
Name: "db-log-sql",
|
||||
Aliases: []string{"log-xorm-sql"}, // TODO: remove in v4.0.0
|
||||
Usage: "enable logging of sql commands",
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_DATABASE_MAX_CONNECTIONS"),
|
||||
Name: "db-max-open-connections",
|
||||
Usage: "max connections xorm is allowed create",
|
||||
Value: 100,
|
||||
},
|
||||
&cli.IntFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_DATABASE_IDLE_CONNECTIONS"),
|
||||
Name: "db-max-idle-connections",
|
||||
Usage: "amount of connections xorm will hold open",
|
||||
Value: 2,
|
||||
},
|
||||
&cli.DurationFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_DATABASE_CONNECTION_TIMEOUT"),
|
||||
Name: "db-max-connection-timeout",
|
||||
Usage: "time an active connection is allowed to stay open",
|
||||
Value: 3 * time.Second,
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_HOST"),
|
||||
|
@ -205,7 +225,8 @@ var flags = append([]cli.Flag{
|
|||
},
|
||||
&cli.StringFlag{
|
||||
Sources: cli.EnvVars("WOODPECKER_DATABASE_DRIVER"),
|
||||
Name: "driver",
|
||||
Name: "db-driver",
|
||||
Aliases: []string{"driver"}, // TODO: remove in v4.0.0
|
||||
Usage: "database driver",
|
||||
Value: "sqlite3",
|
||||
},
|
||||
|
@ -213,9 +234,10 @@ var flags = append([]cli.Flag{
|
|||
Sources: cli.NewValueSourceChain(
|
||||
cli.File(os.Getenv("WOODPECKER_DATABASE_DATASOURCE_FILE")),
|
||||
cli.EnvVar("WOODPECKER_DATABASE_DATASOURCE")),
|
||||
Name: "datasource",
|
||||
Usage: "database driver configuration string",
|
||||
Value: datasourceDefaultValue(),
|
||||
Name: "db-datasource",
|
||||
Aliases: []string{"datasource"}, // TODO: remove in v4.0.0
|
||||
Usage: "database driver configuration string",
|
||||
Value: datasourceDefaultValue(),
|
||||
},
|
||||
&cli.StringFlag{
|
||||
Sources: cli.NewValueSourceChain(
|
||||
|
|
|
@ -51,11 +51,14 @@ const (
|
|||
)
|
||||
|
||||
func setupStore(ctx context.Context, c *cli.Command) (store.Store, error) {
|
||||
datasource := c.String("datasource")
|
||||
driver := c.String("driver")
|
||||
datasource := c.String("db-datasource")
|
||||
driver := c.String("db-driver")
|
||||
xorm := store.XORM{
|
||||
Log: c.Bool("log-xorm"),
|
||||
ShowSQL: c.Bool("log-xorm-sql"),
|
||||
Log: c.Bool("db-log"),
|
||||
ShowSQL: c.Bool("db-log-sql"),
|
||||
MaxOpenConns: int(c.Int("db-max-open-connections")),
|
||||
MaxIdleConns: int(c.Int("db-max-idle-connections")),
|
||||
ConnMaxLifetime: c.Duration("db-max-connection-timeout"),
|
||||
}
|
||||
|
||||
if driver == "sqlite3" {
|
||||
|
|
|
@ -159,17 +159,35 @@ Configures the logging level. Possible values are `trace`, `debug`, `info`, `war
|
|||
Output destination for logs.
|
||||
'stdout' and 'stderr' can be used as special keywords.
|
||||
|
||||
### `WOODPECKER_LOG_XORM`
|
||||
### `WOODPECKER_DATABASE_LOG`
|
||||
|
||||
> Default: `false`
|
||||
|
||||
Enable XORM logs.
|
||||
Enable logging in database engine (currently xorm).
|
||||
|
||||
### `WOODPECKER_LOG_XORM_SQL`
|
||||
### `WOODPECKER_DATABASE_LOG_SQL`
|
||||
|
||||
> Default: `false`
|
||||
|
||||
Enable XORM SQL command logs.
|
||||
Enable logging of sql commands.
|
||||
|
||||
### `WOODPECKER_DATABASE_MAX_CONNECTIONS`
|
||||
|
||||
> Default: `100`
|
||||
|
||||
Max database connections xorm is allowed create.
|
||||
|
||||
### `WOODPECKER_DATABASE_IDLE_CONNECTIONS`
|
||||
|
||||
> Default: `2`
|
||||
|
||||
Amount of database connections xorm will hold open.
|
||||
|
||||
### `WOODPECKER_DATABASE_CONNECTION_TIMEOUT`
|
||||
|
||||
> Default: `3 Seconds`
|
||||
|
||||
Time an active database connection is allowed to stay open.
|
||||
|
||||
### `WOODPECKER_DEBUG_PRETTY`
|
||||
|
||||
|
|
|
@ -36,6 +36,7 @@ This will be the next version of Woodpecker.
|
|||
|
||||
## Admin migrations
|
||||
|
||||
- Deprecate `WOODPECKER_LOG_XORM` and `WOODPECKER_LOG_XORM_SQL` use `"WOODPECKER_DATABASE_LOG` and `"WOODPECKER_DATABASE_LOG_SQL`
|
||||
- Deprecate `WOODPECKER_FILTER_LABELS` use `WOODPECKER_AGENT_LABELS`
|
||||
- Move docker resource limit settings from server into agent configuration
|
||||
- Rename server environment variable `WOODPECKER_ESCALATE` to `WOODPECKER_PLUGINS_PRIVILEGED`
|
||||
|
|
|
@ -14,9 +14,14 @@
|
|||
|
||||
package store
|
||||
|
||||
import "time"
|
||||
|
||||
type XORM struct {
|
||||
Log bool
|
||||
ShowSQL bool
|
||||
Log bool
|
||||
ShowSQL bool
|
||||
MaxIdleConns int
|
||||
MaxOpenConns int
|
||||
ConnMaxLifetime time.Duration
|
||||
}
|
||||
|
||||
// Opts are options for a new database connection.
|
||||
|
|
|
@ -45,6 +45,9 @@ func NewEngine(opts *store.Opts) (store.Store, error) {
|
|||
logger := newXORMLogger(level)
|
||||
engine.SetLogger(logger)
|
||||
engine.ShowSQL(opts.XORM.ShowSQL)
|
||||
engine.SetMaxOpenConns(opts.XORM.MaxOpenConns)
|
||||
engine.SetMaxIdleConns(opts.XORM.MaxIdleConns)
|
||||
engine.SetConnMaxLifetime(opts.XORM.ConnMaxLifetime)
|
||||
|
||||
return &storage{
|
||||
engine: engine,
|
||||
|
|
Loading…
Reference in a new issue