Connection logs now record how a connection was made (`connection_method`) separately from which app made it (`app_name`). Storage, the HTTP API, search filters, and the UI move to the new fields. Legacy agent reports and the deprecated `type` field keep working. - Add `connection_method` (`ssh`, `reconnecting_pty`, `workspace_app`, `port_forwarding`, `tunnel`) and optional `app_name` and `app_display_name` to `GET /api/v2/connectionlog`. Deprecate `type` and make it a plain string in the API and the Go SDK. - Add `method:` and repeatable `app:` search filters. `type:` keeps its old results but can't be combined with the new filters. - Replace the Type menu with a Method menu, show the app next to the method in each row, and warn when a filter uses `type:`. - Change the Active SSH connections preset to `method:ssh`, so it also includes SSH sessions from VS Code and JetBrains apps. - Generate `codersdk.ConnectionLogMethod` from the database enum with `typegen dbenums`. - Migration 000617 rewrites `connection_logs` under an ACCESS EXCLUSIVE lock, which takes about 50 seconds for 10 million rows. `vscode` and `jetbrains` rows become `ssh` rows with that app. Rolling back folds apps into the old types and loses per-app names. - Document the new filters and how to replace each `type:` value. Closes #27412
38 lines
1.4 KiB
Go
38 lines
1.4 KiB
Go
// Package sdk2db provides common conversion routines from codersdk types to database types
|
|
package sdk2db
|
|
|
|
import (
|
|
"golang.org/x/xerrors"
|
|
|
|
agentproto "github.com/coder/coder/v2/agent/proto"
|
|
"github.com/coder/coder/v2/coderd/database"
|
|
"github.com/coder/coder/v2/coderd/util/slice"
|
|
"github.com/coder/coder/v2/codersdk"
|
|
)
|
|
|
|
func ProvisionerDaemonStatus(status codersdk.ProvisionerDaemonStatus) database.ProvisionerDaemonStatus {
|
|
return database.ProvisionerDaemonStatus(status)
|
|
}
|
|
|
|
func ProvisionerDaemonStatuses(params []codersdk.ProvisionerDaemonStatus) []database.ProvisionerDaemonStatus {
|
|
return slice.List(params, ProvisionerDaemonStatus)
|
|
}
|
|
|
|
// ConnectionLogFromAgentType recovers the method and app name from legacy
|
|
// reports.
|
|
// An unspecified legacy type was used by SSH handlers for unfamiliar apps.
|
|
func ConnectionLogFromAgentType(typ agentproto.Connection_Type) (database.ConnectionLogMethod, string, error) {
|
|
switch typ {
|
|
case agentproto.Connection_SSH, agentproto.Connection_TYPE_UNSPECIFIED:
|
|
return database.ConnectionLogMethodSSH, "", nil
|
|
case agentproto.Connection_JETBRAINS:
|
|
return database.ConnectionLogMethodSSH, "jetbrains", nil
|
|
case agentproto.Connection_VSCODE:
|
|
return database.ConnectionLogMethodSSH, "vscode", nil
|
|
case agentproto.Connection_RECONNECTING_PTY:
|
|
return database.ConnectionLogMethodReconnectingPTY, "", nil
|
|
default:
|
|
return "", "", xerrors.Errorf("unsupported agent connection type %d", typ)
|
|
}
|
|
}
|