chore: rename startup logs to agent logs (#8649)

* chore: rename startup logs to agent logs

This also adds a `source` property to every agent log. It
should allow us to group logs and display them nicer in
the UI as they stream in.

* Fix migration order

* Fix naming

* Rename the frontend

* Fix tests

* Fix down migration

* Match enums for workspace agent logs

* Fix inserting log source

* Fix migration order

* Fix logs tests

* Fix psql insert
This commit is contained in:
Kyle Carberry
2023-07-28 15:57:23 +00:00
committed by GitHub
parent 78b06397a6
commit bd944e0d21
48 changed files with 1471 additions and 876 deletions
+82 -11
View File
@@ -1169,6 +1169,76 @@ func AllWorkspaceAgentLifecycleStateValues() []WorkspaceAgentLifecycleState {
}
}
type WorkspaceAgentLogSource string
const (
WorkspaceAgentLogSourceStartupScript WorkspaceAgentLogSource = "startup_script"
WorkspaceAgentLogSourceShutdownScript WorkspaceAgentLogSource = "shutdown_script"
WorkspaceAgentLogSourceKubernetesLogs WorkspaceAgentLogSource = "kubernetes_logs"
WorkspaceAgentLogSourceEnvbox WorkspaceAgentLogSource = "envbox"
WorkspaceAgentLogSourceEnvbuilder WorkspaceAgentLogSource = "envbuilder"
WorkspaceAgentLogSourceExternal WorkspaceAgentLogSource = "external"
)
func (e *WorkspaceAgentLogSource) Scan(src interface{}) error {
switch s := src.(type) {
case []byte:
*e = WorkspaceAgentLogSource(s)
case string:
*e = WorkspaceAgentLogSource(s)
default:
return fmt.Errorf("unsupported scan type for WorkspaceAgentLogSource: %T", src)
}
return nil
}
type NullWorkspaceAgentLogSource struct {
WorkspaceAgentLogSource WorkspaceAgentLogSource `json:"workspace_agent_log_source"`
Valid bool `json:"valid"` // Valid is true if WorkspaceAgentLogSource is not NULL
}
// Scan implements the Scanner interface.
func (ns *NullWorkspaceAgentLogSource) Scan(value interface{}) error {
if value == nil {
ns.WorkspaceAgentLogSource, ns.Valid = "", false
return nil
}
ns.Valid = true
return ns.WorkspaceAgentLogSource.Scan(value)
}
// Value implements the driver Valuer interface.
func (ns NullWorkspaceAgentLogSource) Value() (driver.Value, error) {
if !ns.Valid {
return nil, nil
}
return string(ns.WorkspaceAgentLogSource), nil
}
func (e WorkspaceAgentLogSource) Valid() bool {
switch e {
case WorkspaceAgentLogSourceStartupScript,
WorkspaceAgentLogSourceShutdownScript,
WorkspaceAgentLogSourceKubernetesLogs,
WorkspaceAgentLogSourceEnvbox,
WorkspaceAgentLogSourceEnvbuilder,
WorkspaceAgentLogSourceExternal:
return true
}
return false
}
func AllWorkspaceAgentLogSourceValues() []WorkspaceAgentLogSource {
return []WorkspaceAgentLogSource{
WorkspaceAgentLogSourceStartupScript,
WorkspaceAgentLogSourceShutdownScript,
WorkspaceAgentLogSourceKubernetesLogs,
WorkspaceAgentLogSourceEnvbox,
WorkspaceAgentLogSourceEnvbuilder,
WorkspaceAgentLogSourceExternal,
}
}
type WorkspaceAgentSubsystem string
const (
@@ -1806,10 +1876,10 @@ type WorkspaceAgent struct {
// The number of seconds to wait for the shutdown script to complete. If the script does not complete within this time, the agent lifecycle will be marked as shutdown_timeout.
ShutdownScriptTimeoutSeconds int32 `db:"shutdown_script_timeout_seconds" json:"shutdown_script_timeout_seconds"`
// Total length of startup logs
StartupLogsLength int32 `db:"startup_logs_length" json:"startup_logs_length"`
LogsLength int32 `db:"logs_length" json:"logs_length"`
// Whether the startup logs overflowed in length
StartupLogsOverflowed bool `db:"startup_logs_overflowed" json:"startup_logs_overflowed"`
Subsystem WorkspaceAgentSubsystem `db:"subsystem" json:"subsystem"`
LogsOverflowed bool `db:"logs_overflowed" json:"logs_overflowed"`
Subsystem WorkspaceAgentSubsystem `db:"subsystem" json:"subsystem"`
// When startup script behavior is non-blocking, the workspace will be ready and accessible upon agent connection, when it is blocking, workspace will wait for the startup script to complete before becoming ready and accessible.
StartupScriptBehavior StartupScriptBehavior `db:"startup_script_behavior" json:"startup_script_behavior"`
// The time the agent entered the starting lifecycle state
@@ -1818,6 +1888,15 @@ type WorkspaceAgent struct {
ReadyAt sql.NullTime `db:"ready_at" json:"ready_at"`
}
type WorkspaceAgentLog struct {
AgentID uuid.UUID `db:"agent_id" json:"agent_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
Output string `db:"output" json:"output"`
ID int64 `db:"id" json:"id"`
Level LogLevel `db:"level" json:"level"`
Source WorkspaceAgentLogSource `db:"source" json:"source"`
}
type WorkspaceAgentMetadatum struct {
WorkspaceAgentID uuid.UUID `db:"workspace_agent_id" json:"workspace_agent_id"`
DisplayName string `db:"display_name" json:"display_name"`
@@ -1830,14 +1909,6 @@ type WorkspaceAgentMetadatum struct {
CollectedAt time.Time `db:"collected_at" json:"collected_at"`
}
type WorkspaceAgentStartupLog struct {
AgentID uuid.UUID `db:"agent_id" json:"agent_id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`
Output string `db:"output" json:"output"`
ID int64 `db:"id" json:"id"`
Level LogLevel `db:"level" json:"level"`
}
type WorkspaceAgentStat struct {
ID uuid.UUID `db:"id" json:"id"`
CreatedAt time.Time `db:"created_at" json:"created_at"`