Skip to content

Commit

Permalink
Merge pull request #853 from verrazzano/karak/fix_duplicate_cluster_f…
Browse files Browse the repository at this point in the history
…b_parser

Remove Duplicate Cluster parsers in Fluent-bit config.
  • Loading branch information
benjaminhuo committed Aug 1, 2023
2 parents ae2b1b5 + 0e867b1 commit 03e3df1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
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

0 comments on commit 03e3df1

Please sign in to comment.