8000 chore: remove stats batcher and workspace usage tracker by f0ssel · Pull Request #13393 · coder/coder · GitHub
[go: up one dir, main page]

Skip to content

chore: remove stats batcher and workspace usage tracker #13393

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

Closed
wants to merge 6 commits into from
Closed
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
fix tests
  • Loading branch information
f0ssel committed May 29, 2024
commit ca851baa75493a048d93795bc154eed31418486d
9 changes: 9 additions & 0 deletions coderd/agentapi/stats_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,9 @@ func TestUpdateStates(t *testing.T) {
// User gets fetched to hit the UpdateAgentMetricsFn.
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)

// Agent stats get inserted.
dbM.EXPECT().InsertWorkspaceAgentStats(gomock.Any(), gomock.Any())

// Ensure that pubsub notifications are sent.
notifyDescription := make(chan []byte)
ps.Subscribe(codersdk.WorkspaceNotifyChannel(workspace.ID), func(_ context.Context, description []byte) {
Expand Down Expand Up @@ -221,6 +224,9 @@ func TestUpdateStates(t *testing.T) {
LastUsedAt: now,
}).Return(nil)

// Agent stats get inserted.
dbM.EXPECT().InsertWorkspaceAgentStats(gomock.Any(), gomock.Any())

_, err := api.UpdateStats(context.Background(), req)
require.NoError(t, err)
})
Expand Down Expand Up @@ -353,6 +359,9 @@ func TestUpdateStates(t *testing.T) {
// User gets fetched to hit the UpdateAgentMetricsFn.
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)

// Agent stats get inserted.
dbM.EXPECT().InsertWorkspaceAgentStats(gomock.Any(), gomock.Any())

resp, err := api.UpdateStats(context.Background(), req)
require.NoError(t, err)
require.Equal(t, &agentproto.UpdateStatsResponse{
Expand Down
8 changes: 3 additions & 5 deletions coderd/workspacestats/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ func (r *Reporter) ReportAgentStats(ctx context.Context, now time.Time, workspac
errGroup.Go(func() error {
start := time.Now()
connectionsByProto := json.RawMessage(`[]`)
Copy link
Member

Choose a reason for hiding this comment

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

I wonder if [{}] would be a more accurate representation here? 🤔 Not sure it's necessary though.

payload, err := json.Marshal(stats.ConnectionsByProto)
payload, err := json.Marshal([]map[string]int64{stats.ConnectionsByProto})
if err != nil {
r.opts.Logger.Error(ctx, "unable to marshal agent connections by proto, dropping data", slog.Error(err))
} else {
Expand All @@ -174,16 +174,14 @@ func (r *Reporter) ReportAgentStats(ctx context.Context, now time.Time, workspac
SessionCountSSH: []int64{stats.SessionCountSsh},
ConnectionMedianLatencyMS: []float64{stats.ConnectionMedianLatencyMs},
}

err = r.opts.Database.InsertWorkspaceAgentStats(ctx, params)
elapsed := time.Since(start)
err = r.opts.Database.InsertWorkspaceAgentStats(ctx, params)
if err != nil {
if database.IsQueryCanceledError(err) {
r.opts.Logger.Debug(ctx, "query canceled, skipping insert of workspace agent stats", slog.F("elapsed", elapsed))
return nil
}
r.opts.Logger.Error(ctx, "error inserting workspace agent stats", slog.Error(err), slog.F("elapsed", elapsed))
return nil
return xerrors.Errorf("insert workspace agent stats: %w", err)
}

return nil
Expand Down
0