-
Notifications
You must be signed in to change notification settings - Fork 928
feat: add connectionlogs
API
#18628
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
base: ethan/reroute-connection-logs
Are you sure you want to change the base?
feat: add connectionlogs
API
#18628
Conversation
Warning This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
This stack of pull requests is managed by Graphite. Learn more about stacking. |
|
||
httpapi.Write(ctx, rw, http.StatusOK, codersdk.ConnectionLogResponse{ | ||
ConnectionLogs: convertConnectionLogs(dblogs), | ||
Count: 0, // TODO(ethanndickson): Set count |
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.
This is populated in the next PR in the stack.
8cec6d1
to
482a5d3
Compare
e4e1a04
to
1fcd8d7
Compare
482a5d3
to
ccc7539
Compare
connection_logs.organization_id = @organization_id | ||
ELSE true | ||
END | ||
-- Filter by workspace owner username |
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.
You have user_id
, username
and user_email
filters (I'm assuming to match audit logs), but the new workspace owner filter doesn't have a corresponding id or email filter
@@ -402,6 +403,71 @@ func TestSearchAudit(t *testing.T) { | |||
} | |||
} | |||
|
|||
func TestSearchConnectionLogs(t *testing.T) { | |||
t.Parallel() | |||
testCases := []struct { |
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.
Probably should cover every single param. Since they're all individual and don't really interact with each other you could probably just do this in a single parse.
// ConnectionLogStatus is the status of a connection log entry. | ||
// It's the argument to the `status` filter when fetching connection logs. | ||
type ConnectionLogStatus string | ||
|
||
const ( | ||
ConnectionLogStatusConnected ConnectionLogStatus = "connected" | ||
ConnectionLogStatusDisconnected ConnectionLogStatus = "disconnected" | ||
) |
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.
Unused?
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.
Only used in the frontend for the UI filter😔
@@ -31,7 +31,94 @@ JOIN organizations ON | |||
connection_logs.organization_id = organizations.id | |||
JOIN workspaces ON | |||
connection_logs.workspace_id = workspaces.id | |||
WHERE TRUE | |||
WHERE |
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.
As far as I can tell there's not really any tests that hit all of these filters in the database layer.
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.
I think all (if not most) are tested in querier_test.go
, I'll double check
This is the second PR for moving connection events out of the audit log.
This PR:
/api/v2/connectionlogs
endpointGetAuthorizedConnectionLogsOffset
and thus the endpoint.There's quite a few, but I was aiming for feature parity with the audit log.
organization:<id|name>
workspace_owner:<username>
username:<username>
email:<email>
started_after:<time>
started_before:<time>
closed_after:<time>
workspace_id:<id>
connection_id:<id>
status:<connected|disconnected>
connected
only sessions with a nullclose_time
are returned, ifdisconnected
, only those with a non-nullclose_time
. If filter is omitted, both are returned.Future PRs:
count
onConnectionLogResponse
using a seperate query (to preemptively mitigate the issue described in Audit log slows to a crawl when nearing 1 million entries #17689)