Skip to content

fix(cli): port-forward: update workspace last_used_at #12659

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 21 commits into from
Mar 20, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
279f874
add tests to assert last used at updated on port-forward
johnstcn Mar 18, 2024
8f9b945
add workspaceusage package
johnstcn Mar 18, 2024
e8c842c
add workspace usager tracking to coderd, add endpoint
johnstcn Mar 18, 2024
86704a1
add workspace usage tracking to cli/portforward, fix tests
johnstcn Mar 19, 2024
c99327c
make gen
johnstcn Mar 19, 2024
5876edd
workspaceusage: improve locking and tests
johnstcn Mar 19, 2024
e4e0311
address more PR comments
johnstcn Mar 19, 2024
958d1d1
try to race harder
johnstcn Mar 19, 2024
a36aeb9
add danny's suggestions
johnstcn Mar 20, 2024
692f666
add big big comments
johnstcn Mar 20, 2024
d794e00
fix(database): BatchUpdateWorkspaceLastUsedAt: avoid overwriting olde…
johnstcn Mar 20, 2024
45a0eef
fix(coderd/workspaceusage): log number of consecutive flush errors
johnstcn Mar 20, 2024
8e40efd
upgrade to error log on multiple flush failures
johnstcn Mar 20, 2024
591e1ab
chore(coderd/workspaceusage): add integration-style test with multipl…
johnstcn Mar 20, 2024
0caaf3a
fix(cli/portforward_test.go): use testutil.RequireRecv/SendCtx
johnstcn Mar 20, 2024
cc72868
just use default flush interval
johnstcn Mar 20, 2024
f5f8d75
rename receiver
johnstcn Mar 20, 2024
a2e716d
defer close doneCh
johnstcn Mar 20, 2024
5b64f96
defer instead of cleanup, avoid data race in real pubsub
johnstcn Mar 20, 2024
23ccf21
fix(coderdtest): buffer just in case
johnstcn Mar 20, 2024
c9ac9d2
refactor: unexport Loop, remove panic, simplify external API
johnstcn Mar 20, 2024
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
add danny's suggestions
Co-authored-by: Danny Kopping <danny@coder.com>
  • Loading branch information
johnstcn and dannykopping authored Mar 20, 2024
commit a36aeb9711ca5844fdb2a9af5fd663bcb96851c9
4 changes: 3 additions & 1 deletion coderd/workspaceusage/tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -206,6 +206,7 @@ func (s *uuidSet) UniqueAndClear() []uuid.UUID {
defer s.l.Unlock()
if s.m == nil {
s.m = make(map[uuid.UUID]struct{})
return []uuid.UUID{}
}
l := make([]uuid.UUID, 0)
for k := range s.m {
Expand All @@ -214,8 +215,9 @@ func (s *uuidSet) UniqueAndClear() []uuid.UUID {
// For ease of testing, sort the IDs lexically
sort.Slice(l, func(i, j int) bool {
// For some unfathomable reason, byte arrays are not comparable?
// See https://github.com/golang/go/issues/61004
return bytes.Compare(l[i][:], l[j][:]) < 0
})
s.m = make(map[uuid.UUID]struct{})
clear(s.m)
return l
}
2 changes: 1 addition & 1 deletion codersdk/workspaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ func (c *Client) PostWorkspaceUsage(ctx context.Context, id uuid.UUID) error {
// process.
func (c *Client) UpdateWorkspaceUsageContext(ctx context.Context, id uuid.UUID) func() {
hbCtx, hbCancel := context.WithCancel(ctx)
// Perform one initial heartbeat
// Perform one initial update
if err := c.PostWorkspaceUsage(hbCtx, id); err != nil {
c.logger.Warn(ctx, "failed to post workspace usage", slog.Error(err))
}
Expand Down