mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
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:
parent
0aeee7f265
commit
1381fb6dfc
@ -78,7 +78,10 @@ func (r *xormRepositoryImpl) AddMany(ctx context.Context, items []annotations.It
|
|||||||
hasTags := make([]annotations.Item, 0)
|
hasTags := make([]annotations.Item, 0)
|
||||||
hasNoTags := 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)
|
tags := tag.ParseTagPairs(item.Tags)
|
||||||
item.Tags = tag.JoinTagPairs(tags)
|
item.Tags = tag.JoinTagPairs(tags)
|
||||||
item.Created = timeNow().UnixNano() / int64(time.Millisecond)
|
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 {
|
if item.Epoch == 0 {
|
||||||
item.Epoch = item.Created
|
item.Epoch = item.Created
|
||||||
}
|
}
|
||||||
if err := r.validateItem(&items[i]); err != nil {
|
if err := r.validateItem(item); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(item.Tags) > 0 {
|
if len(item.Tags) > 0 {
|
||||||
hasTags = append(hasTags, item)
|
hasTags = append(hasTags, *item)
|
||||||
} else {
|
} else {
|
||||||
hasNoTags = append(hasNoTags, item)
|
hasNoTags = append(hasNoTags, *item)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -185,6 +185,11 @@ func TestIntegrationAnnotations(t *testing.T) {
|
|||||||
inserted, err := repo.Get(context.Background(), query)
|
inserted, err := repo.Get(context.Background(), query)
|
||||||
require.NoError(t, err)
|
require.NoError(t, err)
|
||||||
assert.Len(t, inserted, count)
|
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) {
|
t.Run("Can batch-insert annotations with tags", func(t *testing.T) {
|
||||||
|
Loading…
Reference in New Issue
Block a user