Alerting: Add max limit for Loki query size in state history API (#89646)
* add setting for query limit * update BuildLogQuery to return error if limit is exceeded * move tests for BuildLogQuery to separate suite
This commit is contained in:
@@ -45,6 +45,7 @@ var (
|
||||
|
||||
type lokiQueryClient interface {
|
||||
RangeQuery(ctx context.Context, query string, start, end, limit int64) (historian.QueryRes, error)
|
||||
MaxQuerySize() int
|
||||
}
|
||||
|
||||
// LokiHistorianStore is a read store that queries Loki for alert state history.
|
||||
@@ -98,8 +99,12 @@ 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), r.client.MaxQuerySize())
|
||||
if err != nil {
|
||||
grafanaErr := errutil.Error{}
|
||||
if errors.As(err, &grafanaErr) {
|
||||
return make([]*annotations.ItemDTO, 0), err
|
||||
}
|
||||
return make([]*annotations.ItemDTO, 0), ErrLokiStoreInternal.Errorf("failed to build loki query: %w", err)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user