Skip to content

Commit

Permalink
add wasm filter piugin
Browse files Browse the repository at this point in the history
Signed-off-by: jiuxia211 <[email protected]>
  • Loading branch information
jiuxia211 committed Aug 28, 2024
1 parent 51ad7fd commit 9d379d2
Show file tree
Hide file tree
Showing 16 changed files with 7,506 additions and 0 deletions.
2 changes: 2 additions & 0 deletions apis/fluentbit/v1alpha2/clusterfilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,8 @@ type FilterItem struct {
Multiline *filter.Multiline `json:"multiline,omitempty"`
// LogToMetrics defines a Log to Metrics Filter configuration.
LogToMetrics *filter.LogToMetrics `json:"logToMetrics,omitempty"`
// Wasm defines a Wasm configuration.
Wasm *filter.Wasm `json:"wasm,omitempty"`
// CustomPlugin defines a Custom plugin configuration.
CustomPlugin *custom.CustomPlugin `json:"customPlugin,omitempty"`
}
Expand Down
2 changes: 2 additions & 0 deletions apis/fluentbit/v1alpha2/fluentbit_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ type FluentBitSpec struct {
SchedulerName string `json:"schedulerName,omitempty"`
// Optional duration in seconds the pod needs to terminate gracefully. Value must be non-negative integer.
TerminationGracePeriodSeconds *int64 `json:"terminationGracePeriodSeconds,omitempty"`
// Storage for wasm file. You will use it if wasm filter is enabled.
WasmFile corev1.VolumeSource `json:"wasmFile,omitempty"`
}

// FluentBitService defines the service of the FluentBit
Expand Down
62 changes: 62 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/filter/wasm.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package filter

import (
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins"
"github.com/fluent/fluent-operator/v2/apis/fluentbit/v1alpha2/plugins/params"
)

// +kubebuilder:object:generate:=true

// Wasm Filter allows you to modify the incoming records using Wasm technology.
// **For full documentation, refer to https://docs.fluentbit.io/manual/pipeline/filters/wasm**
type Wasm struct {
plugins.CommonParams `json:",inline"`
// Path to the built Wasm program that will be used. This can be a relative path against the main configuration file.
WasmPath string `json:"wasmPath,omitempty"`
// Define event format to interact with Wasm programs: msgpack or json. Default: json
EventFormat string `json:"eventFormat,omitempty"`
// Wasm function name that will be triggered to do filtering. It's assumed that the function is built inside the Wasm program specified above.
FunctionName string `json:"functionName,omitempty"`
// Specify the whitelist of paths to be able to access paths from WASM programs.
AccessiblePaths string `json:"accessiblePaths,omitempty"`
// Size of the heap size of Wasm execution. Review unit sizes for allowed values.
// +kubebuilder:validation:Pattern:="^\\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$"
WasmHeapSize string `json:"wasmHeapSize,omitempty"`
// Size of the stack size of Wasm execution. Review unit sizes for allowed values.
// +kubebuilder:validation:Pattern:="^\\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$"
WasmStackSize string `json:"wasmStackSize,omitempty"`
}

// Name is the name of the filter plugin.
func (*Wasm) Name() string {
return "wasm"
}

// Params represents the config options for the filter plugin.
func (w *Wasm) Params(_ plugins.SecretLoader) (*params.KVs, error) {
kvs := params.NewKVs()
err := w.AddCommonParams(kvs)
if err != nil {
return kvs, err
}
if w.WasmPath != "" {
kvs.Insert("Wasm_Path", w.WasmPath)
}
if w.EventFormat != "" {
kvs.Insert("EventFormat", w.EventFormat)
}
if w.FunctionName != "" {
kvs.Insert("Function_Name", w.FunctionName)
}
if w.AccessiblePaths != "" {
kvs.Insert("Accessible_Paths", w.AccessiblePaths)
}
if w.WasmHeapSize != "" {
kvs.Insert("Wasm_Heap_Size", w.WasmHeapSize)
}
if w.WasmStackSize != "" {
kvs.Insert("Wasm_Stack_Size", w.WasmStackSize)
}

return kvs, nil
}
16 changes: 16 additions & 0 deletions apis/fluentbit/v1alpha2/plugins/filter/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions apis/fluentbit/v1alpha2/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,51 @@ spec:
format: int64
type: integer
type: object
wasm:
description: Wasm defines a Wasm configuration.
properties:
accessiblePaths:
description: Specify the whitelist of paths to be able to
access paths from WASM programs.
type: string
alias:
description: Alias for the plugin
type: string
eventFormat:
description: 'Define event format to interact with Wasm
programs: msgpack or json. Default: json'
type: string
functionName:
description: Wasm function name that will be triggered to
do filtering. It's assumed that the function is built
inside the Wasm program specified above.
type: string
retryLimit:
description: 'RetryLimit describes how many times fluent-bit
should retry to send data to a specific output. If set
to false fluent-bit will try indefinetly. If set to any
integer N>0 it will try at most N+1 times. Leading zeros
are not allowed (values such as 007, 0150, 01 do not work).
If this property is not defined fluent-bit will use the
default value: 1.'
pattern: ^(((f|F)alse)|(no_limits)|(no_retries)|([1-9]+[0-9]*))$
type: string
wasmHeapSize:
description: Size of the heap size of Wasm execution. Review
unit sizes for allowed values.
pattern: ^\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$
type: string
wasmPath:
description: Path to the built Wasm program that will be
used. This can be a relative path against the main configuration
file.
type: string
wasmStackSize:
description: Size of the stack size of Wasm execution. Review
unit sizes for allowed values.
pattern: ^\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$
type: string
type: object
type: object
type: array
logLevel:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -879,6 +879,51 @@ spec:
format: int64
type: integer
type: object
wasm:
description: Wasm defines a Wasm configuration.
properties:
accessiblePaths:
description: Specify the whitelist of paths to be able to
access paths from WASM programs.
type: string
alias:
description: Alias for the plugin
type: string
eventFormat:
description: 'Define event format to interact with Wasm
programs: msgpack or json. Default: json'
type: string
functionName:
description: Wasm function name that will be triggered to
do filtering. It's assumed that the function is built
inside the Wasm program specified above.
type: string
retryLimit:
description: 'RetryLimit describes how many times fluent-bit
should retry to send data to a specific output. If set
to false fluent-bit will try indefinetly. If set to any
integer N>0 it will try at most N+1 times. Leading zeros
are not allowed (values such as 007, 0150, 01 do not work).
If this property is not defined fluent-bit will use the
default value: 1.'
pattern: ^(((f|F)alse)|(no_limits)|(no_retries)|([1-9]+[0-9]*))$
type: string
wasmHeapSize:
description: Size of the heap size of Wasm execution. Review
unit sizes for allowed values.
pattern: ^\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$
type: string
wasmPath:
description: Path to the built Wasm program that will be
used. This can be a relative path against the main configuration
file.
type: string
wasmStackSize:
description: Size of the stack size of Wasm execution. Review
unit sizes for allowed values.
pattern: ^\d+(k|K|KB|kb|m|M|MB|mb|g|G|GB|gb)?$
type: string
type: object
type: object
type: array
logLevel:
Expand Down
Loading

0 comments on commit 9d379d2

Please sign in to comment.