@@ -297,6 +297,34 @@ func TestStatsPrometheus(t *testing.T) {
297
297
}
298
298
sortMetricFamilies (expectedDelayMetrics )
299
299
300
+ expectedEscapeMetrics := []* io_prometheus_client.MetricFamily {
301
+ {
302
+ Name : amp ("syslogng_classified_output_events_total" ),
303
+ Type : io_prometheus_client .MetricType_COUNTER .Enum (),
304
+ Metric : []* io_prometheus_client.Metric {
305
+ {
306
+ Label : []* io_prometheus_client.LabelPair {
307
+ newLabel ("app" , "MSWinEventLog\\ t1\\ tSecurity\\ t921448325\\ tFri" ),
308
+ newLabel ("source" , "s_critical_hosts_515" ),
309
+ },
310
+ Counter : & io_prometheus_client.Counter {
311
+ Value : amp (1.0 ),
312
+ },
313
+ },
314
+ {
315
+ Label : []* io_prometheus_client.LabelPair {
316
+ newLabel ("app" , "\\ a\\ t\n \" \\ xfa\\ " ),
317
+ newLabel ("source" , "s_unescaped_bug" ),
318
+ },
319
+ Counter : & io_prometheus_client.Counter {
320
+ Value : amp (1.0 ),
321
+ },
322
+ },
323
+ },
324
+ },
325
+ }
326
+ sortMetricFamilies (expectedEscapeMetrics )
327
+
300
328
testCases := map [string ]struct {
301
329
cc ControlChannel
302
330
expected []* io_prometheus_client.MetricFamily
@@ -322,6 +350,13 @@ func TestStatsPrometheus(t *testing.T) {
322
350
}),
323
351
expected : expectedDelayMetrics ,
324
352
},
353
+ "syslog-ng stats prometheus label escaping" : {
354
+ cc : ControlChannelFunc (func (_ context.Context , cmd string ) (rsp string , err error ) {
355
+ require .Equal (t , "STATS PROMETHEUS" , cmd )
356
+ return PROMETHEUS_ESCAPE_METRICS_OUTPUT , nil
357
+ }),
358
+ expected : expectedEscapeMetrics ,
359
+ },
325
360
}
326
361
327
362
for name , testCase := range testCases {
@@ -460,6 +495,10 @@ syslogng_output_event_delay_sample_age_seconds{driver="http",url="http://localho
460
495
syslogng_output_event_delay_sample_age_seconds{transport="tcp",address="localhost:5555",driver="afsocket",id="#anon-destination0#0"} 31
461
496
`
462
497
498
+ const PROMETHEUS_ESCAPE_METRICS_OUTPUT = `syslogng_classified_output_events_total{app="MSWinEventLog\\t1\\tSecurity\\t921448325\\tFri",source="s_critical_hosts_515"} 1
499
+ syslogng_classified_output_events_total{app="\a\t\n\"\xfa\\",source="s_unescaped_bug"} 1
500
+ `
501
+
463
502
func metricFamiliesToText (mfs []* io_prometheus_client.MetricFamily ) string {
464
503
var buf strings.Builder
465
504
for _ , mf := range mfs {
0 commit comments