From 040351410ae75137550a9bfe96be6fda4ef37c22 Mon Sep 17 00:00:00 2001 From: Brett Jones Date: Wed, 12 Aug 2020 14:16:00 -0500 Subject: [PATCH] Bug 1881996: fix legacy syslog k8s Metadata --- .../forwarding/fluentd/fluent_conf_test.go | 16 +++ .../fluentd/output_conf_legacy_test.go | 135 ++++++++++-------- .../forwarding/fluentd/templates.go | 9 ++ 3 files changed, 103 insertions(+), 57 deletions(-) diff --git a/pkg/generators/forwarding/fluentd/fluent_conf_test.go b/pkg/generators/forwarding/fluentd/fluent_conf_test.go index 21a9fbce3c..0f5e9afa3f 100644 --- a/pkg/generators/forwarding/fluentd/fluent_conf_test.go +++ b/pkg/generators/forwarding/fluentd/fluent_conf_test.go @@ -348,6 +348,14 @@ var _ = Describe("Generating fluentd config", func() { remove_keys req,res,msg,name,level,v,pid,err + + @type record_transformer + enable_ruby + + k8s_audit_level ${record['level']} + level info + + @type viaq_data_model elasticsearch_index_prefix_field 'viaq_index_name' @@ -762,6 +770,14 @@ var _ = Describe("Generating fluentd config", func() { remove_keys req,res,msg,name,level,v,pid,err + + @type record_transformer + enable_ruby + + k8s_audit_level ${record['level']} + level info + + @type viaq_data_model elasticsearch_index_prefix_field 'viaq_index_name' diff --git a/pkg/generators/forwarding/fluentd/output_conf_legacy_test.go b/pkg/generators/forwarding/fluentd/output_conf_legacy_test.go index 674ad9a0ef..4ee8dc1853 100644 --- a/pkg/generators/forwarding/fluentd/output_conf_legacy_test.go +++ b/pkg/generators/forwarding/fluentd/output_conf_legacy_test.go @@ -1,29 +1,29 @@ package fluentd import ( - . "github.com/onsi/ginkgo" - . "github.com/onsi/gomega" + . "github.com/onsi/ginkgo" + . "github.com/onsi/gomega" - loggingv1alpha1 "github.com/openshift/cluster-logging-operator/pkg/apis/logging/v1alpha1" - test "github.com/openshift/cluster-logging-operator/test" + loggingv1alpha1 "github.com/openshift/cluster-logging-operator/pkg/apis/logging/v1alpha1" + test "github.com/openshift/cluster-logging-operator/test" ) var _ = Describe("Generating fluentd legacy output store config blocks", func() { - var ( - err error - lfSpec *loggingv1alpha1.ForwardingSpec - generator *ConfigGenerator - ) - - Context("based on legacy fluentd forward method", func() { - BeforeEach(func() { - lfSpec = &loggingv1alpha1.ForwardingSpec{} - generator, err = NewConfigGenerator(true, false, false) - Expect(err).To(BeNil()) - }) - - It("should produce well formed legacy output label config", func() { - legacyConf := ` + var ( + err error + lfSpec *loggingv1alpha1.ForwardingSpec + generator *ConfigGenerator + ) + + Context("based on legacy fluentd forward method", func() { + BeforeEach(func() { + lfSpec = &loggingv1alpha1.ForwardingSpec{} + generator, err = NewConfigGenerator(true, false, false) + Expect(err).To(BeNil()) + }) + + It("should produce well formed legacy output label config", func() { + legacyConf := ` ## CLO GENERATED CONFIGURATION ### # This file is a copy of the fluentd configuration entrypoint # which should normally be supplied in a configmap. @@ -300,7 +300,14 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func() remove_keys req,res,msg,name,level,v,pid,err - + + @type record_transformer + enable_ruby + + k8s_audit_level ${record['level']} + level info + + @type viaq_data_model elasticsearch_index_prefix_field 'viaq_index_name' @@ -453,21 +460,21 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func() ` - results, err := generator.Generate(lfSpec) - Expect(err).Should(Succeed()) - test.Expect(results).ToEqual(legacyConf) - }) - }) - - Context("based on legacy syslog method", func() { - BeforeEach(func() { - lfSpec = &loggingv1alpha1.ForwardingSpec{} - generator, err = NewConfigGenerator(false, true, false) - Expect(err).To(BeNil()) - }) - - It("should produce well formed legacy output label config", func() { - legacyConf := ` + results, err := generator.Generate(lfSpec) + Expect(err).Should(Succeed()) + test.Expect(results).ToEqual(legacyConf) + }) + }) + + Context("based on legacy syslog method", func() { + BeforeEach(func() { + lfSpec = &loggingv1alpha1.ForwardingSpec{} + generator, err = NewConfigGenerator(false, true, false) + Expect(err).To(BeNil()) + }) + + It("should produce well formed legacy output label config", func() { + legacyConf := ` ## CLO GENERATED CONFIGURATION ### # This file is a copy of the fluentd configuration entrypoint # which should normally be supplied in a configmap. @@ -744,7 +751,14 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func() remove_keys req,res,msg,name,level,v,pid,err - + + @type record_transformer + enable_ruby + + k8s_audit_level ${record['level']} + level info + + @type viaq_data_model elasticsearch_index_prefix_field 'viaq_index_name' @@ -898,21 +912,21 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func() ` - results, err := generator.Generate(lfSpec) - Expect(err).Should(Succeed()) - test.Expect(results).ToEqual(legacyConf) - }) - }) - - Context("based on legacy syslog and fluentd forward method", func() { - BeforeEach(func() { - lfSpec = &loggingv1alpha1.ForwardingSpec{} - generator, err = NewConfigGenerator(true, true, false) - Expect(err).To(BeNil()) - }) - - It("should produce well formed legacy output label config", func() { - legacyConf := ` + results, err := generator.Generate(lfSpec) + Expect(err).Should(Succeed()) + test.Expect(results).ToEqual(legacyConf) + }) + }) + + Context("based on legacy syslog and fluentd forward method", func() { + BeforeEach(func() { + lfSpec = &loggingv1alpha1.ForwardingSpec{} + generator, err = NewConfigGenerator(true, true, false) + Expect(err).To(BeNil()) + }) + + It("should produce well formed legacy output label config", func() { + legacyConf := ` ## CLO GENERATED CONFIGURATION ### # This file is a copy of the fluentd configuration entrypoint # which should normally be supplied in a configmap. @@ -1189,7 +1203,14 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func() remove_keys req,res,msg,name,level,v,pid,err - + + @type record_transformer + enable_ruby + + k8s_audit_level ${record['level']} + level info + + @type viaq_data_model elasticsearch_index_prefix_field 'viaq_index_name' @@ -1362,9 +1383,9 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func() ` - results, err := generator.Generate(lfSpec) - Expect(err).Should(Succeed()) - test.Expect(results).ToEqual(legacyConf) - }) - }) + results, err := generator.Generate(lfSpec) + Expect(err).Should(Succeed()) + test.Expect(results).ToEqual(legacyConf) + }) + }) }) diff --git a/pkg/generators/forwarding/fluentd/templates.go b/pkg/generators/forwarding/fluentd/templates.go index 610f5eab51..2dae6f0eaf 100644 --- a/pkg/generators/forwarding/fluentd/templates.go +++ b/pkg/generators/forwarding/fluentd/templates.go @@ -208,6 +208,15 @@ const fluentConfTemplate = `{{- define "fluentConf" -}} remove_keys req,res,msg,name,level,v,pid,err + + @type record_transformer + enable_ruby + + k8s_audit_level ${record['level']} + level info + + + @type viaq_data_model elasticsearch_index_prefix_field 'viaq_index_name'