diff --git a/build.gradle b/build.gradle index bbfc122005..a9a171da01 100644 --- a/build.gradle +++ b/build.gradle @@ -14,6 +14,7 @@ buildscript { buildVersionQualifier = System.getProperty("build.version_qualifier", "") version_tokens = opensearch_version.tokenize('-') opensearch_build = version_tokens[0] + '.0' + prometheus_binary_version = "2.37.2" if (buildVersionQualifier) { opensearch_build += "-${buildVersionQualifier}" } @@ -21,6 +22,32 @@ buildscript { // 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT (opensearch_build) opensearch_build += "-SNAPSHOT" } + getArchType = { + if (System.getProperty("os.arch").startsWith("x") || System.getProperty("os.arch").startsWith("amd")) { + return "amd64" + } + else { + return "arm64" + } + } + getOSFamilyType = { + def os = org.gradle.internal.os.OperatingSystem.current(); + if (os.isMacOsX()) { + return "darwin" + } + else if(os.isLinux()){ + return "linux" + } + else if(os.isWindows()) { + return "windows" + } + else { + return os.getFamilyName().toString() + } + } + getPrometheusBinaryLocation = { -> + return "https://github.com/prometheus/prometheus/releases/download/v${prometheus_binary_version}/prometheus-${prometheus_binary_version}."+ getOSFamilyType() + "-" + getArchType() + ".tar.gz" + } } repositories { diff --git a/doctest/build.gradle b/doctest/build.gradle index ebcb85f724..aa58cf9893 100644 --- a/doctest/build.gradle +++ b/doctest/build.gradle @@ -29,19 +29,21 @@ task bootstrap(type: Exec) { task startPrometheus(type: SpawnProcessTask) { doFirst { download.run { - src 'https://github.com/prometheus/prometheus/releases/download/v2.39.1/prometheus-2.39.1.linux-amd64.tar.gz' + src getPrometheusBinaryLocation() dest new File("$projectDir/bin", 'prometheus.tar.gz') } copy { from tarTree("$projectDir/bin/prometheus.tar.gz") into "$projectDir/bin" } - copy { - from "$projectDir/bin/prometheus.yml" - into "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus" + file("$projectDir/bin").eachDir { + if (it.name.startsWith("prometheus-")) { + println "Renaming folder : " + it.name.toString() + println it.renameTo("$projectDir/bin/prometheus") + } } } - command "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus --storage.tsdb.path=$projectDir/bin/prometheus-2.39.1.linux-amd64/data --config.file=$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus.yml" + 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' } @@ -80,6 +82,8 @@ task stopPrometheus() { process.waitFor() } finally { pidFile.delete() + file("$projectDir/bin/prometheus").deleteDir() + file("$projectDir/bin/prometheus.tar.gz").delete() } } } diff --git a/integ-test/build.gradle b/integ-test/build.gradle index f723c7d67c..454d67eca7 100644 --- a/integ-test/build.gradle +++ b/integ-test/build.gradle @@ -27,6 +27,7 @@ import org.opensearch.gradle.test.RestIntegTestTask import org.opensearch.gradle.testclusters.StandaloneRestIntegTestTask import java.util.concurrent.Callable +import org.gradle.internal.os.OperatingSystem plugins { id "de.undercouch.download" version "5.3.0" @@ -38,6 +39,9 @@ apply plugin: 'java' apply plugin: 'io.freefair.lombok' apply plugin: 'com.wiredforcode.spawn' + + + repositories { mavenCentral() maven { url 'https://jitpack.io' } @@ -113,27 +117,36 @@ testClusters.integTest { plugin ":opensearch-sql-plugin" keystore 'plugins.query.federation.datasources.config', new File("$projectDir/src/test/resources/catalog/", 'catalog.json') } + task startPrometheus(type: SpawnProcessTask) { mustRunAfter ':doctest:doctest' + doFirst { download.run { - src 'https://github.com/prometheus/prometheus/releases/download/v2.39.1/prometheus-2.39.1.linux-amd64.tar.gz' + src getPrometheusBinaryLocation() dest new File("$projectDir/bin", 'prometheus.tar.gz') } copy { from tarTree("$projectDir/bin/prometheus.tar.gz") into "$projectDir/bin" } - copy { - from "$projectDir/bin/prometheus.yml" - into "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus" + file("$projectDir/bin").eachDir { + if (it.name.startsWith("prometheus-")) { + println "Renaming folder : " + it.name.toString() + println it.renameTo("$projectDir/bin/prometheus") + } } } - command "$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus --storage.tsdb.path=$projectDir/bin/prometheus-2.39.1.linux-amd64/data --config.file=$projectDir/bin/prometheus-2.39.1.linux-amd64/prometheus.yml" + command "$projectDir/bin/prometheus/prometheus --storage.tsdb.path=$projectDir/bin/prometheus/data --config.file=$projectDir/bin/prometheus/prometheus.yml" ready 'TSDB started' } -task stopPrometheus(type: KillProcessTask) +task stopPrometheus(type: KillProcessTask) { + doLast { + file("$projectDir/bin/prometheus").deleteDir() + file("$projectDir/bin/prometheus.tar.gz").delete() + } +} stopPrometheus.mustRunAfter startPrometheus