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

Bug 1881996: fix legacy syslog k8s Metadata #721

Merged
merged 1 commit into from
Oct 9, 2020
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
16 changes: 16 additions & 0 deletions pkg/generators/forwarding/fluentd/fluent_conf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,14 @@ var _ = Describe("Generating fluentd config", func() {
</record>
remove_keys req,res,msg,name,level,v,pid,err
</filter>
<filter k8s-audit.log**>
@type record_transformer
enable_ruby
<record>
k8s_audit_level ${record['level']}
level info
</record>
</filter>
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

indent issue

<filter **>
@type viaq_data_model
elasticsearch_index_prefix_field 'viaq_index_name'
Expand Down Expand Up @@ -762,6 +770,14 @@ var _ = Describe("Generating fluentd config", func() {
</record>
remove_keys req,res,msg,name,level,v,pid,err
</filter>
<filter k8s-audit.log**>
@type record_transformer
enable_ruby
<record>
k8s_audit_level ${record['level']}
level info
</record>
</filter>
<filter **>
@type viaq_data_model
elasticsearch_index_prefix_field 'viaq_index_name'
Expand Down
135 changes: 78 additions & 57 deletions pkg/generators/forwarding/fluentd/output_conf_legacy_test.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -300,7 +300,14 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func()
</record>
remove_keys req,res,msg,name,level,v,pid,err
</filter>

<filter k8s-audit.log**>
@type record_transformer
enable_ruby
<record>
k8s_audit_level ${record['level']}
level info
</record>
</filter>
<filter **>
@type viaq_data_model
elasticsearch_index_prefix_field 'viaq_index_name'
Expand Down Expand Up @@ -453,21 +460,21 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func()
</label>
`

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.
Expand Down Expand Up @@ -744,7 +751,14 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func()
</record>
remove_keys req,res,msg,name,level,v,pid,err
</filter>

<filter k8s-audit.log**>
@type record_transformer
enable_ruby
<record>
k8s_audit_level ${record['level']}
level info
</record>
</filter>
<filter **>
@type viaq_data_model
elasticsearch_index_prefix_field 'viaq_index_name'
Expand Down Expand Up @@ -898,21 +912,21 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func()
</label>
`

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.
Expand Down Expand Up @@ -1189,7 +1203,14 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func()
</record>
remove_keys req,res,msg,name,level,v,pid,err
</filter>

<filter k8s-audit.log**>
@type record_transformer
enable_ruby
<record>
k8s_audit_level ${record['level']}
level info
</record>
</filter>
<filter **>
@type viaq_data_model
elasticsearch_index_prefix_field 'viaq_index_name'
Expand Down Expand Up @@ -1362,9 +1383,9 @@ var _ = Describe("Generating fluentd legacy output store config blocks", func()
</label>
`

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)
})
})
})
9 changes: 9 additions & 0 deletions pkg/generators/forwarding/fluentd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,15 @@ const fluentConfTemplate = `{{- define "fluentConf" -}}
remove_keys req,res,msg,name,level,v,pid,err
</filter>

<filter k8s-audit.log**>
@type record_transformer
enable_ruby
<record>
k8s_audit_level ${record['level']}
level info
</record>
</filter>

<filter **>
@type viaq_data_model
elasticsearch_index_prefix_field 'viaq_index_name'
Expand Down