From ed4983d3fdc8897254e0a9bfc03d2a1d8b3a3e2d Mon Sep 17 00:00:00 2001 From: Silvan Date: Wed, 1 Mar 2023 18:05:12 +0100 Subject: [PATCH] fix: emit only if data and marshal invalid metadata * fix(emitter): only emit if there are log records * fix(actions): marshal invalid metadata value into string --- internal/actions/object/metadata.go | 8 ++++++++ internal/logstore/emitters/access/database.go | 3 +++ internal/logstore/emitters/execution/database.go | 3 +++ 3 files changed, 14 insertions(+) diff --git a/internal/actions/object/metadata.go b/internal/actions/object/metadata.go index ba66604f15..0167a1e056 100644 --- a/internal/actions/object/metadata.go +++ b/internal/actions/object/metadata.go @@ -22,6 +22,14 @@ func UserMetadataListFromQuery(c *actions.FieldConfig, metadata *query.UserMetad for i, md := range metadata.Metadata { var value interface{} + if !json.Valid(md.Value) { + var err error + md.Value, err = json.Marshal(string(md.Value)) + if err != nil { + logging.WithError(err).Debug("unable to marshal unknow value") + panic(err) + } + } err := json.Unmarshal(md.Value, &value) if err != nil { logging.WithError(err).Debug("unable to unmarshal into map") diff --git a/internal/logstore/emitters/access/database.go b/internal/logstore/emitters/access/database.go index 494789cdb1..bc121612e3 100644 --- a/internal/logstore/emitters/access/database.go +++ b/internal/logstore/emitters/access/database.go @@ -49,6 +49,9 @@ func (l *databaseLogStorage) QuotaUnit() quota.Unit { } func (l *databaseLogStorage) Emit(ctx context.Context, bulk []logstore.LogRecord) error { + if len(bulk) == 0 { + return nil + } builder := squirrel.Insert(accessLogsTable). Columns( accessTimestampCol, diff --git a/internal/logstore/emitters/execution/database.go b/internal/logstore/emitters/execution/database.go index 499fedd931..106b433200 100644 --- a/internal/logstore/emitters/execution/database.go +++ b/internal/logstore/emitters/execution/database.go @@ -42,6 +42,9 @@ func (l *databaseLogStorage) QuotaUnit() quota.Unit { } func (l *databaseLogStorage) Emit(ctx context.Context, bulk []logstore.LogRecord) error { + if len(bulk) == 0 { + return nil + } builder := squirrel.Insert(executionLogsTable). Columns( executionTimestampCol,