Skip to content

Commit 4390e10

Browse files
LeonLow97cw-Guo
authored andcommitted
Add Tag parameter to fluentbit syslog input
Signed-off-by: Leon Low <[email protected]>
1 parent b6785c6 commit 4390e10

File tree

8 files changed

+76
-0
lines changed

8 files changed

+76
-0
lines changed

apis/fluentbit/v1alpha2/plugins/input/syslog.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ type Syslog struct {
3939
ReceiveBufferSize string `json:"receiveBufferSize,omitempty"`
4040
// Specify the key where the source address will be injected.
4141
SourceAddressKey string `json:"sourceAddressKey,omitempty"`
42+
// Specify a tag to route incoming logs through different parsers to different outputs.
43+
Tag string `json:"tag,omitempty"`
4244
// Specify TLS connector options.
4345
*plugins.TLS `json:"tls,omitempty"`
4446
}
@@ -58,6 +60,7 @@ func (s *Syslog) Params(sl plugins.SecretLoader) (*params.KVs, error) {
5860
plugins.InsertKVString(kvs, "Buffer_Max_Size", s.BufferMaxSize)
5961
plugins.InsertKVString(kvs, "Receive_Buffer_Size", s.ReceiveBufferSize)
6062
plugins.InsertKVString(kvs, "Source_Address_Key", s.SourceAddressKey)
63+
plugins.InsertKVString(kvs, "Tag", s.Tag)
6164

6265
plugins.InsertKVField(kvs, "Port", s.Port)
6366
plugins.InsertKVField(kvs, "Unix_Perm", s.UnixPerm)
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
package input
2+
3+
import (
4+
"testing"
5+
6+
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins"
7+
"github.com/fluent/fluent-operator/v3/apis/fluentbit/v1alpha2/plugins/params"
8+
"github.com/fluent/fluent-operator/v3/pkg/utils"
9+
. "github.com/onsi/gomega"
10+
)
11+
12+
func TestSyslog_Name(t *testing.T) {
13+
g := NewGomegaWithT(t)
14+
syslog := Syslog{}
15+
g.Expect(syslog.Name()).To(Equal("syslog"))
16+
}
17+
18+
func TestSyslog_Params(t *testing.T) {
19+
g := NewGomegaWithT(t)
20+
sl := plugins.NewSecretLoader(nil, "test namespace")
21+
22+
syslog := Syslog{
23+
Mode: "tcp",
24+
Listen: "0.0.0.0",
25+
Port: utils.ToPtr[int32](514),
26+
Path: "/tmp/syslog.sock",
27+
UnixPerm: utils.ToPtr[int32](644),
28+
Parser: "syslog-rfc5424",
29+
BufferChunkSize: "32KB",
30+
BufferMaxSize: "256KB",
31+
ReceiveBufferSize: "1MB",
32+
SourceAddressKey: "source_address",
33+
Tag: "syslog.tag",
34+
}
35+
36+
expected := params.NewKVs()
37+
expected.Insert("Mode", "tcp")
38+
expected.Insert("Listen", "0.0.0.0")
39+
expected.Insert("Path", "/tmp/syslog.sock")
40+
expected.Insert("Parser", "syslog-rfc5424")
41+
expected.Insert("Buffer_Chunk_Size", "32KB")
42+
expected.Insert("Buffer_Max_Size", "256KB")
43+
expected.Insert("Receive_Buffer_Size", "1MB")
44+
expected.Insert("Source_Address_Key", "source_address")
45+
expected.Insert("Tag", "syslog.tag")
46+
expected.Insert("Port", "514")
47+
expected.Insert("Unix_Perm", "644")
48+
49+
kvs, err := syslog.Params(sl)
50+
g.Expect(err).NotTo(HaveOccurred())
51+
g.Expect(kvs).To(Equal(expected))
52+
}

charts/fluent-operator/charts/fluent-bit-crds/crds/fluentbit.fluent.io_clusterinputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ spec:
578578
description: Specify the key where the source address will be
579579
injected.
580580
type: string
581+
tag:
582+
description: Specify a tag to route incoming logs through different
583+
parsers to different outputs.
584+
type: string
581585
tls:
582586
description: Specify TLS connector options.
583587
properties:

config/crd/bases/fluentbit.fluent.io_clusterinputs.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,10 @@ spec:
578578
description: Specify the key where the source address will be
579579
injected.
580580
type: string
581+
tag:
582+
description: Specify a tag to route incoming logs through different
583+
parsers to different outputs.
584+
type: string
581585
tls:
582586
description: Specify TLS connector options.
583587
properties:

docs/plugins/fluentbit/input/syslog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,4 +15,5 @@ Syslog input plugins allows to collect Syslog messages through a Unix socket ser
1515
| bufferMaxSize | Specify the maximum buffer size to receive a Syslog message. If not set, the default size will be the value of Buffer_Chunk_Size. | string |
1616
| receiveBufferSize | Specify the maximum socket receive buffer size. If not set, the default value is OS-dependant, but generally too low to accept thousands of syslog messages per second without loss on udp or unix_udp sockets. Note that on Linux the value is capped by sysctl net.core.rmem_max. | string |
1717
| sourceAddressKey | Specify the key where the source address will be injected. | string |
18+
| tag | Specify a tag to route incoming logs through different parsers to different outputs. | string |
1819
| tls | Specify TLS connector options. | *[plugins.TLS](../tls.md) |

manifests/setup/fluent-operator-crd.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,10 @@ spec:
27052705
description: Specify the key where the source address will be
27062706
injected.
27072707
type: string
2708+
tag:
2709+
description: Specify a tag to route incoming logs through different
2710+
parsers to different outputs.
2711+
type: string
27082712
tls:
27092713
description: Specify TLS connector options.
27102714
properties:

manifests/setup/setup.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2705,6 +2705,10 @@ spec:
27052705
description: Specify the key where the source address will be
27062706
injected.
27072707
type: string
2708+
tag:
2709+
description: Specify a tag to route incoming logs through different
2710+
parsers to different outputs.
2711+
type: string
27082712
tls:
27092713
description: Specify TLS connector options.
27102714
properties:

pkg/utils/utils.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ import (
66
"strings"
77
)
88

9+
func ToPtr[T any](v T) *T {
10+
return &v
11+
}
12+
913
func HashCode(msg string) string {
1014
var h = md5.New()
1115
h.Write([]byte(msg))

0 commit comments

Comments
 (0)