Skip to content

Commit

Permalink
Automate URL building away
Browse files Browse the repository at this point in the history
If you hammer GH API without a login too often, you will get rate
limited over time. As local binaries remain on disk, this should not
be too much of a concern.

Signed-off-by: Richard Hartmann <richih@richih.org>
  • Loading branch information
RichiH committed May 13, 2021
1 parent 07a813a commit 91abb5d
Show file tree
Hide file tree
Showing 7 changed files with 23 additions and 36 deletions.
14 changes: 13 additions & 1 deletion remote_write/latest/latest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io/ioutil"
"log"
"net/http"
"regexp"
"strings"
"time"
)
Expand Down Expand Up @@ -52,7 +53,18 @@ func GetLatestVersion(repo string) string {
}

version := strings.Trim(packageInfo.TagName, "v")
fmt.Println("repository: " + repo + " - version: " + version)
// fmt.Println("repository: " + repo + " - version: " + version)

return version
}

func GetDownloadURL(url string) string {
re := regexp.MustCompile("https://github.com/(.+?/.+?)/.*")
repo := re.ReplaceAllString(url, "$1")
version := GetLatestVersion(repo)

re2 := regexp.MustCompile("(.*)VERSION(.*)")
url = re2.ReplaceAllString(url, "${1}" + version + "${2}")

return url
}
7 changes: 1 addition & 6 deletions remote_write/targets/grafana_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import (
"github.com/prometheus/compliance/remote_write/latest"
)

func getGrafanaDownloadURL() string {
version := latest.GetLatestVersion("grafana/agent")
return "https://github.com/grafana/agent/releases/download/" + version + "/agent-{{.OS}}-{{.Arch}}.zip"
}

func RunGrafanaAgent(opts TargetOptions) error {
binary, err := downloadBinary(getGrafanaDownloadURL(), "agent-{{.OS}}-{{.Arch}}")
binary, err := downloadBinary(latest.GetDownloadURL("https://github.com/grafana/agent/releases/download/vVERSION/agent-{{.OS}}-{{.Arch}}.zip"), "agent-{{.OS}}-{{.Arch}}")
if err != nil {
return err
}
Expand Down
8 changes: 2 additions & 6 deletions remote_write/targets/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,9 @@ import (
"github.com/prometheus/compliance/remote_write/latest"
)

func getOtelDownloadURL() string {
version := latest.GetLatestVersion("open-telemetry/opentelemetry-collector")
return "https://github.com/open-telemetry/opentelemetry-collector/releases/download/v" + version + "/otelcol_{{.OS}}_{{.Arch}}"
}

func RunOtelCollector(opts TargetOptions) error {
binary, err := downloadBinary(getOtelDownloadURL(), "")
binary, err := downloadBinary(latest.GetDownloadURL("https://github.com/open-telemetry/opentelemetry-collector/releases/download/vVERSION/otelcol_{{.OS}}_{{.Arch}}"), "")

if err != nil {
return err
}
Expand Down
6 changes: 1 addition & 5 deletions remote_write/targets/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,9 @@ import (

"github.com/prometheus/compliance/remote_write/latest"
)
func getPrometheusDownloadURL() string {
version := latest.GetLatestVersion("prometheus/prometheus")
return "https://github.com/prometheus/prometheus/releases/download/v" + version + "/prometheus-" + version + ".{{.OS}}-{{.Arch}}.tar.gz"
}

func RunPrometheus(opts TargetOptions) error {
binary, err := downloadBinary(getPrometheusDownloadURL(), "prometheus")
binary, err := downloadBinary(latest.GetDownloadURL("https://github.com/prometheus/prometheus/releases/download/vVERSION/prometheus-VERSION.{{.OS}}-{{.Arch}}.tar.gz"), "prometheus")
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions remote_write/targets/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,8 @@ import (
"github.com/prometheus/compliance/remote_write/latest"
)

func getTelegrafDownloadURL() string {
version := latest.GetLatestVersion("influxdata/telegraf")
return "https://dl.influxdata.com/telegraf/releases/telegraf-" + version + "_{{.OS}}_{{.Arch}}.tar.gz"
}

func RunTelegraf(opts TargetOptions) error {
binary, err := downloadBinary(getTelegrafDownloadURL(), "telegraf")
binary, err := downloadBinary(latest.GetDownloadURL("https://dl.influxdata.com/telegraf/releases/telegraf-VERSION_{{.OS}}_{{.Arch}}.tar.gz"), "telegraf")
if err != nil {
return err
}
Expand Down
10 changes: 4 additions & 6 deletions remote_write/targets/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,21 @@ import (
"github.com/prometheus/compliance/remote_write/latest"
)


func getVectorDownloadURL() string {
version := latest.GetLatestVersion("timberio/vector")
switch runtime.GOOS {
case "darwin":
return "https://github.com/timberio/vector/releases/download/v" + version + "/vector-" + version + "-x86_64-apple-darwin.tar.gz"
return "https://github.com/timberio/vector/releases/download/vVERSION/vector-VERSION-x86_64-apple-darwin.tar.gz"
case "linux":
return "https://github.com/timberio/vector/releases/download/v" + version + "/vector-" + version + "-x86_64-unknown-linux-gnu.tar.gz"
return "https://github.com/timberio/vector/releases/download/vVERSION/vector-VERSION-x86_64-unknown-linux-gnu.tar.gz"
case "windows":
return "https://github.com/timberio/vector/releases/download/v" + version + "/vector-" + version + "-x86_64-pc-windows-msvc.zip"
return "https://github.com/timberio/vector/releases/download/vVERSION/vector-VERSION-x86_64-pc-windows-msvc.zip"
default:
panic("unsupported OS")
}
}

func RunVector(opts TargetOptions) error {
binary, err := downloadBinary(getVectorDownloadURL(), "vector")
binary, err := downloadBinary(latest.GetDownloadURL(getVectorDownloadURL()), "vector")
if err != nil {
return err
}
Expand Down
7 changes: 1 addition & 6 deletions remote_write/targets/vmagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,10 @@ import (
"github.com/prometheus/compliance/remote_write/latest"
)

func getVMAgentDownloadURL() string {
version := latest.GetLatestVersion("VictoriaMetrics/VictoriaMetrics")
return "https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v" + version + "/vmutils-{{.Arch}}-v1.58.0.tar.gz"
}

func RunVMAgent(opts TargetOptions) error {
// NB this won't work on a Mac - need mac builds https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1042!
// If you build it yourself and stick it in the bin/ directory, the tests will work.
binary, err := downloadBinary(getVMAgentDownloadURL(), "vmagent-prod")
binary, err := downloadBinary(latest.GetDownloadURL("https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/vVERSION/vmutils-{{.Arch}}-vVERSION.tar.gz"), "vmagent-prod")
if err != nil {
return err
}
Expand Down

0 comments on commit 91abb5d

Please sign in to comment.