Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gelf output plugin to fluentbit #882

Merged
merged 1 commit into from
Aug 28, 2023
Merged
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
2 changes: 2 additions & 0 deletions apis/fluentbit/v1alpha2/clusteroutput_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,8 @@ type OutputSpec struct {
PrometheusRemoteWrite *output.PrometheusRemoteWrite `json:"prometheusRemoteWrite,omitempty"`
// S3 defines S3 Output configuration.
S3 *output.S3 `json:"s3,omitempty"`
// Gelf defines GELF Output configuration.
Gelf *output.Gelf `json:"gelf,omitempty"`

// CustomPlugin defines Custom Output configuration.
CustomPlugin *custom.CustomPlugin `json:"customPlugin,omitempty"`
Expand Down
85 changes: 85 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/output/gelf_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package output

import (
"fmt"

"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins"
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params"
)

// +kubebuilder:object:generate:=true

// The Gelf output plugin allows to send logs in GELF format directly to a Graylog input using TLS, TCP or UDP protocols. <br />
// **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/outputs/gelf**
type Gelf struct {
// IP address or hostname of the target Graylog server.
Host string `json:"host,omitempty"`
// The port that the target Graylog server is listening on.
// +kubebuilder:validation:Minimum:=1
// +kubebuilder:validation:Maximum:=65535
Port *int32 `json:"port,omitempty"`
// The protocol to use (tls, tcp or udp).
// +kubebuilder:validation:Enum:=tls;tcp;udp
Mode string `json:"mode,omitempty"`
// ShortMessageKey is the key to use as the short message.
ShortMessageKey string `json:"shortMessageKey,omitempty"`
// TimestampKey is the key which its value is used as the timestamp of the message.
TimestampKey string `json:"timestampKey,omitempty"`
// HostKey is the key which its value is used as the name of the host, source or application that sent this message.
HostKey string `json:"hostKey,omitempty"`
// FullMessageKey is the key to use as the long message that can i.e. contain a backtrace.
FullMessageKey string `json:"fullMessageKey,omitempty"`
// LevelKey is the key to be used as the log level.
LevelKey string `json:"levelKey,omitempty"`
// If transport protocol is udp, it sets the size of packets to be sent.
PacketSize *int32 `json:"packetSize,omitempty"`
// If transport protocol is udp, it defines if UDP packets should be compressed.
Compress *bool `json:"compress,omitempty"`
*plugins.TLS `json:"tls,omitempty"`
}

func (_ *Gelf) Name() string {
return "gelf"
}

func (g *Gelf) Params(sl plugins.SecretLoader) (*params.KVs, error) {
kvs := params.NewKVs()
if g.Host != "" {
kvs.Insert("Host", g.Host)
}
if g.Port != nil {
kvs.Insert("Port", fmt.Sprint(*g.Port))
}
if g.Mode != "" {
kvs.Insert("Mode", g.Mode)
}
if g.ShortMessageKey != "" {
kvs.Insert("Gelf_Short_Message_Key", g.ShortMessageKey)
}
if g.TimestampKey != "" {
kvs.Insert("Gelf_Timestamp_Key", g.TimestampKey)
}
if g.HostKey != "" {
kvs.Insert("Gelf_Host_Key", g.HostKey)
}
if g.FullMessageKey != "" {
kvs.Insert("Gelf_Full_Message_Key", g.FullMessageKey)
}
if g.LevelKey != "" {
kvs.Insert("Gelf_Level_Key", g.LevelKey)
}
if g.PacketSize != nil {
kvs.Insert("Packet_Size", fmt.Sprint(*g.PacketSize))
}
if g.Compress != nil {
kvs.Insert("Compress", fmt.Sprint(*g.Compress))
}
if g.TLS != nil {
tls, err := g.TLS.Params(sl)
if err != nil {
return nil, err
}
kvs.Merge(tls)
}
return kvs, nil
}
48 changes: 48 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/output/gelf_types_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package output

import (
"testing"

"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins"
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params"
. "github.com/onsi/gomega"
)

func TestOutput_Gelf_Params(t *testing.T) {
g := NewGomegaWithT(t)

sl := plugins.NewSecretLoader(nil, "test namespace")

dd := Gelf{
Host: "127.0.0.1",
Port: ptrInt32(1234),
Mode: "udp",
ShortMessageKey: "short_message",
TimestampKey: "timestamp",
HostKey: "host",
FullMessageKey: "full_message",
LevelKey: "level",
PacketSize: ptrInt32(1000),
Compress: ptrBool(true),
}

expected := params.NewKVs()
expected.Insert("Host", "127.0.0.1")
expected.Insert("Port", "1234")
expected.Insert("Mode", "udp")
expected.Insert("Gelf_Short_Message_Key", "short_message")
expected.Insert("Gelf_Timestamp_Key", "timestamp")
expected.Insert("Gelf_Host_Key", "host")
expected.Insert("Gelf_Full_Message_Key", "full_message")
expected.Insert("Gelf_Level_Key", "level")
expected.Insert("Packet_Size", "1000")
expected.Insert("Compress", "true")

kvs, err := dd.Params(sl)
g.Expect(err).NotTo(HaveOccurred())
g.Expect(kvs).To(Equal(expected))
}

func ptrInt32(v int32) *int32 {
return &v
}
35 changes: 35 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/output/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions apis/fluentbit/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -840,6 +840,121 @@ spec:
type: object
type: object
type: object
gelf:
description: Gelf defines GELF Output configuration.
properties:
compress:
description: If transport protocol is udp, it defines if UDP packets
should be compressed.
type: boolean
fullMessageKey:
description: FullMessageKey is the key to use as the long message
that can i.e. contain a backtrace.
type: string
host:
description: IP address or hostname of the target Graylog server.
type: string
hostKey:
description: HostKey is the key which its value is used as the
name of the host, source or application that sent this message.
type: string
levelKey:
description: LevelKey is the key to be used as the log level.
type: string
mode:
description: The protocol to use (tls, tcp or udp).
enum:
- tls
- tcp
- udp
type: string
packetSize:
description: If transport protocol is udp, it sets the size of
packets to be sent.
format: int32
type: integer
port:
description: The port that the target Graylog server is listening
on.
format: int32
maximum: 65535
minimum: 1
type: integer
shortMessageKey:
description: ShortMessageKey is the key to use as the short message.
type: string
timestampKey:
description: TimestampKey is the key which its value is used as
the timestamp of the message.
type: string
tls:
description: Fluent Bit provides integrated support for Transport
Layer Security (TLS) and it predecessor Secure Sockets Layer
(SSL) respectively.
properties:
caFile:
description: Absolute path to CA certificate file
type: string
caPath:
description: Absolute path to scan for certificate files
type: string
crtFile:
description: Absolute path to Certificate file
type: string
debug:
description: 'Set TLS debug verbosity level. It accept the
following values: 0 (No debug), 1 (Error), 2 (State change),
3 (Informational) and 4 Verbose'
enum:
- 0
- 1
- 2
- 3
- 4
format: int32
type: integer
keyFile:
description: Absolute path to private Key file
type: string
keyPassword:
description: Optional password for tls.key_file file
properties:
valueFrom:
description: ValueSource defines how to find a value's
key.
properties:
secretKeyRef:
description: Selects a key of a secret in the pod's
namespace
properties:
key:
description: The key of the secret to select from. Must
be a valid secret key.
type: string
name:
description: 'Name of the referent. More info:
https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names
TODO: Add other useful fields. apiVersion, kind,
uid?'
type: string
optional:
description: Specify whether the Secret or its
key must be defined
type: boolean
required:
- key
type: object
x-kubernetes-map-type: atomic
type: object
type: object
verify:
description: Force certificate validation
type: boolean
vhost:
description: Hostname to be used for TLS SNI extension
type: string
type: object
type: object
http:
description: HTTP defines HTTP Output configuration.
properties:
Expand Down
Loading