@@ -16,7 +16,7 @@ import (
16
16
)
17
17
18
18
func TestEnablePatroniLogging (t * testing.T ) {
19
- t .Run ("NilInstrumentationSpec " , func (t * testing.T ) {
19
+ t .Run ("EmptyInstrumentationSpec " , func (t * testing.T ) {
20
20
gate := feature .NewGate ()
21
21
assert .NilError (t , gate .SetFromMap (map [string ]bool {
22
22
feature .OpenTelemetryLogs : true ,
@@ -26,9 +26,7 @@ func TestEnablePatroniLogging(t *testing.T) {
26
26
config := NewConfig (nil )
27
27
cluster := new (v1beta1.PostgresCluster )
28
28
require .UnmarshalInto (t , & cluster .Spec , `{
29
- instrumentation: {
30
- logs: { retentionPeriod: 5h },
31
- },
29
+ instrumentation: {}
32
30
}` )
33
31
34
32
EnablePatroniLogging (ctx , cluster , config )
@@ -216,3 +214,137 @@ service:
216
214
` )
217
215
})
218
216
}
217
+
218
+ func TestEnablePatroniMetrics (t * testing.T ) {
219
+ t .Run ("EmptyInstrumentationSpec" , func (t * testing.T ) {
220
+ gate := feature .NewGate ()
221
+ assert .NilError (t , gate .SetFromMap (map [string ]bool {
222
+ feature .OpenTelemetryMetrics : true ,
223
+ }))
224
+ ctx := feature .NewContext (context .Background (), gate )
225
+
226
+ config := NewConfig (nil )
227
+ cluster := new (v1beta1.PostgresCluster )
228
+ require .UnmarshalInto (t , & cluster .Spec , `{
229
+ instrumentation: {}
230
+ }` )
231
+
232
+ EnablePatroniMetrics (ctx , cluster , config )
233
+
234
+ result , err := config .ToYAML ()
235
+ assert .NilError (t , err )
236
+ assert .DeepEqual (t , result , `# Generated by postgres-operator. DO NOT EDIT.
237
+ # Your changes will not be saved.
238
+ exporters:
239
+ debug:
240
+ verbosity: detailed
241
+ prometheus/cpk-monitoring:
242
+ endpoint: 0.0.0.0:9187
243
+ extensions: {}
244
+ processors:
245
+ batch/1s:
246
+ timeout: 1s
247
+ batch/200ms:
248
+ timeout: 200ms
249
+ batch/logs:
250
+ send_batch_size: 8192
251
+ timeout: 200ms
252
+ groupbyattrs/compact: {}
253
+ resourcedetection:
254
+ detectors: []
255
+ override: false
256
+ timeout: 30s
257
+ receivers:
258
+ prometheus/cpk-monitoring:
259
+ config:
260
+ scrape_configs:
261
+ - job_name: patroni
262
+ scheme: https
263
+ scrape_interval: 10s
264
+ static_configs:
265
+ - targets:
266
+ - 0.0.0.0:8008
267
+ tls_config:
268
+ insecure_skip_verify: true
269
+ service:
270
+ extensions: []
271
+ pipelines:
272
+ metrics/patroni:
273
+ exporters:
274
+ - prometheus/cpk-monitoring
275
+ processors:
276
+ - batch/200ms
277
+ - groupbyattrs/compact
278
+ receivers:
279
+ - prometheus/cpk-monitoring
280
+ ` )
281
+ })
282
+
283
+ t .Run ("InstrumentationSpecDefined" , func (t * testing.T ) {
284
+ gate := feature .NewGate ()
285
+ assert .NilError (t , gate .SetFromMap (map [string ]bool {
286
+ feature .OpenTelemetryMetrics : true ,
287
+ }))
288
+ ctx := feature .NewContext (context .Background (), gate )
289
+
290
+ cluster := new (v1beta1.PostgresCluster )
291
+ cluster .Spec .Instrumentation = testInstrumentationSpec ()
292
+ config := NewConfig (cluster .Spec .Instrumentation )
293
+
294
+ EnablePatroniMetrics (ctx , cluster , config )
295
+
296
+ result , err := config .ToYAML ()
297
+ assert .NilError (t , err )
298
+ assert .DeepEqual (t , result , `# Generated by postgres-operator. DO NOT EDIT.
299
+ # Your changes will not be saved.
300
+ exporters:
301
+ debug:
302
+ verbosity: detailed
303
+ googlecloud:
304
+ log:
305
+ default_log_name: opentelemetry.io/collector-exported-log
306
+ project: google-project-name
307
+ prometheus/cpk-monitoring:
308
+ endpoint: 0.0.0.0:9187
309
+ extensions: {}
310
+ processors:
311
+ batch/1s:
312
+ timeout: 1s
313
+ batch/200ms:
314
+ timeout: 200ms
315
+ batch/logs:
316
+ send_batch_size: 8192
317
+ timeout: 200ms
318
+ groupbyattrs/compact: {}
319
+ resourcedetection:
320
+ detectors: []
321
+ override: false
322
+ timeout: 30s
323
+ receivers:
324
+ prometheus/cpk-monitoring:
325
+ config:
326
+ scrape_configs:
327
+ - job_name: patroni
328
+ scheme: https
329
+ scrape_interval: 10s
330
+ static_configs:
331
+ - targets:
332
+ - 0.0.0.0:8008
333
+ tls_config:
334
+ insecure_skip_verify: true
335
+ service:
336
+ extensions: []
337
+ pipelines:
338
+ metrics/patroni:
339
+ exporters:
340
+ - prometheus/cpk-monitoring
341
+ - googlecloud
342
+ processors:
343
+ - batch/200ms
344
+ - groupbyattrs/compact
345
+ receivers:
346
+ - prometheus/cpk-monitoring
347
+ ` )
348
+
349
+ })
350
+ }
0 commit comments