From 01186e596aafe07d8ebb4897e71d107ea4984f96 Mon Sep 17 00:00:00 2001 From: "Peter B. Dick" Date: Tue, 30 Jan 2024 19:11:47 +0100 Subject: [PATCH] Feat: add json format for fluentd output Co-authored-by: Peter Wilcsinszky Signed-off-by: pbdger <81152194+pbdger@users.noreply.github.com> Signed-off-by: Peter Wilcsinszky --- .../crds/logging.banzaicloud.io_fluentdconfigs.yaml | 2 ++ .../crds/logging.banzaicloud.io_loggings.yaml | 2 ++ .../crd/bases/logging.banzaicloud.io_fluentdconfigs.yaml | 2 ++ config/crd/bases/logging.banzaicloud.io_loggings.yaml | 2 ++ config/samples/archive/logging_v1alpha2_logging_debug.yaml | 1 + docs/configuration/crds/v1beta1/fluentd_types.md | 2 ++ pkg/resources/fluentd/config.go | 1 + pkg/resources/fluentd/configsecret.go | 6 ++++-- pkg/sdk/logging/api/v1beta1/fluentd_types.go | 7 +++++++ 9 files changed, 23 insertions(+), 2 deletions(-) diff --git a/charts/logging-operator/crds/logging.banzaicloud.io_fluentdconfigs.yaml b/charts/logging-operator/crds/logging.banzaicloud.io_fluentdconfigs.yaml index a6d0aceacd..f21824e3a6 100644 --- a/charts/logging-operator/crds/logging.banzaicloud.io_fluentdconfigs.yaml +++ b/charts/logging-operator/crds/logging.banzaicloud.io_fluentdconfigs.yaml @@ -1515,6 +1515,8 @@ spec: format: int32 type: integer type: object + logFormat: + type: string logLevel: type: string metrics: diff --git a/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml b/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml index 60d73a8ead..493f47b43a 100644 --- a/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml +++ b/charts/logging-operator/crds/logging.banzaicloud.io_loggings.yaml @@ -4808,6 +4808,8 @@ spec: format: int32 type: integer type: object + logFormat: + type: string logLevel: type: string metrics: diff --git a/config/crd/bases/logging.banzaicloud.io_fluentdconfigs.yaml b/config/crd/bases/logging.banzaicloud.io_fluentdconfigs.yaml index a6d0aceacd..f21824e3a6 100644 --- a/config/crd/bases/logging.banzaicloud.io_fluentdconfigs.yaml +++ b/config/crd/bases/logging.banzaicloud.io_fluentdconfigs.yaml @@ -1515,6 +1515,8 @@ spec: format: int32 type: integer type: object + logFormat: + type: string logLevel: type: string metrics: diff --git a/config/crd/bases/logging.banzaicloud.io_loggings.yaml b/config/crd/bases/logging.banzaicloud.io_loggings.yaml index 60d73a8ead..493f47b43a 100644 --- a/config/crd/bases/logging.banzaicloud.io_loggings.yaml +++ b/config/crd/bases/logging.banzaicloud.io_loggings.yaml @@ -4808,6 +4808,8 @@ spec: format: int32 type: integer type: object + logFormat: + type: string logLevel: type: string metrics: diff --git a/config/samples/archive/logging_v1alpha2_logging_debug.yaml b/config/samples/archive/logging_v1alpha2_logging_debug.yaml index a5f685064b..1376f5871c 100644 --- a/config/samples/archive/logging_v1alpha2_logging_debug.yaml +++ b/config/samples/archive/logging_v1alpha2_logging_debug.yaml @@ -4,6 +4,7 @@ metadata: name: defaultlogging spec: fluentd: + logFormat: text logLevel: debug disablePvc: true fluentbit: diff --git a/docs/configuration/crds/v1beta1/fluentd_types.md b/docs/configuration/crds/v1beta1/fluentd_types.md index 600911b7b5..970b18ce90 100644 --- a/docs/configuration/crds/v1beta1/fluentd_types.md +++ b/docs/configuration/crds/v1beta1/fluentd_types.md @@ -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} diff --git a/pkg/resources/fluentd/config.go b/pkg/resources/fluentd/config.go index 89d74e6e09..516e2adb06 100644 --- a/pkg/resources/fluentd/config.go +++ b/pkg/resources/fluentd/config.go @@ -33,6 +33,7 @@ var fluentdInputTemplate = ` # Enable RPC endpoint (this allows to trigger config reload without restart) rpc_endpoint 127.0.0.1:24444 + format {{ .LogFormat }} log_level {{ .LogLevel }} workers {{ .Workers }} {{- if .RootDir }} diff --git a/pkg/resources/fluentd/configsecret.go b/pkg/resources/fluentd/configsecret.go index ff7e635504..65364ca5e4 100644 --- a/pkg/resources/fluentd/configsecret.go +++ b/pkg/resources/fluentd/configsecret.go @@ -27,8 +27,9 @@ import ( ) type fluentdConfig struct { - LogLevel string - Monitor struct { + LogFormat string + LogLevel string + Monitor struct { Enabled bool Port int32 Path string @@ -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, } diff --git a/pkg/sdk/logging/api/v1beta1/fluentd_types.go b/pkg/sdk/logging/api/v1beta1/fluentd_types.go index e0e8e7ca09..16e29fc876 100644 --- a/pkg/sdk/logging/api/v1beta1/fluentd_types.go +++ b/pkg/sdk/logging/api/v1beta1/fluentd_types.go @@ -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 @@ -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" }