From f4ed7b35205e87001e715ee7b0ac223f2f23e7da Mon Sep 17 00:00:00 2001 From: "Thibault \"bui\" Koechlin" Date: Thu, 25 Apr 2024 13:43:38 +0200 Subject: [PATCH] Truncate meta data (#2966) * truncate meta-data if they are too big --- pkg/database/alerts.go | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/pkg/database/alerts.go b/pkg/database/alerts.go index 0502c2531..5559cbb39 100644 --- a/pkg/database/alerts.go +++ b/pkg/database/alerts.go @@ -636,14 +636,24 @@ func (c *Client) createAlertChunk(machineID string, owner *ent.Machine, alerts [ if len(alertItem.Meta) > 0 { metaBulk := make([]*ent.MetaCreate, len(alertItem.Meta)) for i, metaItem := range alertItem.Meta { + key := metaItem.Key + value := metaItem.Value + if len(metaItem.Value) > 4095 { + c.Log.Warningf("truncated meta %s : value too long", metaItem.Key) + value = value[:4095] + } + if len(metaItem.Key) > 255 { + c.Log.Warningf("truncated meta %s : key too long", metaItem.Key) + key = key[:255] + } metaBulk[i] = c.Ent.Meta.Create(). - SetKey(metaItem.Key). - SetValue(metaItem.Value) + SetKey(key). + SetValue(value) } metas, err = c.Ent.Meta.CreateBulk(metaBulk...).Save(c.CTX) if err != nil { - return nil, errors.Wrapf(BulkError, "creating alert meta: %s", err) + c.Log.Warningf("error creating alert meta: %s", err) } }