Skip to content

Commit

Permalink
chore(meter): add more validation for the group by field
Browse files Browse the repository at this point in the history
  • Loading branch information
tothandras committed Feb 22, 2024
1 parent 2dee27a commit 395924c
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/models/meter.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 395924c

Please sign in to comment.