Alerting: Use org store to read organization IDs (#99938)

This commit is contained in:
Alexander Akhmetov
2025-02-03 15:38:16 +01:00
committed by GitHub
parent a18fa4af8f
commit d6c1e3bb45
15 changed files with 104 additions and 173 deletions
@@ -3,8 +3,6 @@ package state
import (
"context"
"fmt"
"maps"
"slices"
"time"
"github.com/grafana/grafana/pkg/infra/log"
@@ -28,30 +26,6 @@ func NewMultiInstanceReader(logger log.Logger, r1, r2 InstanceReader) *MultiInst
}
}
// FetchOrgIds merges org IDs from both readers.
func (m *MultiInstanceReader) FetchOrgIds(ctx context.Context) ([]int64, error) {
orgsOne, err := m.ProtoDBReader.FetchOrgIds(ctx)
if err != nil {
return nil, fmt.Errorf("failed to fetch org IDs from ProtoDBReader: %w", err)
}
orgsTwo, err := m.DBReader.FetchOrgIds(ctx)
if err != nil {
return nil, fmt.Errorf("failed to fetch org IDs from DBReader: %w", err)
}
orgsSet := make(map[int64]struct{})
for _, orgID := range orgsOne {
orgsSet[orgID] = struct{}{}
}
for _, orgID := range orgsTwo {
orgsSet[orgID] = struct{}{}
}
return slices.Collect(maps.Keys(orgsSet)), nil
}
// ListAlertInstances fetches alert instances for a query from both readers,
// groups them by rule UID, and returns the newest instances for each rule as a
// single slice.