Alerting: Persist annotations from multidimensional rules in batches (#56575)
* Reduce piecemeal state fields * Read data directly off state instead of rule * Unify state and context into single struct * Expose contextual information to layer above setNextState * Work in terms of ContextualState and call historian in batches * Call annotations service in batches * Export format state and reason and remove workaround in unrelated test package * Add new method to annotation service for batch inserting * Fix loop variable aliasing bug caught by linter, didn't change behavior * Incl timerange on annotation tests * Insert one at a time if tags are present * Point to rule from ContextualState rather than copy fields * Build annotations and copy data prior to starting goroutine * Rename to StateTransition * Use new bulk-insert utility * Remove rule from StateTransition and pass in directly to historian * Simplify annotations logic since we have only one rule * Fix logs and context, nilcheck, simplify method name * Regenerate mock
This commit is contained in:
@@ -163,6 +163,47 @@ func TestIntegrationAnnotations(t *testing.T) {
|
||||
require.Error(t, err)
|
||||
require.ErrorIs(t, err, annotations.ErrBaseTagLimitExceeded)
|
||||
|
||||
t.Run("Can batch-insert annotations", func(t *testing.T) {
|
||||
count := 10
|
||||
items := make([]annotations.Item, count)
|
||||
for i := 0; i < count; i++ {
|
||||
items[i] = annotations.Item{
|
||||
OrgId: 100,
|
||||
Type: "batch",
|
||||
Epoch: 12,
|
||||
}
|
||||
}
|
||||
|
||||
err := repo.AddMany(context.Background(), items)
|
||||
|
||||
require.NoError(t, err)
|
||||
query := &annotations.ItemQuery{OrgId: 100, SignedInUser: testUser}
|
||||
inserted, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, inserted, count)
|
||||
})
|
||||
|
||||
t.Run("Can batch-insert annotations with tags", func(t *testing.T) {
|
||||
count := 10
|
||||
items := make([]annotations.Item, count)
|
||||
for i := 0; i < count; i++ {
|
||||
items[i] = annotations.Item{
|
||||
OrgId: 101,
|
||||
Type: "batch",
|
||||
Epoch: 12,
|
||||
}
|
||||
}
|
||||
items[0].Tags = []string{"type:test"}
|
||||
|
||||
err := repo.AddMany(context.Background(), items)
|
||||
|
||||
require.NoError(t, err)
|
||||
query := &annotations.ItemQuery{OrgId: 101, SignedInUser: testUser}
|
||||
inserted, err := repo.Get(context.Background(), query)
|
||||
require.NoError(t, err)
|
||||
assert.Len(t, inserted, count)
|
||||
})
|
||||
|
||||
t.Run("Can query for annotation by id", func(t *testing.T) {
|
||||
items, err := repo.Get(context.Background(), &annotations.ItemQuery{
|
||||
OrgId: 1,
|
||||
@@ -448,6 +489,7 @@ func TestIntegrationAnnotationListingWithRBAC(t *testing.T) {
|
||||
OrgId: 1,
|
||||
DashboardId: 2,
|
||||
Epoch: 10,
|
||||
Tags: []string{"foo:bar"},
|
||||
}
|
||||
err = repo.Add(context.Background(), dash2Annotation)
|
||||
require.NoError(t, err)
|
||||
|
||||
Reference in New Issue
Block a user