C++ log message handler now remembers C++ process copyright message (elastic/elasticsearch#743)

Once we're in x-pack this (or the portion of it containing the version)
can be returned in the ml feature info of the x-pack info endpoint

Relates elastic/elasticsearch#566

Original commit: elastic/x-pack-elasticsearch@b2ea740a6d
This commit is contained in:
David Roberts 2017-01-17 17:19:48 +00:00 committed by GitHub
parent cfb94b6627
commit 449a74b2fd
2 changed files with 15 additions and 5 deletions

View File

@ -50,6 +50,7 @@ public class CppLogMessageHandler implements Closeable {
private volatile boolean hasLogStreamEnded;
private volatile boolean seenFatalError;
private volatile long pid;
private volatile String cppCopyright;
/**
* @param jobId May be null or empty if the logs are from a process not associated with a job.
@ -132,6 +133,10 @@ public class CppLogMessageHandler implements Closeable {
return pid;
}
public String getCppCopyright() {
return cppCopyright;
}
/**
* Expected to be called very infrequently.
*/
@ -185,12 +190,15 @@ public class CppLogMessageHandler implements Closeable {
pid = latestPid;
pidLatch.countDown();
}
String latestMessage = msg.getMessage();
if (cppCopyright == null && latestMessage.contains("Copyright")) {
cppCopyright = latestMessage;
}
// TODO: Is there a way to preserve the original timestamp when re-logging?
if (jobId != null) {
LOGGER.log(level, "[{}] {}/{} {}@{} {}", jobId, msg.getLogger(), latestPid, msg.getFile(), msg.getLine(),
msg.getMessage());
LOGGER.log(level, "[{}] {}/{} {}@{} {}", jobId, msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), latestMessage);
} else {
LOGGER.log(level, "{}/{} {}@{} {}", msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), msg.getMessage());
LOGGER.log(level, "{}/{} {}@{} {}", msg.getLogger(), latestPid, msg.getFile(), msg.getLine(), latestMessage);
}
// TODO: Could send the message for indexing instead of or as well as logging it
} catch (IOException e) {

View File

@ -27,8 +27,8 @@ public class CppLogMessageHandlerTests extends ESTestCase {
+ "/var/folders/k5/5sqcdlps5sg3cvlp783gcz740000h0/T/controller_log_784\",\"class\":\"ml\","
+ "\"method\":\"core::CLogger::reconfigureLogToNamedPipe\",\"file\":\"CLogger.cc\",\"line\":333}\n"
+ "{\"logger\":\"controller\",\"timestamp\":1478261151445,\"level\":\"INFO\",\"pid\":10211,\"thread\":\"0x7fff7d2a8000\","
+ "\"message\":\"controller (64 bit): Version based on 6.5.0 (Build DEVELOPMENT BUILD by dave) "
+ "Copyright (c) 2016 Elasticsearch BV\",\"method\":\"main\",\"file\":\"Main.cc\",\"line\":123}\n"
+ "\"message\":\"controller (64 bit): Version based on 6.0.0-alpha1 (Build b0d6ef8819418c) "
+ "Copyright (c) 2017 Elasticsearch BV\",\"method\":\"main\",\"file\":\"Main.cc\",\"line\":123}\n"
+ "{\"logger\":\"controller\",\"timestamp\":1478261169065,\"level\":\"ERROR\",\"pid\":10211,\"thread\":\"0x7fff7d2a8000\","
+ "\"message\":\"Did not understand verb 'a'\",\"class\":\"ml\","
+ "\"method\":\"controller::CCommandProcessor::handleCommand\",\"file\":\"CCommandProcessor.cc\",\"line\":100}\n"
@ -43,6 +43,8 @@ public class CppLogMessageHandlerTests extends ESTestCase {
assertTrue(handler.hasLogStreamEnded());
assertEquals(10211L, handler.getPid(Duration.ofMillis(1)));
assertEquals("controller (64 bit): Version based on 6.0.0-alpha1 (Build b0d6ef8819418c) "
+ "Copyright (c) 2017 Elasticsearch BV", handler.getCppCopyright());
assertEquals("Did not understand verb 'a'\n", handler.getErrors());
assertFalse(handler.seenFatalError());
}