[v11.1.x] Annotations: Fix composite store read (#94181)
* Annotations: Fix composite store read (#94158)
* Annotations: Fix composite store read
* Add test
* check error
(cherry picked from commit bd1741653d)
* re-format
* re-format
This commit is contained in:
@@ -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,7 @@ import (
|
||||
"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"
|
||||
@@ -29,8 +30,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/stretchr/testify/require"
|
||||
)
|
||||
|
||||
func TestMain(m *testing.M) {
|
||||
@@ -94,7 +93,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,
|
||||
@@ -120,7 +119,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,
|
||||
@@ -144,7 +143,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,
|
||||
@@ -170,7 +169,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,
|
||||
@@ -200,7 +199,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,
|
||||
@@ -229,7 +228,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,
|
||||
@@ -263,7 +262,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,
|
||||
|
||||
Reference in New Issue
Block a user