From b95c97135293ef64ff0f95f568af350572efc112 Mon Sep 17 00:00:00 2001 From: David Turner Date: Mon, 12 Feb 2018 18:45:46 +0100 Subject: [PATCH] More logging in the rolling-upgrade `waitWithAuth` (elastic/x-pack-elasticsearch#3908) Previously this could fail without logging anything, if there was no exception thrown. Now it records the last status code as well as the last exception, and logs something either way. Original commit: elastic/x-pack-elasticsearch@753333e579e1d999843bac896d36461295800045 --- qa/rolling-upgrade/build.gradle | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/qa/rolling-upgrade/build.gradle b/qa/rolling-upgrade/build.gradle index 80e389fe834..25519022b27 100644 --- a/qa/rolling-upgrade/build.gradle +++ b/qa/rolling-upgrade/build.gradle @@ -21,6 +21,7 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant -> // wait up to two minutes final long stopTime = System.currentTimeMillis() + (2 * 60000L); Exception lastException = null; + int lastResponseCode = 0 while (System.currentTimeMillis() < stopTime) { @@ -36,7 +37,8 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant -> httpURLConnection.setConnectTimeout(1000); httpURLConnection.setReadTimeout(30000); // read needs to wait for nodes! httpURLConnection.connect(); - if (httpURLConnection.getResponseCode() == 200) { + lastResponseCode = httpURLConnection.getResponseCode() + if (lastResponseCode == 200) { tmpFile.withWriter StandardCharsets.UTF_8.name(), { it.write(httpURLConnection.getInputStream().getText(StandardCharsets.UTF_8.name())) } @@ -54,8 +56,13 @@ Closure waitWithAuth = { NodeInfo node, AntBuilder ant -> // did not start, so wait a bit before trying again Thread.sleep(500L); } - if (tmpFile.exists() == false && lastException != null) { - logger.error("final attempt of calling cluster health failed", lastException) + if (tmpFile.exists() == false) { + final String message = "final attempt of calling cluster health failed [lastResponseCode=${lastResponseCode}]" + if (lastException != null) { + logger.error(message, lastException) + } else { + logger.error(message + " [no exception]") + } } return tmpFile.exists() }