-
Notifications
You must be signed in to change notification settings - Fork 692
feat: add helm values to configure pgx connection #2399
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
base: release/v0.10.x
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -137,10 +137,14 @@ type Config struct { | |
| // that originates TLS upstream. Off by default; | ||
| MCPEgressPlaintext bool | ||
| Database struct { | ||
| Url string | ||
| UrlFile string | ||
| VectorEnabled bool | ||
| SkipMigrations bool | ||
| Url string | ||
| UrlFile string | ||
| VectorEnabled bool | ||
| SkipMigrations bool | ||
| MaxConns int // 0 = unset (pgx default) | ||
| MinConns int // -1 = unset (pgx default); 0 is a valid value | ||
| MaxConnIdleTime time.Duration // 0 = unset (pgx default) | ||
| MaxConnLifetime time.Duration // 0 = unset (pgx default) | ||
| } | ||
| Substrate struct { | ||
| AteAPIEndpoint string | ||
|
|
@@ -183,6 +187,10 @@ func (cfg *Config) SetFlags(commandLine *flag.FlagSet) { | |
| commandLine.StringVar(&cfg.Database.UrlFile, "postgres-database-url-file", "", "Path to a file containing the PostgreSQL database URL. Takes precedence over --postgres-database-url.") | ||
| commandLine.BoolVar(&cfg.Database.VectorEnabled, "database-vector-enabled", true, "Enable pgvector extension and memory table. Requires pgvector to be installed on the PostgreSQL server.") | ||
| commandLine.BoolVar(&cfg.Database.SkipMigrations, "skip-migrations", false, "Do not run database migrations at startup; instead verify the database is already migrated and fail if it is not. Migrations must be applied out-of-band (e.g. from a pipeline or pre-upgrade hook). Settable via the SKIP_MIGRATIONS env var.") | ||
| commandLine.IntVar(&cfg.Database.MaxConns, "db-max-conns", 0, "Maximum number of connections in the Postgres pool. 0 leaves the pgx default.") | ||
| commandLine.IntVar(&cfg.Database.MinConns, "db-min-conns", -1, "Minimum number of connections in the Postgres pool. -1 leaves the pgx default.") | ||
| commandLine.DurationVar(&cfg.Database.MaxConnIdleTime, "db-max-conn-idle-time", 0, "Maximum idle time before a Postgres pool connection is closed. 0 leaves the pgx default (30m).") | ||
| commandLine.DurationVar(&cfg.Database.MaxConnLifetime, "db-max-conn-lifetime", 0, "Maximum lifetime of a Postgres pool connection. 0 leaves the pgx default (1h).") | ||
|
|
||
| commandLine.StringVar(&cfg.WatchNamespaces, "watch-namespaces", "", "The namespaces to watch for .") | ||
|
|
||
|
|
@@ -230,6 +238,32 @@ func (cfg *Config) SetFlags(commandLine *flag.FlagSet) { | |
| commandLine.StringVar(&agent_translator.DefaultAgentBindHost, "default-agent-bind-host", agent_translator.DefaultAgentBindHost, "Default host address for agent pods to bind to. Use '0.0.0.0' for IPv4 only or '::' for dual-stack (IPv4+IPv6).") | ||
| } | ||
|
|
||
| // postgresConfigFromApp builds a database.PostgresConfig from app flags. | ||
| // Zero/unset flag values leave the corresponding pool field nil so pgx defaults apply. | ||
| func postgresConfigFromApp(dbURL string, cfg *Config) *database.PostgresConfig { | ||
| pgCfg := &database.PostgresConfig{ | ||
| URL: dbURL, | ||
| VectorEnabled: cfg.Database.VectorEnabled, | ||
| } | ||
| if cfg.Database.MaxConns > 0 { | ||
| v := int32(cfg.Database.MaxConns) | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For each of these, we should probably have an upper bound as well. At least since an int converted to an int32 can truncate. Probably not an issue in practice, though, as that is an incredibly large number.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't think that would be a realistic config though |
||
| pgCfg.MaxConns = &v | ||
| } | ||
| if cfg.Database.MinConns >= 0 { | ||
| v := int32(cfg.Database.MinConns) | ||
| pgCfg.MinConns = &v | ||
| } | ||
| if cfg.Database.MaxConnIdleTime > 0 { | ||
| v := cfg.Database.MaxConnIdleTime | ||
| pgCfg.MaxConnIdleTime = &v | ||
| } | ||
| if cfg.Database.MaxConnLifetime > 0 { | ||
| v := cfg.Database.MaxConnLifetime | ||
| pgCfg.MaxConnLifetime = &v | ||
| } | ||
| return pgCfg | ||
| } | ||
|
|
||
| // LoadFromEnv loads configuration values from environment variables. | ||
| // Flag names are converted to uppercase with underscores (e.g., metrics-bind-address -> METRICS_BIND_ADDRESS). | ||
| func LoadFromEnv(fs *flag.FlagSet) error { | ||
|
|
@@ -512,10 +546,7 @@ func Start(getExtensionConfig GetExtensionConfig, extraSources []migrations.Sour | |
| } | ||
|
|
||
| // Connect to database | ||
| db, err := database.Connect(ctx, &database.PostgresConfig{ | ||
| URL: dbURL, | ||
| VectorEnabled: cfg.Database.VectorEnabled, | ||
| }) | ||
| db, err := database.Connect(ctx, postgresConfigFromApp(dbURL, &cfg)) | ||
| if err != nil { | ||
| setupLog.Error(err, "unable to connect to database") | ||
| os.Exit(1) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We should definitely validate that
minConnsis greater thanmaxConnsifminConnsis set.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fair point, added the check