Wasm 입력 플러그인
WebAssembly(Wasm)로 만든 플러그인을 Fluent Bit 입력으로 통합하는 방법을 알려드릴게요. Wasm/WASI 프로그램을 입력 소스로 쓸 수 있답니다.
출처: 문서
본문
WebAssembly(Wasm)는 스택 기반 가상 머신을 위한 이진 명령 형식입니다.
Fluent Bit는 입력과 필터 플러그인에 대해 Wasm/WASI 객체로 빌드된 Wasm 플러그인의 통합을 지원합니다. Wasm 필터 플러그인의 인터페이스는 현재 개발 중이지만 동작은 합니다.
사전 요구 사항 (Prerequisites)
Fluent Bit 빌드
Wasm 플러그인을 실행하는 데 추가 요구 사항은 없습니다.
Wasm 프로그램용
Fluent Bit는 다음 Wasm 툴체인을 지원합니다:
wasm32-wasip1의 Rust- rustc 1.62.1 (
e092d0b6b2022-07-16) 이상
- rustc 1.62.1 (
wasm32-wasi의 TinyGo- v0.24.0 이상
- WASI SDK 13 이상
시작하기 (Get started)
Wasm 지원으로 Fluent Bit를 컴파일하세요. 예:
cd build/
cmake ..
make
컴파일되면 wasm을 처리하는 새 플러그인이 보입니다. 예:
$ bin/fluent-bit -h
Usage: fluent-bit [OPTION]
Inputs
# ... other input plugin stuffs
exec_wasi Exec WASI Input
Filters
# ... other filter plugin stuffs
wasm WASM program filter
입력 플러그인용 Wasm 입력 빌드
Fluent Bit의 Wasm 입력은 Rust 타겟에서 wasm32-wasip1, TinyGo 타겟에서 wasm32-wasi로도 알려진 WASI ABI를 가정합니다.
추가 구성 요소 설치
TinyGo와 WASI SDK는 기본적으로 Wasm 타겟을 지원합니다. Rust의 wasm32-wasip1 타겟을 사용할 때는 rustup을 사용해 설치해야 합니다. 그런 다음 타겟 구성 요소를 다음과 같이 설치합니다:
rustup target add wasm32-wasip1
Wasm/WASI 프로그램 요구 사항
Wasm 입력 플러그인은 WASI main 함수 진입점이 있는 함수를 실행하며, Fluent Bit의 Wasm 입력 플러그인은 Wasm 프로그램의 stdout을 통해 통신합니다.
Wasm 프로그램은 로그를 Fluent Bit에 수집하기 위해 stdout을 처리해야 합니다.
빌드가 완료되면 Wasm/WASI 프로그램이 준비됩니다. 그런 다음 다음 Fluent Bit 구성 중 하나로 해당 프로그램을 실행할 수 있습니다:
{% tabs %} {% tab title="fluent-bit.yaml" %}
pipeline:
inputs:
- name: exec_wasi
tag: exec.wasi.local
wasi_path: /path/to/wasi_built_json.wasm
# For security reasons, WASM/WASI program cannot access its outer world
# without accessible permissions. Uncomment below 'accessible_paths' and
# run Fluent Bit from the 'wasi_path' location:
# accessible_paths /path/to/fluent-bit
outputs:
- name: stdout
match: '*'
{% endtab %}
{% tab title="fluent-bit.conf" %}
[INPUT]
Name exec_wasi
Tag exec.wasi.local
WASI_Path /path/to/wasi_built_json.wasm
# For security reasons, WASM/WASI program cannot access its outer world
# without accessible permissions. Uncomment below 'accessible_paths' and
# run Fluent Bit from the 'wasi_path' location:
# accessible_paths /path/to/fluent-bit
[OUTPUT]
Name stdout
Match *
{% endtab %} {% endtabs %}
구조화된 로그를 처리하는 예는 Rust serde-json 예시를 참고하세요.