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

This commit is contained in:
Matthew Jacobson 2024-02-19 10:30:13 -05:00 committed by GitHub
parent b56f6ed0dc
commit 87ab98ea95
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 10 additions and 1 deletions

View File

@ -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 {

View File

@ -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()