-
Notifications
You must be signed in to change notification settings - Fork 86
Constrain minion log bytes to about 20MB. #281
Conversation
return LessBytes.toString(buf); | ||
} catch (Exception e) { | ||
log.warn("", e); | ||
} | ||
return ""; | ||
} | ||
|
||
private static void addExceedingMsg(byte[] buf, String charsetName) { | ||
try { | ||
byte[] lastLine = "\nCannot display all lines. Reduce lines!\n".getBytes(charsetName); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I recommend making the message even more explicit, including information about:
- the byte limit, and that it was exceeeded
- change "reduce lines" to something like "reduce number of lines" or "reduce requested lines"
return LessBytes.toString(buf); | ||
} catch (Exception e) { | ||
log.warn("", e); | ||
} | ||
return ""; | ||
} | ||
|
||
private static void addExceedingMsg(byte[] buf, String charsetName) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just hardcode the UTF-8 into this method for now
private static void addExceedingMsg(byte[] buf, String charsetName) { | ||
try { | ||
byte[] lastLine = "\nCannot display all lines. Reduce lines!\n".getBytes(charsetName); | ||
for (int lastLineIndex = 0; lastLineIndex < lastLine.length; lastLineIndex++) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't System.arraycopy() be better?
for (int lastLineIndex = 0; lastLineIndex < lastLine.length; lastLineIndex++) { | ||
buf[logBufLimit - lastLine.length + lastLineIndex] = lastLine[lastLineIndex]; | ||
} | ||
} catch (Exception e) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"Exception" is too broad.
raf.read(buf); | ||
byte[] buf = null; | ||
// limiting log reads below 20MB, in case of reaching heap limit and crashing minion | ||
if(bytesRead >= logBufLimit) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Each of these 4 sections could be replaced by a call to a new method you can create. the raf.seek() calls can be made before the call to the method. Something like "readFileBytesLimited(long requestedBytes)" which returns a new byte[] created in the method.
Looks good. Let's wait to merge until after the next successful hydra release. |
Limiting log byte[] to size 20M. Print out warning if exceeds.