Skip to content

Validate and use pgbouncer logfile config #4252

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

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

benjaminjb
Copy link
Contributor

@benjaminjb benjaminjb commented Aug 21, 2025

With OTEL and the new additional volume settings, we want to allow users to set their pgbouncer
log config without breaking OTEL.

(This version does not have a lot of guardrails guiding the user to find a safe setting. We may want to
consider that or punt this idea to a new ticket.)

Checklist:

  • Have you added an explanation of what your changes do and why you'd like them to be included?
  • Have you updated or added documentation for the change, as applicable?
  • Have you tested your changes on all related environments with successful results, as applicable?
    • Have you added automated tests?

Type of Changes:

  • New feature
  • Bug fix
  • Documentation
  • Testing enhancement
  • Other

What is the current behavior (link to any open issues here)?

Users can set any logfile config for pgbouncer, which might interfere with our OTEL

What is the new behavior (if this is a feature change)?

  • Breaking change (fix or feature that would cause existing functionality to change)

We now restrict users to only set a logfile with the .log suffix; and we get the config to handle the OTEL-related logic

TODO: Restrict the logfile to only certain locations?

Other Information:
Issues: [PGO-2565]

@@ -127,9 +127,13 @@ func clusterINI(ctx context.Context, cluster *v1beta1.PostgresCluster) string {
"unix_socket_dir": "",
}

// Override the above with any specified settings.
maps.Copy(global, cluster.Spec.Proxy.PGBouncer.Config.Global)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I felt better letting the user override some of our settings above

@benjaminjb benjaminjb marked this pull request as ready for review August 21, 2025 18:39
@benjaminjb benjaminjb requested review from cbandy and dsessler7 August 21, 2025 18:57
Comment on lines +62 to +65
create_directory := false
if directory != "/tmp" {
create_directory = true
}
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I ran into an error when I had set the logfile conf to a non tmp location -- our collector startup has

` + shell.MakeDirectories(logDir, path.Join(logDir, "receiver"))

which would seem to have solved the issue, but I suppose pgbouncer might start up and error out before this. And the pgbouncer container should manage its own logfile location.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah. I used the postgres-startup container for this. This is one of the situations I would love to solve with a Go sidecar.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 In this moment, we could augment the entrypoint.

Command: []string{"sh", "-c", "--",
	mkdirs + `; exec "$@"`, "--",
	"pgbouncer", iniFileAbsolutePath},

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just re-tested in two scenarios (with OTEL, without OTEL) and even without any special setup of the files, it seemed to work fine. I wonder if the error I saw before was related to the fsGroup not being set.

(Also, when I run shell.MakeDirectories, now I get an error about chmod not being allowed.)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

chmod not being allowed

What storage do you have? That sounds like NFS, maybe.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've been using GKE for testing this, I want to run some more tests to double-check everything


// PodSecurityContext returns a v1.PodSecurityContext for cluster that can write
// to PersistentVolumes.
func PodSecurityContext(fsgroup int64, supplementalGroups []int64, openshift bool) *corev1.PodSecurityContext {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤔 I think I'd prefer the caller to pass in fsgroup = 0 when they know its OpenShift, but a single place with this knowledge is good, too.

🤔 🤔 PgBouncer is deployed from a PostgresCluster spec which has an isOpenShift override.

// +optional
// +mapType=granular
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻 I want these granular/set/atomic markers on all the new collections we add to the API.

@@ -26,7 +26,12 @@ type PGBouncerConfiguration struct {

// Settings that apply to the entire PgBouncer process.
// More info: https://www.pgbouncer.org/config.html
//
// # Logging
// +kubebuilder:validation:XValidation:rule=`!has(self.logfile) || self.logfile.endsWith('.log')`,message=`logfile config must end with '.log'`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❓ Where does the file go if there is no directory here? What if there's a relative directory?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants