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

Commita32951c

Browse files
authored
fix: reduce idle workspace queries (#7022)
1 parent63f9ef2 commita32951c

File tree

5 files changed

+14
-68
lines changed

5 files changed

+14
-68
lines changed

‎coderd/apidoc/docs.go‎

Lines changed: 3 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: 3 additions & 0 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/coderd.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ func New(options *Options) *API {
186186
panic("coderd: both AppHostname and AppHostnameRegex must be set or unset")
187187
}
188188
ifoptions.AgentConnectionUpdateFrequency==0 {
189-
options.AgentConnectionUpdateFrequency=3*time.Second
189+
options.AgentConnectionUpdateFrequency=15*time.Second
190190
}
191191
ifoptions.AgentInactiveDisconnectTimeout==0 {
192192
// Multiply the update by two to allow for some lag-time.

‎coderd/workspaceagents.go‎

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ import (
3737
"github.com/coder/coder/coderd/httpmw"
3838
"github.com/coder/coder/coderd/rbac"
3939
"github.com/coder/coder/coderd/tracing"
40+
"github.com/coder/coder/coderd/util/ptr"
4041
"github.com/coder/coder/codersdk"
4142
"github.com/coder/coder/codersdk/agentsdk"
4243
"github.com/coder/coder/tailnet"
@@ -818,8 +819,9 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
818819

819820
// We use a custom heartbeat routine here instead of `httpapi.Heartbeat`
820821
// because we want to log the agent's last ping time.
821-
lastPing:=time.Now()// Since the agent initiated the request, assume it's alive.
822-
varpingMu sync.Mutex
822+
varlastPing atomic.Pointer[time.Time]
823+
lastPing.Store(ptr.Ref(time.Now()))// Since the agent initiated the request, assume it's alive.
824+
823825
gopprof.Do(ctx,pprof.Labels("agent",workspaceAgent.ID.String()),func(ctx context.Context) {
824826
// TODO(mafredri): Is this too frequent? Use separate ping disconnect timeout?
825827
t:=time.NewTicker(api.AgentConnectionUpdateFrequency)
@@ -840,9 +842,7 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
840842
iferr!=nil {
841843
return
842844
}
843-
pingMu.Lock()
844-
lastPing=time.Now()
845-
pingMu.Unlock()
845+
lastPing.Store(ptr.Ref(time.Now()))
846846
}
847847
})
848848

@@ -950,9 +950,7 @@ func (api *API) workspaceAgentCoordinate(rw http.ResponseWriter, r *http.Request
950950
case<-ticker.C:
951951
}
952952

953-
pingMu.Lock()
954-
lastPing:=lastPing
955-
pingMu.Unlock()
953+
lastPing:=*lastPing.Load()
956954

957955
varconnectionStatusChangedbool
958956
iftime.Since(lastPing)>api.AgentInactiveDisconnectTimeout {
@@ -1163,6 +1161,7 @@ func convertWorkspaceAgent(derpMap *tailcfg.DERPMap, coordinator tailnet.Coordin
11631161
// @Param request body agentsdk.Stats true "Stats request"
11641162
// @Success 200 {object} agentsdk.StatsResponse
11651163
// @Router /workspaceagents/me/report-stats [post]
1164+
// @x-apidocgen {"skip": true}
11661165
func (api*API)workspaceAgentReportStats(rw http.ResponseWriter,r*http.Request) {
11671166
ctx:=r.Context()
11681167

‎docs/api/agents.md‎

Lines changed: 0 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -394,65 +394,6 @@ curl -X GET http://coder-server:8080/api/v2/workspaceagents/me/manifest \
394394

395395
To perform this operation, you must be authenticated.[Learn more](authentication.md).
396396

397-
##Submit workspace agent stats
398-
399-
###Code samples
400-
401-
```shell
402-
# Example request using curl
403-
curl -X POST http://coder-server:8080/api/v2/workspaceagents/me/report-stats \
404-
-H'Content-Type: application/json' \
405-
-H'Accept: application/json' \
406-
-H'Coder-Session-Token: API_KEY'
407-
```
408-
409-
`POST /workspaceagents/me/report-stats`
410-
411-
>Body parameter
412-
413-
```json
414-
{
415-
"connection_count":0,
416-
"connection_median_latency_ms":0,
417-
"connections_by_proto": {
418-
"property1":0,
419-
"property2":0
420-
},
421-
"rx_bytes":0,
422-
"rx_packets":0,
423-
"session_count_jetbrains":0,
424-
"session_count_reconnecting_pty":0,
425-
"session_count_ssh":0,
426-
"session_count_vscode":0,
427-
"tx_bytes":0,
428-
"tx_packets":0
429-
}
430-
```
431-
432-
###Parameters
433-
434-
| Name| In| Type| Required| Description|
435-
| ------| ----| ------------------------------------------| --------| -------------|
436-
|`body`| body|[agentsdk.Stats](schemas.md#agentsdkstats)| true| Stats request|
437-
438-
###Example responses
439-
440-
>200 Response
441-
442-
```json
443-
{
444-
"report_interval":0
445-
}
446-
```
447-
448-
###Responses
449-
450-
| Status| Meaning| Description| Schema|
451-
| ------| -------------------------------------------------------| -----------| ----------------------------------------------------------|
452-
| 200|[OK](https://tools.ietf.org/html/rfc7231#section-6.3.1)| OK|[agentsdk.StatsResponse](schemas.md#agentsdkstatsresponse)|
453-
454-
To perform this operation, you must be authenticated.[Learn more](authentication.md).
455-
456397
##Get workspace agent by ID
457398

458399
###Code samples

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp