From 34779e8f38cd9d574e7cd6fb2da6a0ab5f3fef38 Mon Sep 17 00:00:00 2001 From: Konstantin Lebedev <9497591+kmlebedev@users.noreply.github.com> Date: Mon, 13 Dec 2021 13:39:39 +0500 Subject: [PATCH] force enable asynchronous I/O sending events to Fluentd --- weed/s3api/s3api_object_handlers.go | 2 +- weed/s3api/s3err/audit_fluent.go | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/weed/s3api/s3api_object_handlers.go b/weed/s3api/s3api_object_handlers.go index 491657f3b..a792dc3d3 100644 --- a/weed/s3api/s3api_object_handlers.go +++ b/weed/s3api/s3api_object_handlers.go @@ -261,7 +261,7 @@ func (s3a *S3ApiServer) DeleteMultipleObjectsHandler(w http.ResponseWriter, r *h } if auditLog != nil { auditLog.Key = entryName - go s3err.PostAccessLog(*auditLog) + s3err.PostAccessLog(*auditLog) } } diff --git a/weed/s3api/s3err/audit_fluent.go b/weed/s3api/s3err/audit_fluent.go index aba3428f6..fcc5f9a0f 100644 --- a/weed/s3api/s3err/audit_fluent.go +++ b/weed/s3api/s3err/audit_fluent.go @@ -67,6 +67,12 @@ func InitAuditLog(config string) { if len(fluentConfig.TagPrefix) == 0 && len(environment) > 0 { fluentConfig.TagPrefix = environment } + fluentConfig.Async = true + fluentConfig.AsyncResultCallback = func(data []byte, err error) { + if err != nil { + glog.Warning("Error while posting log: ", err) + } + } var err error Logger, err = fluent.New(*fluentConfig) if err != nil { @@ -162,11 +168,9 @@ func PostLog(r *http.Request, HTTPStatusCode int, errorCode ErrorCode) { if Logger == nil { return } - go func(log *AccessLog) { - if err := Logger.Post(tag, *log); err != nil { - glog.Warning("Error while posting log: ", err) - } - }(GetAccessLog(r, HTTPStatusCode, errorCode)) + if err := Logger.Post(tag, *GetAccessLog(r, HTTPStatusCode, errorCode)); err != nil { + glog.Warning("Error while posting log: ", err) + } } func PostAccessLog(log AccessLog) {