Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions remote_write/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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/`.

Expand Down
69 changes: 69 additions & 0 deletions remote_write/latest/latest.go
Original file line number Diff line number Diff line change
@@ -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
}
6 changes: 3 additions & 3 deletions remote_write/targets/grafana_agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
7 changes: 4 additions & 3 deletions remote_write/targets/otel.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions remote_write/targets/prometheus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
8 changes: 5 additions & 3 deletions remote_write/targets/telegraf.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
11 changes: 6 additions & 5 deletions remote_write/targets/vector.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions remote_write/targets/vmagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down