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
Add rule evaluation time #3491
Add rule evaluation time #3491
Conversation
rules/recording.go
Outdated
} | ||
|
||
// EvalTimeSeconds returns the time in seconds it took to evaluate the recording rule. | ||
func (rule *RecordingRule) EvalTimeSeconds() float64 { |
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.
Is there a race here that warrants a lock?
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.
Thanks for spotting! Added locks for reading and updating both the recording and alert rule's evaluation times.
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.
@gouthamve Is there any further changes to be made here?
web/ui/templates/rules.html
Outdated
<tr> | ||
<td class="rule_cell">{{.HTMLSnippet pathPrefix}}</td> | ||
<td>{{humanizeDuration .EvalTimeSeconds}}</td> | ||
{{end}} |
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.
{{end}}
should come after </tr>
rules/manager.go
Outdated
@@ -176,6 +180,7 @@ func (g *Group) run() { | |||
g.Eval(start) | |||
|
|||
iterationDuration.Observe(time.Since(start).Seconds()) | |||
g.EvaluationTimeSeconds = time.Since(start).Seconds() |
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.
This is another race here. When templating we are reading it without a lock.
Add a setter and accessor for 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.
Done 👍
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.
Final nit and after that 👍
rules/manager.go
Outdated
@@ -115,19 +115,24 @@ type Rule interface { | |||
Eval(context.Context, time.Time, *promql.Engine, *url.URL) (promql.Vector, error) | |||
// String returns a human-readable string representation of the rule. | |||
String() string | |||
|
|||
UpdateEvalTimeSeconds(float64) |
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.
Below we have GetEvaluationTimeSeconds
and setEvaluationTimeSeconds
while here the names are different for same functionality. Can we sync those?
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.
Got it. Thanks for the review! 👍
Added evaluation time to both rule groups and rules on /rules.
This makes for easier debugging when trying to identify an expensive rule or rule group.
See screenshot for example:
Any thoughts?