Skip to content

NIFI-15989: Improve purge threshold time formatting#11313

Open
ohnoitsyou wants to merge 1 commit into
apache:mainfrom
ohnoitsyou:NIFI-15989_time-format-formatting
Open

NIFI-15989: Improve purge threshold time formatting#11313
ohnoitsyou wants to merge 1 commit into
apache:mainfrom
ohnoitsyou:NIFI-15989_time-format-formatting

Conversation

@ohnoitsyou

Copy link
Copy Markdown
Contributor

Update the purge threshold output to be more human readable.

Existing output will show the value in milliseconds which can be
difficult to read quickly. Use Apache Commons lang3 to get the
threhold in a format like "30 days", "7 days 4 hours", etc.

Summary

NIFI-15989

Specifically in WriteAheadStorePartition, the maintenance task outputs the threshold as a measure of milliseconds which can be difficult to parse quickly.

Pass the value of the field olderThan that's passed to purgeOldEvents through the Apache commons DurationFormatUtils.formatDurationWords to get the output in a more human readable format. e.g.:

  • 2592000000 -> "30 days"
  • 2592010000 -> "30 days 0 hours 0 minutes 10 seconds"
  • 3600000 -> "1 hour"

Pulled in Apache Commons lang3 into Persistent Provenance Repository module. It was already in test scope, now it is additionally in compile.

Tracking

Please complete the following tracking steps prior to pull request creation.

Issue Tracking

Pull Request Tracking

  • Pull Request title starts with Apache NiFi Jira issue number, such as NIFI-00000
  • Pull Request commit message starts with Apache NiFi Jira issue number, as such NIFI-00000
  • Pull request contains commits signed with a registered key indicating Verified status

Pull Request Formatting

  • Pull Request based on current revision of the main branch
  • Pull Request refers to a feature branch with one commit containing changes

Verification

Please indicate the verification steps performed prior to pull request creation.

Build

  • Build completed using ./mvnw clean install -P contrib-check
    • JDK 21
    • JDK 25

Licensing

  • New dependencies are compatible with the Apache License 2.0 according to the License Policy
  • New dependencies are documented in applicable LICENSE and NOTICE files

Documentation

  • Documentation formatting appears as expected in rendered files

Update the purge threshold output to be more human readable.
Existing output will show the value in milliseconds which can be
  difficult to read quickly. Use Apache Commons lang3 to get the
  threhold in a format like "30 days", "7 days 4 hours", etc.

@exceptionfactory exceptionfactory 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.

Thanks for proposing this improvement @ohnoitsyou.

Although other modules include the commons-lang3 dependency, introducing this dependency for the sole purpose of improving the logging message does not seem worth the addition.

@ohnoitsyou

Copy link
Copy Markdown
Contributor Author

I had considered adding a function to the FormatUtils located in commons. Unfortunately it also doesn't have lang3 in it, but it would centralize the functionality.

The end user this request came from only mentioned this particular log. I'm sure there are other places it would make sense to have a log message formatted in this way.

@exceptionfactory

Copy link
Copy Markdown
Contributor

In relation to log formatting, additional dependencies should be avoided.

There is certainly a balance to strike between readability and consistency, but in this case, the log message already includes the number of units, which also makes it more consistent for potential parsing.

With that background, this doesn't seem like a good candidate for changing.

@dan-s1

dan-s1 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

@exceptionfactory Could the org.apache.nifi.time.DurationFormat found in the nifi-api be used for this? Or does this also have the limitation that the nifi-api is not currently a dependency?

@ohnoitsyou

Copy link
Copy Markdown
Contributor Author

@dan-s1 Unfortunately DurationFormat doesn't include a string based output.

@dan-s1

dan-s1 commented Jun 5, 2026

Copy link
Copy Markdown
Contributor

@dan-s1 Unfortunately DurationFormat doesn't include a string based output.

Yeah I realize. I thought it might have been included as a dependency and you would have to still add some code to produce a string output.

@ohnoitsyou

Copy link
Copy Markdown
Contributor Author

@exceptionfactory If we still wanted to pursue something like this where the message is more expressive about the time frame, is there something you might suggest?

Obviously this in a single place doesn't make a huge impact, but I bet if I did some digging I could find lots of places where having a large number of millis formatted in words would improve readability.

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