Skip to content

Commit dd24368

Browse files
chore!: remove deprecated agent v1 routes (#13486)
1 parent e7bea17 commit dd24368

File tree

15 files changed

+156
-2895
lines changed

15 files changed

+156
-2895
lines changed

coderd/apidoc/docs.go

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

coderd/apidoc/swagger.json

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

coderd/coderd.go

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1002,23 +1002,11 @@ func New(options *Options) *API {
10021002
Optional: false,
10031003
}))
10041004
r.Get("/rpc", api.workspaceAgentRPC)
1005-
r.Get("/manifest", api.workspaceAgentManifest)
1006-
// This route is deprecated and will be removed in a future release.
1007-
// New agents will use /me/manifest instead.
1008-
r.Get("/metadata", api.workspaceAgentManifest)
1009-
r.Post("/startup", api.postWorkspaceAgentStartup)
1010-
r.Patch("/startup-logs", api.patchWorkspaceAgentLogsDeprecated)
10111005
r.Patch("/logs", api.patchWorkspaceAgentLogs)
1012-
r.Post("/app-health", api.postWorkspaceAppHealth)
10131006
// Deprecated: Required to support legacy agents
10141007
r.Get("/gitauth", api.workspaceAgentsGitAuth)
10151008
r.Get("/external-auth", api.workspaceAgentsExternalAuth)
10161009
r.Get("/gitsshkey", api.agentGitSSHKey)
1017-
r.Get("/coordinate", api.workspaceAgentCoordinate)
1018-
r.Post("/report-stats", api.workspaceAgentReportStats)
1019-
r.Post("/report-lifecycle", api.workspaceAgentReportLifecycle)
1020-
r.Post("/metadata", api.workspaceAgentPostMetadata)
1021-
r.Post("/metadata/{key}", api.workspaceAgentPostMetadataDeprecated)
10221010
r.Post("/log-source", api.workspaceAgentPostLogSource)
10231011
})
10241012
r.Route("/{workspaceagent}", func(r chi.Router) {

coderd/deprecated.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@ package coderd
33
import (
44
"net/http"
55

6-
"github.com/go-chi/chi/v5"
7-
8-
"cdr.dev/slog"
96
"github.com/coder/coder/v2/coderd/httpapi"
107
"github.com/coder/coder/v2/coderd/httpmw"
118
"github.com/coder/coder/v2/codersdk"
12-
"github.com/coder/coder/v2/codersdk/agentsdk"
139
)
1410

1511
// @Summary Removed: Get parameters by template version
@@ -34,19 +30,6 @@ func templateVersionSchemaDeprecated(rw http.ResponseWriter, r *http.Request) {
3430
httpapi.Write(r.Context(), rw, http.StatusOK, []struct{}{})
3531
}
3632

37-
// @Summary Removed: Patch workspace agent logs
38-
// @ID removed-patch-workspace-agent-logs
39-
// @Security CoderSessionToken
40-
// @Accept json
41-
// @Produce json
42-
// @Tags Agents
43-
// @Param request body agentsdk.PatchLogs true "logs"
44-
// @Success 200 {object} codersdk.Response
45-
// @Router /workspaceagents/me/startup-logs [patch]
46-
func (api *API) patchWorkspaceAgentLogsDeprecated(rw http.ResponseWriter, r *http.Request) {
47-
api.patchWorkspaceAgentLogs(rw, r)
48-
}
49-
5033
// @Summary Removed: Get logs by workspace agent
5134
// @ID removed-get-logs-by-workspace-agent
5235
// @Security CoderSessionToken
@@ -77,45 +60,6 @@ func (api *API) workspaceAgentsGitAuth(rw http.ResponseWriter, r *http.Request)
7760
api.workspaceAgentsExternalAuth(rw, r)
7861
}
7962

80-
// @Summary Removed: Submit workspace agent metadata
81-
// @ID removed-submit-workspace-agent-metadata
82-
// @Security CoderSessionToken
83-
// @Accept json
84-
// @Tags Agents
85-
// @Param request body agentsdk.PostMetadataRequestDeprecated true "Workspace agent metadata request"
86-
// @Param key path string true "metadata key" format(string)
87-
// @Success 204 "Success"
88-
// @Router /workspaceagents/me/metadata/{key} [post]
89-
// @x-apidocgen {"skip": true}
90-
func (api *API) workspaceAgentPostMetadataDeprecated(rw http.ResponseWriter, r *http.Request) {
91-
ctx := r.Context()
92-
93-
var req agentsdk.PostMetadataRequestDeprecated
94-
if !httpapi.Read(ctx, rw, r, &req) {
95-
return
96-
}
97-
98-
workspaceAgent := httpmw.WorkspaceAgent(r)
99-
100-
key := chi.URLParam(r, "key")
101-
102-
err := api.workspaceAgentUpdateMetadata(ctx, workspaceAgent, agentsdk.PostMetadataRequest{
103-
Metadata: []agentsdk.Metadata{
104-
{
105-
Key: key,
106-
WorkspaceAgentMetadataResult: req,
107-
},
108-
},
109-
})
110-
if err != nil {
111-
api.Logger.Error(ctx, "failed to handle metadata request", slog.Error(err))
112-
httpapi.InternalServerError(rw, err)
113-
return
114-
}
115-
116-
httpapi.Write(ctx, rw, http.StatusNoContent, nil)
117-
}
118-
11963
// @Summary Removed: Get workspace resources for workspace build
12064
// @ID removed-get-workspace-resources-for-workspace-build
12165
// @Security CoderSessionToken

coderd/prometheusmetrics/insights/metricscollector_test.go

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ import (
1818

1919
"cdr.dev/slog"
2020
"cdr.dev/slog/sloggers/slogtest"
21+
agentproto "github.com/coder/coder/v2/agent/proto"
2122
"github.com/coder/coder/v2/coderd/coderdtest"
2223
"github.com/coder/coder/v2/coderd/database"
2324
"github.com/coder/coder/v2/coderd/database/dbauthz"
@@ -87,25 +88,37 @@ func TestCollectInsights(t *testing.T) {
8788
)
8889

8990
// Start an agent so that we can generate stats.
90-
var agentClients []*agentsdk.Client
91+
var agentClients []agentproto.DRPCAgentClient
9192
for i, agent := range []database.WorkspaceAgent{agent1, agent2} {
9293
agentClient := agentsdk.New(client.URL)
9394
agentClient.SetSessionToken(agent.AuthToken.String())
9495
agentClient.SDK.SetLogger(logger.Leveled(slog.LevelDebug).Named(fmt.Sprintf("agent%d", i+1)))
95-
agentClients = append(agentClients, agentClient)
96+
conn, err := agentClient.ConnectRPC(context.Background())
97+
require.NoError(t, err)
98+
agentAPI := agentproto.NewDRPCAgentClient(conn)
99+
agentClients = append(agentClients, agentAPI)
96100
}
97101

102+
defer func() {
103+
for a := range agentClients {
104+
err := agentClients[a].DRPCConn().Close()
105+
require.NoError(t, err)
106+
}
107+
}()
108+
98109
// Fake app stats
99-
_, err = agentClients[0].PostStats(context.Background(), &agentsdk.Stats{
100-
// ConnectionCount must be positive as database query ignores stats with no active connections at the time frame
101-
ConnectionsByProto: map[string]int64{"TCP": 1},
102-
ConnectionCount: 1,
103-
ConnectionMedianLatencyMS: 15,
104-
// Session counts must be positive, but the exact value is ignored.
105-
// Database query approximates it to 60s of usage.
106-
SessionCountSSH: 99,
107-
SessionCountJetBrains: 47,
108-
SessionCountVSCode: 34,
110+
_, err = agentClients[0].UpdateStats(context.Background(), &agentproto.UpdateStatsRequest{
111+
Stats: &agentproto.Stats{
112+
// ConnectionCount must be positive as database query ignores stats with no active connections at the time frame
113+
ConnectionsByProto: map[string]int64{"TCP": 1},
114+
ConnectionCount: 1,
115+
ConnectionMedianLatencyMs: 15,
116+
// Session counts must be positive, but the exact value is ignored.
117+
// Database query approximates it to 60s of usage.
118+
SessionCountSsh: 99,
119+
SessionCountJetbrains: 47,
120+
SessionCountVscode: 34,
121+
},
109122
})
110123
require.NoError(t, err, "unable to post fake stats")
111124

coderd/prometheusmetrics/prometheusmetrics_test.go

Lines changed: 35 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020
"cdr.dev/slog"
2121
"cdr.dev/slog/sloggers/slogtest"
2222

23+
agentproto "github.com/coder/coder/v2/agent/proto"
2324
"github.com/coder/coder/v2/coderd/agentmetrics"
2425
"github.com/coder/coder/v2/coderd/coderdtest"
2526
"github.com/coder/coder/v2/coderd/database"
@@ -415,36 +416,45 @@ func TestAgentStats(t *testing.T) {
415416

416417
user := coderdtest.CreateFirstUser(t, client)
417418

418-
agent1 := prepareWorkspaceAndAgent(t, client, user, 1)
419-
agent2 := prepareWorkspaceAndAgent(t, client, user, 2)
420-
agent3 := prepareWorkspaceAndAgent(t, client, user, 3)
419+
agent1 := prepareWorkspaceAndAgent(ctx, t, client, user, 1)
420+
agent2 := prepareWorkspaceAndAgent(ctx, t, client, user, 2)
421+
agent3 := prepareWorkspaceAndAgent(ctx, t, client, user, 3)
422+
defer agent1.DRPCConn().Close()
423+
defer agent2.DRPCConn().Close()
424+
defer agent3.DRPCConn().Close()
421425

422426
registry := prometheus.NewRegistry()
423427

424428
// given
425429
var i int64
426430
for i = 0; i < 3; i++ {
427-
_, err = agent1.PostStats(ctx, &agentsdk.Stats{
428-
TxBytes: 1 + i, RxBytes: 2 + i,
429-
SessionCountVSCode: 3 + i, SessionCountJetBrains: 4 + i, SessionCountReconnectingPTY: 5 + i, SessionCountSSH: 6 + i,
430-
ConnectionCount: 7 + i, ConnectionMedianLatencyMS: 8000,
431-
ConnectionsByProto: map[string]int64{"TCP": 1},
431+
_, err = agent1.UpdateStats(ctx, &agentproto.UpdateStatsRequest{
432+
Stats: &agentproto.Stats{
433+
TxBytes: 1 + i, RxBytes: 2 + i,
434+
SessionCountVscode: 3 + i, SessionCountJetbrains: 4 + i, SessionCountReconnectingPty: 5 + i, SessionCountSsh: 6 + i,
435+
ConnectionCount: 7 + i, ConnectionMedianLatencyMs: 8000,
436+
ConnectionsByProto: map[string]int64{"TCP": 1},
437+
},
432438
})
433439
require.NoError(t, err)
434440

435-
_, err = agent2.PostStats(ctx, &agentsdk.Stats{
436-
TxBytes: 2 + i, RxBytes: 4 + i,
437-
SessionCountVSCode: 6 + i, SessionCountJetBrains: 8 + i, SessionCountReconnectingPTY: 10 + i, SessionCountSSH: 12 + i,
438-
ConnectionCount: 8 + i, ConnectionMedianLatencyMS: 10000,
439-
ConnectionsByProto: map[string]int64{"TCP": 1},
441+
_, err = agent2.UpdateStats(ctx, &agentproto.UpdateStatsRequest{
442+
Stats: &agentproto.Stats{
443+
TxBytes: 2 + i, RxBytes: 4 + i,
444+
SessionCountVscode: 6 + i, SessionCountJetbrains: 8 + i, SessionCountReconnectingPty: 10 + i, SessionCountSsh: 12 + i,
445+
ConnectionCount: 8 + i, ConnectionMedianLatencyMs: 10000,
446+
ConnectionsByProto: map[string]int64{"TCP": 1},
447+
},
440448
})
441449
require.NoError(t, err)
442450

443-
_, err = agent3.PostStats(ctx, &agentsdk.Stats{
444-
TxBytes: 3 + i, RxBytes: 6 + i,
445-
SessionCountVSCode: 12 + i, SessionCountJetBrains: 14 + i, SessionCountReconnectingPTY: 16 + i, SessionCountSSH: 18 + i,
446-
ConnectionCount: 9 + i, ConnectionMedianLatencyMS: 12000,
447-
ConnectionsByProto: map[string]int64{"TCP": 1},
451+
_, err = agent3.UpdateStats(ctx, &agentproto.UpdateStatsRequest{
452+
Stats: &agentproto.Stats{
453+
TxBytes: 3 + i, RxBytes: 6 + i,
454+
SessionCountVscode: 12 + i, SessionCountJetbrains: 14 + i, SessionCountReconnectingPty: 16 + i, SessionCountSsh: 18 + i,
455+
ConnectionCount: 9 + i, ConnectionMedianLatencyMs: 12000,
456+
ConnectionsByProto: map[string]int64{"TCP": 1},
457+
},
448458
})
449459
require.NoError(t, err)
450460
}
@@ -596,7 +606,7 @@ func TestExperimentsMetric(t *testing.T) {
596606
}
597607
}
598608

599-
func prepareWorkspaceAndAgent(t *testing.T, client *codersdk.Client, user codersdk.CreateFirstUserResponse, workspaceNum int) *agentsdk.Client {
609+
func prepareWorkspaceAndAgent(ctx context.Context, t *testing.T, client *codersdk.Client, user codersdk.CreateFirstUserResponse, workspaceNum int) agentproto.DRPCAgentClient {
600610
authToken := uuid.NewString()
601611

602612
version := coderdtest.CreateTemplateVersion(t, client, user.OrganizationID, &echo.Responses{
@@ -611,9 +621,12 @@ func prepareWorkspaceAndAgent(t *testing.T, client *codersdk.Client, user coders
611621
})
612622
coderdtest.AwaitWorkspaceBuildJobCompleted(t, client, workspace.LatestBuild.ID)
613623

614-
agentClient := agentsdk.New(client.URL)
615-
agentClient.SetSessionToken(authToken)
616-
return agentClient
624+
ac := agentsdk.New(client.URL)
625+
ac.SetSessionToken(authToken)
626+
conn, err := ac.ConnectRPC(ctx)
627+
require.NoError(t, err)
628+
agentAPI := agentproto.NewDRPCAgentClient(conn)
629+
return agentAPI
617630
}
618631

619632
var (

0 commit comments

Comments
 (0)