From 7104351d20cfef78db4a55eb5231121c5adc30cf Mon Sep 17 00:00:00 2001 From: "renovate[bot]" <29139614+renovate[bot]@users.noreply.github.com> Date: Thu, 26 Oct 2023 09:38:20 +0000 Subject: [PATCH] fix(deps): update github.com/fluent/fluent-bit-go digest to a7a013e --- go.mod | 2 +- go.sum | 4 +- .../fluent/fluent-bit-go/output/decoder.go | 39 +++++++++++++++---- .../fluent/fluent-bit-go/output/flb_output.h | 1 + .../fluent/fluent-bit-go/output/output.go | 26 +++++++++---- vendor/modules.txt | 4 +- 6 files changed, 56 insertions(+), 20 deletions(-) diff --git a/go.mod b/go.mod index fd6104c1c40b..729ee561998a 100644 --- a/go.mod +++ b/go.mod @@ -33,7 +33,7 @@ require ( github.com/facette/natsort v0.0.0-20181210072756-2cd4dd1e2dcb github.com/fatih/color v1.15.0 github.com/felixge/fgprof v0.9.3 - github.com/fluent/fluent-bit-go v0.0.0-20190925192703-ea13c021720c + github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c github.com/fsouza/fake-gcs-server v1.7.0 github.com/go-kit/log v0.2.1 github.com/go-logfmt/logfmt v0.6.0 diff --git a/go.sum b/go.sum index 792b91d419e7..c5e9eceec1cb 100644 --- a/go.sum +++ b/go.sum @@ -579,8 +579,8 @@ github.com/felixge/fgprof v0.9.3 h1:VvyZxILNuCiUCSXtPtYmmtGvb65nqXh2QFWc0Wpf2/g= github.com/felixge/fgprof v0.9.3/go.mod h1:RdbpDgzqYVh/T9fPELJyV7EYJuHB55UTEULNun8eiPw= github.com/felixge/httpsnoop v1.0.3 h1:s/nj+GCswXYzN5v2DpNMuMQYe+0DDwt5WVCU6CWBdXk= github.com/felixge/httpsnoop v1.0.3/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/fluent/fluent-bit-go v0.0.0-20190925192703-ea13c021720c h1:QwbffUs/+ptC4kTFPEN9Ej2latTq3bZJ5HO/OwPXYMs= -github.com/fluent/fluent-bit-go v0.0.0-20190925192703-ea13c021720c/go.mod h1:WQX+afhrekY9rGK+WT4xvKSlzmia9gDoLYu4GGYGASQ= +github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c h1:yKN46XJHYC/gvgH2UsisJ31+n4K3S7QYZSfU2uAWjuI= +github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c/go.mod h1:L92h+dgwElEyUuShEwjbiHjseW410WIcNz+Bjutc8YQ= github.com/flynn/go-shlex v0.0.0-20150515145356-3f9db97f8568/go.mod h1:xEzjJPgXI435gkrCt3MPfRiAkVrwSbHsst4LCFVfpJc= github.com/fogleman/gg v1.2.1-0.20190220221249-0403632d5b90/go.mod h1:R/bRT+9gY/C5z7JzPU0zXsXHKM4/ayA+zqcVNZzPa1k= github.com/form3tech-oss/jwt-go v3.2.2+incompatible/go.mod h1:pbq4aXjuKjdthFRnoDwaVPLA+WlJuPGy+QneDUgJi2k= diff --git a/vendor/github.com/fluent/fluent-bit-go/output/decoder.go b/vendor/github.com/fluent/fluent-bit-go/output/decoder.go index fe2dc960a6fb..ffdf5b3626bc 100644 --- a/vendor/github.com/fluent/fluent-bit-go/output/decoder.go +++ b/vendor/github.com/fluent/fluent-bit-go/output/decoder.go @@ -18,12 +18,13 @@ package output import ( - "unsafe" - "reflect" + "C" "encoding/binary" - "github.com/ugorji/go/codec" + "reflect" "time" - "C" + "unsafe" + + "github.com/ugorji/go/codec" ) type FLBDecoder struct { @@ -54,12 +55,12 @@ func (f FLBTime) UpdateExt(dest interface{}, v interface{}) { panic("unsupported") } -func NewDecoder(data unsafe.Pointer, length int) (*FLBDecoder) { +func NewDecoder(data unsafe.Pointer, length int) *FLBDecoder { var b []byte dec := new(FLBDecoder) dec.handle = new(codec.MsgpackHandle) - dec.handle.SetExt(reflect.TypeOf(FLBTime{}), 0, &FLBTime{}) + dec.handle.SetBytesExt(reflect.TypeOf(FLBTime{}), 0, &FLBTime{}) b = C.GoBytes(data, C.int(length)) dec.mpdec = codec.NewDecoderBytes(b, dec.handle) @@ -77,10 +78,32 @@ func GetRecord(dec *FLBDecoder) (ret int, ts interface{}, rec map[interface{}]in } slice := reflect.ValueOf(m) - t := slice.Index(0).Interface() + if slice.Kind() != reflect.Slice || slice.Len() != 2 { + return -2, 0, nil + } + + var t interface{} + ts = slice.Index(0).Interface() + switch ty := ts.(type) { + case FLBTime: + t = ty + case uint64: + t = ty + case []interface{}: // for Fluent Bit V2 metadata type of format + s := reflect.ValueOf(ty) + if s.Kind() != reflect.Slice || s.Len() < 2 { + return -4, 0, nil + } + t = s.Index(0).Interface() + default: + return -5, 0, nil + } data := slice.Index(1) - map_data := data.Interface().(map[interface{}] interface{}) + map_data, ok := data.Interface().(map[interface{}]interface{}) + if !ok { + return -3, 0, nil + } return 0, t, map_data } diff --git a/vendor/github.com/fluent/fluent-bit-go/output/flb_output.h b/vendor/github.com/fluent/fluent-bit-go/output/flb_output.h index 3a392376998d..b01fd65ab5cc 100644 --- a/vendor/github.com/fluent/fluent-bit-go/output/flb_output.h +++ b/vendor/github.com/fluent/fluent-bit-go/output/flb_output.h @@ -22,6 +22,7 @@ struct flb_api { char *(*output_get_property) (char *, void *); + char *_; }; struct flb_plugin_proxy_context { diff --git a/vendor/github.com/fluent/fluent-bit-go/output/output.go b/vendor/github.com/fluent/fluent-bit-go/output/output.go index bbb10a674d5e..ff9c01baf0cb 100644 --- a/vendor/github.com/fluent/fluent-bit-go/output/output.go +++ b/vendor/github.com/fluent/fluent-bit-go/output/output.go @@ -24,6 +24,7 @@ package output */ import "C" import ( + "sync" "unsafe" ) @@ -64,18 +65,29 @@ func FLBPluginUnregister(def unsafe.Pointer) { func FLBPluginConfigKey(plugin unsafe.Pointer, key string) string { _key := C.CString(key) - return C.GoString(C.output_get_property(_key, plugin)) + value := C.GoString(C.output_get_property(_key, plugin)) + C.free(unsafe.Pointer(_key)) + return value } -var contexts []interface{} +var contexts sync.Map +// FLBPluginSetContext sets the context for plugin to ctx. +// +// Limit FLBPluginSetContext calls to once per plugin instance for best performance. func FLBPluginSetContext(plugin unsafe.Pointer, ctx interface{}) { - i := len(contexts) - contexts = append(contexts, ctx) + // Allocate a byte of memory in the C heap and fill it with '\0', + // then convert its pointer into the C type void*, represented by unsafe.Pointer. + // The C string is not managed by Go GC, so it will not be freed automatically. + i := unsafe.Pointer(C.CString("")) + // uintptr(i) returns the memory address of i, which is unique in the heap. + contexts.Store(uintptr(i), ctx) p := (*FLBOutPlugin)(plugin) - p.context.remote_context = unsafe.Pointer(uintptr(i)) + p.context.remote_context = i } -func FLBPluginGetContext(i unsafe.Pointer) interface{} { - return contexts[int(uintptr(i))] +// FLBPluginGetContext reads the context associated with proxyCtx. +func FLBPluginGetContext(proxyCtx unsafe.Pointer) interface{} { + v, _ := contexts.Load(uintptr(proxyCtx)) + return v } diff --git a/vendor/modules.txt b/vendor/modules.txt index cafc9755c668..eef9d8cd7c6b 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -635,8 +635,8 @@ github.com/felixge/fgprof # github.com/felixge/httpsnoop v1.0.3 ## explicit; go 1.13 github.com/felixge/httpsnoop -# github.com/fluent/fluent-bit-go v0.0.0-20190925192703-ea13c021720c -## explicit +# github.com/fluent/fluent-bit-go v0.0.0-20230731091245-a7a013e2473c +## explicit; go 1.14 github.com/fluent/fluent-bit-go/output # github.com/fsnotify/fsnotify v1.6.0 ## explicit; go 1.16