Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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
benjaminjb wants to merge 14 commits into CrunchyData:main
base: main
Choose a base branch
Loading
from benjaminjb:benjb/log-pgbouncer

Conversation

Copy link
Contributor

@benjaminjb benjaminjb commented Aug 21, 2025
edited
Loading

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]

@benjaminjb benjaminjb marked this pull request as ready for review August 21, 2025 18:39

// 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.

Copy link
Contributor Author

@benjaminjb benjaminjb Aug 25, 2025

Choose a reason for hiding this comment

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

on PodSecurityContext, fsgroup is a pointer (with omitempty) so we don't want to set it at all, right?

Copy link
Member

Choose a reason for hiding this comment

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

Right. I was picturing L33 as if fsgroup > 0

Copy link
Contributor Author

@benjaminjb benjaminjb Sep 2, 2025

Choose a reason for hiding this comment

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

OK, updated to try it out -- is that clearer/easier to use?

@@ -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?

@@ -598,6 +598,7 @@ type PostgresInstanceSetStatus struct {
type PostgresProxySpec struct {

// Defines a PgBouncer proxy and connection pooler.
// +kubebuilder:validation:XValidation:rule=`!has(self.config) || !has(self.config.global) || !has(self.config.global.logfile) || self.config.global.logfile.startsWith('/tmp/logs/pgbouncer/') || self.volumes.additional.exists(x, self.config.global.logfile.startsWith("/volumes/"+x.name))`,message=`logfile destination is restricted to '/tmp/logs/pgbouncer/' or an existing additional volume`
Copy link
Member

Choose a reason for hiding this comment

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

❓ can this be on the PGBouncerPodSpec godoc?


// 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.

Right. I was picturing L33 as if fsgroup > 0

@@ -598,6 +598,7 @@ type PostgresInstanceSetStatus struct {
type PostgresProxySpec struct {

// Defines a PgBouncer proxy and connection pooler.
// +kubebuilder:validation:XValidation:rule=`!has(self.config) || !has(self.config.global) || !has(self.config.global.logfile) || self.config.global.logfile.startsWith('/tmp/logs/pgbouncer/') || self.volumes.additional.exists(x, self.config.global.logfile.startsWith("/volumes/"+x.name))`,message=`logfile destination is restricted to '/tmp/logs/pgbouncer/' or an existing additional volume`
Copy link
Member

Choose a reason for hiding this comment

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

🤔 Is this any more legible? I have no idea.

self.?config.global.logfile.optMap(f, f.startsWith("/tmp/logs/pgbouncer/") || self.?volumes.additional.optMap(a, a.exists(v, f.startsWith("/volumes/" + v.name))).orValue(true)

Copy link
Member

Choose a reason for hiding this comment

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

📝 a is only referenced once, so maybe ditching an optional is better.

-additional.optMap(a, a.exists(v,
+additional.orValue([]).exists(v,
self.?config.global.logfile.optMap(f, f.startsWith("/tmp/logs/pgbouncer/") || self.?volumes.additional.orValue([]).exists(v, f.startsWith("/volumes/" + v.name))).orValue(true)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Reviewers

@cbandy cbandy cbandy left review comments

@dsessler7 dsessler7 dsessler7 left review comments

At least 1 approving review is required to merge this pull request.

Assignees
No one assigned
Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

AltStyle によって変換されたページ (->オリジナル) /