Skip to content

Commit

Permalink
Feat: add json format for fluentd output
Browse files Browse the repository at this point in the history
Co-authored-by: Peter Wilcsinszky <[email protected]>
Signed-off-by: pbdger <[email protected]>
Signed-off-by: Peter Wilcsinszky <[email protected]>
  • Loading branch information
Peter B. Dick and pepov committed Apr 29, 2024
1 parent c9411c7 commit 01186e5
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,8 @@ spec:
format: int32
type: integer
type: object
logFormat:
type: string
logLevel:
type: string
metrics:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4808,6 +4808,8 @@ spec:
format: int32
type: integer
type: object
logFormat:
type: string
logLevel:
type: string
metrics:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_fluentdconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -1515,6 +1515,8 @@ spec:
format: int32
type: integer
type: object
logFormat:
type: string
logLevel:
type: string
metrics:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_loggings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4808,6 +4808,8 @@ spec:
format: int32
type: integer
type: object
logFormat:
type: string
logLevel:
type: string
metrics:
Expand Down
1 change: 1 addition & 0 deletions config/samples/archive/logging_v1alpha2_logging_debug.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ metadata:
name: defaultlogging
spec:
fluentd:
logFormat: text
logLevel: debug
disablePvc: true
fluentbit:
Expand Down
2 changes: 2 additions & 0 deletions docs/configuration/crds/v1beta1/fluentd_types.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,8 @@ Ignore same log lines [more info]( https://docs.fluentd.org/deployment/logging#i

### livenessProbe (*corev1.Probe, optional) {#fluentdspec-livenessprobe}

### logFormat (string, optional) {#fluentdspec-logformat}


### logLevel (string, optional) {#fluentdspec-loglevel}

Expand Down
1 change: 1 addition & 0 deletions pkg/resources/fluentd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ var fluentdInputTemplate = `
# Enable RPC endpoint (this allows to trigger config reload without restart)
<system>
rpc_endpoint 127.0.0.1:24444
format {{ .LogFormat }}
log_level {{ .LogLevel }}
workers {{ .Workers }}
{{- if .RootDir }}
Expand Down
6 changes: 4 additions & 2 deletions pkg/resources/fluentd/configsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ import (
)

type fluentdConfig struct {
LogLevel string
Monitor struct {
LogFormat string
LogLevel string
Monitor struct {
Enabled bool
Port int32
Path string
Expand Down Expand Up @@ -59,6 +60,7 @@ func (r *Reconciler) generateConfigSecret(fluentdSpec v1beta1.FluentdSpec) (map[
IgnoreRepeatedLogInterval: fluentdSpec.IgnoreRepeatedLogInterval,
EnableMsgpackTimeSupport: fluentdSpec.EnableMsgpackTimeSupport,
Workers: fluentdSpec.Workers,
LogFormat: fluentdSpec.LogFormat,
LogLevel: fluentdSpec.LogLevel,
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/sdk/logging/api/v1beta1/fluentd_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ type FluentdSpec struct {
Scaling *FluentdScaling `json:"scaling,omitempty"`
Workers int32 `json:"workers,omitempty"`
RootDir string `json:"rootDir,omitempty"`
// Set the logging format. Allowed values are: text and json.
// Default: text
// +kubebuilder:validation:enum=json,text
LogFormat string `json:"logFormat,omitempty" plugin:"default:text"`
// +kubebuilder:validation:enum=fatal,error,warn,info,debug,trace
LogLevel string `json:"logLevel,omitempty"`
// Ignore same log lines
Expand Down Expand Up @@ -184,6 +188,9 @@ func (f *FluentdSpec) SetDefaults() error {
f.Annotations["prometheus.io/port"] = fmt.Sprintf("%d", f.Metrics.Port)
}
}
if f.LogFormat == "" {
f.LogFormat = "text"
}
if f.LogLevel == "" {
f.LogLevel = "info"
}
Expand Down

0 comments on commit 01186e5

Please sign in to comment.