-
Notifications
You must be signed in to change notification settings - Fork 782
/
db.go
92 lines (82 loc) · 2.83 KB
/
db.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
package e2edb
import (
"fmt"
"os"
"path/filepath"
"strconv"
"strings"
"github.com/cortexproject/cortex/integration/e2e"
"github.com/cortexproject/cortex/integration/e2e/images"
)
const (
MinioAccessKey = "Cheescake"
MinioSecretKey = "supersecret"
)
// NewMinio returns minio server, used as a local replacement for S3.
func NewMinio(port int, bktNames ...string) *e2e.HTTPService {
return newMinio(port, map[string]string{}, bktNames...)
}
func newMinio(port int, envVars map[string]string, bktNames ...string) *e2e.HTTPService {
commands := []string{}
for _, bkt := range bktNames {
commands = append(commands, fmt.Sprintf("mkdir -p /data/%s", bkt))
}
commands = append(commands, fmt.Sprintf("minio server --address :%v --quiet /data", port))
m := e2e.NewHTTPService(
fmt.Sprintf("minio-%v", port),
images.Minio,
// Create the "cortex" bucket before starting minio
e2e.NewCommandWithoutEntrypoint("sh", "-c", strings.Join(commands, " && ")),
e2e.NewHTTPReadinessProbe(port, "/minio/health/ready", 200, 200),
port,
)
envVars["MINIO_ACCESS_KEY"] = MinioAccessKey
envVars["MINIO_SECRET_KEY"] = MinioSecretKey
envVars["MINIO_BROWSER"] = "off"
envVars["ENABLE_HTTPS"] = "0"
m.SetEnvVars(envVars)
return m
}
func NewConsul() *e2e.HTTPService {
return NewConsulWithName("consul")
}
func NewConsulWithName(name string) *e2e.HTTPService {
return e2e.NewHTTPService(
name,
images.Consul,
// Run consul in "dev" mode so that the initial leader election is immediate
e2e.NewCommand("agent", "-server", "-client=0.0.0.0", "-dev", "-log-level=err"),
e2e.NewHTTPReadinessProbe(8500, "/v1/operator/autopilot/health", 200, 200, `"Healthy": true`),
8500,
)
}
func NewETCD() *e2e.HTTPService {
return e2e.NewHTTPService(
"etcd",
images.ETCD,
e2e.NewCommand("/usr/local/bin/etcd", "--listen-client-urls=http://0.0.0.0:2379", "--advertise-client-urls=http://0.0.0.0:2379", "--listen-metrics-urls=http://0.0.0.0:9000", "--log-level=error"),
e2e.NewHTTPReadinessProbe(9000, "/health", 200, 204),
2379,
9000, // Metrics
)
}
func NewPrometheus(flags map[string]string) *e2e.HTTPService {
return NewPrometheusWithName("prometheus", flags)
}
func NewPrometheusWithName(name string, flags map[string]string) *e2e.HTTPService {
prom := e2e.NewHTTPService(
name,
images.Prometheus,
e2e.NewCommandWithoutEntrypoint("prometheus", e2e.BuildArgs(e2e.MergeFlags(map[string]string{
"--storage.tsdb.path": filepath.Join(e2e.ContainerSharedDir, "data"),
"--storage.tsdb.max-block-duration": "2h",
"--log.level": "info",
"--web.listen-address": ":9090",
"--config.file": filepath.Join(e2e.ContainerSharedDir, "prometheus.yml"),
}, flags))...),
e2e.NewHTTPReadinessProbe(9090, "/-/ready", 200, 200),
9090,
)
prom.SetUser(strconv.Itoa(os.Getuid()))
return prom
}