Skip to content

Commit 2968b93

Browse files
committed
This PR enhances the failure message emitted to console when a test cluster node fails to come up.
When `./gradlew run` fails, we would frequently need to see the node's log (stored elsewhere on disk) to learn what went wrong, but it is common expectation that errors would show up in console with other gradle output. This can lead to a frustrating developer experience, so we should point to the log location for debugging next steps. For the case of a cluster, the log message points to the log file of the first node. Hopefully, that is enough of a hint and the developer can pursue the logs of other nodes as needed.
1 parent 0df0873 commit 2968b93

File tree

3 files changed

+31
-8
lines changed

3 files changed

+31
-8
lines changed

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchCluster.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -592,7 +592,14 @@ public void waitForAllConditions() {
592592
writeUnicastHostsFiles();
593593

594594
LOGGER.info("Starting to wait for cluster to form");
595-
waitForConditions(waitConditions, System.currentTimeMillis(), CLUSTER_UP_TIMEOUT, CLUSTER_UP_TIMEOUT_UNIT, this);
595+
waitForConditions(
596+
waitConditions,
597+
getFirstNode().getLogsDir().toString(),
598+
System.currentTimeMillis(),
599+
CLUSTER_UP_TIMEOUT,
600+
CLUSTER_UP_TIMEOUT_UNIT,
601+
this
602+
);
596603
}
597604

598605
@Override

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/ElasticsearchNode.java

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,11 @@ public Path getConfigDir() {
421421
return configFile.getParent();
422422
}
423423

424+
@Internal
425+
public Path getLogsDir() {
426+
return confPathLogs;
427+
}
428+
424429
@Override
425430
@Input
426431
public boolean isPreserveDataDir() {
@@ -896,6 +901,7 @@ private void startElasticsearchProcess() {
896901
}
897902
}
898903
LOGGER.info("Running `{}` in `{}` for {} env: {}", command, workingDir, this, environment);
904+
LOGGER.info("In case of node failure, check {} logs available at: {}", this.name, confPathLogs);
899905
Process esProcess;
900906
try {
901907
esProcess = processBuilder.start();
@@ -1621,12 +1627,19 @@ public boolean isProcessAlive() {
16211627
}
16221628

16231629
void waitForAllConditions() {
1624-
waitForConditions(waitConditions, System.currentTimeMillis(), NODE_UP_TIMEOUT_UNIT.toMillis(NODE_UP_TIMEOUT) +
1625-
// Installing plugins at config time and loading them when nods start requires additional time we need to
1626-
// account for
1627-
ADDITIONAL_CONFIG_TIMEOUT_UNIT.toMillis(
1628-
ADDITIONAL_CONFIG_TIMEOUT * (plugins.size() + keystoreFiles.size() + keystoreSettings.size() + credentials.size())
1629-
), TimeUnit.MILLISECONDS, this);
1630+
waitForConditions(
1631+
waitConditions,
1632+
confPathLogs.toString(),
1633+
System.currentTimeMillis(),
1634+
NODE_UP_TIMEOUT_UNIT.toMillis(NODE_UP_TIMEOUT) +
1635+
// Installing plugins at config time and loading them when nods start requires additional time we need to
1636+
// account for
1637+
ADDITIONAL_CONFIG_TIMEOUT_UNIT.toMillis(
1638+
ADDITIONAL_CONFIG_TIMEOUT * (plugins.size() + keystoreFiles.size() + keystoreSettings.size() + credentials.size())
1639+
),
1640+
TimeUnit.MILLISECONDS,
1641+
this
1642+
);
16301643
}
16311644

16321645
@Override

build-tools/src/main/java/org/elasticsearch/gradle/testclusters/TestClusterConfiguration.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ public interface TestClusterConfiguration {
130130

131131
default void waitForConditions(
132132
LinkedHashMap<String, Predicate<TestClusterConfiguration>> waitConditions,
133+
String logsPath,
133134
long startedAtMillis,
134135
long nodeUpTimeout,
135136
TimeUnit nodeUpTimeoutUnit,
@@ -142,7 +143,9 @@ default void waitForConditions(
142143
Throwable lastException = null;
143144
while (System.currentTimeMillis() - startedAtMillis < TimeUnit.MILLISECONDS.convert(nodeUpTimeout, nodeUpTimeoutUnit)) {
144145
if (context.isProcessAlive() == false) {
145-
throw new TestClustersException("process was found dead while waiting for " + description + ", " + this);
146+
throw new TestClustersException(
147+
"process was found dead while waiting for " + description + ", " + this + ". Node logs available at: " + logsPath
148+
);
146149
}
147150

148151
try {

0 commit comments

Comments
 (0)