-
Notifications
You must be signed in to change notification settings - Fork 979
fix(coderd): workspaceapps: update last_used_at when workspace app reports stats #11603
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
Changes from 1 commit
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
39b846f
fix(coderd): workspaceapps: update last_used_at when workspace app re…
johnstcn d858bac
fix tests
johnstcn 07176ef
fix linter
johnstcn ef8d3ab
use the correct client
johnstcn 601136c
add flush to wsproxy tests
johnstcn 184af27
use unbuffered channels for flush
johnstcn 1f9012e
maybe fix race conditions?
johnstcn 862b1ff
hack: wait for connections to fully close
johnstcn f522ea6
reword comments
johnstcn b714d69
improve comment
johnstcn 8573ba7
address PR comments
johnstcn File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
maybe fix race conditions?
- Loading branch information
commit 1f9012e4195f61327b8dc32854fd85a6c791fda4
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,7 +147,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
require.NoError(t, err) | ||
require.True(t, loc.Query().Has("message")) | ||
require.True(t, loc.Query().Has("redirect")) | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails) | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails) | ||
}) | ||
|
||
t.Run("LoginWithoutAuthOnProxy", func(t *testing.T) { | ||
|
@@ -185,7 +185,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
// request is getting stripped. | ||
require.Equal(t, u.Path, redirectURI.Path+"/") | ||
require.Equal(t, u.RawQuery, redirectURI.RawQuery) | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails) | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails) | ||
}) | ||
|
||
t.Run("NoAccessShould404", func(t *testing.T) { | ||
|
@@ -396,7 +396,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
// TODO(@deansheather): This should be 400. There's a todo in the | ||
// resolve request code to fix this. | ||
require.Equal(t, http.StatusInternalServerError, resp.StatusCode) | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails) | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails) | ||
}) | ||
}) | ||
|
||
|
@@ -1570,16 +1570,23 @@ func assertWorkspaceLastUsedAtUpdated(t testing.TB, details *Details) { | |
t.Helper() | ||
|
||
details.FlushStats() | ||
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. Same here, looping flush seems better than waiting an arbitrary time? 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. A loop-flush here would probably just execute after the first iteration. |
||
ws, err := details.SDKClient.Workspace(context.Background(), details.Workspace.ID) | ||
require.NoError(t, err) | ||
require.Greater(t, ws.LastUsedAt, details.Workspace.LastUsedAt, "workspace LastUsedAt not updated when it should have been") | ||
// Despite our efforts with the flush channel, this is inherently racy. | ||
// Retry a few times to ensure that the stats collection pipeline has flushed. | ||
require.Eventually(t, func() bool { | ||
ws, err := details.SDKClient.Workspace(context.Background(), details.Workspace.ID) | ||
assert.NoError(t, err) | ||
return ws.LastUsedAt.After(details.Workspace.LastUsedAt) | ||
}, testutil.WaitShort, testutil.IntervalMedium, "workspace LastUsedAt not updated when it should have been") | ||
} | ||
|
||
// Except when it sometimes shouldn't (e.g. no access) | ||
func assertWorkspaceLastUsedAtNotUpdated(t testing.TB, details *Details) { | ||
t.Helper() | ||
|
||
details.FlushStats() | ||
// Despite our efforts with the flush channel, this is inherently racy. | ||
// Wait for a short time to ensure that the stats collection pipeline has flushed. | ||
<-time.After(testutil.IntervalSlow) | ||
ws, err := details.SDKClient.Workspace(context.Background(), details.Workspace.ID) | ||
require.NoError(t, err) | ||
require.Equal(t, ws.LastUsedAt, details.Workspace.LastUsedAt, "workspace LastUsedAt updated when it should not have been") | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
review: I'm counting this as a successful and valid attempt to access a workspace.