Alerting: Store instance annotations in alert rule state (#114975)

Alerting: Store annotations in alert instance state
This commit is contained in:
Alexander Akhmetov
2025-12-09 13:52:42 +01:00
committed by GitHub
parent 6746c978b4
commit c59d5d1c8e
17 changed files with 258 additions and 109 deletions
@@ -0,0 +1,34 @@
package models
import (
"encoding/json"
)
// InstanceAnnotations is an extension to map[string]string with methods
// for database serialization.
type InstanceAnnotations map[string]string
// FromDB loads annotations stored in the database as JSON into InstanceAnnotations.
// FromDB is part of the xorm Conversion interface.
func (a *InstanceAnnotations) FromDB(b []byte) error {
if len(b) == 0 {
*a = nil
return nil
}
annotations := make(map[string]string)
err := json.Unmarshal(b, &annotations)
if err != nil {
return err
}
*a = annotations
return nil
}
// ToDB serializes InstanceAnnotations to JSON for database storage.
// ToDB is part of the xorm Conversion interface.
func (a *InstanceAnnotations) ToDB() ([]byte, error) {
if a == nil || len(*a) == 0 {
return nil, nil
}
return json.Marshal(*a)
}