Skip to content

Commit bd2e22a

Browse files
jcantrillopenshift-merge-bot[bot]
authored andcommitted
LOG-6661: fix inconsistency for syslog facillity and severity templating
1 parent d5cf253 commit bd2e22a

File tree

9 files changed

+32
-26
lines changed

9 files changed

+32
-26
lines changed

api/observability/v1/output_types.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,7 @@ type Syslog struct {
10831083
// Emergency Alert Critical Error Warning Notice Informational Debug
10841084
//
10851085
// +kubebuilder:validation:Optional
1086+
// +kubebuilder:validation:Pattern:=`^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$`
10861087
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Severity",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
10871088
Severity string `json:"severity,omitempty"`
10881089

@@ -1099,6 +1100,7 @@ type Syslog struct {
10991100
// local0 local1 local2 local3 local4 local5 local6 local7
11001101
//
11011102
// +kubebuilder:validation:Optional
1103+
// +kubebuilder:validation:Pattern:=`^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$`
11021104
// +operator-sdk:csv:customresourcedefinitions:type=spec,displayName="Facility",xDescriptors={"urn:alm:descriptor:com.tectonic.ui:text"}
11031105
Facility string `json:"facility,omitempty"`
11041106

bundle/manifests/observability.openshift.io_clusterlogforwarders.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,7 @@ spec:
23592359
kernel user mail daemon auth syslog lpr news
23602360
uucp cron authpriv ftp ntp security console solaris-cron
23612361
local0 local1 local2 local3 local4 local5 local6 local7
2362+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
23622363
type: string
23632364
msgId:
23642365
description: |-
@@ -2437,6 +2438,7 @@ spec:
24372438
The value can be a decimal integer or one of these case-insensitive keywords:
24382439
24392440
Emergency Alert Critical Error Warning Notice Informational Debug
2441+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
24402442
type: string
24412443
tuning:
24422444
description: Tuning specs tuning for the output

config/crd/bases/observability.openshift.io_clusterlogforwarders.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2359,6 +2359,7 @@ spec:
23592359
kernel user mail daemon auth syslog lpr news
23602360
uucp cron authpriv ftp ntp security console solaris-cron
23612361
local0 local1 local2 local3 local4 local5 local6 local7
2362+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
23622363
type: string
23632364
msgId:
23642365
description: |-
@@ -2437,6 +2438,7 @@ spec:
24372438
The value can be a decimal integer or one of these case-insensitive keywords:
24382439
24392440
Emergency Alert Critical Error Warning Notice Informational Debug
2441+
pattern: ^(([a-zA-Z0-9-_.\/])*(\{(\.[a-zA-Z0-9_]+|\."[^"]+")+((\|\|)(\.[a-zA-Z0-9_]+|\.?"[^"]+")+)*\|\|"[^"]*"\})*)*$
24402442
type: string
24412443
tuning:
24422444
description: Tuning specs tuning for the output

internal/generator/vector/output/syslog/syslog.go

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -161,12 +161,6 @@ func (se SyslogEncoding) Template() string {
161161
codec = "syslog"
162162
except_fields = ["_internal"]
163163
rfc = "{{.RFC}}"
164-
{{ if .Facility }}
165-
facility = "{{.Facility}}"
166-
{{ end }}
167-
{{ if .Severity }}
168-
severity = "{{.Severity}}"
169-
{{ end }}
170164
{{ .AddLogSource }}
171165
{{ .PayloadKey }}
172166
{{end}}`
@@ -183,7 +177,7 @@ func New(id string, o obs.OutputSpec, inputs []string, secrets observability.Sec
183177
}
184178
}
185179
parseEncodingID := vectorhelpers.MakeID(id, "parse_encoding")
186-
templateFieldPairs := getEncodingTemplatesAndFields(o.Syslog)
180+
templateFieldPairs := getEncodingTemplatesAndFields(*o.Syslog)
187181
u, _ := url.Parse(o.Syslog.URL)
188182
sink := Output(id, o, []string{parseEncodingID}, secrets, op, u.Scheme, u.Host)
189183
if strategy != nil {
@@ -220,24 +214,26 @@ func Output(id string, o obs.OutputSpec, inputs []string, secrets observability.
220214

221215
// getEncodingTemplatesAndFields determines which encoding fields are templated
222216
// so that the templates can be parsed to appropriate VRL
223-
func getEncodingTemplatesAndFields(s *obs.Syslog) EncodingTemplateField {
217+
func getEncodingTemplatesAndFields(s obs.Syslog) EncodingTemplateField {
224218
templateFields := EncodingTemplateField{
225219
FieldVRLList: []FieldVRLStringPair{},
226220
}
227221

228222
if s.Facility == "" {
229-
templateFields.FieldVRLList = append(templateFields.FieldVRLList, FieldVRLStringPair{
230-
Field: "facility",
231-
VRLString: commontemplate.TransformUserTemplateToVRL(`{._internal.syslog.facility || "user"}`),
232-
})
223+
s.Facility = `{._internal.syslog.facility || "user"}`
233224
}
225+
templateFields.FieldVRLList = append(templateFields.FieldVRLList, FieldVRLStringPair{
226+
Field: "facility",
227+
VRLString: commontemplate.TransformUserTemplateToVRL(s.Facility),
228+
})
234229

235230
if s.Severity == "" {
236-
templateFields.FieldVRLList = append(templateFields.FieldVRLList, FieldVRLStringPair{
237-
Field: "severity",
238-
VRLString: commontemplate.TransformUserTemplateToVRL(`{._internal.syslog.severity || "informational"}`),
239-
})
231+
s.Severity = `{._internal.syslog.severity || "informational"}`
240232
}
233+
templateFields.FieldVRLList = append(templateFields.FieldVRLList, FieldVRLStringPair{
234+
Field: "severity",
235+
VRLString: commontemplate.TransformUserTemplateToVRL(s.Severity),
236+
})
241237

242238
if s.ProcId == "" {
243239
s.ProcId = `{._internal.syslog.proc_id || "-"}`

internal/generator/vector/output/syslog/syslog_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -112,8 +112,8 @@ var _ = Describe("vector syslog clf output", func() {
112112
spec.Syslog = &obs.Syslog{
113113
URL: "tls://logserver:6514",
114114
RFC: obs.SyslogRFC5424,
115-
Facility: "$$.message.facility",
116-
Severity: "$$.message.severity",
115+
Facility: `{.facility||"none"}`,
116+
Severity: `{.severity||"none"}`,
117117
AppName: `{.app_name||"none"}`,
118118
MsgId: `{.msg_id||"none"}`,
119119
ProcId: `{.proc_id||"none"}`,

internal/generator/vector/output/syslog/tls_with_field_references.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ if .log_type == "audit" {
2222
._internal.syslog.severity = "informational"
2323
._internal.syslog.facility = "security"
2424
}
25+
.facility = to_string!(.facility||"none")
26+
.severity = to_string!(.severity||"none")
2527
.proc_id = to_string!(.proc_id||"none")
2628
.app_name = to_string!(.app_name||"none")
2729
.msg_id = to_string!(.msg_id||"none")
@@ -43,10 +45,10 @@ mode = "tcp"
4345
codec = "syslog"
4446
except_fields = ["_internal"]
4547
rfc = "rfc5424"
46-
facility = "$$.message.facility"
47-
severity = "$$.message.severity"
4848
add_log_source = false
4949
payload_key = "payload_key"
50+
facility = "$$.message.facility"
51+
severity = "$$.message.severity"
5052
proc_id = "$$.message.proc_id"
5153
app_name = "$$.message.app_name"
5254
msg_id = "$$.message.msg_id"

internal/generator/vector/output/syslog/udp_with_every_setting.toml

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,8 @@ if .log_type == "audit" {
2121
._internal.syslog.severity = "informational"
2222
._internal.syslog.facility = "security"
2323
}
24+
.facility = "kern"
25+
.severity = "critical"
2426
.proc_id = "procID"
2527
.tag = "appName"
2628
if exists(.proc_id) && .proc_id != "-" && .proc_id != "" {
@@ -43,9 +45,9 @@ mode = "udp"
4345
codec = "syslog"
4446
except_fields = ["_internal"]
4547
rfc = "rfc3164"
46-
facility = "kern"
47-
severity = "critical"
4848
add_log_source = false
4949
payload_key = "payload_key"
50+
facility = "$$.message.facility"
51+
severity = "$$.message.severity"
5052
proc_id = "$$.message.proc_id"
5153
tag = "$$.message.tag"

test/functional/outputs/syslog/rfc3164_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,8 @@ var _ = Describe("[Functional][Outputs][Syslog] RFC3164 tests", func() {
3636
obstestruntime.NewClusterLogForwarderBuilder(framework.Forwarder).
3737
FromInput(obs.InputTypeApplication).
3838
ToSyslogOutput(obs.SyslogRFC3164, func(spec *obs.OutputSpec) {
39-
spec.Syslog.Facility = "$.message.facility_key"
40-
spec.Syslog.Severity = "$.message.severity_key"
39+
spec.Syslog.Facility = `{.facility_key||"notfound"}`
40+
spec.Syslog.Severity = `{.severity_key||"notfound"}`
4141
spec.Syslog.RFC = obs.SyslogRFC3164
4242
})
4343
Expect(framework.Deploy()).To(BeNil())

test/functional/outputs/syslog/rfc5424_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,8 @@ var _ = Describe("[Functional][Outputs][Syslog] RFC5424 tests", func() {
9595
obstestruntime.NewClusterLogForwarderBuilder(framework.Forwarder).
9696
FromInput(obs.InputTypeApplication).
9797
ToSyslogOutput(obs.SyslogRFC5424, func(spec *obs.OutputSpec) {
98-
spec.Syslog.Facility = "$.message.facility_key"
99-
spec.Syslog.Severity = "$.message.severity_key"
98+
spec.Syslog.Facility = `{.facility_key||"notfound"}`
99+
spec.Syslog.Severity = `{.severity_key||"notfound"}`
100100
})
101101
Expect(framework.Deploy()).To(BeNil())
102102

0 commit comments

Comments
 (0)