Skip to content

Commit

Permalink
syslog-ng-ctl: add test for incorrect escaping
Browse files Browse the repository at this point in the history
Prior to the following patch, syslog-ng/AxoSyslog escaped control
characters and '\' incorrectly.

axoflow/axosyslog#224

Signed-off-by: László Várady <laszlo.varady@axoflow.com>
  • Loading branch information
MrAnno committed Jul 26, 2024
1 parent 83879ef commit fd3bfdd
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions pkg/syslog-ng-ctl/stats_prometheus_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -297,6 +297,34 @@ func TestStatsPrometheus(t *testing.T) {
}
sortMetricFamilies(expectedDelayMetrics)

expectedEscapeMetrics := []*io_prometheus_client.MetricFamily{
{
Name: amp("syslogng_classified_output_events_total"),
Type: io_prometheus_client.MetricType_COUNTER.Enum(),
Metric: []*io_prometheus_client.Metric{
{
Label: []*io_prometheus_client.LabelPair{
newLabel("app", "MSWinEventLog\\t1\\tSecurity\\t921448325\\tFri"),
newLabel("source", "s_critical_hosts_515"),
},
Counter: &io_prometheus_client.Counter{
Value: amp(1.0),
},
},
{
Label: []*io_prometheus_client.LabelPair{
newLabel("app", "\\a\\t\n\"\\xfa\\"),
newLabel("source", "s_unescaped_bug"),
},
Counter: &io_prometheus_client.Counter{
Value: amp(1.0),
},
},
},
},
}
sortMetricFamilies(expectedEscapeMetrics)

testCases := map[string]struct {
cc ControlChannel
expected []*io_prometheus_client.MetricFamily
Expand All @@ -322,6 +350,13 @@ func TestStatsPrometheus(t *testing.T) {
}),
expected: expectedDelayMetrics,
},
"syslog-ng stats prometheus label escaping": {
cc: ControlChannelFunc(func(_ context.Context, cmd string) (rsp string, err error) {
require.Equal(t, "STATS PROMETHEUS", cmd)
return PROMETHEUS_ESCAPE_METRICS_OUTPUT, nil
}),
expected: expectedEscapeMetrics,
},
}

for name, testCase := range testCases {
Expand Down Expand Up @@ -460,6 +495,10 @@ syslogng_output_event_delay_sample_age_seconds{driver="http",url="http://localho
syslogng_output_event_delay_sample_age_seconds{transport="tcp",address="localhost:5555",driver="afsocket",id="#anon-destination0#0"} 31
`

const PROMETHEUS_ESCAPE_METRICS_OUTPUT = `syslogng_classified_output_events_total{app="MSWinEventLog\\t1\\tSecurity\\t921448325\\tFri",source="s_critical_hosts_515"} 1
syslogng_classified_output_events_total{app="\a\t\n\"\xfa\\",source="s_unescaped_bug"} 1
`

func metricFamiliesToText(mfs []*io_prometheus_client.MetricFamily) string {
var buf strings.Builder
for _, mf := range mfs {
Expand Down

0 comments on commit fd3bfdd

Please sign in to comment.