From ada7df50884ed9390bc4ae55b42c80d5db1ad98f Mon Sep 17 00:00:00 2001 From: Rene Groeschke Date: Fri, 16 May 2025 14:34:34 -0700 Subject: [PATCH] [Test] Rework detecting elasticsearch process in docker tests (#128013) (#128103) * [Test] Rework detecting elasticsearch process in docker tests This tweaks detecting the elasticsearch process id by using jps instead of ps which has been problematic in the past exceeding available COLUMN sizes due to es commandline invocation getting longer and longer * Remove few muted tests * Reuse ps for detecting processes but use pipe to find the right one jps doesnt work well with different users * Tweak java command running lookup to work with wolfi * Cleanup changes * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine (cherry picked from commit f0d7ec47b5e998cf19ebef107ea53b1b1aee4a82) # Conflicts: # muted-tests.yml # qa/packaging/src/test/java/org/elasticsearch/packaging/util/docker/Docker.java --- .../packaging/util/docker/Docker.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/qa/packaging/src/test/java/org/elasticsearch/packaging/util/docker/Docker.java b/qa/packaging/src/test/java/org/elasticsearch/packaging/util/docker/Docker.java index 7bb45e602940..ff1f3a931459 100644 --- a/qa/packaging/src/test/java/org/elasticsearch/packaging/util/docker/Docker.java +++ b/qa/packaging/src/test/java/org/elasticsearch/packaging/util/docker/Docker.java @@ -75,6 +75,13 @@ public class Docker { public static final int STARTUP_SLEEP_INTERVAL_MILLISECONDS = 1000; public static final int STARTUP_ATTEMPTS_MAX = 30; + private static final String ELASTICSEARCH_FULL_CLASSNAME = "org.elasticsearch.bootstrap.Elasticsearch"; + private static final String FIND_ELASTICSEARCH_PROCESS = "for pid in $(ps -eo pid,comm | grep java | awk '\\''{print $1}'\\''); " + + "do cmdline=$(tr \"\\0\" \" \" < /proc/$pid/cmdline 2>/dev/null); [[ $cmdline == *" + + ELASTICSEARCH_FULL_CLASSNAME + + "* ]] && echo \"$pid: $cmdline\"; done"; + // The length of the command exceeds what we can use for COLUMNS so we use a pipe to detect the process we're looking for + /** * Tracks the currently running Docker image. An earlier implementation used a fixed container name, * but that appeared to cause problems with repeatedly destroying and recreating containers with @@ -185,11 +192,8 @@ public class Docker { try { // Give the container enough time for security auto-configuration or a chance to crash out Thread.sleep(STARTUP_SLEEP_INTERVAL_MILLISECONDS); - - // Set COLUMNS so that `ps` doesn't truncate its output - psOutput = dockerShell.run("bash -c 'COLUMNS=3000 ps ax'").stdout(); - - if (psOutput.contains("org.elasticsearch.bootstrap.Elasticsearch")) { + psOutput = dockerShell.run("bash -c '" + FIND_ELASTICSEARCH_PROCESS + " | wc -l'").stdout(); + if (psOutput.contains("1")) { isElasticsearchRunning = true; break; }