Skip to content

Rotate pgbouncer logs#4095

Merged
dsessler7 merged 6 commits intoCrunchyData:mainfrom
dsessler7:rotate-pgbouncer-logs
Feb 18, 2025
Merged

Rotate pgbouncer logs#4095
dsessler7 merged 6 commits intoCrunchyData:mainfrom
dsessler7:rotate-pgbouncer-logs

Conversation

@dsessler7
Copy link
Copy Markdown
Collaborator

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

No log rotation.

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

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

Allows the rotation of pgbouncer logs.

Other Information:

// files have been rotated. The pgbouncer process is sent a sighup signal.
// TODO: Should this go here or in controller/postgrescluster/pgbouncer.go?
// Or somewhere in the internal/pgbouncer folder, for that matter?
PGBouncerPostRotateScript = "pkill -HUP --exact pgbouncer"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Kinda feel like this should be in the pgbouncer.go

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Agreed. Moving it.

if hours < 24 {
return int(hours), "hourly"
}
return int(math.Round(hours / 24)), "daily"
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I want to flag this for a lot of documentation -- if I put in 3weeks of logs, I might expect 3 weeks of logs, not 21 days.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Similarly, if I put in 36 hours, I might expect 36 hours, not 2 days.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Well, 3 weeks of logs is 21 days of logs, we will just be keeping 21 log files where each is a day's worth of logs rather than 3 log files where each is a week's worth of logs... But yeah, we will definitely need plenty of emphasis on the fact that we will be rounding up to the nearest day for hour amounts that aren't multiples of 24.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't think that needs to be documented. The user specifies how much to retain, not the method for retaining it.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

Good point. Should probably still make a note that we round up to the nearest day so users aren't confused at least.

…hen not set.

Move PGBouncerPostRotateScript to collector package.
Round daily retention count up to the nearest day.

// If a retentionPeriod is set and this is a pod that uses logrotate for
// log rotation, add config volume and mount for logrotate config
if includeLogrotate && spec != nil && spec.Logs != nil && spec.Logs.RetentionPeriod != nil {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Do we require RetentionPeriod or are we allowing that to be blank and we'll default to a day?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

We allow it to be blank and default to a day.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

I'll remove the check for spec etc here

…rotate config.

Round up (ceil) on retentionPeriod duration and add a test.
Fix typo.
@dsessler7 dsessler7 merged commit 8304899 into CrunchyData:main Feb 18, 2025
19 checks passed
@dsessler7 dsessler7 deleted the rotate-pgbouncer-logs branch February 18, 2025 21:51
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.

3 participants