-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow custom rule for promql/range_query
Fixes #1064
- Loading branch information
Showing
10 changed files
with
243 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package config | ||
|
||
import ( | ||
"errors" | ||
|
||
"github.com/cloudflare/pint/internal/checks" | ||
) | ||
|
||
type RangeQuerySettings struct { | ||
Max string `hcl:"max" json:"max"` | ||
Comment string `hcl:"comment,optional" json:"comment,omitempty"` | ||
Severity string `hcl:"severity,optional" json:"severity,omitempty"` | ||
} | ||
|
||
func (s RangeQuerySettings) validate() error { | ||
if s.Max != "" { | ||
dur, err := parseDuration(s.Max) | ||
if err != nil { | ||
return err | ||
} | ||
if dur == 0 { | ||
return errors.New("range_query max value cannot be zero") | ||
} | ||
} | ||
|
||
if s.Severity != "" { | ||
if _, err := checks.ParseSeverity(s.Severity); err != nil { | ||
return err | ||
} | ||
} | ||
|
||
return nil | ||
} | ||
|
||
func (s RangeQuerySettings) getSeverity(fallback checks.Severity) checks.Severity { | ||
if s.Severity != "" { | ||
sev, _ := checks.ParseSeverity(s.Severity) | ||
return sev | ||
} | ||
return fallback | ||
} |
Oops, something went wrong.