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

Remove Duplicate Cluster parsers in Fluent-bit config. #853

Merged
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
6 changes: 3 additions & 3 deletions apis/fluentbit/v1alpha2/clusterfluentbitconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -280,8 +280,8 @@ func (cfg ClusterFluentBitConfig) RenderMainConfig(sl plugins.SecretLoader, inpu
func (cfg ClusterFluentBitConfig) RenderParserConfig(sl plugins.SecretLoader, parsers ClusterParserList, nsParserLists []ParserList,
nsClusterParserLists []ClusterParserList) (string, error) {
var buf bytes.Buffer

parserSections, err := parsers.Load(sl)
existingParsers := make(map[string]bool)
parserSections, err := parsers.Load(sl, existingParsers)
if err != nil {
return "", err
}
Expand All @@ -304,7 +304,7 @@ func (cfg ClusterFluentBitConfig) RenderParserConfig(sl plugins.SecretLoader, pa
}

for _, item := range nsClusterParserLists {
nsClusterParserSections, err := item.Load(sl)
nsClusterParserSections, err := item.Load(sl, existingParsers)
if err != nil {
return "", err
}
Expand Down
7 changes: 5 additions & 2 deletions apis/fluentbit/v1alpha2/clusterparser_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,14 @@ func (a ParserByName) Len() int { return len(a) }
func (a ParserByName) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a ParserByName) Less(i, j int) bool { return a[i].Name < a[j].Name }

func (list ClusterParserList) Load(sl plugins.SecretLoader) (string, error) {
func (list ClusterParserList) Load(sl plugins.SecretLoader, existingParsers map[string]bool) (string, error) {
var buf bytes.Buffer

sort.Sort(ParserByName(list.Items))

for _, item := range list.Items {
if existingParsers[item.Name] {
continue
}
merge := func(p plugins.Plugin) error {
if p == nil || reflect.ValueOf(p).IsNil() {
return nil
Expand All @@ -117,6 +119,7 @@ func (list ClusterParserList) Load(sl plugins.SecretLoader) (string, error) {
buf.WriteString(fmt.Sprintf(" Decode_Field_As %s\n", decorder.DecodeFieldAs))
}
}
existingParsers[item.Name] = true
return nil
}

Expand Down
Loading