-
-
Notifications
You must be signed in to change notification settings - Fork 636
sa: Stop injecting max_statement_time and long_query_time into DSNs #8490
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
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 |
|---|---|---|
|
|
@@ -21,19 +21,19 @@ func TestInvalidDSN(t *testing.T) { | |
| _, err := DBMapForTest("invalid") | ||
| test.AssertError(t, err, "DB connect string missing the slash separating the database name") | ||
|
|
||
| DSN := "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&stringVarThatDoesntExist=%27whoopsidaisies" | ||
| DSN := "policy:password@tcp(foo-database:1337)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&stringVarThatDoesntExist=%27whoopsidaisies" | ||
| _, err = DBMapForTest(DSN) | ||
| test.AssertError(t, err, "Variable does not exist in curated system var list, but didn't return an error and should have") | ||
|
|
||
| DSN = "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=2" | ||
| DSN = "policy:password@tcp(foo-database:1337)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=2" | ||
| _, err = DBMapForTest(DSN) | ||
| test.AssertError(t, err, "Variable is unable to be set in the SESSION scope, but was declared") | ||
|
|
||
| DSN = "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&optimizer_switch=incorrect-quoted-string" | ||
| DSN = "policy:password@tcp(foo-database:1337)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&optimizer_switch=incorrect-quoted-string" | ||
| _, err = DBMapForTest(DSN) | ||
| test.AssertError(t, err, "Variable declared with incorrect quoting") | ||
|
|
||
| DSN = "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=%272%27" | ||
| DSN = "policy:password@tcp(foo-database:1337)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms&concurrent_insert=%272%27" | ||
| _, err = DBMapForTest(DSN) | ||
| test.AssertError(t, err, "Integer enum declared, but should not have been quoted") | ||
| } | ||
|
|
@@ -75,9 +75,8 @@ func TestDbSettings(t *testing.T) { | |
| oldSetConnMaxIdleTime(db, connMaxIdleTime) | ||
| } | ||
| dsnFile := path.Join(t.TempDir(), "dbconnect") | ||
| err := os.WriteFile(dsnFile, | ||
| []byte("sa@tcp(boulder-proxysql:6033)/boulder_sa_integration"), | ||
| os.ModeAppend) | ||
|
|
||
| err := os.WriteFile(dsnFile, []byte(vars.DBConnSA), os.ModeAppend) | ||
|
Member
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'm not strictly sticking to |
||
| test.AssertNotError(t, err, "writing dbconnect file") | ||
|
|
||
| config := cmd.DBConfig{ | ||
|
|
@@ -108,7 +107,7 @@ func TestDbSettings(t *testing.T) { | |
| // TODO: Change this to test `newDbMapFromMySQLConfig` instead? | ||
| func TestNewDbMap(t *testing.T) { | ||
| const mysqlConnectURL = "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?readTimeout=800ms&writeTimeout=800ms" | ||
| const expected = "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?clientFoundRows=true&parseTime=true&readTimeout=800ms&writeTimeout=800ms&long_query_time=0.640000&max_statement_time=0.760000&sql_mode=%27STRICT_ALL_TABLES%27" | ||
| const expected = "policy:password@tcp(boulder-proxysql:6033)/boulder_policy_integration?clientFoundRows=true&parseTime=true&readTimeout=800ms&writeTimeout=800ms&sql_mode=%27STRICT_ALL_TABLES%27" | ||
| oldSQLOpen := sqlOpen | ||
| defer func() { | ||
| sqlOpen = oldSQLOpen | ||
|
|
@@ -146,27 +145,6 @@ func TestStrictness(t *testing.T) { | |
| } | ||
| } | ||
|
|
||
| func TestTimeouts(t *testing.T) { | ||
| dbMap, err := DBMapForTest(vars.DBConnSA + "?max_statement_time=1") | ||
| if err != nil { | ||
| t.Fatal("Error setting up DB:", err) | ||
| } | ||
| // SLEEP is defined to return 1 if it was interrupted, but we want to actually | ||
| // get an error to simulate what would happen with a slow query. So we wrap | ||
| // the SLEEP in a subselect. | ||
| _, err = dbMap.ExecContext(ctx, `SELECT 1 FROM (SELECT SLEEP(5)) as subselect;`) | ||
| if err == nil { | ||
| t.Fatal("Expected error when running slow query, got none.") | ||
| } | ||
|
|
||
| // We expect to get: | ||
| // Error 1969: Query execution was interrupted (max_statement_time exceeded) | ||
| // https://mariadb.com/kb/en/mariadb/mariadb-error-codes/ | ||
| if !strings.Contains(err.Error(), "Error 1969") { | ||
| t.Fatalf("Got wrong type of error: %s", err) | ||
| } | ||
| } | ||
|
|
||
| // TestAutoIncrementSchema tests that all of the tables in the boulder_* | ||
| // databases that have auto_increment columns use BIGINT for the data type. Our | ||
| // data is too big for INT. | ||
|
|
@@ -190,40 +168,7 @@ func TestAdjustMySQLConfig(t *testing.T) { | |
| conf := &mysql.Config{} | ||
| err := adjustMySQLConfig(conf) | ||
| test.AssertNotError(t, err, "unexpected err setting server variables") | ||
| test.AssertDeepEquals(t, conf.Params, map[string]string{ | ||
| "sql_mode": "'STRICT_ALL_TABLES'", | ||
| }) | ||
|
|
||
| conf = &mysql.Config{ReadTimeout: 100 * time.Second} | ||
| err = adjustMySQLConfig(conf) | ||
| test.AssertNotError(t, err, "unexpected err setting server variables") | ||
| test.AssertDeepEquals(t, conf.Params, map[string]string{ | ||
| "sql_mode": "'STRICT_ALL_TABLES'", | ||
| "max_statement_time": "95.000000", | ||
| "long_query_time": "80.000000", | ||
| }) | ||
|
|
||
| conf = &mysql.Config{ | ||
| ReadTimeout: 100 * time.Second, | ||
| Params: map[string]string{ | ||
| "max_statement_time": "0", | ||
| }, | ||
| } | ||
| err = adjustMySQLConfig(conf) | ||
| test.AssertNotError(t, err, "unexpected err setting server variables") | ||
| test.AssertDeepEquals(t, conf.Params, map[string]string{ | ||
| "sql_mode": "'STRICT_ALL_TABLES'", | ||
| "long_query_time": "80.000000", | ||
| }) | ||
|
|
||
| conf = &mysql.Config{ | ||
| Params: map[string]string{ | ||
| "max_statement_time": "0", | ||
| }, | ||
| } | ||
| err = adjustMySQLConfig(conf) | ||
| test.AssertNotError(t, err, "unexpected err setting server variables") | ||
| test.AssertDeepEquals(t, conf.Params, map[string]string{ | ||
| "sql_mode": "'STRICT_ALL_TABLES'", | ||
| }) | ||
| test.Assert(t, conf.ParseTime, "ParseTime should be enabled") | ||
| test.Assert(t, conf.ClientFoundRows, "ClientFoundRows should be enabled") | ||
| test.AssertDeepEquals(t, conf.Params, map[string]string{"sql_mode": "'STRICT_ALL_TABLES'"}) | ||
| } | ||
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,25 +1,41 @@ | ||
| package vars | ||
|
|
||
| import "fmt" | ||
|
|
||
| const ( | ||
| dbURL = "%s@tcp(boulder-proxysql:6033)/%s" | ||
| import ( | ||
| "fmt" | ||
| "net" | ||
| "os" | ||
| ) | ||
|
|
||
| var dbAddr = func() string { | ||
| addr := os.Getenv("DB_ADDR") | ||
| if addr == "" { | ||
| panic("environment variable DB_ADDR must be set") | ||
| } | ||
| _, _, err := net.SplitHostPort(addr) | ||
| if err != nil { | ||
| panic(fmt.Sprintf("environment variable DB_ADDR (%s) is not a valid address with host and port: %s", addr, err)) | ||
| } | ||
| return addr | ||
| }() | ||
|
|
||
| func dsn(user, database string) string { | ||
| return fmt.Sprintf("%s@tcp(%s)/%s", user, dbAddr, database) | ||
| } | ||
|
|
||
| var ( | ||
| // DBConnSA is the sa database connection | ||
| DBConnSA = fmt.Sprintf(dbURL, "sa", "boulder_sa_test") | ||
| DBConnSA = dsn("sa", "boulder_sa_test") | ||
| // DBConnSAMailer is the sa mailer database connection | ||
| DBConnSAMailer = fmt.Sprintf(dbURL, "mailer", "boulder_sa_test") | ||
| DBConnSAMailer = dsn("mailer", "boulder_sa_test") | ||
| // DBConnSAFullPerms is the sa database connection with full perms | ||
| DBConnSAFullPerms = fmt.Sprintf(dbURL, "test_setup", "boulder_sa_test") | ||
| DBConnSAFullPerms = dsn("test_setup", "boulder_sa_test") | ||
| // DBConnSAIntegrationFullPerms is the sa database connection for the | ||
| // integration test DB, with full perms | ||
| DBConnSAIntegrationFullPerms = fmt.Sprintf(dbURL, "test_setup", "boulder_sa_integration") | ||
| DBConnSAIntegrationFullPerms = dsn("test_setup", "boulder_sa_integration") | ||
| // DBInfoSchemaRoot is the root user and the information_schema connection. | ||
| DBInfoSchemaRoot = fmt.Sprintf(dbURL, "root", "information_schema") | ||
| DBInfoSchemaRoot = dsn("root", "information_schema") | ||
| // DBConnIncidents is the incidents database connection. | ||
| DBConnIncidents = fmt.Sprintf(dbURL, "incidents_sa", "incidents_sa_test") | ||
| DBConnIncidents = dsn("incidents_sa", "incidents_sa_test") | ||
| // DBConnIncidentsFullPerms is the incidents database connection with full perms. | ||
| DBConnIncidentsFullPerms = fmt.Sprintf(dbURL, "test_setup", "incidents_sa_test") | ||
| DBConnIncidentsFullPerms = dsn("test_setup", "incidents_sa_test") | ||
| ) |
Uh oh!
There was an error while loading. Please reload this page.