Skip to content

Commit 35ecbf6

Browse files
authored
Include node thread name in IT tests logs (#124761)
1 parent a49fa0b commit 35ecbf6

File tree

4 files changed

+17
-11
lines changed

4 files changed

+17
-11
lines changed

server/src/main/java/org/elasticsearch/common/util/concurrent/EsExecutors.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -305,7 +305,7 @@ public static String threadName(Settings settings, String namePrefix) {
305305

306306
public static String threadName(final String nodeName, final String namePrefix) {
307307
// TODO missing node names should only be allowed in tests
308-
return "elasticsearch" + (nodeName.isEmpty() ? "" : "[") + nodeName + (nodeName.isEmpty() ? "" : "]") + "[" + namePrefix + "]";
308+
return nodeName.isEmpty() == false ? "elasticsearch[" + nodeName + "][" + namePrefix + "]" : "elasticsearch[" + namePrefix + "]";
309309
}
310310

311311
public static String executorName(String threadName) {

test/framework/src/main/java/org/elasticsearch/common/logging/TestThreadInfoPatternConverter.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public void format(LogEvent event, StringBuilder toAppendTo) {
5050
}
5151
}
5252

53-
private static final Pattern ELASTICSEARCH_THREAD_NAME_PATTERN = Pattern.compile("elasticsearch\\[(.+)\\]\\[.+\\].+");
53+
private static final Pattern ELASTICSEARCH_THREAD_NAME_PATTERN = Pattern.compile("elasticsearch\\[(.+\\]\\[.+\\]\\[.+)\\].*");
5454
private static final Pattern TEST_THREAD_NAME_PATTERN = Pattern.compile("TEST-.+\\.(.+)-seed#\\[.+\\]");
5555
private static final Pattern TEST_SUITE_INIT_THREAD_NAME_PATTERN = Pattern.compile("SUITE-.+-worker");
5656
private static final Pattern NOT_YET_NAMED_NODE_THREAD_NAME_PATTERN = Pattern.compile("test_SUITE-CHILD_VM.+cluster\\[T#(.+)\\]");
5757

5858
static String threadInfo(String threadName) {
5959
Matcher m = ELASTICSEARCH_THREAD_NAME_PATTERN.matcher(threadName);
6060
if (m.matches()) {
61-
// Thread looks like a node thread so use the node name
61+
// Thread looks like a node thread. Display it entirely
6262
return m.group(1);
6363
}
6464
m = TEST_THREAD_NAME_PATTERN.matcher(threadName);

test/framework/src/main/resources/log4j2-test.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
appender.console.type = Console
22
appender.console.name = console
33
appender.console.layout.type = PatternLayout
4-
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}] [%test_thread_info]%marker %m%n
4+
appender.console.layout.pattern = [%d{ISO8601}][%-5p][%-25c{1.}][%test_thread_info]%marker %m%n
55

66
rootLogger.level = ${sys:tests.es.logger.level:-info}
77
rootLogger.appenderRef.console.ref = console

test/framework/src/test/java/org/elasticsearch/common/logging/TestThreadInfoPatternConverterTests.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import org.junit.BeforeClass;
1515

1616
import static org.elasticsearch.common.logging.TestThreadInfoPatternConverter.threadInfo;
17+
import static org.hamcrest.Matchers.equalTo;
1718

1819
public class TestThreadInfoPatternConverterTests extends ESTestCase {
1920
private static String suiteInfo;
@@ -23,19 +24,24 @@ public static void captureSuiteInfo() {
2324
suiteInfo = threadInfo(Thread.currentThread().getName());
2425
}
2526

26-
public void testThreadInfo() {
27+
public void testElasticsearchThreadInfo() {
2728
// Threads that are part of a node get the node name
28-
String nodeName = randomAlphaOfLength(5);
29-
String threadName = EsExecutors.threadName(nodeName, randomAlphaOfLength(20)) + "[T#" + between(0, 1000) + "]";
30-
assertEquals(nodeName, threadInfo(threadName));
29+
var nodeName = randomAlphaOfLength(5);
30+
var prefix = randomAlphaOfLength(20);
31+
var thread = "T#" + between(0, 1000);
32+
var threadName = EsExecutors.threadName(nodeName, prefix) + "[" + thread + "]";
33+
assertThat(threadInfo(threadName), equalTo(nodeName + "][" + prefix + "][" + thread));
34+
}
3135

32-
// Test threads get the test name
36+
public void testCaseNameThreadInfo() {
3337
assertEquals(getTestName(), threadInfo(Thread.currentThread().getName()));
38+
}
3439

35-
// Suite initialization gets "suite"
40+
public void testSuiteThreadInfo() {
3641
assertEquals("suite", suiteInfo);
42+
}
3743

38-
// And stuff that doesn't match anything gets wrapped in [] so we can see it
44+
public void testUnmatchedThreadInfo() {
3945
String unmatched = randomAlphaOfLength(5);
4046
assertEquals("[" + unmatched + "]", threadInfo(unmatched));
4147
}

0 commit comments

Comments
 (0)