Skip to content

Config files are included in arbitrary order when using @INCLUDE command with a wildcardΒ #5612

@lht

Description

@lht

Bug Report

Describe the bug
Config files are included in arbitrary order when using @INCLUDE command with wildcard characters

To Reproduce

Populate some config files.

cat <<EOF > /tmp/flb-20.conf
[FILTER]
  Name modify
  Alias rename_key
  Match *
  Condition Key_exists service
  rename service svc
EOF

cat <<EOF > /tmp/flb-10.conf
[FILTER]
  Name modify
  Alias add_key
  Match *
  Condition Key_exists tool
  Add service hello
EOF

Confirm the files are listed in the order such as:

# ls --sort=none /tmp | grep ^flb.*conf
flb-20.conf
flb-10.conf

Main configuration file: main.conf

[SERVICE]
  Flush           5
  Daemon          off

[INPUT]
  Name dummy
  Dummy  {"tool": "fluent"}
  Tag dummy

[OUTPUT]
  Name stdout
  Match *

@INCLUDE /tmp/flb-*.conf

Start fluent-bit,

# /fluent-bit/bin/fluent-bit -c main.conf
Fluent Bit v1.9.5
* Copyright (C) 2015-2022 The Fluent Bit Authors
* Fluent Bit is a CNCF sub-project under the umbrella of Fluentd
* https://fluentbit.io

[2022/06/22 12:34:50] [ info] [fluent bit] version=1.9.5, commit=9ec43447b6, pid=163
[2022/06/22 12:34:50] [ info] [storage] version=1.2.0, type=memory-only, sync=normal, checksum=disabled, max_chunks_up=128
[2022/06/22 12:34:50] [ info] [cmetrics] version=0.3.4
[2022/06/22 12:34:50] [ info] [sp] stream processor started
[2022/06/22 12:34:50] [ info] [output:stdout:stdout.0] worker #0 started
[0] dummy: [1655901290.831520000, {"tool"=>"fluent", "service"=>"hello"}]
...

Expected behavior
Expect flb-10.conf is included before flb-20.conf and a field svc=>hello exists in the final event.

[0] dummy: [1655901294.831573400, {"tool"=>"fluent", "svc"=>"hello"}]

Also in the step of populating the config files, If flb-10.conf is created before flb-20.conf, we get the expected result.

Your Environment

  • Version used: 1.9.5
  • Operating System and version
    Linux 674dd909c68f 5.10.76-linuxkit #1 SMP Mon Nov 8 10:21:19 UTC 2021 x86_64 GNU/Linux

Additional context

We have multiple configuration files for our Kubernetes clusters and we combine them with Kustomize configmapGenerator. Wildcard is used in @INCLUDE command because different clusters require different combinations of config files. We need certain config files be included in determined order and expect the glob matched files are sorted by name.

GLOB_NOSORT is used when globing the files

ret_glb = glob(glb_path, GLOB_NOSORT, NULL, &glb);

This probably is not needed. According to https://man7.org/linux/man-pages/man3/glob.3.html

   GLOB_NOSORT
          Don't sort the returned pathnames.  The only reason to do
          this is to save processing time.  By default, the returned
          pathnames are sorted.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions