diff --git a/backend/pkg/db/postgres/alert.go b/backend/pkg/db/postgres/alert.go index a820c2ee4..964977bd3 100644 --- a/backend/pkg/db/postgres/alert.go +++ b/backend/pkg/db/postgres/alert.go @@ -157,7 +157,11 @@ func (a *Alert) CanCheck() bool { } func (a *Alert) Build() (sq.SelectBuilder, error) { - colDef := LeftToDb[a.Query.Left] + colDef, ok := LeftToDb[a.Query.Left] + if !ok { + return sq.Select(), errors.New(fmt.Sprintf("!! unsupported metric '%s' from alert: %d:%s\n", a.Query.Left, a.AlertID, a.Name)) + } + subQ := sq. Select(colDef.formula + " AS value"). From(colDef.table). @@ -221,4 +225,4 @@ func (a *Alert) Build() (sq.SelectBuilder, error) { return q, errors.New("unsupported detection method") } return q, nil -} +} \ No newline at end of file diff --git a/ee/backend/pkg/db/postgres/alert.go b/ee/backend/pkg/db/postgres/alert.go index b9b4d5446..301d7b540 100644 --- a/ee/backend/pkg/db/postgres/alert.go +++ b/ee/backend/pkg/db/postgres/alert.go @@ -157,7 +157,11 @@ func (a *Alert) CanCheck() bool { } func (a *Alert) Build() (sq.SelectBuilder, error) { - colDef := LeftToDb[a.Query.Left] + colDef, ok := LeftToDb[a.Query.Left] + if !ok { + return sq.Select(), errors.New(fmt.Sprintf("!! unsupported metric '%s' from alert: %d:%s\n", a.Query.Left, a.AlertID, a.Name)) + } + subQ := sq. Select(colDef.formula + " AS value"). From(colDef.table). @@ -221,4 +225,4 @@ func (a *Alert) Build() (sq.SelectBuilder, error) { return q, errors.New("unsupported detection method") } return q, nil -} +} \ No newline at end of file