New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Alerting: Fix evaluation interval validation #56115
Conversation
Drone build failed: https://drone.grafana.net/grafana/grafana-enterprise/35742 |
I had some time to play around with a parser that I think could work to parse this type of duration, it's different from the traditional
https://gist.github.com/gillesdemey/6c251dc4f810d8e60ec2958eb9aa7225 |
I've appended some changes that should correctly validate:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM but my review is slightly biased :)
Drone build failed: https://drone.grafana.net/grafana/grafana-enterprise/36084 |
…valuation-interval-validation
// 0 is a special value meaning for equals evaluation interval | ||
if (millisFor === 0) { | ||
if (Number(value) === 0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm afraid it's not enough. 0s
is also valid for
value. Actually, it's what we get from the API when the user set for=0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let's make sure we also support 0
as that is a format that Prometheus accepts
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! 🎉
I added a non-blocking comment 👀
const diff = durationToMilliseconds(duration); | ||
if (diff < MIN_TIME_RANGE_STEP_S * 1000) { | ||
try { | ||
const duration = parsePrometheusDuration(value); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would name this const withmillisEvery
or millisEvaluateEvery
to be consistent with the For
, and I think it would be more clear
return durationToMilliseconds(parseDuration(duration)); | ||
} | ||
|
||
export function isValidPrometheusDuration(duration: string): boolean { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👏
@@ -15,7 +15,10 @@ interface RuleConfigStatusProps { | |||
export function RuleConfigStatus({ rule }: RuleConfigStatusProps) { | |||
const styles = useStyles2(getStyles); | |||
|
|||
const { exceedsLimit } = checkEvaluationIntervalGlobalLimit(rule.group.interval); | |||
const { exceedsLimit } = useMemo( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡
Drone build failed: https://drone.grafana.net/grafana/grafana-enterprise/36498 |
// a strict golang time.ParseDuration compatible format | ||
if (!alertGroupEvaluateEvery || !isValidPrometheusDuration(alertGroupEvaluateEvery)) { | ||
// config.unifiedAlerting.minInterval should be Prometheus-compatible duration | ||
// However, Go's gtime library has issues with parsing y,w,d |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Technically it's our own grafana-sdk-go
's gtime
package :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so why can't we fix it? 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that might introduce some unwanted side-effects :D
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-56115-to-v8.5.x origin/v8.5.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x d945091ff14a5d66c6b34fe75e72ef5befa19be8
# Push it to GitHub
git push --set-upstream origin backport-56115-to-v8.5.x
git switch main
# Remove the local backport branch
git branch -D backport-56115-to-v8.5.x Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-56115-to-v9.0.x origin/v9.0.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x d945091ff14a5d66c6b34fe75e72ef5befa19be8
# Push it to GitHub
git push --set-upstream origin backport-56115-to-v9.0.x
git switch main
# Remove the local backport branch
git branch -D backport-56115-to-v9.0.x Then, create a pull request where the |
The backport to
To backport manually, run these commands in your terminal: # Fetch latest updates from GitHub
git fetch
# Create a new branch
git switch --create backport-56115-to-v9.1.x origin/v9.1.x
# Cherry-pick the merged commit of this pull request and resolve the conflicts
git cherry-pick -x d945091ff14a5d66c6b34fe75e72ef5befa19be8
# Push it to GitHub
git push --set-upstream origin backport-56115-to-v9.1.x
git switch main
# Remove the local backport branch
git branch -D backport-56115-to-v9.1.x Then, create a pull request where the |
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com> (cherry picked from commit d945091)
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com> (cherry picked from commit d945091)
Co-authored-by: Gilles De Mey <gilles.de.mey@gmail.com> (cherry picked from commit d945091)
What this PR does / why we need it:
This PR fixes evaluation interval validation
Which issue(s) this PR fixes:
Fixes #55357, #55649
Special notes for your reviewer:
WIP: Prometheus validation regex doesn't play well in JS