Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Constrain minion log bytes to about 20MB. #281

Merged
merged 4 commits into from
Jun 25, 2018
Merged

Conversation

Tingting-He-ODC
Copy link
Contributor

Limiting log byte[] to size 20M. Print out warning if exceeds.

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);
Copy link
Contributor

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) {
Copy link
Contributor

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++) {
Copy link
Contributor

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) {
Copy link
Contributor

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) {
Copy link
Contributor

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.

@tedpearson
Copy link
Contributor

Looks good. Let's wait to merge until after the next successful hydra release.

@tedpearson tedpearson merged commit 653c3f3 into master Jun 25, 2018
@tedpearson tedpearson deleted the log-line-limited branch June 25, 2018 19:29
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants