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

Commit00a2413

Browse files
authored
feat: add telemetry support for workspace agent subsystem (#7579)
1 parent52bb84a commit00a2413

26 files changed

+366
-27
lines changed

‎agent/agent.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@ type Options struct {
6262
IgnorePortsmap[int]string
6363
SSHMaxTimeout time.Duration
6464
TailnetListenPortuint16
65+
Subsystem codersdk.AgentSubsystem
6566
}
6667

6768
typeClientinterface {
@@ -119,6 +120,7 @@ func New(options Options) Agent {
119120
ignorePorts:options.IgnorePorts,
120121
connStatsChan:make(chan*agentsdk.Stats,1),
121122
sshMaxTimeout:options.SSHMaxTimeout,
123+
subsystem:options.Subsystem,
122124
}
123125
a.init(ctx)
124126
returna
@@ -136,6 +138,7 @@ type agent struct {
136138
// listing all listening ports. This is helpful to hide ports that
137139
// are used by the agent, that the user does not care about.
138140
ignorePortsmap[int]string
141+
subsystem codersdk.AgentSubsystem
139142

140143
reconnectingPTYs sync.Map
141144
reconnectingPTYTimeout time.Duration
@@ -488,6 +491,7 @@ func (a *agent) run(ctx context.Context) error {
488491
err=a.client.PostStartup(ctx, agentsdk.PostStartupRequest{
489492
Version:buildinfo.Version(),
490493
ExpandedDirectory:manifest.Directory,
494+
Subsystem:a.subsystem,
491495
})
492496
iferr!=nil {
493497
returnxerrors.Errorf("update workspace agent version: %w",err)
@@ -1455,3 +1459,8 @@ func expandDirectory(dir string) (string, error) {
14551459
}
14561460
returndir,nil
14571461
}
1462+
1463+
// EnvAgentSubsystem is the environment variable used to denote the
1464+
// specialized environment in which the agent is running
1465+
// (e.g. envbox, envbuilder).
1466+
constEnvAgentSubsystem="CODER_AGENT_SUBSYSTEM"

‎cli/agent.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ import (
2626
"github.com/coder/coder/agent/reaper"
2727
"github.com/coder/coder/buildinfo"
2828
"github.com/coder/coder/cli/clibase"
29+
"github.com/coder/coder/codersdk"
2930
"github.com/coder/coder/codersdk/agentsdk"
3031
)
3132

@@ -197,6 +198,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
197198
returnxerrors.Errorf("add executable to $PATH: %w",err)
198199
}
199200

201+
subsystem:=inv.Environ.Get(agent.EnvAgentSubsystem)
200202
agnt:=agent.New(agent.Options{
201203
Client:client,
202204
Logger:logger,
@@ -218,6 +220,7 @@ func (r *RootCmd) workspaceAgent() *clibase.Cmd {
218220
},
219221
IgnorePorts:ignorePorts,
220222
SSHMaxTimeout:sshMaxTimeout,
223+
Subsystem:codersdk.AgentSubsystem(subsystem),
221224
})
222225

223226
debugSrvClose:=ServeHandler(ctx,logger,agnt.HTTPDebug(),debugAddress,"debug")

‎cli/agent_test.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ import (
1212
"github.com/stretchr/testify/assert"
1313
"github.com/stretchr/testify/require"
1414

15+
"github.com/coder/coder/agent"
1516
"github.com/coder/coder/cli/clitest"
1617
"github.com/coder/coder/coderd/coderdtest"
18+
"github.com/coder/coder/codersdk"
1719
"github.com/coder/coder/provisioner/echo"
1820
"github.com/coder/coder/provisionersdk/proto"
1921
"github.com/coder/coder/pty/ptytest"
@@ -235,4 +237,43 @@ func TestWorkspaceAgent(t *testing.T) {
235237
_,err=uuid.Parse(strings.TrimSpace(string(token)))
236238
require.NoError(t,err)
237239
})
240+
241+
t.Run("PostStartup",func(t*testing.T) {
242+
t.Parallel()
243+
244+
authToken:=uuid.NewString()
245+
client:=coderdtest.New(t,&coderdtest.Options{
246+
IncludeProvisionerDaemon:true,
247+
})
248+
user:=coderdtest.CreateFirstUser(t,client)
249+
version:=coderdtest.CreateTemplateVersion(t,client,user.OrganizationID,&echo.Responses{
250+
Parse:echo.ParseComplete,
251+
ProvisionApply:echo.ProvisionApplyWithAgent(authToken),
252+
})
253+
template:=coderdtest.CreateTemplate(t,client,user.OrganizationID,version.ID)
254+
coderdtest.AwaitTemplateVersionJob(t,client,version.ID)
255+
workspace:=coderdtest.CreateWorkspace(t,client,user.OrganizationID,template.ID)
256+
coderdtest.AwaitWorkspaceBuildJob(t,client,workspace.LatestBuild.ID)
257+
258+
logDir:=t.TempDir()
259+
inv,_:=clitest.New(t,
260+
"agent",
261+
"--auth","token",
262+
"--agent-token",authToken,
263+
"--agent-url",client.URL.String(),
264+
"--log-dir",logDir,
265+
)
266+
// Set the subsystem for the agent.
267+
inv.Environ.Set(agent.EnvAgentSubsystem,string(codersdk.AgentSubsystemEnvbox))
268+
269+
pty:=ptytest.New(t).Attach(inv)
270+
271+
clitest.Start(t,inv)
272+
pty.ExpectMatch("starting agent")
273+
274+
resources:=coderdtest.AwaitWorkspaceAgents(t,client,workspace.ID)
275+
require.Len(t,resources,1)
276+
require.Len(t,resources[0].Agents,1)
277+
require.Equal(t,codersdk.AgentSubsystemEnvbox,resources[0].Agents[0].Subsystem)
278+
})
238279
}

‎coderd/apidoc/docs.go

Lines changed: 15 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/database/dbauthz/querier_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1029,7 +1029,8 @@ func (s *MethodTestSuite) TestWorkspace() {
10291029
res:=dbgen.WorkspaceResource(s.T(),db, database.WorkspaceResource{JobID:build.JobID})
10301030
agt:=dbgen.WorkspaceAgent(s.T(),db, database.WorkspaceAgent{ResourceID:res.ID})
10311031
check.Args(database.UpdateWorkspaceAgentStartupByIDParams{
1032-
ID:agt.ID,
1032+
ID:agt.ID,
1033+
Subsystem:database.WorkspaceAgentSubsystemNone,
10331034
}).Asserts(ws,rbac.ActionUpdate).Returns()
10341035
}))
10351036
s.Run("GetWorkspaceAgentStartupLogsAfter",s.Subtest(func(db database.Store,check*expects) {

‎coderd/database/dbfake/databasefake.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3702,6 +3702,7 @@ func (q *fakeQuerier) UpdateWorkspaceAgentStartupByID(_ context.Context, arg dat
37023702

37033703
agent.Version=arg.Version
37043704
agent.ExpandedDirectory=arg.ExpandedDirectory
3705+
agent.Subsystem=arg.Subsystem
37053706
q.workspaceAgents[index]=agent
37063707
returnnil
37073708
}

‎coderd/database/dump.sql

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BEGIN;
2+
ALTERTABLE workspace_agents DROP COLUMN subsystem;
3+
DROPTYPE workspace_agent_subsystem;
4+
COMMIT;
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
BEGIN;
2+
CREATETYPEworkspace_agent_subsystemAS ENUM ('envbuilder','envbox','none');
3+
ALTERTABLE workspace_agents ADD COLUMN subsystem workspace_agent_subsystemNOT NULL default'none';
4+
COMMIT;

‎coderd/database/models.go

Lines changed: 63 additions & 1 deletion
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp