Alerting: Fix panic in provisioning filter contacts by unknown name (#83070)

This commit is contained in:
Matthew Jacobson authored and GitHub committed 2024-02-19 17:30:13 +02:00
1 parent b56f6ed0dc
commit 87ab98ea95
2 files changed
+10 -1

No files matched your search

@@ -80,7 +80,7 @@ func (ecp *ContactPointService) GetContactPoints(ctx context.Context, q ContactP
return nil, convertRecSvcErr(err)
}
grafanaReceivers := []*apimodels.GettableGrafanaReceiver{}
if q.Name != "" {
if q.Name != "" && len(res) > 0 {
grafanaReceivers = res[0].GettableGrafanaReceivers.GrafanaManagedReceivers // we only expect one receiver group
} else {
for _, r := range res {
@@ -53,6 +53,15 @@ func TestContactPointService(t *testing.T) {
require.Equal(t, "slack receiver", cps[0].Name)
})
t.Run("service filters contact points by name, returns empty when no match", func(t *testing.T) {
sut := createContactPointServiceSut(t, secretsService)
cps, err := sut.GetContactPoints(context.Background(), cpsQueryWithName(1, "unknown"), nil)
require.NoError(t, err)
require.Len(t, cps, 0)
})
t.Run("service stitches contact point into org's AM config", func(t *testing.T) {
sut := createContactPointServiceSut(t, secretsService)
newCp := createTestContactPoint()