From 141296c1729c93ffbccdfa07027ce5321c873e82 Mon Sep 17 00:00:00 2001 From: vamsi-amazon Date: Sun, 13 Nov 2022 15:14:32 -0800 Subject: [PATCH] arch type fix Signed-off-by: vamsi-amazon --- build.gradle | 23 +++++++++++++++++++++++ doctest/build.gradle | 15 ++++++++++----- integ-test/build.gradle | 26 ++++++++++++++++++++------ 3 files changed, 53 insertions(+), 11 deletions(-) diff --git a/build.gradle b/build.gradle index bbfc122005..a7d93de91f 100644 --- a/build.gradle +++ b/build.gradle @@ -21,6 +21,29 @@ buildscript { // 2.0.0-rc1-SNAPSHOT -> 2.0.0.0-rc1-SNAPSHOT (opensearch_build) opensearch_build += "-SNAPSHOT" } + getPrometheusBinaryLocation = { -> + def os = org.gradle.internal.os.OperatingSystem.current() + println "*** Building on ${os.familyName} / ${os.name} / ${os.version} / ${System.getProperty("os.arch")}." + // Currently only considering linux and macos. Need to evolve this logic once we start supporting other os types. + if (os.isMacOsX()) { + //x64, x86-64, amd64 + if (System.getProperty("os.arch").startsWith("x") || System.getProperty("os.arch").startsWith("amd")) { + return "https://github.com/prometheus/prometheus/releases/download/v2.37.2/prometheus-2.37.2.darwin-amd64.tar.gz" + } + else { + return "https://github.com/prometheus/prometheus/releases/download/v2.37.2/prometheus-2.37.2.darwin-arm64.tar.gz" + } + } + else { + //x64, x86-64, amd64 + if (System.getProperty("os.arch").startsWith("x") || System.getProperty("os.arch").startsWith("amd")) { + return "https://github.com/prometheus/prometheus/releases/download/v2.37.2/prometheus-2.37.2.linux-amd64.tar.gz" + } + else { + return "https://github.com/prometheus/prometheus/releases/download/v2.37.2/prometheus-2.37.2.linux-arm64.tar.gz" + } + } + } } repositories { diff --git a/doctest/build.gradle b/doctest/build.gradle index ebcb85f724..bbe292b833 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,9 @@ task stopPrometheus() { process.waitFor() } finally { pidFile.delete() + println "Deleting prometheus folder" + println file("$projectDir/bin/prometheus").deleteDir() + println file("$projectDir/bin/prometheus.tar.gz").delete() } } } diff --git a/integ-test/build.gradle b/integ-test/build.gradle index f723c7d67c..567d8ca99e 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,37 @@ 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 { + println "Deleting prometheus folder" + println file("$projectDir/bin/prometheus").deleteDir() + println file("$projectDir/bin/prometheus.tar.gz").delete() + } +} stopPrometheus.mustRunAfter startPrometheus