forked from observatorium/loki-benchmarks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
benchmarks_suite_test.go
109 lines (84 loc) · 2.72 KB
/
benchmarks_suite_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
package benchmarks_test
import (
"fmt"
"io/ioutil"
"os"
"testing"
"time"
. "github.com/onsi/ginkgo"
"github.com/onsi/ginkgo/reporters"
. "github.com/onsi/gomega"
"gopkg.in/yaml.v2"
"k8s.io/client-go/kubernetes/scheme"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/client/apiutil"
k8sconfig "sigs.k8s.io/controller-runtime/pkg/client/config"
"github.com/observatorium/loki-benchmarks/internal/config"
"github.com/observatorium/loki-benchmarks/internal/metrics"
internalreporters "github.com/observatorium/loki-benchmarks/internal/reporters"
)
var (
benchCfg *config.Benchmark
k8sClient client.Client
metricsClient metrics.Client
reportDir string
defaultLatchRange = "5m"
defaultRetry = 5 * time.Second
defaultTimeout = 60 * time.Second
defaultLatchTimeout = 5 * time.Minute
)
func init() {
// Read target environment
env := os.Getenv("TARGET_ENV")
if env == "" {
panic("Missing TARGET_ENV env variable")
}
reportDir = os.Getenv("REPORT_DIR")
if reportDir == "" {
panic("Missing REPORT_DIR env variable")
}
promURL := os.Getenv("PROMETHEUS_URL")
promToken := os.Getenv("PROMETHEUS_TOKEN")
// Read config for benchmark tests
filename := fmt.Sprintf("../config/%s.yaml", env)
yamlFile, err := ioutil.ReadFile(filename)
if err != nil {
panic(fmt.Sprintf("Failed reading benchmark configuration file: %s", filename))
}
benchCfg = &config.Benchmark{}
err = yaml.Unmarshal(yamlFile, benchCfg)
if err != nil {
panic(fmt.Sprintf("Failed to marshal benchmark configuration file %s with errors %v", filename, err))
}
fmt.Printf("\nUsing benchmark configuration:\n===============================\n%s\n", yamlFile)
if promURL == "" {
promURL = benchCfg.Metrics.URL
}
// Create a client to collect metrics
metricsClient, err = metrics.NewClient(promURL, promToken, 10*time.Second)
if err != nil {
panic("Failed to create metrics client")
}
// Create kubernetes client for deployments
cfg, err := k8sconfig.GetConfig()
if err != nil {
panic("Failed to read kubeconfig")
}
mapper, err := apiutil.NewDynamicRESTMapper(cfg)
if err != nil {
panic("Failed to create new dynamic REST mapper")
}
opts := client.Options{Scheme: scheme.Scheme, Mapper: mapper}
k8sClient, err = client.New(cfg, opts)
if err != nil {
panic("Failed to create new k8s client")
}
}
func TestBenchmarks(t *testing.T) {
RegisterFailHandler(Fail)
jr := reporters.NewJUnitReporter(fmt.Sprintf("%s/junit.xml", reportDir))
csv := internalreporters.NewCsvReporter(reportDir)
gp := internalreporters.NewGnuplotReporter(reportDir)
rm := internalreporters.NewReadmeReporter(reportDir)
RunSpecsWithDefaultAndCustomReporters(t, "Benchmarks Suite", []Reporter{jr, csv, gp, rm})
}