Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 1 addition & 8 deletions internal/generator/vector/output/syslog/syslog.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,16 +38,9 @@ func (s Syslog) Name() string {

func (s Syslog) Template() string {
return `{{define "` + s.Name() + `" -}}
[transforms.{{.ComponentID}}_json]
type = "remap"
inputs = {{.Inputs}}
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
'''

[sinks.{{.ComponentID}}]
type = "socket"
inputs = ["{{.ComponentID}}_json"]
inputs = {{.Inputs}}
address = "{{.Address}}"
mode = "{{.Mode}}"
{{end}}`
Expand Down
45 changes: 5 additions & 40 deletions internal/generator/vector/output/syslog/syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,11 @@ source = '''
}
}
}

'''
[transforms.example_json]
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
'''

[sinks.example]
type = "socket"
inputs = ["example_json"]
inputs = ["example_dedot"]
address = "logserver:514"
mode = "xyz"

Expand Down Expand Up @@ -85,16 +78,9 @@ source = '''
}
'''

[transforms.example_json]
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
'''

[sinks.example]
type = "socket"
inputs = ["example_json"]
inputs = ["example_dedot"]
address = "logserver:514"
mode = "tcp"

Expand Down Expand Up @@ -130,16 +116,9 @@ source = '''
}
'''

[transforms.example_json]
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
'''

[sinks.example]
type = "socket"
inputs = ["example_json"]
inputs = ["example_dedot"]
address = "logserver:514"
mode = "tcp"

Expand Down Expand Up @@ -180,16 +159,9 @@ source = '''
}
'''

[transforms.example_json]
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
'''

[sinks.example]
type = "socket"
inputs = ["example_json"]
inputs = ["example_dedot"]
address = "logserver:514"
mode = "udp"

Expand Down Expand Up @@ -231,16 +203,9 @@ source = '''
}
'''

[transforms.example_json]
type = "remap"
inputs = ["example_dedot"]
source = '''
. = merge(., parse_json!(string!(.message))) ?? .
'''

[sinks.example]
type = "socket"
inputs = ["example_json"]
inputs = ["example_dedot"]
address = "logserver:6514"
mode = "tcp"

Expand Down
24 changes: 0 additions & 24 deletions test/functional/outputs/syslog/forward_to_syslog_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,30 +131,6 @@ var _ = Describe("[Functional][Outputs][Syslog] Functional tests", func() {
Expect(getProcID(fields)).To(Equal("myproc"))
Expect(getMsgID(fields)).To(Equal("mymsg"))
})
It("should take values of appname, procid, messageid from record", func() {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's try to enable these tests by introducing the JSON parse filter to demonstrate how this functionality should be work

Copy link
Contributor Author

@vparfonov vparfonov Apr 30, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5.9 don't have JSON parse filter, i will do it in 6.x

functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(join(setSyslogSpecValues, func(spec *logging.OutputSpec) {
spec.Syslog.AppName = "$.message.appname_key"
spec.Syslog.ProcID = "$.message.procid_key"
spec.Syslog.MsgID = "$.message.msgid_key"
}), logging.OutputTypeSyslog)
Expect(framework.Deploy()).To(BeNil())

// Log message data
for _, log := range JSONApplicationLogs {
log = functional.NewFullCRIOLogMessage(timestamp, log)
Expect(framework.WriteMessagesToApplicationLog(log, 1)).To(BeNil())
}
// Read line from Syslog output
outputlogs, err := framework.ReadRawApplicationLogsFrom(logging.OutputTypeSyslog)
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(outputlogs).ToNot(BeEmpty())
fields := strings.Split(outputlogs[0], " ")
Expect(getAppName(fields)).To(Equal("rec_appname"))
Expect(getProcID(fields)).To(Equal("rec_procid"))
Expect(getMsgID(fields)).To(Equal("rec_msgid"))
})
It("should take values from fluent tag", func() {
if testfw.LogCollectionType != logging.LogCollectionTypeFluentd {
Skip("Test requires fluentd")
Expand Down
28 changes: 0 additions & 28 deletions test/functional/outputs/syslog/rfc3164_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,37 +55,9 @@ var _ = Describe("[Functional][Outputs][Syslog] RFC3164 tests", func() {
Expect(outputlogs[0]).To(MatchRegexp(expMatch), "Exp to find tag in received message")
Expect(outputlogs[0]).To(MatchRegexp(`{"index":.*1,.*"timestamp":.*1,.*"tag_key":.*"rec_tag"}`), "Exp to find the original message in received message")
},

Entry("should use the value from the record and include the message", "$.message.tag_key", "rec_tag", false),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same comment here. Also, let's add a test which demonstrates the bug no longer exists and proves we fixed it

Entry("should use the value from the complete tag and include the message", "tag", `kubernetes\.var\.log.pods\..*`, true),
Entry("should use values from parts of the tag and include the message", "${tag[0]}#${tag[-2]}", `kubernetes#.*`, true),
)
Describe("configured with values for facility,severity", func() {
It("should use values from the record", func() {
functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(func(spec *logging.OutputSpec) {
spec.Syslog.Facility = "$.message.facility_key"
spec.Syslog.Severity = "$.message.severity_key"
spec.Syslog.RFC = e2e.RFC3164.String()
spec.Syslog.Tag = "myTag"
}, logging.OutputTypeSyslog)
Expect(framework.Deploy()).To(BeNil())

record := `{"index": 1, "timestamp": 1, "facility_key": "local0", "severity_key": "Informational"}`
crioMessage := functional.NewFullCRIOLogMessage(functional.CRIOTime(time.Now()), record)
Expect(framework.WriteMessagesToApplicationLog(crioMessage, 1)).To(BeNil())

outputlogs, err := framework.ReadRawApplicationLogsFrom(logging.OutputTypeSyslog)
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(outputlogs).To(HaveLen(1), "Expected the receiver to receive the message")

// 134 = Facility(local0/16)*8 + Severity(Informational/6)
// The 1 after <134> is version, which is always set to 1
expectedPriority := "<134>1 "
Expect(outputlogs[0]).To(MatchRegexp(expectedPriority), "Exp to find tag in received message")
})
})

DescribeTable("configured to addLogSourceToMessage should add namespace, pod, container name", func(source string, requiresFluentd bool) {
if requiresFluentd && testfw.LogCollectionType != logging.LogCollectionTypeFluentd {
Expand Down
27 changes: 0 additions & 27 deletions test/functional/outputs/syslog/rfc5424_test.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package syslog

import (
"fmt"
"strings"
"time"

Expand Down Expand Up @@ -53,40 +52,14 @@ var _ = Describe("[Functional][Outputs][Syslog] RFC5424 tests", func() {
outputlogs, err := framework.ReadRawApplicationLogsFrom(logging.OutputTypeSyslog)
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(outputlogs).To(HaveLen(1), "Expected the receiver to receive the message")
expMatch := fmt.Sprintf(`( %s )`, expInfo)
Expect(outputlogs[0]).To(MatchRegexp(expMatch), "Exp to match the appname/procid/msgid in received message")
Expect(outputlogs[0]).To(MatchRegexp(record), "Exp to find the original message in received message")
},

Entry("should use the value from the record and include the message", "$.message.appname_key", "$.message.msgid_key", "$.message.procid_key", "rec_appname rec_procid rec_msgid", false),
Entry("should use the value from the complete tag and include the message", "tag", "mymsg", "myproc", `kubernetes\.var\.log.pods\..*myproc mymsg`, true),
Entry("should use values from parts of the tag and include the message", "${tag[0]}#${tag[-2]}", "mymsg", "myproc", `kubernetes#.*myproc mymsg`, true),
)
Describe("configured with values for facility,severity", func() {
It("should use values from the record", func() {
functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
ToOutputWithVisitor(func(spec *logging.OutputSpec) {
spec.Syslog.Facility = "$.message.facility_key"
spec.Syslog.Severity = "$.message.severity_key"
spec.Syslog.RFC = e2e.RFC5424.String()
}, logging.OutputTypeSyslog)
Expect(framework.Deploy()).To(BeNil())

record := `{"index":1,"timestamp":1,"facility_key":"local0","severity_key":"Informational"}`
crioMessage := functional.NewFullCRIOLogMessage(functional.CRIOTime(time.Now()), record)
Expect(framework.WriteMessagesToApplicationLog(crioMessage, 1)).To(BeNil())

outputlogs, err := framework.ReadRawApplicationLogsFrom(logging.OutputTypeSyslog)
Expect(err).To(BeNil(), "Expected no errors reading the logs")
Expect(outputlogs).To(HaveLen(1), "Expected the receiver to receive the message")

// 134 = Facility(local0/16)*8 + Severity(Informational/6)
// The 1 after <134> is version, which is always set to 1
expectedPriority := "<134>1 "
Expect(outputlogs[0]).To(MatchRegexp(expectedPriority), "Exp to find tag in received message")
})
})
It("should be able to send a large payload", func() {
functional.NewClusterLogForwarderBuilder(framework.Forwarder).
FromInput(logging.InputNameApplication).
Expand Down