Skip to content

Commit 234bb48

Browse files
committed
clean up agent socket client.
remove unused types and simplify the interface
1 parent 381eea1 commit 234bb48

File tree

1 file changed

+8
-53
lines changed

1 file changed

+8
-53
lines changed

codersdk/agentsdk/socket_client.go

Lines changed: 8 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,13 @@ import (
66
"net"
77
"os"
88
"path/filepath"
9-
"time"
109

1110
"golang.org/x/xerrors"
1211

1312
"github.com/hashicorp/yamux"
1413
"storj.io/drpc"
1514

1615
"github.com/coder/coder/v2/agent/agentsocket/proto"
17-
"github.com/coder/coder/v2/agent/unit"
1816
"github.com/coder/coder/v2/codersdk/drpcsdk"
1917
)
2018

@@ -72,84 +70,61 @@ func (c *SocketClient) Close() error {
7270
}
7371

7472
// Ping sends a ping request to the agent
75-
func (c *SocketClient) Ping(ctx context.Context) (*PingResponse, error) {
76-
resp, err := c.client.Ping(ctx, &proto.PingRequest{})
73+
func (c *SocketClient) Ping(ctx context.Context) error {
74+
_, err := c.client.Ping(ctx, &proto.PingRequest{})
7775
if err != nil {
78-
return nil, err
76+
return err
7977
}
8078

81-
return &PingResponse{
82-
Message: resp.Message,
83-
Timestamp: resp.Timestamp.AsTime(),
84-
}, nil
79+
return nil
8580
}
8681

8782
// SyncStart starts a unit in the dependency graph
8883
func (c *SocketClient) SyncStart(ctx context.Context, unitName string) error {
89-
resp, err := c.client.SyncStart(ctx, &proto.SyncStartRequest{
84+
_, err := c.client.SyncStart(ctx, &proto.SyncStartRequest{
9085
Unit: unitName,
9186
})
9287
if err != nil {
9388
return err
9489
}
9590

96-
if !resp.Success {
97-
return xerrors.Errorf("sync start failed: %s", resp.Message)
98-
}
99-
10091
return nil
10192
}
10293

10394
// SyncWant declares a dependency between units
10495
func (c *SocketClient) SyncWant(ctx context.Context, unitName, dependsOn string) error {
105-
resp, err := c.client.SyncWant(ctx, &proto.SyncWantRequest{
96+
_, err := c.client.SyncWant(ctx, &proto.SyncWantRequest{
10697
Unit: unitName,
10798
DependsOn: dependsOn,
10899
})
109100
if err != nil {
110101
return err
111102
}
112103

113-
if !resp.Success {
114-
return xerrors.Errorf("sync want failed: %s", resp.Message)
115-
}
116-
117104
return nil
118105
}
119106

120107
// SyncComplete marks a unit as complete in the dependency graph
121108
func (c *SocketClient) SyncComplete(ctx context.Context, unitName string) error {
122-
resp, err := c.client.SyncComplete(ctx, &proto.SyncCompleteRequest{
109+
_, err := c.client.SyncComplete(ctx, &proto.SyncCompleteRequest{
123110
Unit: unitName,
124111
})
125112
if err != nil {
126113
return err
127114
}
128115

129-
if !resp.Success {
130-
return xerrors.Errorf("sync complete failed: %s", resp.Message)
131-
}
132-
133116
return nil
134117
}
135118

136119
// SyncReady requests whether a unit is ready to be started. That is, all dependencies are satisfied.
137120
func (c *SocketClient) SyncReady(ctx context.Context, unitName string) error {
138-
resp, err := c.client.SyncReady(ctx, &proto.SyncReadyRequest{
121+
_, err := c.client.SyncReady(ctx, &proto.SyncReadyRequest{
139122
Unit: unitName,
140123
})
141124
if err != nil {
142125
return err
143126
}
144127

145-
if !resp.Success {
146-
// Check if this is a dependencies not satisfied error
147-
if resp.Message == unit.ErrDependenciesNotSatisfied.Error() {
148-
return unit.ErrDependenciesNotSatisfied
149-
}
150-
return xerrors.Errorf("sync ready failed: %s", resp.Message)
151-
}
152-
153128
return nil
154129
}
155130

@@ -218,26 +193,6 @@ func discoverSocketPath() (string, error) {
218193
return "", xerrors.New("agent socket not found")
219194
}
220195

221-
// Response types for backward compatibility
222-
type PingResponse struct {
223-
Message string `json:"message"`
224-
Timestamp time.Time `json:"timestamp"`
225-
}
226-
227-
type HealthResponse struct {
228-
Status string `json:"status"`
229-
Timestamp time.Time `json:"timestamp"`
230-
Uptime string `json:"uptime"`
231-
}
232-
233-
type AgentInfo struct {
234-
ID string `json:"id"`
235-
Version string `json:"version"`
236-
Status string `json:"status"`
237-
StartedAt time.Time `json:"started_at"`
238-
Uptime string `json:"uptime"`
239-
}
240-
241196
type SyncStatusResponse struct {
242197
Success bool `json:"success"`
243198
Message string `json:"message"`

0 commit comments

Comments
 (0)