Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

feat: add telemetry support for workspace agent subsystem#7579

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sreya merged 13 commits intomainfromjon/envboxtelem
May 18, 2023
Merged
Show file tree
Hide file tree
Changes from1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
PrevPrevious commit
NextNext commit
add test for agent CLI
  • Loading branch information
@sreya
sreya committedMay 17, 2023
commit2b4140f39cac809276867ccecfe8e43e67a473ff
12 changes: 6 additions & 6 deletionsagent/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -62,7 +62,7 @@ type Options struct {
IgnorePorts map[int]string
SSHMaxTimeout time.Duration
TailnetListenPort uint16
Subsystemagentsdk.AgentSubsystem
Subsystemcodersdk.AgentSubsystem
}

type Client interface {
Expand DownExpand Up@@ -138,7 +138,7 @@ type agent struct {
// listing all listening ports. This is helpful to hide ports that
// are used by the agent, that the user does not care about.
ignorePorts map[int]string
subsystemagentsdk.AgentSubsystem
subsystemcodersdk.AgentSubsystem

reconnectingPTYs sync.Map
reconnectingPTYTimeout time.Duration
Expand DownExpand Up@@ -1467,11 +1467,11 @@ const EnvAgentSubsystem = "CODER_AGENT_SUBSYSTEM"

// SubsystemFromEnv returns the subsystem (if any) the agent
// is running inside of.
func SubsystemFromEnv()agentsdk.AgentSubsystem {
func SubsystemFromEnv()codersdk.AgentSubsystem {
ss := os.Getenv(EnvAgentSubsystem)
switchagentsdk.AgentSubsystem(ss) {
caseagentsdk.AgentSubsystemEnvbox:
returnagentsdk.AgentSubsystemEnvbox
switchcodersdk.AgentSubsystem(ss) {
casecodersdk.AgentSubsystemEnvbox:
returncodersdk.AgentSubsystemEnvbox
default:
return ""
}
Expand Down
4 changes: 3 additions & 1 deletioncli/agent.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -26,6 +26,7 @@ import (
"github.com/coder/coder/agent/reaper"
"github.com/coder/coder/buildinfo"
"github.com/coder/coder/cli/clibase"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/codersdk/agentsdk"
)

Expand DownExpand Up@@ -197,6 +198,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
return xerrors.Errorf("add executable to $PATH: %w", err)
}

subsystem := inv.Environ.Get(agent.EnvAgentSubsystem)
agnt := agent.New(agent.Options{
Client: client,
Logger: logger,
Expand All@@ -218,7 +220,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
},
IgnorePorts: ignorePorts,
SSHMaxTimeout: sshMaxTimeout,
Subsystem:agent.SubsystemFromEnv(),
Subsystem:codersdk.AgentSubsystem(subsystem),
})

debugSrvClose := ServeHandler(ctx, logger, agnt.HTTPDebug(), debugAddress, "debug")
Expand Down
41 changes: 41 additions & 0 deletionscli/agent_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -12,8 +12,10 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"

"github.com/coder/coder/agent"
"github.com/coder/coder/cli/clitest"
"github.com/coder/coder/coderd/coderdtest"
"github.com/coder/coder/codersdk"
"github.com/coder/coder/provisioner/echo"
"github.com/coder/coder/provisionersdk/proto"
"github.com/coder/coder/pty/ptytest"
Expand DownExpand Up@@ -235,4 +237,43 @@ func TestWorkspaceAgent(t *testing.T) {
_, err = uuid.Parse(strings.TrimSpace(string(token)))
require.NoError(t, err)
})

t.Run("PostStartup", func(t *testing.T) {
t.Parallel()

authToken := uuid.NewString()
client := coderdtest.New(t, &coderdtest.Options{
IncludeProvisionerDaemon: true,
})
user := coderdtest.CreateFirstUser(t, client)
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
Parse: echo.ParseComplete,
ProvisionApply: echo.ProvisionApplyWithAgent(authToken),
})
template := coderdtest.CreateTemplate(t, client, user.OrganizationID, version.ID)
coderdtest.AwaitTemplateVersionJob(t, client, version.ID)
workspace := coderdtest.CreateWorkspace(t, client, user.OrganizationID, template.ID)
coderdtest.AwaitWorkspaceBuildJob(t, client, workspace.LatestBuild.ID)

logDir := t.TempDir()
inv, _ := clitest.New(t,
"agent",
"--auth", "token",
"--agent-token", authToken,
"--agent-url", client.URL.String(),
"--log-dir", logDir,
)
// Set the subsystem for the agent.
inv.Environ.Set(agent.EnvAgentSubsystem, string(codersdk.AgentSubsystemEnvbox))

pty := ptytest.New(t).Attach(inv)

clitest.Start(t, inv)
pty.ExpectMatch("starting agent")

resources := coderdtest.AwaitWorkspaceAgents(t, client, workspace.ID)
require.Len(t, resources, 1)
require.Len(t, resources[0].Agents, 1)
require.Equal(t, codersdk.AgentSubsystemEnvbox, resources[0].Agents[0].Subsystem)
})
}
5 changes: 3 additions & 2 deletionscoderd/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -1130,6 +1130,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
StartupScriptTimeoutSeconds: dbAgent.StartupScriptTimeoutSeconds,
ShutdownScript: dbAgent.ShutdownScript.String,
ShutdownScriptTimeoutSeconds: dbAgent.ShutdownScriptTimeoutSeconds,
Subsystem: codersdk.AgentSubsystem(dbAgent.Subsystem),
}
node := coordinator.Node(dbAgent.ID)
if node != nil {
Expand DownExpand Up@@ -1985,9 +1986,9 @@ func convertWorkspaceAgentStartupLog(logEntry database.WorkspaceAgentStartupLog)
}
}

func convertWorkspaceAgentSubsystem(ssagentsdk.AgentSubsystem) database.WorkspaceAgentSubsystem {
func convertWorkspaceAgentSubsystem(sscodersdk.AgentSubsystem) database.WorkspaceAgentSubsystem {
switch ss {
caseagentsdk.AgentSubsystemEnvbox:
casecodersdk.AgentSubsystemEnvbox:
return database.WorkspaceAgentSubsystemEnvbox
default:
return database.WorkspaceAgentSubsystemNone
Expand Down
12 changes: 3 additions & 9 deletionscodersdk/agentsdk/agentsdk.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -453,12 +453,6 @@ func (c *Client) ReportStats(ctx context.Context, log slog.Logger, statsChan <-c
}), nil
}

type AgentSubsystem string

const (
AgentSubsystemEnvbox AgentSubsystem = "envbox"
)

// Stats records the Agent's network connection statistics for use in
// user-facing metrics and debugging.
type Stats struct {
Expand DownExpand Up@@ -550,9 +544,9 @@ func (c *Client) PostLifecycle(ctx context.Context, req PostLifecycleRequest) er
}

type PostStartupRequest struct {
Version string `json:"version"`
ExpandedDirectory string `json:"expanded_directory"`
Subsystem AgentSubsystem `json:"subsystem"`
Version string`json:"version"`
ExpandedDirectory string`json:"expanded_directory"`
Subsystemcodersdk.AgentSubsystem `json:"subsystem"`
}

func (c *Client) PostStartup(ctx context.Context, req PostStartupRequest) error {
Expand Down
13 changes: 10 additions & 3 deletionscodersdk/workspaceagents.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -130,9 +130,10 @@ type WorkspaceAgent struct {
// LoginBeforeReady if true, the agent will delay logins until it is ready (e.g. executing startup script has ended).
LoginBeforeReady bool `json:"login_before_ready"`
// StartupScriptTimeoutSeconds is the number of seconds to wait for the startup script to complete. If the script does not complete within this time, the agent lifecycle will be marked as start_timeout.
StartupScriptTimeoutSeconds int32 `json:"startup_script_timeout_seconds"`
ShutdownScript string `json:"shutdown_script,omitempty"`
ShutdownScriptTimeoutSeconds int32 `json:"shutdown_script_timeout_seconds"`
StartupScriptTimeoutSeconds int32 `json:"startup_script_timeout_seconds"`
ShutdownScript string `json:"shutdown_script,omitempty"`
ShutdownScriptTimeoutSeconds int32 `json:"shutdown_script_timeout_seconds"`
Subsystem AgentSubsystem `json:"subsytem"`
}

type DERPRegion struct {
Expand DownExpand Up@@ -553,3 +554,9 @@ type WorkspaceAgentStartupLog struct {
Output string `json:"output"`
Level LogLevel `json:"level"`
}

type AgentSubsystem string

const (
AgentSubsystemEnvbox AgentSubsystem = "envbox"
)

[8]ページ先頭

©2009-2025 Movatter.jp