diff --git a/remote_write/README.md b/remote_write/README.md index 1c0e3324..6f782444 100644 --- a/remote_write/README.md +++ b/remote_write/README.md @@ -33,6 +33,7 @@ The repo tests the following remote write senders: - [InfluxData's Telegraf](https://github.com/influxdata/telegraf). - The [OpenTelemetry Collector](https://github.com/open-telemetry/opentelemetry-collector). - The [VictoriaMetrics Agent](https://github.com/VictoriaMetrics/VictoriaMetrics/tree/master/app/vmagent), unless you're on [Mac OS X](https://github.com/VictoriaMetrics/VictoriaMetrics/issues/1042). +- [Timber.io Vector](https://github.com/timberio/vector). If you want to test a dev version of your sender, simply put your binary in `bin/`. diff --git a/remote_write/latest/latest.go b/remote_write/latest/latest.go new file mode 100644 index 00000000..5a6a02aa --- /dev/null +++ b/remote_write/latest/latest.go @@ -0,0 +1,69 @@ +package latest + +import ( + "encoding/json" + "io/ioutil" + "log" + "net/http" + "regexp" + "strings" + "time" +) + +func GetLatestVersion(repo string) string { + url := "https://api.github.com/repos/" + repo + "/releases/latest" + + httpClient := http.Client{ + Timeout: time.Second * 2, // Timeout after 2 seconds + } + + req, err := http.NewRequest(http.MethodGet, url, nil) + if err != nil { + log.Fatal(err) + } + + req.Header.Add("Accept", "application/vnd.github.v3+json") + + res, getErr := httpClient.Do(req) + if getErr != nil { + log.Fatal(getErr) + } + + if res.Body != nil { + defer res.Body.Close() + } + + body, readErr := ioutil.ReadAll(res.Body) + if readErr != nil { + log.Fatal(readErr) + } + + type PackageInfo struct { + TagName string `json:"tag_name"` + CreatedAt time.Time `json:"created_at"` + PublishedAt time.Time `json:"published_at"` + } + + var packageInfo PackageInfo + + jsonErr := json.Unmarshal(body, &packageInfo) + if jsonErr != nil { + log.Fatal(jsonErr) + } + + version := strings.Trim(packageInfo.TagName, "v") +// 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 +} diff --git a/remote_write/targets/grafana_agent.go b/remote_write/targets/grafana_agent.go index 0da2d006..865c1e5f 100644 --- a/remote_write/targets/grafana_agent.go +++ b/remote_write/targets/grafana_agent.go @@ -3,12 +3,12 @@ package targets import ( "fmt" "os" -) -const grafanaAgentDownloadURL = "https://github.com/grafana/agent/releases/download/v0.13.1/agent-{{.OS}}-{{.Arch}}.zip" + "github.com/prometheus/compliance/remote_write/latest" +) func RunGrafanaAgent(opts TargetOptions) error { - binary, err := downloadBinary(grafanaAgentDownloadURL, "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 } diff --git a/remote_write/targets/otel.go b/remote_write/targets/otel.go index 36433b67..c6c5f92a 100644 --- a/remote_write/targets/otel.go +++ b/remote_write/targets/otel.go @@ -3,12 +3,13 @@ package targets import ( "fmt" "os" -) -const otelDownloadURL = "https://github.com/open-telemetry/opentelemetry-collector/releases/download/v0.26.0/otelcol_{{.OS}}_{{.Arch}}" + "github.com/prometheus/compliance/remote_write/latest" +) func RunOtelCollector(opts TargetOptions) error { - binary, err := downloadBinary(otelDownloadURL, "") + binary, err := downloadBinary(latest.GetDownloadURL("https://github.com/open-telemetry/opentelemetry-collector/releases/download/vVERSION/otelcol_{{.OS}}_{{.Arch}}"), "") + if err != nil { return err } diff --git a/remote_write/targets/prometheus.go b/remote_write/targets/prometheus.go index b167bb8b..346a12bf 100644 --- a/remote_write/targets/prometheus.go +++ b/remote_write/targets/prometheus.go @@ -3,12 +3,12 @@ package targets import ( "fmt" "os" -) -const prometheusDownloadURL = "https://github.com/prometheus/prometheus/releases/download/v2.26.0/prometheus-2.26.0.{{.OS}}-{{.Arch}}.tar.gz" + "github.com/prometheus/compliance/remote_write/latest" +) func RunPrometheus(opts TargetOptions) error { - binary, err := downloadBinary(prometheusDownloadURL, "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 } diff --git a/remote_write/targets/telegraf.go b/remote_write/targets/telegraf.go index 66a71c5a..75a716cb 100644 --- a/remote_write/targets/telegraf.go +++ b/remote_write/targets/telegraf.go @@ -3,12 +3,14 @@ package targets import ( "fmt" "os" -) -const telegrafURL = "https://dl.influxdata.com/telegraf/releases/telegraf-1.18.2_{{.OS}}_{{.Arch}}.tar.gz" + "github.com/prometheus/compliance/remote_write/latest" +) func RunTelegraf(opts TargetOptions) error { - binary, err := downloadBinary(telegrafURL, "telegraf") + version := "1.18.2" + binary, err := downloadBinary(latest.GetDownloadURL("https://dl.influxdata.com/telegraf/releases/telegraf-" + version + "_{{.OS}}_{{.Arch}}.tar.gz"), "telegraf") + fmt.Println("Telegraf version needs to be updated by hand, for now") if err != nil { return err } diff --git a/remote_write/targets/vector.go b/remote_write/targets/vector.go index dac9dc72..195f48c4 100644 --- a/remote_write/targets/vector.go +++ b/remote_write/targets/vector.go @@ -4,24 +4,25 @@ import ( "fmt" "os" "runtime" + + "github.com/prometheus/compliance/remote_write/latest" ) func getVectorDownloadURL() string { - var version string = "0.13.1" 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 } diff --git a/remote_write/targets/vmagent.go b/remote_write/targets/vmagent.go index 415af3c0..a7c517f3 100644 --- a/remote_write/targets/vmagent.go +++ b/remote_write/targets/vmagent.go @@ -3,14 +3,14 @@ package targets import ( "fmt" "os" -) -const vmagentURL = "https://github.com/VictoriaMetrics/VictoriaMetrics/releases/download/v1.59.0/vmutils-{{.Arch}}-v1.59.0.tar.gz" + "github.com/prometheus/compliance/remote_write/latest" +) 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(vmagentURL, "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 }