[v9.5.x] Expressions/threshold: Fix incorrect thresholds args length (#66926)

Expressions/threshold: Fix incorrect thresholds args length (#66859)

(cherry picked from commit 350de3f3bf)

Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com>
This commit is contained in:
Grot (@grafanabot)
2023-04-20 13:15:59 +02:00
committed by GitHub
co-authored by Gilles De Mey
parent 006cea2192
commit dcc5190620
2 changed files with 77 additions and 3 deletions
+11
View File
@@ -29,6 +29,17 @@ var (
)
func NewThresholdCommand(refID, referenceVar, thresholdFunc string, conditions []float64) (*ThresholdCommand, error) {
switch thresholdFunc {
case ThresholdIsOutsideRange, ThresholdIsWithinRange:
if len(conditions) < 2 {
return nil, fmt.Errorf("incorrect number of arguments: got %d but need 2", len(conditions))
}
case ThresholdIsAbove, ThresholdIsBelow:
if len(conditions) < 1 {
return nil, fmt.Errorf("incorrect number of arguments: got %d but need 1", len(conditions))
}
}
return &ThresholdCommand{
RefID: refID,
ReferenceVar: referenceVar,