-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sketch out implementation for Go custom plugins to support OTel exten…
…sions
- Loading branch information
1 parent
58c1330
commit 8d46b52
Showing
8 changed files
with
309 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
#!/bin/bash | ||
|
||
# !! TODO: move to a Makefile | ||
|
||
CGO_CFLAGS="-I${HOME}/src/fluent-bit/include -I${HOME}/src/fluent-bit/lib/monkey/include -I${HOME}/src/fluent-bit/build/lib/monkey/include/monkey -I${HOME}/src/fluent-bit/lib/cfl/include -I${HOME}/src/fluent-bit/lib/cfl/lib/xxhash -I${HOME}/src/fluent-bit/lib/cmetrics/include -I${HOME}/src/fluent-bit/lib/flb_libco -I${HOME}/src/fluent-bit/lib/c-ares-1.33.1/include -I${HOME}/src/fluent-bit/lib/msgpack-c/include -I${HOME}/src/fluent-bit/lib/ctraces/include -I${HOME}/src/fluent-bit/lib/ctraces/lib/mpack/src" CGO_LDFLAGS="-L${HOME}/src/fluent-bit/build/lib -lfluent-bit" sh -c 'echo CGO_CFLAGS=${CGO_CFLAGS}; echo CGO_LDFLAGS=${CGO_LDFLAGS}; go build -buildmode=c-shared -o build/bin/custom_extensions_go.so github.com/fluent/fluent-bit/plugins/custom_extensions_go' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
module github.com/fluent/fluent-bit | ||
|
||
go 1.23.0 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
// Fluent Bit Go! | ||
// ============== | ||
// Copyright (C) 2024 The Fluent Bit Go Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// | ||
|
||
package main | ||
|
||
// #include <stdlib.h> | ||
// #include "fluent-bit/flb_plugin.h" | ||
// #include "fluent-bit/flb_plugin_proxy.h" | ||
// #include "fluent-bit/flb_custom.h" | ||
import "C" | ||
|
||
import ( | ||
"fmt" | ||
"time" | ||
"unsafe" | ||
) | ||
|
||
// Define constants matching Fluent Bit core | ||
const ( | ||
FLB_ERROR = C.FLB_ERROR | ||
FLB_OK = C.FLB_OK | ||
FLB_RETRY = C.FLB_RETRY | ||
|
||
FLB_PROXY_CUSTOM_PLUGIN = C.FLB_CF_CUSTOM | ||
FLB_PROXY_GOLANG = C.FLB_PROXY_GOLANG | ||
) | ||
|
||
// Local type to define a plugin definition | ||
type ( | ||
FLBPluginProxyDef C.struct_flb_plugin_proxy_def | ||
FLBCustomInstance C.struct_flb_custom_instance | ||
) | ||
|
||
// When the FLBPluginInit is triggered by Fluent Bit, a plugin context | ||
// is passed and the next step is to invoke this FLBPluginRegister() function | ||
// to fill the required information: type, proxy type, flags name and | ||
// description. | ||
// | ||
//export FLBPluginRegister | ||
func FLBPluginRegister(def unsafe.Pointer, name, desc string) int { | ||
p := (*FLBPluginProxyDef)(def) | ||
p._type = FLB_PROXY_CUSTOM_PLUGIN | ||
p.proxy = FLB_PROXY_GOLANG | ||
p.flags = 0 | ||
p.name = C.CString(name) | ||
p.description = C.CString(desc) | ||
return 0 | ||
} | ||
|
||
// (fluentbit will call this) | ||
// plugin (context) pointer to fluentbit context (state/ c code) | ||
// | ||
//export FLBPluginInit | ||
func FLBPluginInit(plugin unsafe.Pointer) int { | ||
extensions := FLBPluginConfigKey(plugin, "extensions") | ||
fmt.Printf("[flb-go] extensions = '%s'\n", extensions) | ||
go func() { | ||
for { | ||
fmt.Printf("[flb-go] Go extensions alive %v\n", time.Now()) | ||
time.Sleep(10 * time.Second) | ||
} | ||
}() | ||
return FLB_OK | ||
} | ||
|
||
// Release resources allocated by the plugin initialization | ||
// | ||
//export FLBPluginUnregister | ||
func FLBPluginUnregister(def unsafe.Pointer) { | ||
p := (*FLBPluginProxyDef)(def) | ||
C.free(unsafe.Pointer(p.name)) | ||
C.free(unsafe.Pointer(p.description)) | ||
} | ||
|
||
//export FLBPluginExit | ||
func FLBPluginExit() int { | ||
return FLB_OK | ||
} | ||
|
||
func FLBPluginConfigKey(plugin unsafe.Pointer, key string) string { | ||
k := C.CString(key) | ||
p := plugin | ||
v := C.GoString(C.flb_custom_get_property(k, (*C.struct_flb_custom_instance)(p))) | ||
C.free(unsafe.Pointer(k)) | ||
return v | ||
} | ||
|
||
func main() { | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters