Skip to content

fix: pass in time parameter to prevent flakes #11023

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

Merged
merged 6 commits into from
Dec 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
strip monotonic clock from parsing
  • Loading branch information
f0ssel committed Dec 4, 2023
commit 0d8c561d76d5cafe3152925e67e4e0f852d688d7
3 changes: 3 additions & 0 deletions coderd/insights.go
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,9 @@ func parseInsightsStartAndEndTime(ctx context.Context, rw http.ResponseWriter, s
{"end_time", endTimeString, &endTime},
} {
t, err := time.Parse(insightsTimeLayout, qp.value)
// strip monotonic clock reading
// so presentation time and arithmetic operations are consistent
t = t.Round(0)
Copy link
Member

Choose a reason for hiding this comment

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

I don't think we need to strip the monotonic clock here since we're parsing a string. Monotonic clock should only be present when time.Now() is used. 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah I just learned that after making this :P

if err != nil {
httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
Message: "Query parameter has invalid value.",
Expand Down
10 changes: 5 additions & 5 deletions coderd/insights_internal_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,18 @@ import (
func Test_parseInsightsStartAndEndTime(t *testing.T) {
t.Parallel()

t.Logf("local: %s", time.Local)
t.Logf("machine location: %s", time.Now().Location())
layout := insightsTimeLayout
now := time.Now().UTC()
t.Logf("now: %s", now)
t.Logf("location: %s", now.Location())
t.Logf("now location: %s", now.Location())
y, m, d := now.Date()
today := time.Date(y, m, d, 0, 0, 0, 0, time.UTC)
t.Logf("today: %s", now)
t.Logf("today: %s", today)
thisHour := time.Date(y, m, d, now.Hour(), 0, 0, 0, time.UTC)
t.Logf("thisHour: %s", now)
t.Logf("thisHour: %s", thisHour)
thisHourRoundUp := thisHour.Add(time.Hour)
t.Logf("thisHourRoundUp: %s", now)
t.Logf("thisHourRoundUp: %s", thisHourRoundUp)

helsinki, err := time.LoadLocation("Europe/Helsinki")
require.NoError(t, err)
Expand Down