forked from cortexproject/cortex
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigs.go
205 lines (175 loc) · 5.46 KB
/
configs.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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
// +build requires_docker
package main
import (
"fmt"
"path/filepath"
"strings"
"text/template"
"github.com/cortexproject/cortex/integration/e2e"
e2edb "github.com/cortexproject/cortex/integration/e2e/db"
)
type storeConfig struct {
From, IndexStore string
}
const (
networkName = "e2e-cortex-test"
bucketName = "cortex"
cortexConfigFile = "config.yaml"
cortexSchemaConfigFile = "schema.yaml"
blocksStorageEngine = "tsdb"
clientCertFile = "certs/client.crt"
clientKeyFile = "certs/client.key"
caCertFile = "certs/root.crt"
serverCertFile = "certs/server.crt"
serverKeyFile = "certs/server.key"
storeConfigTemplate = `
- from: {{.From}}
store: {{.IndexStore}}
schema: v9
index:
prefix: cortex_
period: 168h
chunks:
prefix: cortex_chunks_
period: 168h
`
cortexAlertmanagerUserConfigYaml = `route:
receiver: "example_receiver"
group_by: ["example_groupby"]
receivers:
- name: "example_receiver"
`
cortexRulerUserConfigYaml = `groups:
- name: rule
interval: 100s
rules:
- record: test_rule
alert: ""
expr: up
for: 0s
labels: {}
annotations: {}
`
)
var (
cortexSchemaConfigYaml = buildSchemaConfigWith([]storeConfig{{From: "2019-03-20", IndexStore: "aws-dynamo"}})
AlertmanagerFlags = map[string]string{
"-alertmanager.configs.poll-interval": "1s",
"-alertmanager.web.external-url": "http://localhost/api/prom",
}
AlertmanagerLocalFlags = map[string]string{
"-alertmanager.storage.type": "local",
"-alertmanager.storage.local.path": filepath.Join(e2e.ContainerSharedDir, "alertmanager_configs"),
}
AlertmanagerS3Flags = map[string]string{
"-alertmanager.storage.type": "s3",
"-alertmanager.storage.s3.buckets": "cortex-alerts",
"-alertmanager.storage.s3.force-path-style": "true",
"-alertmanager.storage.s3.url": fmt.Sprintf("s3://%s:%s@%s-minio-9000.:9000", e2edb.MinioAccessKey, e2edb.MinioSecretKey, networkName),
}
RulerConfigs = map[string]string{
"-ruler.enable-sharding": "false",
"-ruler.poll-interval": "2s",
"-experimental.ruler.enable-api": "true",
"-ruler.storage.type": "s3",
"-ruler.storage.s3.buckets": "cortex-rules",
"-ruler.storage.s3.force-path-style": "true",
"-ruler.storage.s3.url": fmt.Sprintf("s3://%s:%s@%s-minio-9000.:9000", e2edb.MinioAccessKey, e2edb.MinioSecretKey, networkName),
}
BlocksStorageFlags = map[string]string{
"-store.engine": blocksStorageEngine,
"-experimental.tsdb.backend": "s3",
"-experimental.tsdb.block-ranges-period": "1m",
"-experimental.tsdb.bucket-store.sync-interval": "5s",
"-experimental.tsdb.retention-period": "5m",
"-experimental.tsdb.ship-interval": "1m",
"-experimental.tsdb.head-compaction-interval": "1s",
"-experimental.tsdb.s3.access-key-id": e2edb.MinioAccessKey,
"-experimental.tsdb.s3.secret-access-key": e2edb.MinioSecretKey,
"-experimental.tsdb.s3.bucket-name": bucketName,
"-experimental.tsdb.s3.endpoint": fmt.Sprintf("%s-minio-9000:9000", networkName),
"-experimental.tsdb.s3.insecure": "true",
}
BlocksStorageConfig = buildConfigFromTemplate(`
storage:
engine: tsdb
tsdb:
backend: s3
block_ranges_period: ["1m"]
retention_period: 5m
ship_interval: 1m
bucket_store:
sync_interval: 5s
s3:
bucket_name: cortex
access_key_id: {{.MinioAccessKey}}
secret_access_key: {{.MinioSecretKey}}
endpoint: {{.MinioEndpoint}}
insecure: true
`, struct {
MinioAccessKey string
MinioSecretKey string
MinioEndpoint string
}{
MinioAccessKey: e2edb.MinioAccessKey,
MinioSecretKey: e2edb.MinioSecretKey,
MinioEndpoint: fmt.Sprintf("%s-minio-9000:9000", networkName),
})
ChunksStorageFlags = map[string]string{
"-dynamodb.url": fmt.Sprintf("dynamodb://u:p@%s-dynamodb.:8000", networkName),
"-table-manager.poll-interval": "1m",
"-schema-config-file": filepath.Join(e2e.ContainerSharedDir, cortexSchemaConfigFile),
"-table-manager.retention-period": "168h",
}
ChunksStorageConfig = buildConfigFromTemplate(`
storage:
aws:
dynamodb:
dynamodb_url: {{.DynamoDBURL}}
table_manager:
poll_interval: 1m
retention_period: 168h
schema:
{{.SchemaConfig}}
`, struct {
DynamoDBURL string
SchemaConfig string
}{
DynamoDBURL: fmt.Sprintf("dynamodb://u:p@%s-dynamodb.:8000", networkName),
SchemaConfig: indentConfig(cortexSchemaConfigYaml, 2),
})
)
func buildConfigFromTemplate(tmpl string, data interface{}) string {
t, err := template.New("config").Parse(tmpl)
if err != nil {
panic(err)
}
w := &strings.Builder{}
if err = t.Execute(w, data); err != nil {
panic(err)
}
return w.String()
}
func indentConfig(config string, indentation int) string {
output := strings.Builder{}
for _, line := range strings.Split(config, "\n") {
if line == "" {
output.WriteString("\n")
continue
}
output.WriteString(strings.Repeat(" ", indentation))
output.WriteString(line)
output.WriteString("\n")
}
return output.String()
}
func buildSchemaConfigWith(configs []storeConfig) string {
configYamls := ""
for _, config := range configs {
configYamls += buildConfigFromTemplate(
storeConfigTemplate,
config,
)
}
return "configs:" + configYamls
}