-
Notifications
You must be signed in to change notification settings - Fork 978
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
Changes from 1 commit
39b846f
d858bac
07176ef
ef8d3ab
601136c
184af27
1f9012e
862b1ff
f522ea6
b714d69
8573ba7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -119,7 +119,9 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
body, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.Contains(t, string(body), "Path-based applications are disabled") | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails.AppClient(t), appDetails) | ||
// Even though path-based apps are disabled, the request should indicate | ||
// that the workspace was used. | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
}) | ||
|
||
t.Run("LoginWithoutAuthOnPrimary", func(t *testing.T) { | ||
|
@@ -200,7 +202,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
require.Equal(t, http.StatusNotFound, resp.StatusCode) | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
// TODO(cian): A blocked request should not count as workspace usage. | ||
// assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
}) | ||
|
||
t.Run("RedirectsWithSlash", func(t *testing.T) { | ||
|
@@ -215,7 +218,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
require.Equal(t, http.StatusTemporaryRedirect, resp.StatusCode) | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails.AppClient(t), appDetails) | ||
// TODO(cian): The initial redirect should not count as workspace usage. | ||
// assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
Comment on lines
+221
to
+222
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. review: follow-up |
||
}) | ||
|
||
t.Run("RedirectsWithQuery", func(t *testing.T) { | ||
|
@@ -233,7 +237,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
loc, err := resp.Location() | ||
require.NoError(t, err) | ||
require.Equal(t, proxyTestAppQuery, loc.RawQuery) | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails.AppClient(t), appDetails) | ||
// TODO(cian): The initial redirect should not count as workspace usage. | ||
// assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
Comment on lines
+240
to
+241
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. review: follow-up |
||
}) | ||
|
||
t.Run("Proxies", func(t *testing.T) { | ||
|
@@ -341,7 +346,8 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
body, err := io.ReadAll(resp.Body) | ||
require.NoError(t, err) | ||
require.Contains(t, string(body), "must be accessed with the full username, not @me") | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
// TODO(cian): A blocked request should not count as workspace usage. | ||
// assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
Comment on lines
+349
to
+350
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. review: follow-up |
||
}) | ||
|
||
t.Run("ForwardsIP", func(t *testing.T) { | ||
|
@@ -373,7 +379,9 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
require.NoError(t, err) | ||
defer resp.Body.Close() | ||
require.Equal(t, http.StatusBadGateway, resp.StatusCode) | ||
assertWorkspaceLastUsedAtNotUpdated(t, appDetails.AppClient(t), appDetails) | ||
// An valid authenticated attempt to access a workspace app | ||
// should count as usage regardless of success. | ||
assertWorkspaceLastUsedAtUpdated(t, appDetails.AppClient(t), appDetails) | ||
}) | ||
|
||
t.Run("NoProxyPort", func(t *testing.T) { | ||
|
@@ -562,7 +570,6 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
require.NoError(t, err) | ||
resp.Body.Close() | ||
require.Equal(t, http.StatusOK, resp.StatusCode) | ||
assertWorkspaceLastUsedAtUpdated(t, appClient, appDetails) | ||
}) | ||
} | ||
}) | ||
|
@@ -1445,16 +1452,12 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
t.Run("ReportStats", func(t *testing.T) { | ||
t.Parallel() | ||
|
||
flush := make(chan chan<- struct{}, 1) | ||
|
||
reporter := &fakeStatsReporter{} | ||
appDetails := setupProxyTest(t, &DeploymentOptions{ | ||
StatsCollectorOptions: workspaceapps.StatsCollectorOptions{ | ||
Reporter: reporter, | ||
ReportInterval: time.Hour, | ||
RollupWindow: time.Minute, | ||
|
||
Flush: flush, | ||
}, | ||
}) | ||
|
||
|
@@ -1472,10 +1475,7 @@ func Run(t *testing.T, appHostIsPrimary bool, factory DeploymentFactory) { | |
var stats []workspaceapps.StatsReport | ||
require.Eventually(t, func() bool { | ||
// Keep flushing until we get a non-empty stats report. | ||
flushDone := make(chan struct{}, 1) | ||
flush <- flushDone | ||
<-flushDone | ||
|
||
appDetails.FlushStats() | ||
stats = reporter.stats() | ||
return len(stats) > 0 | ||
}, testutil.WaitLong, testutil.IntervalFast, "stats not reported") | ||
|
@@ -1572,7 +1572,7 @@ func assertWorkspaceLastUsedAtUpdated(t testing.TB, client *codersdk.Client, det | |
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 := client.Workspace(context.Background(), details.Workspace.ID) | ||
require.NoError(t, err) | ||
require.Greater(t, ws.UpdatedAt, details.Workspace.UpdatedAt, "workspace last used at not updated when it should have been") | ||
require.Greater(t, ws.LastUsedAt, details.Workspace.LastUsedAt, "workspace LastUsedAt not updated when it should have been") | ||
} | ||
|
||
// Except when it sometimes shouldn't (e.g. no access) | ||
|
@@ -1582,5 +1582,5 @@ func assertWorkspaceLastUsedAtNotUpdated(t testing.TB, client *codersdk.Client, | |
details.FlushStats() | ||
ws, err := client.Workspace(context.Background(), details.Workspace.ID) | ||
require.NoError(t, err) | ||
require.Equal(t, ws.UpdatedAt, details.Workspace.UpdatedAt, "workspace last used at updated when it shouldn't have been") | ||
require.Equal(t, ws.LastUsedAt, details.Workspace.LastUsedAt, "workspace LastUsedAt updated when it should not have been") | ||
} |
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: leaving this here to address in a follow-up. As this is now tied to stats collection, we bump whenever there are app usage stats for a workspace.