Zookeeper-3735: fix the bad format of RATE_LOGGER#1275
Zookeeper-3735: fix the bad format of RATE_LOGGER#1275jonomorris wants to merge 6 commits intoapache:masterfrom
Conversation
Unit tests for RateLogger. Added Javadoc to RateLogger.
Fix style problems. Add Javadoc.
maoling
left a comment
There was a problem hiding this comment.
I also found other two nits: we need to log zxid with Hex. Could you plz also fix them in passing:)
RATE_LOGGER.rateLimitLog("Digests are not matching. Value is Zxid.", String.valueOf(zxid));
| if (now - timestamp >= LOG_INTERVAL) { | ||
| // log previous message and value | ||
| flush(); | ||
| msg = newMsg; |
There was a problem hiding this comment.
Why do you need this change? Time interval has elapsed, reset count?
There was a problem hiding this comment.
If the time interval has elapsed call flush writing the existing value and current message count then save the message with new value provided as the first message received after the flush with count 1.
This change makes it consistent with an explicit flush, where the flush method is called on the RateLogger object, which writes the current message along with exiting value and current message count.
There was a problem hiding this comment.
- Haha, not very persuasive for me:).
- And for test, when time interval has elapsed and at the same time,
flush()is called explicitly, the tests will become complicated.
e.g:
A Permutation and Combination of these three lines
currentTime.set(DEFAULT_LOGGING_INTERVAL + 1L);
rateLogger.rateLimitLog("test message one.", "value-four");
rateLogger.flush();
There was a problem hiding this comment.
Hey @maoling, yes sorry there's a bit going on in that last unit test. I can simplify it to just test the flush after setting the elapsed time:
currentTime.set(DEFAULT_LOGGING_INTERVAL + 1L);
I guess I just wanted to demonstrate that how the message and value are retained after the message is flushed when the logging-interval is exceeded.
Did you want this bit of code in RateLogger reverted?
There was a problem hiding this comment.
@jono-morris
Take it easy, let's wait here for other people's review and comment
| rateLogger.rateLimitLog("test message one", "value-two"); | ||
| rateLogger.rateLimitLog("test message one", "value-three"); | ||
| Thread.sleep(2 * rateLogInterval); | ||
| // same message after rate interval triggers implicit flush |
There was a problem hiding this comment.
this test may be flaky, you can look at other example how to mock timing (e.g.: CreateContainerTest#testMaxNeverUsedInterval)
There was a problem hiding this comment.
Updated RateLogger to get current time from a method with package access that is overridden during unit testing. This allows the time to be explicitly set similar to the way you have suggested.
…and explicitly set time in RateLogger test cases.
|
Also updated RateLogger calls in reportDigestMismatch and reportDigestMismatch methods to use |
|
Not required |
The message written to the Rate-logger was modified to conform with the way the Rate-logger composes messages it writes to the underlying logger.
RateLogger updates: