-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.go
288 lines (228 loc) · 10.1 KB
/
config.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
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
package main
import (
"io/ioutil"
"os"
"strings"
"github.com/BurntSushi/toml"
aslog "github.com/aerospike/aerospike-client-go/v6/logger"
log "github.com/sirupsen/logrus"
)
// Config represents the aerospike-prometheus-exporter configuration
type Config struct {
AeroProm struct {
CertFile string `toml:"cert_file"`
KeyFile string `toml:"key_file"`
RootCA string `toml:"root_ca"`
KeyFilePassphrase string `toml:"key_file_passphrase"`
MetricLabels map[string]string `toml:"labels"`
Bind string `toml:"bind"`
Timeout uint8 `toml:"timeout"`
LogFile string `toml:"log_file"`
LogLevel string `toml:"log_level"`
BasicAuthUsername string `toml:"basic_auth_username"`
BasicAuthPassword string `toml:"basic_auth_password"`
} `toml:"Agent"`
Aerospike struct {
Host string `toml:"db_host"`
Port uint16 `toml:"db_port"`
CertFile string `toml:"cert_file"`
KeyFile string `toml:"key_file"`
KeyFilePassphrase string `toml:"key_file_passphrase"`
NodeTLSName string `toml:"node_tls_name"`
RootCA string `toml:"root_ca"`
AuthMode string `toml:"auth_mode"`
User string `toml:"user"`
Password string `toml:"password"`
Timeout uint8 `toml:"timeout"`
LatencyBucketsCount uint8 `toml:"latency_buckets_count"`
JobMetricsAllowlist []string `toml:"job_metrics_allowlist"`
JobMetricsBlocklist []string `toml:"job_metrics_blocklist"`
JobMetricsAllowlistEnabled bool
JobMetricsBlocklistEnabled bool
// knob to disable job metrics collection (for internal use only, will be deprecated)
DisableJobMetrics bool `toml:"disable_job_metrics"`
SindexMetricsAllowlist []string `toml:"sindex_metrics_allowlist"`
SindexMetricsBlocklist []string `toml:"sindex_metrics_blocklist"`
SindexMetricsAllowlistEnabled bool
SindexMetricsBlocklistEnabled bool
// knob to disable sindex metrics collection (for internal use only, will be deprecated)
DisableSindexMetrics bool `toml:"disable_sindex_metrics"`
UserMetricsUsersAllowlist []string `toml:"user_metrics_users_allowlist"`
UserMetricsUsersBlocklist []string `toml:"user_metrics_users_blocklist"`
UserMetricsUsersAllowlistEnabled bool
UserMetricsUsersBlocklistEnabled bool
NamespaceMetricsAllowlist []string `toml:"namespace_metrics_allowlist"`
SetMetricsAllowlist []string `toml:"set_metrics_allowlist"`
NodeMetricsAllowlist []string `toml:"node_metrics_allowlist"`
XdrMetricsAllowlist []string `toml:"xdr_metrics_allowlist"`
NamespaceMetricsAllowlistEnabled bool
SetMetricsAllowlistEnabled bool
NodeMetricsAllowlistEnabled bool
XdrMetricsAllowlistEnabled bool
NamespaceMetricsBlocklist []string `toml:"namespace_metrics_blocklist"`
SetMetricsBlocklist []string `toml:"set_metrics_blocklist"`
NodeMetricsBlocklist []string `toml:"node_metrics_blocklist"`
XdrMetricsBlocklist []string `toml:"xdr_metrics_blocklist"`
NamespaceMetricsBlocklistEnabled bool
SetMetricsBlocklistEnabled bool
NodeMetricsBlocklistEnabled bool
XdrMetricsBlocklistEnabled bool
// Tolerate older whitelist and blacklist configurations for a while
NamespaceMetricsWhitelist []string `toml:"namespace_metrics_whitelist"`
SetMetricsWhitelist []string `toml:"set_metrics_whitelist"`
NodeMetricsWhitelist []string `toml:"node_metrics_whitelist"`
XdrMetricsWhitelist []string `toml:"xdr_metrics_whitelist"`
NamespaceMetricsBlacklist []string `toml:"namespace_metrics_blacklist"`
SetMetricsBlacklist []string `toml:"set_metrics_blacklist"`
NodeMetricsBlacklist []string `toml:"node_metrics_blacklist"`
XdrMetricsBlacklist []string `toml:"xdr_metrics_blacklist"`
} `toml:"Aerospike"`
LogFile *os.File
}
// Validate and update exporter configuration
func (c *Config) validateAndUpdate() {
if c.AeroProm.Bind == "" {
c.AeroProm.Bind = ":9145"
}
if c.AeroProm.Timeout == 0 {
c.AeroProm.Timeout = 5
}
if c.Aerospike.AuthMode == "" {
c.Aerospike.AuthMode = "internal"
}
if c.Aerospike.Timeout == 0 {
c.Aerospike.Timeout = 5
}
}
// Initialize exporter configuration
func initConfig(configFile string, config *Config) {
// to print everything out regarding reading the config in app init
log.SetLevel(log.DebugLevel)
log.Infof("Loading configuration file %s", configFile)
blob, err := ioutil.ReadFile(configFile)
if err != nil {
log.Fatalln(err)
}
md, err := toml.Decode(string(blob), &config)
if err != nil {
log.Fatalln(err)
}
initAllowlistAndBlocklistConfigs(config, md)
config.LogFile = setLogFile(config.AeroProm.LogFile)
aslog.Logger.SetLogger(log.StandardLogger())
setLogLevel(config.AeroProm.LogLevel)
}
// Set log file path
func setLogFile(filepath string) *os.File {
if len(strings.TrimSpace(filepath)) > 0 {
out, err := os.OpenFile(filepath, os.O_RDWR|os.O_CREATE|os.O_APPEND, 0666)
if err != nil {
log.Fatalf("Error opening file: %v", err)
}
log.SetOutput(out)
return out
}
return nil
}
// Set logging level
func setLogLevel(level string) {
level = strings.ToLower(level)
switch level {
case "info":
log.SetLevel(log.InfoLevel)
aslog.Logger.SetLevel(aslog.INFO)
case "warning", "warn":
log.SetLevel(log.WarnLevel)
aslog.Logger.SetLevel(aslog.WARNING)
case "error", "err":
log.SetLevel(log.ErrorLevel)
aslog.Logger.SetLevel(aslog.ERR)
case "debug":
log.SetLevel(log.DebugLevel)
aslog.Logger.SetLevel(aslog.DEBUG)
case "trace":
log.SetLevel(log.TraceLevel)
aslog.Logger.SetLevel(aslog.DEBUG)
default:
log.SetLevel(log.InfoLevel)
aslog.Logger.SetLevel(aslog.INFO)
}
}
// Initialize Allowlist and Blocklist configurations
func initAllowlistAndBlocklistConfigs(config *Config, md toml.MetaData) {
// Initialize AllowlistEnabled config
config.Aerospike.NamespaceMetricsAllowlistEnabled = md.IsDefined("Aerospike", "namespace_metrics_allowlist")
config.Aerospike.SetMetricsAllowlistEnabled = md.IsDefined("Aerospike", "set_metrics_allowlist")
config.Aerospike.NodeMetricsAllowlistEnabled = md.IsDefined("Aerospike", "node_metrics_allowlist")
config.Aerospike.XdrMetricsAllowlistEnabled = md.IsDefined("Aerospike", "xdr_metrics_allowlist")
config.Aerospike.UserMetricsUsersAllowlistEnabled = md.IsDefined("Aerospike", "user_metrics_users_allowlist")
config.Aerospike.UserMetricsUsersBlocklistEnabled = md.IsDefined("Aerospike", "user_metrics_users_blocklist")
config.Aerospike.JobMetricsAllowlistEnabled = md.IsDefined("Aerospike", "job_metrics_allowlist")
config.Aerospike.JobMetricsBlocklistEnabled = md.IsDefined("Aerospike", "job_metrics_blocklist")
config.Aerospike.SindexMetricsAllowlistEnabled = md.IsDefined("Aerospike", "sindex_metrics_allowlist")
config.Aerospike.SindexMetricsBlocklistEnabled = md.IsDefined("Aerospike", "sindex_metrics_blocklist")
// Initialize BlocklistEnabled config
config.Aerospike.NamespaceMetricsBlocklistEnabled = md.IsDefined("Aerospike", "namespace_metrics_blocklist")
config.Aerospike.SetMetricsBlocklistEnabled = md.IsDefined("Aerospike", "set_metrics_blocklist")
config.Aerospike.NodeMetricsBlocklistEnabled = md.IsDefined("Aerospike", "node_metrics_blocklist")
config.Aerospike.XdrMetricsBlocklistEnabled = md.IsDefined("Aerospike", "xdr_metrics_blocklist")
// Tolerate older whitelist and blacklist configurations for a while.
// If whitelist and blacklist configs are defined copy them into allowlist and blocklist.
// Error out if both configurations are used at the same time.
if md.IsDefined("Aerospike", "namespace_metrics_whitelist") {
if config.Aerospike.NamespaceMetricsAllowlistEnabled {
log.Fatalf("namespace_metrics_whitelist and namespace_metrics_allowlist are mutually exclusive!")
}
config.Aerospike.NamespaceMetricsAllowlistEnabled = true
config.Aerospike.NamespaceMetricsAllowlist = config.Aerospike.NamespaceMetricsWhitelist
}
if md.IsDefined("Aerospike", "set_metrics_whitelist") {
if config.Aerospike.SetMetricsAllowlistEnabled {
log.Fatalf("set_metrics_whitelist and set_metrics_allowlist are mutually exclusive!")
}
config.Aerospike.SetMetricsAllowlistEnabled = true
config.Aerospike.SetMetricsAllowlist = config.Aerospike.SetMetricsWhitelist
}
if md.IsDefined("Aerospike", "node_metrics_whitelist") {
if config.Aerospike.NodeMetricsAllowlistEnabled {
log.Fatalf("node_metrics_whitelist and node_metrics_allowlist are mutually exclusive!")
}
config.Aerospike.NodeMetricsAllowlistEnabled = true
config.Aerospike.NodeMetricsAllowlist = config.Aerospike.NodeMetricsWhitelist
}
if md.IsDefined("Aerospike", "xdr_metrics_whitelist") {
if config.Aerospike.XdrMetricsAllowlistEnabled {
log.Fatalf("xdr_metrics_whitelist and xdr_metrics_allowlist are mutually exclusive!")
}
config.Aerospike.XdrMetricsAllowlistEnabled = true
config.Aerospike.XdrMetricsAllowlist = config.Aerospike.XdrMetricsWhitelist
}
if md.IsDefined("Aerospike", "namespace_metrics_blacklist") {
if config.Aerospike.NamespaceMetricsBlocklistEnabled {
log.Fatalf("namespace_metrics_blacklist and namespace_metrics_blocklist are mutually exclusive!")
}
config.Aerospike.NamespaceMetricsBlocklistEnabled = true
config.Aerospike.NamespaceMetricsBlocklist = config.Aerospike.NamespaceMetricsBlacklist
}
if md.IsDefined("Aerospike", "set_metrics_blacklist") {
if config.Aerospike.SetMetricsBlocklistEnabled {
log.Fatalf("set_metrics_blacklist and set_metrics_blocklist are mutually exclusive!")
}
config.Aerospike.SetMetricsBlocklistEnabled = true
config.Aerospike.SetMetricsBlocklist = config.Aerospike.SetMetricsBlacklist
}
if md.IsDefined("Aerospike", "node_metrics_blacklist") {
if config.Aerospike.NodeMetricsBlocklistEnabled {
log.Fatalf("node_metrics_blacklist and node_metrics_blocklist are mutually exclusive!")
}
config.Aerospike.NodeMetricsBlocklistEnabled = true
config.Aerospike.NodeMetricsBlocklist = config.Aerospike.NodeMetricsBlacklist
}
if md.IsDefined("Aerospike", "xdr_metrics_blacklist") {
if config.Aerospike.XdrMetricsBlocklistEnabled {
log.Fatalf("xdr_metrics_blacklist and xdr_metrics_blocklist are mutually exclusive!")
}
config.Aerospike.XdrMetricsBlocklistEnabled = true
config.Aerospike.XdrMetricsBlocklist = config.Aerospike.XdrMetricsBlacklist
}
}