Skip to content

bug: fluentbit lua filter code fails to generate valid lua code #1692

@v-davegillies-upscale

Description

@v-davegillies-upscale

Describe the issue

I'm attempting to use the lua filter plugin but am seeing this error:

error] [luajit] error loading buffer: [string "fluentbit.lua"]:1: 'end' expected near '<eof>'

To Reproduce

apiVersion: fluentbit.fluent.io/v1alpha2
kind: ClusterFilter
metadata:
  name: my-filter
  labels:
    fluentbit.fluent.io/enabled: "true"
spec:
  match: "*"
  filters:
    - lua:
        code: |
          function cb_print(tag, timestamp, record)
              -- Add cluster and environment metadata
              record["cluster_name"] = os.getenv("CLUSTER_NAME") or "unknown"
              record["environment"] = os.getenv("CLUSTER_ENV") or "unknown"
              record["node_name"] = os.getenv("NODE_NAME") or "unknown"

              -- Add time fields for partitioning
              local t = os.date("*t", timestamp)
              record["year"] = string.format("%04d", t.year)
              record["month"] = string.format("%02d", t.month)
              record["day"] = string.format("%02d", t.day)
              record["hour"] = string.format("%02d", t.hour)
              record["minute"] = string.format("%02d", t.min)

              return 1, timestamp, record
          end
        call: "cb_print"

Expected behavior

That it'll result in valid lua code that fluentbit can use

Your Environment

- Fluent Operator version: 3.4.2
- Container Runtime: ghcr.io/fluent/fluent-operator/fluent-bit:v3.2.10
- Operating system:
- Kernel version:

How did you install fluent operator?

No response

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions