Skip to content

Commit d6b025d

Browse files
authored
Revert "feat: add activity status and autostop reason to workspace overview (coder#11987)" (coder#12144)
Related to coder#11987 This reverts commit d37b131.
1 parent 04991f4 commit d6b025d

File tree

22 files changed

+117
-645
lines changed

22 files changed

+117
-645
lines changed

coderd/agentapi/api.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,6 @@ func New(opts Options) *API {
114114
api.StatsAPI = &StatsAPI{
115115
AgentFn: api.agent,
116116
Database: opts.Database,
117-
Pubsub: opts.Pubsub,
118117
Log: opts.Log,
119118
StatsBatcher: opts.StatsBatcher,
120119
TemplateScheduleStore: opts.TemplateScheduleStore,

coderd/agentapi/stats.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,8 @@ import (
1616
"github.com/coder/coder/v2/coderd/autobuild"
1717
"github.com/coder/coder/v2/coderd/database"
1818
"github.com/coder/coder/v2/coderd/database/dbtime"
19-
"github.com/coder/coder/v2/coderd/database/pubsub"
2019
"github.com/coder/coder/v2/coderd/prometheusmetrics"
2120
"github.com/coder/coder/v2/coderd/schedule"
22-
"github.com/coder/coder/v2/codersdk"
2321
)
2422

2523
type StatsBatcher interface {
@@ -29,7 +27,6 @@ type StatsBatcher interface {
2927
type StatsAPI struct {
3028
AgentFn func(context.Context) (database.WorkspaceAgent, error)
3129
Database database.Store
32-
Pubsub pubsub.Pubsub
3330
Log slog.Logger
3431
StatsBatcher StatsBatcher
3532
TemplateScheduleStore *atomic.Pointer[schedule.TemplateScheduleStore]
@@ -133,16 +130,5 @@ func (a *StatsAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsR
133130
return nil, xerrors.Errorf("update stats in database: %w", err)
134131
}
135132

136-
// Tell the frontend about the new agent report, now that everything is updated
137-
a.publishWorkspaceAgentStats(ctx, workspace.ID)
138-
139133
return res, nil
140134
}
141-
142-
func (a *StatsAPI) publishWorkspaceAgentStats(ctx context.Context, workspaceID uuid.UUID) {
143-
err := a.Pubsub.Publish(codersdk.WorkspaceNotifyChannel(workspaceID), codersdk.WorkspaceNotifyDescriptionAgentStatsOnly)
144-
if err != nil {
145-
a.Log.Warn(ctx, "failed to publish workspace agent stats",
146-
slog.F("workspace_id", workspaceID), slog.Error(err))
147-
}
148-
}

coderd/agentapi/stats_test.go

Lines changed: 11 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package agentapi_test
22

33
import (
4-
"bytes"
54
"context"
65
"database/sql"
76
"sync"
@@ -20,11 +19,8 @@ import (
2019
"github.com/coder/coder/v2/coderd/database"
2120
"github.com/coder/coder/v2/coderd/database/dbmock"
2221
"github.com/coder/coder/v2/coderd/database/dbtime"
23-
"github.com/coder/coder/v2/coderd/database/pubsub"
2422
"github.com/coder/coder/v2/coderd/prometheusmetrics"
2523
"github.com/coder/coder/v2/coderd/schedule"
26-
"github.com/coder/coder/v2/codersdk"
27-
"github.com/coder/coder/v2/testutil"
2824
)
2925

3026
type statsBatcher struct {
@@ -82,10 +78,8 @@ func TestUpdateStates(t *testing.T) {
8278
t.Parallel()
8379

8480
var (
85-
now = dbtime.Now()
86-
dbM = dbmock.NewMockStore(gomock.NewController(t))
87-
ps = pubsub.NewInMemory()
88-
81+
now = dbtime.Now()
82+
dbM = dbmock.NewMockStore(gomock.NewController(t))
8983
templateScheduleStore = schedule.MockTemplateScheduleStore{
9084
GetFn: func(context.Context, database.Store, uuid.UUID) (schedule.TemplateScheduleOptions, error) {
9185
panic("should not be called")
@@ -131,7 +125,6 @@ func TestUpdateStates(t *testing.T) {
131125
return agent, nil
132126
},
133127
Database: dbM,
134-
Pubsub: ps,
135128
StatsBatcher: batcher,
136129
TemplateScheduleStore: templateScheduleStorePtr(templateScheduleStore),
137130
AgentStatsRefreshInterval: 10 * time.Second,
@@ -171,15 +164,6 @@ func TestUpdateStates(t *testing.T) {
171164
// User gets fetched to hit the UpdateAgentMetricsFn.
172165
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
173166

174-
// Ensure that pubsub notifications are sent.
175-
publishAgentStats := make(chan bool)
176-
ps.Subscribe(codersdk.WorkspaceNotifyChannel(workspace.ID), func(_ context.Context, description []byte) {
177-
go func() {
178-
publishAgentStats <- bytes.Equal(description, codersdk.WorkspaceNotifyDescriptionAgentStatsOnly)
179-
close(publishAgentStats)
180-
}()
181-
})
182-
183167
resp, err := api.UpdateStats(context.Background(), req)
184168
require.NoError(t, err)
185169
require.Equal(t, &agentproto.UpdateStatsResponse{
@@ -195,13 +179,7 @@ func TestUpdateStates(t *testing.T) {
195179
require.Equal(t, user.ID, batcher.lastUserID)
196180
require.Equal(t, workspace.ID, batcher.lastWorkspaceID)
197181
require.Equal(t, req.Stats, batcher.lastStats)
198-
ctx := testutil.Context(t, testutil.WaitShort)
199-
select {
200-
case <-ctx.Done():
201-
t.Error("timed out while waiting for pubsub notification")
202-
case wasAgentStatsOnly := <-publishAgentStats:
203-
require.Equal(t, wasAgentStatsOnly, true)
204-
}
182+
205183
require.True(t, updateAgentMetricsFnCalled)
206184
})
207185

@@ -211,7 +189,6 @@ func TestUpdateStates(t *testing.T) {
211189
var (
212190
now = dbtime.Now()
213191
dbM = dbmock.NewMockStore(gomock.NewController(t))
214-
ps = pubsub.NewInMemory()
215192
templateScheduleStore = schedule.MockTemplateScheduleStore{
216193
GetFn: func(context.Context, database.Store, uuid.UUID) (schedule.TemplateScheduleOptions, error) {
217194
panic("should not be called")
@@ -237,7 +214,6 @@ func TestUpdateStates(t *testing.T) {
237214
return agent, nil
238215
},
239216
Database: dbM,
240-
Pubsub: ps,
241217
StatsBatcher: batcher,
242218
TemplateScheduleStore: templateScheduleStorePtr(templateScheduleStore),
243219
AgentStatsRefreshInterval: 10 * time.Second,
@@ -268,8 +244,7 @@ func TestUpdateStates(t *testing.T) {
268244
t.Parallel()
269245

270246
var (
271-
db = dbmock.NewMockStore(gomock.NewController(t))
272-
ps = pubsub.NewInMemory()
247+
dbM = dbmock.NewMockStore(gomock.NewController(t))
273248
req = &agentproto.UpdateStatsRequest{
274249
Stats: &agentproto.Stats{
275250
ConnectionsByProto: map[string]int64{}, // len() == 0
@@ -280,8 +255,7 @@ func TestUpdateStates(t *testing.T) {
280255
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
281256
return agent, nil
282257
},
283-
Database: db,
284-
Pubsub: ps,
258+
Database: dbM,
285259
StatsBatcher: nil, // should not be called
286260
TemplateScheduleStore: nil, // should not be called
287261
AgentStatsRefreshInterval: 10 * time.Second,
@@ -316,9 +290,7 @@ func TestUpdateStates(t *testing.T) {
316290
nextAutostart := now.Add(30 * time.Minute).UTC() // always sent to DB as UTC
317291

318292
var (
319-
db = dbmock.NewMockStore(gomock.NewController(t))
320-
ps = pubsub.NewInMemory()
321-
293+
dbM = dbmock.NewMockStore(gomock.NewController(t))
322294
templateScheduleStore = schedule.MockTemplateScheduleStore{
323295
GetFn: func(context.Context, database.Store, uuid.UUID) (schedule.TemplateScheduleOptions, error) {
324296
return schedule.TemplateScheduleOptions{
@@ -349,8 +321,7 @@ func TestUpdateStates(t *testing.T) {
349321
AgentFn: func(context.Context) (database.WorkspaceAgent, error) {
350322
return agent, nil
351323
},
352-
Database: db,
353-
Pubsub: ps,
324+
Database: dbM,
354325
StatsBatcher: batcher,
355326
TemplateScheduleStore: templateScheduleStorePtr(templateScheduleStore),
356327
AgentStatsRefreshInterval: 15 * time.Second,
@@ -370,26 +341,26 @@ func TestUpdateStates(t *testing.T) {
370341
}
371342

372343
// Workspace gets fetched.
373-
db.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(database.GetWorkspaceByAgentIDRow{
344+
dbM.EXPECT().GetWorkspaceByAgentID(gomock.Any(), agent.ID).Return(database.GetWorkspaceByAgentIDRow{
374345
Workspace: workspace,
375346
TemplateName: template.Name,
376347
}, nil)
377348

378349
// We expect an activity bump because ConnectionCount > 0. However, the
379350
// next autostart time will be set on the bump.
380-
db.EXPECT().ActivityBumpWorkspace(gomock.Any(), database.ActivityBumpWorkspaceParams{
351+
dbM.EXPECT().ActivityBumpWorkspace(gomock.Any(), database.ActivityBumpWorkspaceParams{
381352
WorkspaceID: workspace.ID,
382353
NextAutostart: nextAutostart,
383354
}).Return(nil)
384355

385356
// Workspace last used at gets bumped.
386-
db.EXPECT().UpdateWorkspaceLastUsedAt(gomock.Any(), database.UpdateWorkspaceLastUsedAtParams{
357+
dbM.EXPECT().UpdateWorkspaceLastUsedAt(gomock.Any(), database.UpdateWorkspaceLastUsedAtParams{
387358
ID: workspace.ID,
388359
LastUsedAt: now,
389360
}).Return(nil)
390361

391362
// User gets fetched to hit the UpdateAgentMetricsFn.
392-
db.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
363+
dbM.EXPECT().GetUserByID(gomock.Any(), user.ID).Return(user, nil)
393364

394365
resp, err := api.UpdateStats(context.Background(), req)
395366
require.NoError(t, err)

coderd/workspaces.go

Lines changed: 1 addition & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package coderd
22

33
import (
4-
"bytes"
54
"context"
65
"database/sql"
76
"encoding/json"
@@ -1344,48 +1343,7 @@ func (api *API) watchWorkspace(rw http.ResponseWriter, r *http.Request) {
13441343
<-senderClosed
13451344
}()
13461345

1347-
sendUpdate := func(_ context.Context, description []byte) {
1348-
// The agent stats get updated frequently, so we treat these as a special case and only
1349-
// send a partial update. We primarily care about updating the `last_used_at` and
1350-
// `latest_build.deadline` properties.
1351-
if bytes.Equal(description, codersdk.WorkspaceNotifyDescriptionAgentStatsOnly) {
1352-
workspace, err := api.Database.GetWorkspaceByID(ctx, workspace.ID)
1353-
if err != nil {
1354-
_ = sendEvent(ctx, codersdk.ServerSentEvent{
1355-
Type: codersdk.ServerSentEventTypeError,
1356-
Data: codersdk.Response{
1357-
Message: "Internal error fetching workspace.",
1358-
Detail: err.Error(),
1359-
},
1360-
})
1361-
return
1362-
}
1363-
1364-
workspaceBuild, err := api.Database.GetLatestWorkspaceBuildByWorkspaceID(ctx, workspace.ID)
1365-
if err != nil {
1366-
_ = sendEvent(ctx, codersdk.ServerSentEvent{
1367-
Type: codersdk.ServerSentEventTypeError,
1368-
Data: codersdk.Response{
1369-
Message: "Internal error fetching workspace build.",
1370-
Detail: err.Error(),
1371-
},
1372-
})
1373-
return
1374-
}
1375-
1376-
_ = sendEvent(ctx, codersdk.ServerSentEvent{
1377-
Type: codersdk.ServerSentEventTypePartial,
1378-
Data: struct {
1379-
database.Workspace
1380-
LatestBuild database.WorkspaceBuild `json:"latest_build"`
1381-
}{
1382-
Workspace: workspace,
1383-
LatestBuild: workspaceBuild,
1384-
},
1385-
})
1386-
return
1387-
}
1388-
1346+
sendUpdate := func(_ context.Context, _ []byte) {
13891347
workspace, err := api.Database.GetWorkspaceByID(ctx, workspace.ID)
13901348
if err != nil {
13911349
_ = sendEvent(ctx, codersdk.ServerSentEvent{

codersdk/serversentevents.go

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,9 @@ type ServerSentEvent struct {
2020
type ServerSentEventType string
2121

2222
const (
23-
ServerSentEventTypePing ServerSentEventType = "ping"
24-
ServerSentEventTypeData ServerSentEventType = "data"
25-
ServerSentEventTypePartial ServerSentEventType = "partial"
26-
ServerSentEventTypeError ServerSentEventType = "error"
23+
ServerSentEventTypePing ServerSentEventType = "ping"
24+
ServerSentEventTypeData ServerSentEventType = "data"
25+
ServerSentEventTypeError ServerSentEventType = "error"
2726
)
2827

2928
func ServerSentEventReader(ctx context.Context, rc io.ReadCloser) func() (*ServerSentEvent, error) {

codersdk/workspaces.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,6 @@ func (c *Client) UnfavoriteWorkspace(ctx context.Context, workspaceID uuid.UUID)
497497
return nil
498498
}
499499

500-
var WorkspaceNotifyDescriptionAgentStatsOnly = []byte("agentStatsOnly")
501-
502500
// WorkspaceNotifyChannel is the PostgreSQL NOTIFY
503501
// channel to listen for updates on. The payload is empty,
504502
// because the size of a workspace payload can be very large.

site/src/api/typesGenerated.ts

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

site/src/hooks/useTime.ts

Lines changed: 0 additions & 32 deletions
This file was deleted.

site/src/modules/workspaces/activity.ts

Lines changed: 0 additions & 45 deletions
This file was deleted.

site/src/pages/UserSettingsPage/AccountPage/AccountPage.test.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,12 @@ describe("AccountPage", () => {
2929
Promise.resolve({
3030
id: userId,
3131
email: "user@coder.com",
32-
created_at: new Date().toISOString(),
32+
created_at: new Date().toString(),
3333
status: "active",
3434
organization_ids: ["123"],
3535
roles: [],
3636
avatar_url: "",
37-
last_seen_at: new Date().toISOString(),
37+
last_seen_at: new Date().toString(),
3838
login_type: "password",
3939
theme_preference: "",
4040
...data,

0 commit comments

Comments
 (0)