[v9.3.x] Annotations: Fix EpochEnd being zero for Alert-generated annotations (#60988)
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
(cherry picked from commit 1381fb6dfc)
Co-authored-by: Alexander Weaver <weaver.alex.d@gmail.com>
This commit is contained in:
co-authored by
Alexander Weaver
parent
17882d7c36
commit
b43e6e64e1
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -184,6 +184,11 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
inserted, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, inserted, count)
|
||||
for _, ins := range inserted {
|
||||
require.Equal(t, int64(12), ins.Time)
|
||||
require.Equal(t, int64(12), ins.TimeEnd)
|
||||
require.Equal(t, ins.Created, ins.Updated)
|
||||
}
|
||||
})
|
||||
|
||||
t.Run("Can batch-insert annotations with tags", func(t *testing.T) {
|
||||
|
||||
Reference in New Issue
Block a user