Skip to content

Commit 96f27c6

Browse files
committed
Respond to Steven's feedback
1 parent 9bd442c commit 96f27c6

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

coderd/database/migrations/000039_agent_stats.up.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
CREATE TABLE agent_stats (
2-
id text NOT NULL,
2+
id uuid NOT NULL,
33
PRIMARY KEY (id),
44
created_at timestamptz NOT NULL,
55
user_id uuid NOT NULL,

coderd/metrics.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (api *API) daus(rw http.ResponseWriter, r *http.Request) {
7676
httpapi.Write(rw, http.StatusOK, resp)
7777
}
7878

79-
const AgentStatIntervalEnv = "CODER_AGENT_STAT_INTERVAL"
79+
const AgentStatIntervalEnv = "CODER_AGENT_STAT_INTERVAL_MS"
8080

8181
func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Request) {
8282
api.websocketWaitMutex.Lock()
@@ -177,6 +177,7 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
177177
var insert = !reflect.DeepEqual(lastReport, rep)
178178

179179
api.Logger.Debug(ctx, "read stats report",
180+
slog.F("interval", interval),
180181
slog.F("agent", workspaceAgent.ID),
181182
slog.F("resource", resource.ID),
182183
slog.F("workspace", workspace.ID),

codersdk/metrics.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,11 @@ func (c *Client) AgentReportStats(
5555
go func() {
5656
defer close(doneCh)
5757

58-
for r := retry.New(time.Second, time.Hour); r.Wait(ctx); {
58+
// If the agent connection succeeds for a while, then fails, then succeeds
59+
// for a while (etc.) the retry may hit the maximum. This is a normal
60+
// case for long-running agents that experience coderd upgrades, so
61+
// we use a short maximum retry limit.
62+
for r := retry.New(time.Second, time.Minute); r.Wait(ctx); {
5963
err = func() error {
6064
conn, res, err := websocket.Dial(ctx, serverURL.String(), &websocket.DialOptions{
6165
HTTPClient: httpClient,

0 commit comments

Comments
 (0)