From e197b1241b01c0096a888f1934ae204356c90cb2 Mon Sep 17 00:00:00 2001 From: Lantao Jin Date: Tue, 14 Oct 2025 12:48:57 +0800 Subject: [PATCH 1/3] Check server status before starting Prometheus Signed-off-by: Lantao Jin --- doctest/build.gradle | 12 +++++++++++- integ-test/build.gradle | 12 +++++++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/doctest/build.gradle b/doctest/build.gradle index f01d457a59f..763c9889de2 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -43,6 +43,16 @@ task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) { } +def isPrometheusRunning = { -> + try { + def process = "pgrep -f prometheus".execute() + def output = process.text + return !output.trim().isEmpty() + } catch (Exception e) { + return false + } +} + task startPrometheus(type: SpawnProcessTask) { doFirst { download.run { @@ -63,7 +73,7 @@ task startPrometheus(type: SpawnProcessTask) { command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' pidLockFileName ".prom.pid.lock" - onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" } + onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" && !isPrometheusRunning } } //evaluationDependsOn(':') diff --git a/integ-test/build.gradle b/integ-test/build.gradle index 8578d882844..a479ebec957 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -295,6 +295,16 @@ testClusters { } } +def isPrometheusRunning = { -> + try { + def process = "pgrep -f prometheus".execute() + def output = process.text + return !output.trim().isEmpty() + } catch (Exception e) { + return false + } +} + task startPrometheus(type: SpawnProcessTask) { mustRunAfter ':doctest:doctest' @@ -319,7 +329,7 @@ task startPrometheus(type: SpawnProcessTask) { } command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' - onlyIf { !ignorePrometheus } + onlyIf { !ignorePrometheus && !isPrometheusRunning } } task stopPrometheus(type: KillProcessTask) { From fca271204970d4d3ace3198beac5a9ac404dec1e Mon Sep 17 00:00:00 2001 From: Lantao Jin Date: Tue, 14 Oct 2025 17:29:34 +0800 Subject: [PATCH 2/3] Change to func call Signed-off-by: Lantao Jin --- doctest/build.gradle | 9 ++++++--- integ-test/build.gradle | 10 +++++++--- 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/doctest/build.gradle b/doctest/build.gradle index 763c9889de2..7ad9f7a1ab0 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -43,12 +43,15 @@ task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) { } -def isPrometheusRunning = { -> +def isPrometheusRunning() { try { def process = "pgrep -f prometheus".execute() def output = process.text - return !output.trim().isEmpty() + def result = !output.trim().isEmpty() + println "Prometheus running status: ${result}" + return result } catch (Exception e) { + println "Error checking Prometheus process: ${e.message}" return false } } @@ -73,7 +76,7 @@ task startPrometheus(type: SpawnProcessTask) { command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' pidLockFileName ".prom.pid.lock" - onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" && !isPrometheusRunning } + onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" && !isPrometheusRunning() } } //evaluationDependsOn(':') diff --git a/integ-test/build.gradle b/integ-test/build.gradle index a479ebec957..21dcd4f07d5 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -295,12 +295,15 @@ testClusters { } } -def isPrometheusRunning = { -> +def isPrometheusRunning() { try { def process = "pgrep -f prometheus".execute() def output = process.text - return !output.trim().isEmpty() + def result = !output.trim().isEmpty() + println "Prometheus running status: ${result}" + return result } catch (Exception e) { + println "Error checking Prometheus process: ${e.message}" return false } } @@ -329,7 +332,8 @@ task startPrometheus(type: SpawnProcessTask) { } command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' - onlyIf { !ignorePrometheus && !isPrometheusRunning } + println "Prometheus started" + onlyIf { !ignorePrometheus && !isPrometheusRunning() } } task stopPrometheus(type: KillProcessTask) { From b851b7b5f2161caa1dc2832faa41955a2145e226 Mon Sep 17 00:00:00 2001 From: Lantao Jin Date: Tue, 14 Oct 2025 17:47:18 +0800 Subject: [PATCH 3/3] Fix doc Signed-off-by: Lantao Jin --- doctest/build.gradle | 2 +- integ-test/build.gradle | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/doctest/build.gradle b/doctest/build.gradle index 7ad9f7a1ab0..d758a6de4b8 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -43,7 +43,7 @@ task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) { } -def isPrometheusRunning() { +def isPrometheusRunning = { -> try { def process = "pgrep -f prometheus".execute() def output = process.text diff --git a/integ-test/build.gradle b/integ-test/build.gradle index 21dcd4f07d5..8a55e4c47c3 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -332,7 +332,6 @@ task startPrometheus(type: SpawnProcessTask) { } command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' - println "Prometheus started" onlyIf { !ignorePrometheus && !isPrometheusRunning() } }