Truncate meta data (#2966)

* truncate meta-data if they are too big
This commit is contained in:
Thibault "bui" Koechlin 2024-04-25 13:43:38 +02:00 committed by GitHub
parent 60431804d8
commit f4ed7b3520
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -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)
}
}