[v10.4.x] Annotations: Fix composite store read (#94179)

* Annotations: Fix composite store read (#94158)

* Annotations: Fix composite store read

* Add test

* check error

(cherry picked from commit bd1741653d)

* re-format
This commit is contained in:
Alexander Zobnin
2024-10-04 11:02:05 +02:00
committed by GitHub
parent 8db7d753cb
commit e8b2507d97
10 changed files with 91 additions and 68 deletions
@@ -8,23 +8,21 @@ import (
"sort"
"time"
"github.com/prometheus/client_golang/prometheus"
"golang.org/x/exp/constraints"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
"github.com/grafana/grafana/pkg/services/annotations"
"github.com/grafana/grafana/pkg/services/annotations/accesscontrol"
"github.com/grafana/grafana/pkg/services/featuremgmt"
"github.com/grafana/grafana/pkg/services/ngalert"
"golang.org/x/exp/constraints"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
ngmetrics "github.com/grafana/grafana/pkg/services/ngalert/metrics"
ngmodels "github.com/grafana/grafana/pkg/services/ngalert/models"
"github.com/grafana/grafana/pkg/services/ngalert/state"
"github.com/grafana/grafana/pkg/services/ngalert/state/historian"
historymodel "github.com/grafana/grafana/pkg/services/ngalert/state/historian/model"
"github.com/prometheus/client_golang/prometheus"
"github.com/grafana/grafana/pkg/services/annotations"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/util/errutil"
)
@@ -73,7 +71,7 @@ func (r *LokiHistorianStore) Type() string {
return "loki"
}
func (r *LokiHistorianStore) Get(ctx context.Context, query *annotations.ItemQuery, accessResources *accesscontrol.AccessResources) ([]*annotations.ItemDTO, error) {
func (r *LokiHistorianStore) Get(ctx context.Context, query annotations.ItemQuery, accessResources *accesscontrol.AccessResources) ([]*annotations.ItemDTO, error) {
if query.Type == "annotation" {
return make([]*annotations.ItemDTO, 0), nil
}
@@ -96,7 +94,7 @@ func (r *LokiHistorianStore) Get(ctx context.Context, query *annotations.ItemQue
}
}
logQL, err := historian.BuildLogQuery(buildHistoryQuery(query, accessResources.Dashboards, rule.UID))
logQL, err := historian.BuildLogQuery(buildHistoryQuery(&query, accessResources.Dashboards, rule.UID))
if err != nil {
return make([]*annotations.ItemDTO, 0), ErrLokiStoreInternal.Errorf("failed to build loki query: %w", err)
}
@@ -178,7 +176,7 @@ func (r *LokiHistorianStore) annotationsFromStream(stream historian.Stream, ac a
return items
}
func (r *LokiHistorianStore) GetTags(ctx context.Context, query *annotations.TagsQuery) (annotations.FindTagsResult, error) {
func (r *LokiHistorianStore) GetTags(ctx context.Context, query annotations.TagsQuery) (annotations.FindTagsResult, error) {
return annotations.FindTagsResult{Tags: []*annotations.TagsDTO{}}, nil
}
@@ -11,6 +11,9 @@ import (
"testing"
"time"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
"github.com/grafana/grafana/pkg/components/simplejson"
"github.com/grafana/grafana/pkg/infra/db"
"github.com/grafana/grafana/pkg/infra/log"
@@ -28,9 +31,6 @@ import (
historymodel "github.com/grafana/grafana/pkg/services/ngalert/state/historian/model"
"github.com/grafana/grafana/pkg/setting"
"github.com/grafana/grafana/pkg/tests/testsuite"
"github.com/prometheus/client_golang/prometheus"
"github.com/stretchr/testify/require"
)
func TestMain(m *testing.M) {
@@ -100,7 +100,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,
@@ -126,7 +126,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,
@@ -150,7 +150,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,
@@ -176,7 +176,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,
@@ -206,7 +206,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,
@@ -235,7 +235,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,
@@ -269,7 +269,7 @@ func TestIntegrationAlertStateHistoryStore(t *testing.T) {
}
res, err := store.Get(
context.Background(),
&query,
query,
&annotation_ac.AccessResources{
Dashboards: map[string]int64{
dashboard1.UID: dashboard1.ID,