-
Notifications
You must be signed in to change notification settings - Fork 32
feat(core): Add statement timeout parameter. #3544
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: main
Are you sure you want to change the base?
Changes from 1 commit
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 |
|---|---|---|
|
|
@@ -89,15 +89,16 @@ type PoolConfig struct { | |
| } | ||
|
|
||
| type Config struct { | ||
| Host string `mapstructure:"host" json:"host" default:"localhost"` | ||
| Port int `mapstructure:"port" json:"port" default:"5432"` | ||
| Database string `mapstructure:"database" json:"database" default:"opentdf"` | ||
| User string `mapstructure:"user" json:"user" default:"postgres"` | ||
| Password string `mapstructure:"password" json:"password" default:"changeme"` | ||
| SSLMode string `mapstructure:"sslmode" json:"sslmode" default:"prefer"` | ||
| Schema string `mapstructure:"schema" json:"schema" default:"opentdf"` | ||
| ConnectTimeout int `mapstructure:"connect_timeout_seconds" json:"connect_timeout_seconds" default:"15"` | ||
| Pool PoolConfig `mapstructure:"pool" json:"pool"` | ||
| Host string `mapstructure:"host" json:"host" default:"localhost"` | ||
| Port int `mapstructure:"port" json:"port" default:"5432"` | ||
| Database string `mapstructure:"database" json:"database" default:"opentdf"` | ||
| User string `mapstructure:"user" json:"user" default:"postgres"` | ||
| Password string `mapstructure:"password" json:"password" default:"changeme"` | ||
| SSLMode string `mapstructure:"sslmode" json:"sslmode" default:"prefer"` | ||
| Schema string `mapstructure:"schema" json:"schema" default:"opentdf"` | ||
| ConnectTimeout int `mapstructure:"connect_timeout_seconds" json:"connect_timeout_seconds" default:"15"` | ||
| StatementTimeout string `mapstructure:"statement_timeout" json:"statement_timeout"` | ||
|
c-r33d marked this conversation as resolved.
Outdated
|
||
| Pool PoolConfig `mapstructure:"pool" json:"pool"` | ||
|
|
||
| RunMigrations bool `mapstructure:"runMigrations" json:"runMigrations" default:"true"` | ||
| MigrationsFS *embed.FS `mapstructure:"-" json:"-"` | ||
|
|
@@ -114,6 +115,7 @@ func (c Config) LogValue() slog.Value { | |
| slog.String("sslmode", c.SSLMode), | ||
| slog.String("schema", c.Schema), | ||
| slog.Int("connect_timeout_seconds", c.ConnectTimeout), | ||
| slog.String("statement_timeout", c.StatementTimeout), | ||
|
c-r33d marked this conversation as resolved.
Outdated
|
||
| slog.Group("pool", | ||
| slog.Int("max_connection_count", int(c.Pool.MaxConns)), | ||
| slog.Int("min_connection_count", int(c.Pool.MinConns)), | ||
|
|
@@ -250,6 +252,10 @@ func (c Config) buildConfig() (*pgxpool.Config, error) { | |
| parsed.MaxConnIdleTime = time.Duration(c.Pool.MaxConnIdleTime) * time.Second | ||
| parsed.HealthCheckPeriod = time.Duration(c.Pool.HealthCheckPeriod) * time.Second | ||
|
|
||
| if c.StatementTimeout != "" { | ||
| parsed.ConnConfig.RuntimeParams["statement_timeout"] = c.StatementTimeout | ||
| } | ||
|
c-r33d marked this conversation as resolved.
Outdated
Comment on lines
+255
to
+257
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. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# How are migrations run? Do they reuse the pool/SQLDB built from buildConfig?
rg -nP --type=go -C4 '\b(RunMigrations|runMigrations|Migrate|migrat)' service/pkg/db
# Find the migration runner entrypoint and what conn/pool it uses
ast-grep --pattern 'func ($_ $_) RunMigrations($$$) { $$$ }'Repository: opentdf/platform Length of output: 10075
The
if c.StatementTimeoutSeconds > 0 {
parsed.ConnConfig.RuntimeParams["statement_timeout"] = fmt.Sprintf("%ds", c.StatementTimeoutSeconds)
}🤖 Prompt for AI Agents
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. This is a good point. Should we override this client setting while running migrations? @c-r33d 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.
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. Yes, I actually was rethinking how I was going to do this because of the coderabbit comment. The problem is that we run migrations during startup and that uses the pool that where we have already specified. I will check if we can override this with a command-level |
||
|
|
||
| // Configure the search_path schema immediately on connection opening | ||
| parsed.AfterConnect = func(ctx context.Context, conn *pgx.Conn) error { | ||
| _, err := conn.Exec(ctx, "SET search_path TO "+pgx.Identifier{c.Schema}.Sanitize()) | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.