Skip to content

Commit cd30512

Browse files
committed
ongoing and complete
1 parent 493ffa7 commit cd30512

File tree

8 files changed

+30
-21
lines changed

8 files changed

+30
-21
lines changed

coderd/database/dbmem/dbmem.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14110,7 +14110,7 @@ func (q *FakeQuerier) GetAuthorizedConnectionLogsOffset(ctx context.Context, arg
1411014110
continue
1411114111
}
1411214112
isConnected := !clog.CloseTime.Valid
14113-
if (arg.Status == "connected" && !isConnected) || (arg.Status == "disconnected" && isConnected) {
14113+
if (arg.Status == string(codersdk.ConnectionLogStatusOngoing) && !isConnected) || (arg.Status == string(codersdk.ConnectionLogStatusCompleted) && isConnected) {
1411414114
continue
1411514115
}
1411614116
}

coderd/database/querier_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/coder/coder/v2/coderd/provisionerdserver"
3131
"github.com/coder/coder/v2/coderd/rbac"
3232
"github.com/coder/coder/v2/coderd/rbac/policy"
33+
"github.com/coder/coder/v2/codersdk"
3334
"github.com/coder/coder/v2/provisionersdk"
3435
"github.com/coder/coder/v2/testutil"
3536
)
@@ -2410,16 +2411,16 @@ func TestConnectionLogsOffsetFilters(t *testing.T) {
24102411
expectedLogIDs: []uuid.UUID{log1.ID},
24112412
},
24122413
{
2413-
name: "StatusConnected",
2414+
name: "StatusOngoing",
24142415
params: database.GetConnectionLogsOffsetParams{
2415-
Status: string(database.ConnectionStatusConnected),
2416+
Status: string(codersdk.ConnectionLogStatusOngoing),
24162417
},
24172418
expectedLogIDs: []uuid.UUID{log4.ID},
24182419
},
24192420
{
2420-
name: "StatusDisconnected",
2421+
name: "StatusCompleted",
24212422
params: database.GetConnectionLogsOffsetParams{
2422-
Status: string(database.ConnectionStatusDisconnected),
2423+
Status: string(codersdk.ConnectionLogStatusCompleted),
24232424
},
24242425
expectedLogIDs: []uuid.UUID{log2.ID, log3.ID},
24252426
},
@@ -2428,7 +2429,7 @@ func TestConnectionLogsOffsetFilters(t *testing.T) {
24282429
params: database.GetConnectionLogsOffsetParams{
24292430
OrganizationID: orgA.Org.ID,
24302431
Type: string(database.ConnectionTypeVscode),
2431-
Status: string(database.ConnectionStatusDisconnected),
2432+
Status: string(codersdk.ConnectionLogStatusCompleted),
24322433
},
24332434
expectedLogIDs: []uuid.UUID{log2.ID},
24342435
},

coderd/database/queries.sql.go

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

coderd/database/queries/connectionlogs.sql

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,10 +116,10 @@ WHERE
116116
-- Filter by whether the session has a close_time
117117
AND CASE
118118
WHEN @status :: text != '' THEN
119-
((@status :: connection_status = 'connected' AND close_time IS NULL) OR
120-
(@status :: connection_status = 'disconnected' AND close_time IS NOT NULL)) AND
119+
((@status = 'ongoing' AND close_time IS NULL) OR
120+
(@status = 'completed' AND close_time IS NOT NULL)) AND
121121
-- Exclude web events, since we don't know their close time.
122-
type NOT IN ('workspace_app', 'port_forwarding')
122+
"type" NOT IN ('workspace_app', 'port_forwarding')
123123
ELSE true
124124
END
125125
-- Authorize Filter clause will be injected below in

coderd/searchquery/search.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func ConnectionLogs(ctx context.Context, db database.Store, query string, apiKey
9090
StartedBefore: parser.Time3339Nano(values, time.Time{}, "started_before"),
9191
WorkspaceID: parser.UUID(values, uuid.Nil, "workspace_id"),
9292
ConnectionID: parser.UUID(values, uuid.Nil, "connection_id"),
93-
Status: string(httpapi.ParseCustom(parser, values, "", "status", httpapi.ParseEnum[database.ConnectionStatus])),
93+
Status: string(httpapi.ParseCustom(parser, values, "", "status", httpapi.ParseEnum[codersdk.ConnectionLogStatus])),
9494
}
9595

9696
if filter.Username == "me" {

coderd/searchquery/search_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -427,7 +427,7 @@ func TestSearchConnectionLogs(t *testing.T) {
427427
query := fmt.Sprintf(`organization:testorg workspace_owner:testowner `+
428428
`workspace_owner_email:owner@example.com type:port_forwarding username:testuser `+
429429
`user_email:test@example.com started_after:"2023-01-01T00:00:00Z" `+
430-
`started_before:"2023-01-16T12:00:00+12:00" workspace_id:%s connection_id:%s status:connected`,
430+
`started_before:"2023-01-16T12:00:00+12:00" workspace_id:%s connection_id:%s status:ongoing`,
431431
workspaceID.String(), connectionID.String())
432432

433433
values, errs := searchquery.ConnectionLogs(context.Background(), db, query, database.APIKey{})
@@ -444,7 +444,7 @@ func TestSearchConnectionLogs(t *testing.T) {
444444
StartedBefore: time.Date(2023, 1, 16, 0, 0, 0, 0, time.UTC),
445445
WorkspaceID: workspaceID,
446446
ConnectionID: connectionID,
447-
Status: string(database.ConnectionStatusConnected),
447+
Status: string(codersdk.ConnectionLogStatusOngoing),
448448
}
449449

450450
require.Equal(t, expected, values)

codersdk/connectionlog.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,22 @@ const (
5151

5252
// ConnectionLogStatus is the status of a connection log entry.
5353
// It's the argument to the `status` filter when fetching connection logs.
54-
// This is only used in the frontend, not the backend.
5554
type ConnectionLogStatus string
5655

5756
const (
58-
ConnectionLogStatusConnected ConnectionLogStatus = "connected"
59-
ConnectionLogStatusDisconnected ConnectionLogStatus = "disconnected"
57+
ConnectionLogStatusOngoing ConnectionLogStatus = "ongoing"
58+
ConnectionLogStatusCompleted ConnectionLogStatus = "completed"
6059
)
6160

61+
func (s ConnectionLogStatus) Valid() bool {
62+
switch s {
63+
case ConnectionLogStatusOngoing, ConnectionLogStatusCompleted:
64+
return true
65+
default:
66+
return false
67+
}
68+
}
69+
6270
type ConnectionLogWebInfo struct {
6371
UserAgent string `json:"user_agent"`
6472
// User is omitted if the connection event was from an unauthenticated user.

site/src/api/typesGenerated.ts

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

0 commit comments

Comments
 (0)