Skip to content

Break diags log rotation into subroutines#13254

Open
JosiahWI wants to merge 2 commits into
apache:masterfrom
JosiahWI:refactor/log-rotation
Open

Break diags log rotation into subroutines#13254
JosiahWI wants to merge 2 commits into
apache:masterfrom
JosiahWI:refactor/log-rotation

Conversation

@JosiahWI

@JosiahWI JosiahWI commented Jun 10, 2026

Copy link
Copy Markdown
Contributor

This change reduces a small amount of duplication and introduces meaningful function names. I'm cleaning this up now because there are (very minor) bugs in the log rotation logic (I have not filed issues yet), and my hope is that this refactoring makes the code easier to understand and review for those bugfixes.

This change restructures conditional flow to use guard clauses instead of nesting all the logic in conditional checks.

  • Extract Diags::roll_diags_on_filesize

  • Extract Diags::roll_diags_on_interval

  • Extract Diags::roll_streams_on_filesize

  • Extract Diags::roll_streams_on_interval

  • Extract Diags::remake_logfile

  • Extract Diags::swap_diagslog

This change reduces a small amount of duplication and introduces
meaningful function names. I'm cleaning this up now because there
are bugs in the log rotation logic (I have not filed issues yet),
and my hope is that this refactoring makes the code easier to understand
and review for those bugfixes.

* Extract `Diags::roll_diags_on_filesize`

* Extract `Diags::roll_diags_on_interval`

* Extract `Diags::roll_streams_on_filesize`

* Extract `Diags::roll_streams_on_interval`

* Extract `Diags::remake_logfile`

* Extract `Diags::swap_diagslog`
@JosiahWI JosiahWI added this to the 11.0.0 milestone Jun 10, 2026
@JosiahWI JosiahWI self-assigned this Jun 10, 2026
Copilot AI review requested due to automatic review settings June 10, 2026 17:08
Comment thread src/tscore/Diags.cc
// rotate according to the (same || different) scheme, it would not be difficult to add
// some more config options in records.yaml and said feature into this function.
if (ret_val) {
ink_assert(!need_consider_stderr);

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Instead of asserting that this flag was set, I am asserting at an earlier point that the condition for setting the flag is met. The code was originally designed to be a little easier to change if more output stream flexibility was needed. Since that obviously hasn't happened for a long time, and was only a small amount of code, I have removed the extra logic flow and this flag entirely, simplifying the code.

Copilot AI left a comment

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.

Pull request overview

This PR refactors diagnostic and output log rotation in Diags by extracting the previously inlined rotation logic into named helper subroutines, aiming to reduce duplication and make upcoming bugfixes easier to review.

Changes:

  • Extracted size-based and time-based rotation logic for diags.log into roll_diags_on_filesize() / roll_diags_on_interval().
  • Extracted size-based and time-based rotation logic for stdout/stderr output logs into roll_streams_on_filesize() / roll_streams_on_interval().
  • Centralized logfile recreation / swapping logic via remake_logfile() and swap_diagslog(), using std::unique_ptr for safer ownership.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
src/tscore/Diags.cc Refactors log rotation and reseating logic into helpers; introduces unique_ptr management and guard-clause flow.
include/tscore/DiagsTypes.h Declares the newly extracted private helper methods on Diags.

Comment thread src/tscore/Diags.cc
Comment thread src/tscore/Diags.cc Outdated
Comment thread src/tscore/Diags.cc Outdated
Comment thread src/tscore/Diags.cc Outdated
Comment thread src/tscore/Diags.cc Outdated
* Include `<stdexcept>` for `std::runtime_error`

* Make catch statements consistent

* Assert stdout/stderr filename invariant in release builds
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants