aggregate booleans for ease of reading

Signed-off-by: schou <pschou@users.noreply.github.com>
This commit is contained in:
schou 2021-02-23 02:39:22 -05:00
parent 71712183ac
commit 22bfc11738

View File

@ -400,43 +400,47 @@ func (ng *Engine) validateOpts(expr parser.Expr) error {
return nil return nil
} }
atModifierUsed := false
negativeOffsetUsed := false
var validationErr error var validationErr error
parser.Inspect(expr, func(node parser.Node, path []parser.Node) error { parser.Inspect(expr, func(node parser.Node, path []parser.Node) error {
switch n := node.(type) { switch n := node.(type) {
case *parser.VectorSelector: case *parser.VectorSelector:
if !ng.enableAtModifier && if n.Timestamp != nil || n.StartOrEnd == parser.START || n.StartOrEnd == parser.END {
(n.Timestamp != nil || n.StartOrEnd == parser.START || n.StartOrEnd == parser.END) { atModifierUsed = true
validationErr = ErrValidationAtModifierDisabled
return validationErr
} }
if !ng.enableNegativeOffset && n.OriginalOffset < 0 { if n.OriginalOffset < 0 {
validationErr = ErrValidationNegativeOffsetDisabled negativeOffsetUsed = true
return validationErr
} }
case *parser.MatrixSelector: case *parser.MatrixSelector:
vs := n.VectorSelector.(*parser.VectorSelector) vs := n.VectorSelector.(*parser.VectorSelector)
if !ng.enableAtModifier && if vs.Timestamp != nil || vs.StartOrEnd == parser.START || vs.StartOrEnd == parser.END {
(vs.Timestamp != nil || vs.StartOrEnd == parser.START || vs.StartOrEnd == parser.END) { atModifierUsed = true
validationErr = ErrValidationAtModifierDisabled
return validationErr
} }
if !ng.enableNegativeOffset && vs.OriginalOffset < 0 { if vs.OriginalOffset < 0 {
validationErr = ErrValidationNegativeOffsetDisabled negativeOffsetUsed = true
return validationErr
} }
case *parser.SubqueryExpr: case *parser.SubqueryExpr:
if !ng.enableAtModifier && if n.Timestamp != nil || n.StartOrEnd == parser.START || n.StartOrEnd == parser.END {
(n.Timestamp != nil || n.StartOrEnd == parser.START || n.StartOrEnd == parser.END) { atModifierUsed = true
validationErr = ErrValidationAtModifierDisabled
return validationErr
} }
if !ng.enableNegativeOffset && n.OriginalOffset < 0 { if n.OriginalOffset < 0 {
validationErr = ErrValidationNegativeOffsetDisabled negativeOffsetUsed = true
return validationErr
} }
} }
if atModifierUsed && !ng.enableAtModifier {
validationErr = ErrValidationAtModifierDisabled
return validationErr
}
if negativeOffsetUsed && !ng.enableNegativeOffset {
validationErr = ErrValidationNegativeOffsetDisabled
return validationErr
}
return nil return nil
}) })