Skip to content

Unable to read environment variable values through the FLB_ENV table in Lua Scripts #10432

@nilushancosta

Description

@nilushancosta

Bug Report

Describe the bug
I want to pass values to Lua scipts through environment variables. I found that this capability was introduced through #9617. So I tried to access env variables through the FLB_ENV table. However the values weren't readable through this table.

To Reproduce
I was able to reproduce this behaviour using the following. This reproduces the example given in #9617. But this time I used the Helm chart.

  • Steps to reproduce the problem:
    Install fluent bit with the following Helm values file.
    helm install fluent-bit fluent/fluent-bit -f values.yaml
config:
  inputs: |
    [INPUT]
        Name    random
        Samples 10
        Tag     test

  filters: |
    [FILTER]
        Name  lua
        Match *
        Call  append_tag
        Script /fluent-bit/scripts/test.lua
            
  outputs: |
    [OUTPUT]
        Name  stdout
        Match *

env:
- name: A
  value: "aaa"
- name: B
  value: "bbb"
- name: C
  value: "ccc"

luaScripts:
  test.lua: |
    function append_tag(tag, timestamp, record)
        new_record = record
        new_record["my_env"] = FLB_ENV
        return 1, timestamp, new_record 
    end

Expected behavior
I expected the environment variables passed through env to be added to the my_env field. However that field was empty in the output. The outputs were like this

[0] test: [[1749063484.893196105, {}], {"rand_value"=>-9223372036854775808, "my_env"=>{}}]

Screenshots

Your Environment

  • Version used: v4.0.1
  • Configuration:
  • Environment name and version (e.g. Kubernetes? What version?): Kubernetes v1.32.4+k3s1
  • Server type and version:
  • Operating System and version:
  • Filters and plugins: random, lua, stdout

Additional context

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