-
Notifications
You must be signed in to change notification settings - Fork 888
feat(coderd/healthcheck): allow configuring database hc threshold #10623
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
Changes from all commits
2484951
9e5c030
42477e3
15361a3
20e713e
8115ffe
bc8e200
973a9bb
58361e8
1de19c0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,20 +10,30 @@ import ( | |
"github.com/coder/coder/v2/coderd/database" | ||
) | ||
|
||
const ( | ||
DatabaseDefaultThreshold = 15 * time.Millisecond | ||
) | ||
|
||
// @typescript-generate DatabaseReport | ||
type DatabaseReport struct { | ||
Healthy bool `json:"healthy"` | ||
Reachable bool `json:"reachable"` | ||
Latency string `json:"latency"` | ||
LatencyMs int `json:"latency_ms"` | ||
Error *string `json:"error"` | ||
Healthy bool `json:"healthy"` | ||
Reachable bool `json:"reachable"` | ||
Latency string `json:"latency"` | ||
LatencyMS int64 `json:"latency_ms"` | ||
ThresholdMS int64 `json:"threshold_ms"` | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we add the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Me either, and the fact that I don't know why this particular fence exists makes me pause before knocking it down. I do know that Instead of parsing the Go string representation ( |
||
Error *string `json:"error"` | ||
} | ||
|
||
type DatabaseReportOptions struct { | ||
DB database.Store | ||
DB database.Store | ||
Threshold time.Duration | ||
} | ||
|
||
func (r *DatabaseReport) Run(ctx context.Context, opts *DatabaseReportOptions) { | ||
r.ThresholdMS = opts.Threshold.Milliseconds() | ||
if r.ThresholdMS == 0 { | ||
r.ThresholdMS = DatabaseDefaultThreshold.Milliseconds() | ||
} | ||
ctx, cancel := context.WithTimeout(ctx, 5*time.Second) | ||
defer cancel() | ||
|
||
|
@@ -43,10 +53,8 @@ func (r *DatabaseReport) Run(ctx context.Context, opts *DatabaseReportOptions) { | |
// Take the median ping. | ||
latency := pings[pingCount/2] | ||
r.Latency = latency.String() | ||
r.LatencyMs = int(latency.Milliseconds()) | ||
// Somewhat arbitrary, but if the latency is over 15ms, we consider it | ||
// unhealthy. | ||
if latency < 15*time.Millisecond { | ||
r.LatencyMS = latency.Milliseconds() | ||
if r.LatencyMS < r.ThresholdMS { | ||
r.Healthy = true | ||
} | ||
r.Reachable = true | ||
|
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 this would be smoother as
databaseThreshold
vsthresholdDatabase
(same with flags, etc)