NIFI-15989: Improve purge threshold time formatting#11313
Conversation
exceptionfactory
left a comment
There was a problem hiding this comment.
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.
|
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. |
|
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. |
|
@exceptionfactory Could the |
|
@dan-s1 Unfortunately |
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. |
|
@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. |
|
@ohnoitsyou I think it would be acceptable to have a new method in the nifi-utils.jar FormatUtils class that does this. Perhaps named To get an idea how to implement it, check out the nifi-api DurationFormat class. It has some private methods that do something similar. |
|
Just a caution on adding some new method, although it might be useful, I'm not sure it would make sense to change log messages. It might in very specific cases, but it would be a case-by-case question. |
|
If this specific log message should not be changed, then we should close this PR. However, I will say that I have also wondered if this specific log message could be improved to make it more human readable. |
|
Taking a fresh look at this, I could see adjusting the log message to include both the original number and units, plus something descriptive, immediately after, in parentheses. This kind of approach is similar to displaying seconds and nanoseconds on application startup. That would still require a new method in |
4f3e7c8 to
1b32eb3
Compare
|
@exceptionfactory @mosermw I took a stab at implementing a duration to words function in nifi-utils. I also converted the |
f496532 to
488f3e3
Compare
|
@exceptionfactory Not to bug too much, but if this could be reviewed, I found a place where the formatting function would be useful in another related class and I'd like to take advantage of it. |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for continuing the work on this @ohnoitsyou. The new format methods look good in general, I noted a few stylistic recommendations, but this looks close to completion.
683d362 to
72d732d
Compare
|
@exceptionfactory Got those updated. If I could get the workflows approved, hopefully we can push this over the finish line. |
0997c46 to
2bf480b
Compare
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for the work on this @ohnoitsyou. It looks close to completion, just one general question on formatting.
The spelled out words make the description rather long (1 day 2 hours 10 minutes). What do you think about just using single letters like 1d 2h 10m 30s 100ns? It is still readable, but less verbose, and doesn't need the pluralization.
|
The other approach would be to implement some kind of rounding to the greatest two units (days and hours, hours and minutes, etc), but the single-letter abbreviation might be a way to keep the precision with readability. |
|
Personally, I'd rather abbreviate and be more precise than truncate data. It's still readable while being concise. Edit: that is to say, I'm good with the change. |
Thanks, if you like the abbreviation approach, that sounds good to me. |
a5334ca to
a17cdea
Compare
|
@exceptionfactory Pushed that change, builds on my end. If you could approve the workflows, that'd be appreciated. Trying to keep it up-to-date with main |
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.
Update the EventStorePartition interface to use ChronoUnit instead of TimeUnit. TimeUnit is from java.util.concurrent where as ChronoUnit is from java.time.temporal which is overall more appropriate for time based operations. Add tests for duration to words function.
Add javadoc to the (long, ChronoUnit) version of the formatDurationToWords function Removed extra imports and fixed formatting
a17cdea to
a605c4f
Compare
|
Thanks @ohnoitsyou, the latest set of changes look good. I rebased the branch and plan to merge on successful build completion |
exceptionfactory
left a comment
There was a problem hiding this comment.
Thanks for working through this and moving it to completion @ohnoitsyou! +1 merging
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. Convert milliseconds to a
Durationto get thethreshold 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
olderThanthat's passed topurgeOldEventsthrough a new formatting function innifi-utilsto convert it into a words representation. e.g.:Tracking
Please complete the following tracking steps prior to pull request creation.
Issue Tracking
Pull Request Tracking
NIFI-00000NIFI-00000VerifiedstatusPull Request Formatting
mainbranchVerification
Please indicate the verification steps performed prior to pull request creation.
Build
./mvnw clean install -P contrib-checkLicensing
LICENSEandNOTICEfilesDocumentation