@@ -31,23 +31,28 @@ type Config struct {
31
31
RemoteWrite bool `json:"-"`
32
32
Platform configv1.PlatformType `json:"-"`
33
33
34
- PrometheusOperatorConfig * PrometheusOperatorConfig `json:"prometheusOperator"`
35
- PrometheusOperatorUserWorkloadConfig * PrometheusOperatorConfig `json:"prometheusOperatorUserWorkload"`
36
-
37
- PrometheusK8sConfig * PrometheusK8sConfig `json:"prometheusK8s"`
38
- PrometheusUserWorkloadConfig * PrometheusK8sConfig `json:"prometheusUserWorkload"`
34
+ ClusterMonitoringConfiguration * ClusterMonitoringConfiguration `json:"-"`
35
+ UserWorkloadConfiguration * UserWorkloadConfiguration `json:"-"`
36
+ }
39
37
40
- AlertmanagerMainConfig * AlertmanagerMainConfig `json:"alertmanagerMain"`
41
- KubeStateMetricsConfig * KubeStateMetricsConfig `json:"kubeStateMetrics"`
42
- OpenShiftMetricsConfig * OpenShiftStateMetricsConfig `json:"openshiftStateMetrics"`
43
- GrafanaConfig * GrafanaConfig `json:"grafana"`
44
- EtcdConfig * EtcdConfig `json:"-"`
45
- HTTPConfig * HTTPConfig `json:"http"`
46
- TelemeterClientConfig * TelemeterClientConfig `json:"telemeterClient"`
47
- K8sPrometheusAdapter * K8sPrometheusAdapter `json:"k8sPrometheusAdapter"`
48
- UserWorkloadConfig * UserWorkloadConfig `json:"techPreviewUserWorkload"`
49
- ThanosRulerConfig * ThanosRulerConfig `json:"thanosRuler"`
50
- ThanosQuerierConfig * ThanosQuerierConfig `json:"thanosQuerier"`
38
+ type ClusterMonitoringConfiguration struct {
39
+ PrometheusOperatorConfig * PrometheusOperatorConfig `json:"prometheusOperator"`
40
+ PrometheusK8sConfig * PrometheusK8sConfig `json:"prometheusK8s"`
41
+ AlertmanagerMainConfig * AlertmanagerMainConfig `json:"alertmanagerMain"`
42
+ KubeStateMetricsConfig * KubeStateMetricsConfig `json:"kubeStateMetrics"`
43
+ OpenShiftMetricsConfig * OpenShiftStateMetricsConfig `json:"openshiftStateMetrics"`
44
+ GrafanaConfig * GrafanaConfig `json:"grafana"`
45
+ EtcdConfig * EtcdConfig `json:"-"`
46
+ HTTPConfig * HTTPConfig `json:"http"`
47
+ TelemeterClientConfig * TelemeterClientConfig `json:"telemeterClient"`
48
+ K8sPrometheusAdapter * K8sPrometheusAdapter `json:"k8sPrometheusAdapter"`
49
+ ThanosQuerierConfig * ThanosQuerierConfig `json:"thanosQuerier"`
50
+ UserWorkloadEnabled * bool `json:"enableUserWorkload"`
51
+ // TODO: Remove in 4.7 release.
52
+ PrometheusUserWorkloadConfig * PrometheusK8sConfig `json:"prometheusUserWorkload"`
53
+ PrometheusOperatorUserWorkloadConfig * PrometheusOperatorConfig `json:"prometheusOperatorUserWorkload"`
54
+ ThanosRulerConfig * ThanosRulerConfig `json:"thanosRuler"`
55
+ UserWorkloadConfig * UserWorkloadConfig `json:"techPreviewUserWorkload"`
51
56
}
52
57
53
58
type Images struct {
@@ -75,11 +80,13 @@ type HTTPConfig struct {
75
80
}
76
81
77
82
type PrometheusOperatorConfig struct {
83
+ LogLevel string `json:"logLevel"`
78
84
NodeSelector map [string ]string `json:"nodeSelector"`
79
85
Tolerations []v1.Toleration `json:"tolerations"`
80
86
}
81
87
82
88
type PrometheusK8sConfig struct {
89
+ LogLevel string `json:"logLevel"`
83
90
Retention string `json:"retention"`
84
91
NodeSelector map [string ]string `json:"nodeSelector"`
85
92
Tolerations []v1.Toleration `json:"tolerations"`
@@ -100,6 +107,7 @@ type AlertmanagerMainConfig struct {
100
107
}
101
108
102
109
type ThanosRulerConfig struct {
110
+ LogLevel string `json:"logLevel"`
103
111
NodeSelector map [string ]string `json:"nodeSelector"`
104
112
Tolerations []v1.Toleration `json:"tolerations"`
105
113
Resources * v1.ResourceRequirements `json:"resources"`
@@ -150,15 +158,6 @@ type UserWorkloadConfig struct {
150
158
Enabled * bool `json:"enabled"`
151
159
}
152
160
153
- // IsEnabled returns the underlying value of the `Enabled` boolean pointer.
154
- // It defaults to false if the pointer is nil.
155
- func (c * UserWorkloadConfig ) IsEnabled () bool {
156
- if c .Enabled == nil {
157
- return false
158
- }
159
- return * c .Enabled
160
- }
161
-
162
161
type TelemeterClientConfig struct {
163
162
ClusterID string `json:"clusterID"`
164
163
Enabled * bool `json:"enabled"`
@@ -184,14 +183,15 @@ func (cfg *TelemeterClientConfig) IsEnabled() bool {
184
183
185
184
func NewConfig (content io.Reader ) (* Config , error ) {
186
185
c := Config {}
187
-
188
- err := k8syaml .NewYAMLOrJSONDecoder (content , 100 ).Decode (& c )
186
+ cmc := ClusterMonitoringConfiguration {}
187
+ err := k8syaml .NewYAMLOrJSONDecoder (content , 4096 ).Decode (& cmc )
189
188
if err != nil {
190
189
return nil , err
191
190
}
192
-
191
+ c . ClusterMonitoringConfiguration = & cmc
193
192
res := & c
194
193
res .applyDefaults ()
194
+ c .UserWorkloadConfiguration = NewDefaultUserWorkloadMonitoringConfig ()
195
195
196
196
return res , nil
197
197
}
@@ -200,58 +200,65 @@ func (c *Config) applyDefaults() {
200
200
if c .Images == nil {
201
201
c .Images = & Images {}
202
202
}
203
- if c .PrometheusOperatorConfig == nil {
204
- c .PrometheusOperatorConfig = & PrometheusOperatorConfig {}
203
+ if c .ClusterMonitoringConfiguration == nil {
204
+ c .ClusterMonitoringConfiguration = & ClusterMonitoringConfiguration {}
205
+ }
206
+ if c .ClusterMonitoringConfiguration .PrometheusOperatorConfig == nil {
207
+ c .ClusterMonitoringConfiguration .PrometheusOperatorConfig = & PrometheusOperatorConfig {}
205
208
}
206
- if c .PrometheusOperatorUserWorkloadConfig == nil {
207
- c .PrometheusOperatorUserWorkloadConfig = & PrometheusOperatorConfig {}
209
+ if c .ClusterMonitoringConfiguration . PrometheusOperatorUserWorkloadConfig == nil {
210
+ c .ClusterMonitoringConfiguration . PrometheusOperatorUserWorkloadConfig = & PrometheusOperatorConfig {}
208
211
}
209
- if c .PrometheusK8sConfig == nil {
210
- c .PrometheusK8sConfig = & PrometheusK8sConfig {}
212
+ if c .ClusterMonitoringConfiguration . PrometheusK8sConfig == nil {
213
+ c .ClusterMonitoringConfiguration . PrometheusK8sConfig = & PrometheusK8sConfig {}
211
214
}
212
- if c .PrometheusK8sConfig .Retention == "" {
213
- c .PrometheusK8sConfig .Retention = "15d"
215
+ if c .ClusterMonitoringConfiguration . PrometheusK8sConfig .Retention == "" {
216
+ c .ClusterMonitoringConfiguration . PrometheusK8sConfig .Retention = "15d"
214
217
}
215
- if c .PrometheusUserWorkloadConfig == nil {
216
- c .PrometheusUserWorkloadConfig = & PrometheusK8sConfig {}
218
+ if c .ClusterMonitoringConfiguration . PrometheusUserWorkloadConfig == nil {
219
+ c .ClusterMonitoringConfiguration . PrometheusUserWorkloadConfig = & PrometheusK8sConfig {}
217
220
}
218
- if c .PrometheusUserWorkloadConfig .Retention == "" {
219
- c .PrometheusUserWorkloadConfig .Retention = "15d"
221
+ if c .ClusterMonitoringConfiguration . PrometheusUserWorkloadConfig .Retention == "" {
222
+ c .ClusterMonitoringConfiguration . PrometheusUserWorkloadConfig .Retention = "15d"
220
223
}
221
- if c .AlertmanagerMainConfig == nil {
222
- c .AlertmanagerMainConfig = & AlertmanagerMainConfig {}
224
+ if c .ClusterMonitoringConfiguration . AlertmanagerMainConfig == nil {
225
+ c .ClusterMonitoringConfiguration . AlertmanagerMainConfig = & AlertmanagerMainConfig {}
223
226
}
224
- if c .ThanosRulerConfig == nil {
225
- c .ThanosRulerConfig = & ThanosRulerConfig {}
227
+ if c .ClusterMonitoringConfiguration .UserWorkloadEnabled == nil {
228
+ disable := false
229
+ c .ClusterMonitoringConfiguration .UserWorkloadEnabled = & disable
226
230
}
227
- if c .ThanosQuerierConfig == nil {
228
- c .ThanosQuerierConfig = & ThanosQuerierConfig {}
231
+ if c .ClusterMonitoringConfiguration . ThanosRulerConfig == nil {
232
+ c .ClusterMonitoringConfiguration . ThanosRulerConfig = & ThanosRulerConfig {}
229
233
}
230
- if c .GrafanaConfig == nil {
231
- c .GrafanaConfig = & GrafanaConfig {}
234
+ if c .ClusterMonitoringConfiguration . ThanosQuerierConfig == nil {
235
+ c .ClusterMonitoringConfiguration . ThanosQuerierConfig = & ThanosQuerierConfig {}
232
236
}
233
- if c .KubeStateMetricsConfig == nil {
234
- c .KubeStateMetricsConfig = & KubeStateMetricsConfig {}
237
+ if c .ClusterMonitoringConfiguration . GrafanaConfig == nil {
238
+ c .ClusterMonitoringConfiguration . GrafanaConfig = & GrafanaConfig {}
235
239
}
236
- if c .OpenShiftMetricsConfig == nil {
237
- c .OpenShiftMetricsConfig = & OpenShiftStateMetricsConfig {}
240
+ if c .ClusterMonitoringConfiguration . KubeStateMetricsConfig == nil {
241
+ c .ClusterMonitoringConfiguration . KubeStateMetricsConfig = & KubeStateMetricsConfig {}
238
242
}
239
- if c .HTTPConfig == nil {
240
- c .HTTPConfig = & HTTPConfig {}
243
+ if c .ClusterMonitoringConfiguration . OpenShiftMetricsConfig == nil {
244
+ c .ClusterMonitoringConfiguration . OpenShiftMetricsConfig = & OpenShiftStateMetricsConfig {}
241
245
}
242
- if c .TelemeterClientConfig == nil {
243
- c .TelemeterClientConfig = & TelemeterClientConfig {
246
+ if c .ClusterMonitoringConfiguration .HTTPConfig == nil {
247
+ c .ClusterMonitoringConfiguration .HTTPConfig = & HTTPConfig {}
248
+ }
249
+ if c .ClusterMonitoringConfiguration .TelemeterClientConfig == nil {
250
+ c .ClusterMonitoringConfiguration .TelemeterClientConfig = & TelemeterClientConfig {
244
251
TelemeterServerURL : "https://infogw.api.openshift.com/" ,
245
252
}
246
253
}
247
- if c .K8sPrometheusAdapter == nil {
248
- c .K8sPrometheusAdapter = & K8sPrometheusAdapter {}
254
+ if c .ClusterMonitoringConfiguration . K8sPrometheusAdapter == nil {
255
+ c .ClusterMonitoringConfiguration . K8sPrometheusAdapter = & K8sPrometheusAdapter {}
249
256
}
250
- if c .EtcdConfig == nil {
251
- c .EtcdConfig = & EtcdConfig {}
257
+ if c .ClusterMonitoringConfiguration . EtcdConfig == nil {
258
+ c .ClusterMonitoringConfiguration . EtcdConfig = & EtcdConfig {}
252
259
}
253
- if c .UserWorkloadConfig == nil {
254
- c .UserWorkloadConfig = & UserWorkloadConfig {}
260
+ if c .ClusterMonitoringConfiguration . UserWorkloadConfig == nil {
261
+ c .ClusterMonitoringConfiguration . UserWorkloadConfig = & UserWorkloadConfig {}
255
262
}
256
263
}
257
264
@@ -274,18 +281,18 @@ func (c *Config) SetImages(images map[string]string) {
274
281
}
275
282
276
283
func (c * Config ) SetTelemetryMatches (matches []string ) {
277
- c .PrometheusK8sConfig .TelemetryMatches = matches
284
+ c .ClusterMonitoringConfiguration . PrometheusK8sConfig .TelemetryMatches = matches
278
285
}
279
286
280
287
func (c * Config ) SetRemoteWrite (rw bool ) {
281
288
c .RemoteWrite = rw
282
- if c .RemoteWrite && c .TelemeterClientConfig .TelemeterServerURL == "https://infogw.api.openshift.com/" {
283
- c .TelemeterClientConfig .TelemeterServerURL = "https://infogw.api.openshift.com/metrics/v1/receive"
289
+ if c .RemoteWrite && c .ClusterMonitoringConfiguration . TelemeterClientConfig .TelemeterServerURL == "https://infogw.api.openshift.com/" {
290
+ c .ClusterMonitoringConfiguration . TelemeterClientConfig .TelemeterServerURL = "https://infogw.api.openshift.com/metrics/v1/receive"
284
291
}
285
292
}
286
293
287
294
func (c * Config ) LoadClusterID (load func () (* configv1.ClusterVersion , error )) error {
288
- if c .TelemeterClientConfig .ClusterID != "" {
295
+ if c .ClusterMonitoringConfiguration . TelemeterClientConfig .ClusterID != "" {
289
296
return nil
290
297
}
291
298
@@ -294,12 +301,12 @@ func (c *Config) LoadClusterID(load func() (*configv1.ClusterVersion, error)) er
294
301
return fmt .Errorf ("error loading cluster version: %v" , err )
295
302
}
296
303
297
- c .TelemeterClientConfig .ClusterID = string (cv .Spec .ClusterID )
304
+ c .ClusterMonitoringConfiguration . TelemeterClientConfig .ClusterID = string (cv .Spec .ClusterID )
298
305
return nil
299
306
}
300
307
301
308
func (c * Config ) LoadToken (load func () (* v1.Secret , error )) error {
302
- if c .TelemeterClientConfig .Token != "" {
309
+ if c .ClusterMonitoringConfiguration . TelemeterClientConfig .Token != "" {
303
310
return nil
304
311
}
305
312
@@ -324,12 +331,12 @@ func (c *Config) LoadToken(load func() (*v1.Secret, error)) error {
324
331
return fmt .Errorf ("unmarshaling pull secret failed: %v" , err )
325
332
}
326
333
327
- c .TelemeterClientConfig .Token = ps .Auths .COC .Auth
334
+ c .ClusterMonitoringConfiguration . TelemeterClientConfig .Token = ps .Auths .COC .Auth
328
335
return nil
329
336
}
330
337
331
338
func (c * Config ) LoadProxy (load func () (* configv1.Proxy , error )) error {
332
- if c .HTTPConfig .HTTPProxy != "" || c .HTTPConfig .HTTPSProxy != "" || c .HTTPConfig .NoProxy != "" {
339
+ if c .ClusterMonitoringConfiguration . HTTPConfig .HTTPProxy != "" || c .ClusterMonitoringConfiguration . HTTPConfig .HTTPSProxy != "" || c . ClusterMonitoringConfiguration .HTTPConfig .NoProxy != "" {
333
340
return nil
334
341
}
335
342
@@ -338,9 +345,9 @@ func (c *Config) LoadProxy(load func() (*configv1.Proxy, error)) error {
338
345
return fmt .Errorf ("error loading proxy: %v" , err )
339
346
}
340
347
341
- c .HTTPConfig .HTTPProxy = p .Status .HTTPProxy
342
- c .HTTPConfig .HTTPSProxy = p .Status .HTTPSProxy
343
- c .HTTPConfig .NoProxy = p .Status .NoProxy
348
+ c .ClusterMonitoringConfiguration . HTTPConfig .HTTPProxy = p .Status .HTTPProxy
349
+ c .ClusterMonitoringConfiguration . HTTPConfig .HTTPSProxy = p .Status .HTTPSProxy
350
+ c .ClusterMonitoringConfiguration . HTTPConfig .NoProxy = p .Status .NoProxy
344
351
345
352
return nil
346
353
}
@@ -364,6 +371,67 @@ func NewConfigFromString(content string) (*Config, error) {
364
371
365
372
func NewDefaultConfig () * Config {
366
373
c := & Config {}
374
+ cmc := ClusterMonitoringConfiguration {}
375
+ c .ClusterMonitoringConfiguration = & cmc
376
+ c .UserWorkloadConfiguration = NewDefaultUserWorkloadMonitoringConfig ()
367
377
c .applyDefaults ()
368
378
return c
369
379
}
380
+
381
+ type UserWorkloadConfiguration struct {
382
+ PrometheusOperator * PrometheusOperatorConfig `json:"prometheusOperator"`
383
+ Prometheus * PrometheusK8sConfig `json:"prometheus"`
384
+ ThanosRuler * ThanosRulerConfig `json:"thanosRuler"`
385
+ }
386
+
387
+ func (u * UserWorkloadConfiguration ) applyDefaults () {
388
+ if u .PrometheusOperator == nil {
389
+ u .PrometheusOperator = & PrometheusOperatorConfig {}
390
+ }
391
+ if u .Prometheus == nil {
392
+ u .Prometheus = & PrometheusK8sConfig {}
393
+ }
394
+ if u .ThanosRuler == nil {
395
+ u .ThanosRuler = & ThanosRulerConfig {}
396
+ }
397
+ }
398
+
399
+ func NewUserConfigFromString (content string ) (* UserWorkloadConfiguration , error ) {
400
+ if content == "" {
401
+ return NewDefaultUserWorkloadMonitoringConfig (), nil
402
+ }
403
+ u := & UserWorkloadConfiguration {}
404
+ err := k8syaml .NewYAMLOrJSONDecoder (bytes .NewBuffer ([]byte (content )), 100 ).Decode (& u )
405
+ if err != nil {
406
+ return nil , err
407
+ }
408
+
409
+ u .applyDefaults ()
410
+
411
+ return u , nil
412
+ }
413
+
414
+ func NewDefaultUserWorkloadMonitoringConfig () * UserWorkloadConfiguration {
415
+ u := & UserWorkloadConfiguration {}
416
+ u .applyDefaults ()
417
+ return u
418
+ }
419
+
420
+ // IsUserWorkloadEnabled checks if user workload monitoring is
421
+ // enabled on old or new configuration.
422
+ func (c * Config ) IsUserWorkloadEnabled () bool {
423
+ if * c .ClusterMonitoringConfiguration .UserWorkloadEnabled == true {
424
+ return true
425
+ }
426
+
427
+ return c .ClusterMonitoringConfiguration .UserWorkloadConfig .isEnabled ()
428
+ }
429
+
430
+ // isEnabled returns the underlying value of the `Enabled` boolean pointer.
431
+ // It defaults to false if the pointer is nil.
432
+ func (c * UserWorkloadConfig ) isEnabled () bool {
433
+ if c .Enabled == nil {
434
+ return false
435
+ }
436
+ return * c .Enabled
437
+ }
0 commit comments