Skip to content

fix: floor provisioner job queue wait metric#22184

Merged
zedkipp merged 1 commit intomainfrom
zedkipp/job-queue-negative
Feb 20, 2026
Merged

fix: floor provisioner job queue wait metric#22184
zedkipp merged 1 commit intomainfrom
zedkipp/job-queue-negative

Conversation

@zedkipp
Copy link
Contributor

@zedkipp zedkipp commented Feb 18, 2026

After a PostgreSQL round-trip, job timestamps lose their monotonic clock component, making the subtraction susceptible to wall-clock adjustments producing a small negative delta. Floor at zero since negative queue wait is meaningless. Fixes TestProvisionerJobQueueWaitMetric flakes where small negative values (~2ms) are observed.

coder/internal#1354

@zedkipp zedkipp requested a review from cstyan February 18, 2026 22:32
@zedkipp zedkipp marked this pull request as ready for review February 18, 2026 22:32
After a PostgreSQL round-trip, job timestamps lose their monotonic
clock component, making the subtraction susceptible to wall-clock
adjustments producing a small negative delta. Floor at 1ms since
a zero or negative queue wait is meaningless. Fixes TestProvisionerJobQueueWaitMetric
flakes where small negative values (~ -2ms) are observed.
@zedkipp zedkipp force-pushed the zedkipp/job-queue-negative branch from 4b2cfd9 to 852eabe Compare February 20, 2026 21:07
// round-trip, so the subtraction is based purely on wall-clock time. Floor at
// 1ms as a defensive measure against clock adjustments producing a negative
// delta while acknowledging there's a non-zero queue time.
queueWaitSeconds := max(job.StartedAt.Time.Sub(job.CreatedAt).Seconds(), 0.001)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Discussed with @cstyan and decided to make this max against 1ms, since in reality the queue times can't be exactly zero. When looking at the histogram for this metric most will be much larger than 1ms, so any of these instances will appear as outliers.

@zedkipp zedkipp merged commit 6a783fc into main Feb 20, 2026
27 checks passed
@zedkipp zedkipp deleted the zedkipp/job-queue-negative branch February 20, 2026 23:12
@github-actions github-actions bot locked and limited conversation to collaborators Feb 20, 2026
@zedkipp zedkipp changed the title fix: floor provisioner job queue wait metric at zero fix: floor provisioner job queue wait metric Feb 20, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants