Include node thread name in IT tests logs (#124761)
This commit is contained in:
parent
a49fa0be4a
commit
35ecbf6e87
|
@ -305,7 +305,7 @@ public class EsExecutors {
|
|||
|
||||
public static String threadName(final String nodeName, final String namePrefix) {
|
||||
// TODO missing node names should only be allowed in tests
|
||||
return "elasticsearch" + (nodeName.isEmpty() ? "" : "[") + nodeName + (nodeName.isEmpty() ? "" : "]") + "[" + namePrefix + "]";
|
||||
return nodeName.isEmpty() == false ? "elasticsearch[" + nodeName + "][" + namePrefix + "]" : "elasticsearch[" + namePrefix + "]";
|
||||
}
|
||||
|
||||
public static String executorName(String threadName) {
|
||||
|
|
|
@ -50,7 +50,7 @@ public class TestThreadInfoPatternConverter extends LogEventPatternConverter {
|
|||
}
|
||||
}
|
||||
|
||||
private static final Pattern ELASTICSEARCH_THREAD_NAME_PATTERN = Pattern.compile("elasticsearch\\[(.+)\\]\\[.+\\].+");
|
||||
private static final Pattern ELASTICSEARCH_THREAD_NAME_PATTERN = Pattern.compile("elasticsearch\\[(.+\\]\\[.+\\]\\[.+)\\].*");
|
||||
private static final Pattern TEST_THREAD_NAME_PATTERN = Pattern.compile("TEST-.+\\.(.+)-seed#\\[.+\\]");
|
||||
private static final Pattern TEST_SUITE_INIT_THREAD_NAME_PATTERN = Pattern.compile("SUITE-.+-worker");
|
||||
private static final Pattern NOT_YET_NAMED_NODE_THREAD_NAME_PATTERN = Pattern.compile("test_SUITE-CHILD_VM.+cluster\\[T#(.+)\\]");
|
||||
|
@ -58,7 +58,7 @@ public class TestThreadInfoPatternConverter extends LogEventPatternConverter {
|
|||
static String threadInfo(String threadName) {
|
||||
Matcher m = ELASTICSEARCH_THREAD_NAME_PATTERN.matcher(threadName);
|
||||
if (m.matches()) {
|
||||
// Thread looks like a node thread so use the node name
|
||||
// Thread looks like a node thread. Display it entirely
|
||||
return m.group(1);
|
||||
}
|
||||
m = TEST_THREAD_NAME_PATTERN.matcher(threadName);
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
appender.console.type = Console
|
||||
appender.console.name = console
|
||||
appender.console.layout.type = PatternLayout
|
||||
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%test_thread_info]%marker %m%n
|
||||
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}][%test_thread_info]%marker %m%n
|
||||
|
||||
rootLogger.level = ${sys:tests.es.logger.level:-info}
|
||||
rootLogger.appenderRef.console.ref = console
|
||||
|
|
|
@ -14,6 +14,7 @@ import org.elasticsearch.test.ESTestCase;
|
|||
import org.junit.BeforeClass;
|
||||
|
||||
import static org.elasticsearch.common.logging.TestThreadInfoPatternConverter.threadInfo;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
|
||||
public class TestThreadInfoPatternConverterTests extends ESTestCase {
|
||||
private static String suiteInfo;
|
||||
|
@ -23,19 +24,24 @@ public class TestThreadInfoPatternConverterTests extends ESTestCase {
|
|||
suiteInfo = threadInfo(Thread.currentThread().getName());
|
||||
}
|
||||
|
||||
public void testThreadInfo() {
|
||||
public void testElasticsearchThreadInfo() {
|
||||
// Threads that are part of a node get the node name
|
||||
String nodeName = randomAlphaOfLength(5);
|
||||
String threadName = EsExecutors.threadName(nodeName, randomAlphaOfLength(20)) + "[T#" + between(0, 1000) + "]";
|
||||
assertEquals(nodeName, threadInfo(threadName));
|
||||
var nodeName = randomAlphaOfLength(5);
|
||||
var prefix = randomAlphaOfLength(20);
|
||||
var thread = "T#" + between(0, 1000);
|
||||
var threadName = EsExecutors.threadName(nodeName, prefix) + "[" + thread + "]";
|
||||
assertThat(threadInfo(threadName), equalTo(nodeName + "][" + prefix + "][" + thread));
|
||||
}
|
||||
|
||||
// Test threads get the test name
|
||||
public void testCaseNameThreadInfo() {
|
||||
assertEquals(getTestName(), threadInfo(Thread.currentThread().getName()));
|
||||
}
|
||||
|
||||
// Suite initialization gets "suite"
|
||||
public void testSuiteThreadInfo() {
|
||||
assertEquals("suite", suiteInfo);
|
||||
}
|
||||
|
||||
// And stuff that doesn't match anything gets wrapped in [] so we can see it
|
||||
public void testUnmatchedThreadInfo() {
|
||||
String unmatched = randomAlphaOfLength(5);
|
||||
assertEquals("[" + unmatched + "]", threadInfo(unmatched));
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue