Skip to content

Commit 89dbc31

Browse files
authored
Check server status before starting Prometheus (opensearch-project#4537)
* Check server status before starting Prometheus Signed-off-by: Lantao Jin <ltjin@amazon.com> * Change to func call Signed-off-by: Lantao Jin <ltjin@amazon.com> * Fix doc Signed-off-by: Lantao Jin <ltjin@amazon.com> --------- Signed-off-by: Lantao Jin <ltjin@amazon.com>
1 parent fe62472 commit 89dbc31

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

doctest/build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,19 @@ task bootstrap(type: Exec, dependsOn: ['cloneSqlCli']) {
4343

4444
}
4545

46+
def isPrometheusRunning = { ->
47+
try {
48+
def process = "pgrep -f prometheus".execute()
49+
def output = process.text
50+
def result = !output.trim().isEmpty()
51+
println "Prometheus running status: ${result}"
52+
return result
53+
} catch (Exception e) {
54+
println "Error checking Prometheus process: ${e.message}"
55+
return false
56+
}
57+
}
58+
4659
task startPrometheus(type: SpawnProcessTask) {
4760
doFirst {
4861
download.run {
@@ -63,7 +76,7 @@ task startPrometheus(type: SpawnProcessTask) {
6376
command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml"
6477
ready 'TSDB started'
6578
pidLockFileName ".prom.pid.lock"
66-
onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" }
79+
onlyIf { !ignorePrometheus && getOSFamilyType() != "windows" && !isPrometheusRunning() }
6780
}
6881

6982
//evaluationDependsOn(':')

integ-test/build.gradle

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,19 @@ testClusters {
295295
}
296296
}
297297

298+
def isPrometheusRunning() {
299+
try {
300+
def process = "pgrep -f prometheus".execute()
301+
def output = process.text
302+
def result = !output.trim().isEmpty()
303+
println "Prometheus running status: ${result}"
304+
return result
305+
} catch (Exception e) {
306+
println "Error checking Prometheus process: ${e.message}"
307+
return false
308+
}
309+
}
310+
298311
task startPrometheus(type: SpawnProcessTask) {
299312
mustRunAfter ':doctest:doctest'
300313

@@ -319,7 +332,7 @@ task startPrometheus(type: SpawnProcessTask) {
319332
}
320333
command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml"
321334
ready 'TSDB started'
322-
onlyIf { !ignorePrometheus }
335+
onlyIf { !ignorePrometheus && !isPrometheusRunning() }
323336
}
324337

325338
task stopPrometheus(type: KillProcessTask) {

0 commit comments

Comments
 (0)