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

Commit72d6731

Browse files
authored
fix: Only update workspace LastUsed when the connection payload has changed (#4115)
This was causing every workspace to update last used to time.Now() whencoderd was restarted!
1 parent153e96f commit72d6731

File tree

5 files changed

+63
-1
lines changed

5 files changed

+63
-1
lines changed

‎coderd/database/databasefake/databasefake.go

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -159,6 +159,33 @@ func (q *fakeQuerier) InsertAgentStat(_ context.Context, p database.InsertAgentS
159159
returnstat,nil
160160
}
161161

162+
func (q*fakeQuerier)GetLatestAgentStat(_ context.Context,agentID uuid.UUID) (database.AgentStat,error) {
163+
q.mutex.RLock()
164+
deferq.mutex.RUnlock()
165+
166+
found:=false
167+
latest:= database.AgentStat{}
168+
for_,agentStat:=rangeq.agentStats {
169+
ifagentStat.AgentID!=agentID {
170+
continue
171+
}
172+
if!found {
173+
latest=agentStat
174+
found=true
175+
continue
176+
}
177+
ifagentStat.CreatedAt.After(latest.CreatedAt) {
178+
latest=agentStat
179+
found=true
180+
continue
181+
}
182+
}
183+
if!found {
184+
return database.AgentStat{},sql.ErrNoRows
185+
}
186+
returnlatest,nil
187+
}
188+
162189
func (q*fakeQuerier)GetTemplateDAUs(_ context.Context,templateID uuid.UUID) ([]database.GetTemplateDAUsRow,error) {
163190
q.mutex.Lock()
164191
deferq.mutex.Unlock()

‎coderd/database/querier.go

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

‎coderd/database/queries.sql.go

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

‎coderd/database/queries/agentstats.sql

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ INSERT INTO
1212
VALUES
1313
($1, $2, $3, $4, $5, $6, $7) RETURNING*;
1414

15+
-- name: GetLatestAgentStat :one
16+
SELECT*FROM agent_statsWHERE agent_id= $1ORDER BY created_atDESCLIMIT1;
17+
1518
-- name: GetTemplateDAUs :many
1619
select
1720
(created_at atTIME ZONE'UTC')::dateasdate,

‎coderd/workspaceagents.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -795,10 +795,22 @@ func (api *API) workspaceAgentReportStats(rw http.ResponseWriter, r *http.Reques
795795
}
796796
deferconn.Close(websocket.StatusAbnormalClosure,"")
797797

798+
varlastReport codersdk.AgentStatsReportResponse
799+
latestStat,err:=api.Database.GetLatestAgentStat(r.Context(),workspaceAgent.ID)
800+
iferr==nil {
801+
err=json.Unmarshal(latestStat.Payload,&lastReport)
802+
iferr!=nil {
803+
httpapi.Write(rw,http.StatusInternalServerError, codersdk.Response{
804+
Message:"Failed to unmarshal stat payload.",
805+
Detail:err.Error(),
806+
})
807+
return
808+
}
809+
}
810+
798811
// Allow overriding the stat interval for debugging and testing purposes.
799812
ctx:=r.Context()
800813
timer:=time.NewTicker(api.AgentStatsRefreshInterval)
801-
varlastReport codersdk.AgentStatsReportResponse
802814
for {
803815
err:=wsjson.Write(ctx,conn, codersdk.AgentStatsReportRequest{})
804816
iferr!=nil {

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp