-
Notifications
You must be signed in to change notification settings - Fork 2
fix: update global patroni params for systemd #398
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
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| //go:build e2e_test | ||
|
|
||
| package e2e | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/jackc/pgx/v5" | ||
| api "github.com/pgEdge/control-plane/api/apiv1/gen/control_plane" | ||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestUpdatePatroniGlobalParams(t *testing.T) { | ||
| t.Parallel() | ||
|
|
||
| // I'm intentionally not adding a helper function for this check because | ||
| // this condition will be very temporary. | ||
| if fixture.orchestrator != "systemd" { | ||
| t.Skip("patroni global parameter update is currently unsupported in non-systemd clusters") | ||
| } | ||
|
|
||
| host1 := fixture.HostIDs()[0] | ||
|
|
||
| username := "admin" | ||
| password := "password" | ||
|
|
||
| tLog(t, "creating database") | ||
|
|
||
| ctx := t.Context() | ||
| db := fixture.NewDatabaseFixture(ctx, t, &api.CreateDatabaseRequest{ | ||
| Spec: &api.DatabaseSpec{ | ||
| DatabaseName: "test_global_params", | ||
| DatabaseUsers: []*api.DatabaseUserSpec{ | ||
| { | ||
| Username: username, | ||
| Password: pointerTo(password), | ||
| DbOwner: pointerTo(true), | ||
| Attributes: []string{"LOGIN", "SUPERUSER"}, | ||
| }, | ||
| }, | ||
| Port: pointerTo(0), | ||
| PatroniPort: pointerTo(0), | ||
| Nodes: []*api.DatabaseNodeSpec{ | ||
| { | ||
| Name: "n1", | ||
| HostIds: []api.Identifier{api.Identifier(host1)}, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
|
|
||
| tLog(t, "querying original max connections") | ||
|
|
||
| opts := ConnectionOptions{ | ||
| Username: username, | ||
| Password: password, | ||
| } | ||
| var originalMaxConnections int | ||
| db.WithConnection(ctx, opts, t, func(conn *pgx.Conn) { | ||
| require.NoError(t, conn.QueryRow(ctx, `SELECT setting::integer FROM pg_settings WHERE name = 'max_connections';`).Scan(&originalMaxConnections)) | ||
| }) | ||
|
|
||
| tLogf(t, "got max_connections=%d", originalMaxConnections) | ||
| tLog(t, "updating database to change max connections") | ||
|
|
||
| err := db.Update(ctx, UpdateOptions{ | ||
| Spec: &api.DatabaseSpec{ | ||
| DatabaseName: "test_global_params", | ||
| DatabaseUsers: []*api.DatabaseUserSpec{ | ||
| { | ||
| Username: username, | ||
| DbOwner: pointerTo(true), | ||
| Attributes: []string{"LOGIN", "SUPERUSER"}, | ||
| }, | ||
| }, | ||
| Port: pointerTo(0), | ||
| PatroniPort: pointerTo(0), | ||
| PostgresqlConf: map[string]any{ | ||
| "max_connections": originalMaxConnections + 1, | ||
| }, | ||
| Nodes: []*api.DatabaseNodeSpec{ | ||
| { | ||
| Name: "n1", | ||
| HostIds: []api.Identifier{api.Identifier(host1)}, | ||
| }, | ||
| }, | ||
| }, | ||
| }) | ||
| require.NoError(t, err) | ||
|
|
||
| tLog(t, "querying new max connections") | ||
|
|
||
| var newMaxConnections int | ||
| db.WithConnection(ctx, opts, t, func(conn *pgx.Conn) { | ||
| require.NoError(t, conn.QueryRow(ctx, `SELECT setting::integer FROM pg_settings WHERE name = 'max_connections';`).Scan(&newMaxConnections)) | ||
| }) | ||
|
|
||
| tLogf(t, "got max_connections=%d", newMaxConnections) | ||
|
|
||
| require.Equal(t, originalMaxConnections+1, newMaxConnections) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
If Patroni rejects the request with a 4xx response (for example, due to an invalid parameter value), this currently treats the update as successful. Should we return an error instead of logging a warning and continuing?
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.
That's a good question.
PatchDynamicConfigshould return an error if it gets a 4xx or other unsuccessful response. We have a helper method in that package to validate response codes:control-plane/server/internal/patroni/client.go
Lines 746 to 748 in 99607a1
And then we call it in each client method, like we do here in
PatchDynamicConfig:control-plane/server/internal/patroni/client.go
Lines 527 to 530 in 99607a1
Does that address your concern, or is there an issue in this implementation?
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.
Oh, okay. Thanks! Looks good now — please go ahead and merge it.