From 395924c8a28398a45fabf85739a5e5fd2cbd023f Mon Sep 17 00:00:00 2001 From: Andras Toth <4157749+tothandras@users.noreply.github.com> Date: Thu, 22 Feb 2024 09:40:33 -0800 Subject: [PATCH] chore(meter): add more validation for the group by field --- pkg/models/meter.go | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pkg/models/meter.go b/pkg/models/meter.go index 88d1c49f7..9b09fa70c 100644 --- a/pkg/models/meter.go +++ b/pkg/models/meter.go @@ -226,6 +226,15 @@ func (m *Meter) Validate() error { if !strings.HasPrefix(value, "$") { return fmt.Errorf("meter group by value must start with $ for key %s", key) } + if strings.TrimSpace(key) == "" { + return fmt.Errorf("meter group by key cannot be empty") + } + // keys must be unique + seen := make(map[string]struct{}, len(m.GroupBy)) + if _, ok := seen[key]; ok { + return fmt.Errorf("meter group by key %s is not unique", key) + } + seen[key] = struct{}{} } return nil