-
Notifications
You must be signed in to change notification settings - Fork 937
fix: accumulate agentstats until reported and fix insights DAU offset #15832
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 all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
e97f3a9
fix: accumulate agentstats until reported and fix insights DAU offset
mafredri bd4ae11
fix test
mafredri 53f3275
fix comment
mafredri 57fde09
add comment from PR review
mafredri 7f7df65
refactor stats accumulation
mafredri ff236f0
Update coderd/insights_test.go
mafredri 08dea24
fix format
mafredri 3fc95da
fix failf
mafredri 02bafec
Merge branch 'main' into mafredri-fix-agentstats-acc-and-dau-flake
mafredri 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
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
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
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 |
---|---|---|
|
@@ -89,7 +89,7 @@ func (api *API) returnDAUsInternal(rw http.ResponseWriter, r *http.Request, temp | |
} | ||
for _, row := range rows { | ||
resp.Entries = append(resp.Entries, codersdk.DAUEntry{ | ||
Date: row.StartTime.Format(time.DateOnly), | ||
Date: row.StartTime.In(loc).Format(time.DateOnly), | ||
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: Drive-by fix, the date was off-by-one depending on timezone. |
||
Amount: int(row.ActiveUsers), | ||
}) | ||
} | ||
|
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 |
---|---|---|
|
@@ -48,16 +48,27 @@ func TestDeploymentInsights(t *testing.T) { | |
db, ps := dbtestutil.NewDB(t, dbtestutil.WithDumpOnFailure()) | ||
logger := testutil.Logger(t) | ||
rollupEvents := make(chan dbrollup.Event) | ||
statsInterval := 500 * time.Millisecond | ||
// Speed up the test by controlling batch size and interval. | ||
batcher, closeBatcher, err := workspacestats.NewBatcher(context.Background(), | ||
workspacestats.BatcherWithLogger(logger.Named("batcher").Leveled(slog.LevelDebug)), | ||
workspacestats.BatcherWithStore(db), | ||
workspacestats.BatcherWithBatchSize(1), | ||
workspacestats.BatcherWithInterval(statsInterval), | ||
dannykopping marked this conversation as resolved.
Show resolved
Hide resolved
|
||
) | ||
require.NoError(t, err) | ||
defer closeBatcher() | ||
client := coderdtest.New(t, &coderdtest.Options{ | ||
Database: db, | ||
Pubsub: ps, | ||
Logger: &logger, | ||
IncludeProvisionerDaemon: true, | ||
AgentStatsRefreshInterval: time.Millisecond * 100, | ||
AgentStatsRefreshInterval: statsInterval, | ||
StatsBatcher: batcher, | ||
DatabaseRolluper: dbrollup.New( | ||
logger.Named("dbrollup").Leveled(slog.LevelDebug), | ||
db, | ||
dbrollup.WithInterval(time.Millisecond*100), | ||
dbrollup.WithInterval(statsInterval/2), | ||
dbrollup.WithEventChannel(rollupEvents), | ||
), | ||
}) | ||
|
@@ -76,7 +87,7 @@ func TestDeploymentInsights(t *testing.T) { | |
workspace := coderdtest.CreateWorkspace(t, client, template.ID) | ||
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID) | ||
|
||
ctx := testutil.Context(t, testutil.WaitLong) | ||
ctx := testutil.Context(t, testutil.WaitSuperLong) | ||
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: In race mode, propagating the agent connection stats can take a while. |
||
|
||
// Pre-check, no permission issues. | ||
daus, err := client.DeploymentDAUs(ctx, codersdk.TimezoneOffsetHour(clientTz)) | ||
|
@@ -108,6 +119,13 @@ func TestDeploymentInsights(t *testing.T) { | |
err = sess.Start("cat") | ||
require.NoError(t, err) | ||
|
||
select { | ||
case <-ctx.Done(): | ||
require.Fail(t, "timed out waiting for initial rollup event", ctx.Err()) | ||
case ev := <-rollupEvents: | ||
require.True(t, ev.Init, "want init event") | ||
} | ||
|
||
for { | ||
select { | ||
case <-ctx.Done(): | ||
|
@@ -120,6 +138,7 @@ func TestDeploymentInsights(t *testing.T) { | |
if len(daus.Entries) > 0 && daus.Entries[len(daus.Entries)-1].Amount > 0 { | ||
break | ||
} | ||
t.Logf("waiting for deployment daus to update: %+v", daus) | ||
} | ||
} | ||
|
||
|
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.
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: If the callback was called multiple times before reporting, we lost data as each update is a snapshot since the last.
This can happen if:
I believe the assumption is that the "ConnStatsCallback" reports a realistic count for "now", however, what it actually returns is closer to an additive diff between this and the previous report. Thus, if two callbacks happen in quick succession we're effectively zeroing the actual data.
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.
Great catch!