Annotations: Fix EpochEnd being zero for Alert-generated annotations (#60931)

* Revert linter suggestion

* Re-add nolint

* Work in terms of pointer rather than copy

* Add tests covering validation

* Add comment
This commit is contained in:
Alexander Weaver
2023-01-04 10:16:54 -06:00
committed by GitHub
parent 0aeee7f265
commit 1381fb6dfc
2 changed files with 12 additions and 4 deletions
@@ -78,7 +78,10 @@ func (r *xormRepositoryImpl) AddMany(ctx context.Context, items []annotations.It
hasTags := make([]annotations.Item, 0)
hasNoTags := make([]annotations.Item, 0)
for i, item := range items {
for i := range items {
// The validation logic needs to work in terms of pointers.
// So, force everything else to work in terms of pointers too, to avoid any implicit extra copying.
item := &items[i]
tags := tag.ParseTagPairs(item.Tags)
item.Tags = tag.JoinTagPairs(tags)
item.Created = timeNow().UnixNano() / int64(time.Millisecond)
@@ -86,14 +89,14 @@ func (r *xormRepositoryImpl) AddMany(ctx context.Context, items []annotations.It
if item.Epoch == 0 {
item.Epoch = item.Created
}
if err := r.validateItem(&items[i]); err != nil {
if err := r.validateItem(item); err != nil {
return err
}
if len(item.Tags) > 0 {
hasTags = append(hasTags, item)
hasTags = append(hasTags, *item)
} else {
hasNoTags = append(hasNoTags, item)
hasNoTags = append(hasNoTags, *item)
}
}