Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit a66ffd7

Browse files
committed
Merge remote-tracking branch 'origin/main' into dreamteam/external_proxy
2 parents 22aadf1 + 942aba3 commit a66ffd7

File tree

246 files changed

+3328
-5986
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

246 files changed

+3328
-5986
lines changed

.github/workflows/ci.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,9 @@ jobs:
634634
- name: Publish to Chromatic (non-mainline)
635635
if: github.ref != 'refs/heads/main' && github.repository_owner == 'coder'
636636
uses: chromaui/action@v1
637+
env:
638+
NODE_OPTIONS: "--max_old_space_size=4096"
639+
STORYBOOK: true
637640
with:
638641
buildScriptName: "storybook:build"
639642
exitOnceUploaded: true
@@ -651,6 +654,9 @@ jobs:
651654
- name: Publish to Chromatic (mainline)
652655
if: github.ref == 'refs/heads/main' && github.repository_owner == 'coder'
653656
uses: chromaui/action@v1
657+
env:
658+
NODE_OPTIONS: "--max_old_space_size=4096"
659+
STORYBOOK: true
654660
with:
655661
autoAcceptChanges: true
656662
buildScriptName: "storybook:build"

cli/server.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -704,6 +704,14 @@ func (r *RootCmd) Server(newAPI func(context.Context, *coderd.Options) (*coderd.
704704
}
705705
defer closeWorkspacesFunc()
706706

707+
if cfg.Prometheus.CollectAgentStats {
708+
closeAgentStatsFunc, err := prometheusmetrics.AgentStats(ctx, logger, options.PrometheusRegistry, options.Database, time.Now(), 0)
709+
if err != nil {
710+
return xerrors.Errorf("register agent stats prometheus metric: %w", err)
711+
}
712+
defer closeAgentStatsFunc()
713+
}
714+
707715
//nolint:revive
708716
defer ServeHandler(ctx, logger, promhttp.InstrumentMetricHandler(
709717
options.PrometheusRegistry, promhttp.HandlerFor(options.PrometheusRegistry, promhttp.HandlerOpts{}),
@@ -1214,7 +1222,7 @@ func newProvisionerDaemon(
12141222
JobPollInterval: cfg.Provisioner.DaemonPollInterval.Value(),
12151223
JobPollJitter: cfg.Provisioner.DaemonPollJitter.Value(),
12161224
JobPollDebounce: debounce,
1217-
UpdateInterval: 500 * time.Millisecond,
1225+
UpdateInterval: time.Second,
12181226
ForceCancelInterval: cfg.Provisioner.ForceCancelInterval.Value(),
12191227
Provisioners: provisioners,
12201228
WorkDirectory: tempDir,

cli/testdata/coder_server_--help.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,9 @@ Use a YAML configuration file when your server launch become unwieldy.
9090
--prometheus-address host:port, $CODER_PROMETHEUS_ADDRESS (default: 127.0.0.1:2112)
9191
The bind address to serve prometheus metrics.
9292

93+
--prometheus-collect-agent-stats bool, $CODER_PROMETHEUS_COLLECT_AGENT_STATS
94+
Collect agent stats (may increase charges for metrics storage).
95+
9396
--prometheus-enable bool, $CODER_PROMETHEUS_ENABLE
9497
Serve prometheus metrics on the address defined by prometheus address.
9598

cli/testdata/server-config.yaml.golden

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,9 @@ introspection:
146146
# The bind address to serve prometheus metrics.
147147
# (default: 127.0.0.1:2112, type: host:port)
148148
address: 127.0.0.1:2112
149+
# Collect agent stats (may increase charges for metrics storage).
150+
# (default: <unset>, type: bool)
151+
collect_agent_stats: false
149152
pprof:
150153
# Serve pprof metrics on the address defined by pprof address.
151154
# (default: <unset>, type: bool)

coderd/apidoc/docs.go

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

coderd/database/dbauthz/system.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@ func (q *querier) GetWorkspaceAgentStats(ctx context.Context, createdAfter time.
302302
return q.db.GetWorkspaceAgentStats(ctx, createdAfter)
303303
}
304304

305+
func (q *querier) GetWorkspaceAgentStatsAndLabels(ctx context.Context, createdAfter time.Time) ([]database.GetWorkspaceAgentStatsAndLabelsRow, error) {
306+
return q.db.GetWorkspaceAgentStatsAndLabels(ctx, createdAfter)
307+
}
308+
305309
func (q *querier) GetDeploymentWorkspaceStats(ctx context.Context) (database.GetDeploymentWorkspaceStatsRow, error) {
306310
return q.db.GetDeploymentWorkspaceStats(ctx)
307311
}

coderd/database/dbfake/databasefake.go

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4002,6 +4002,77 @@ func (q *fakeQuerier) GetWorkspaceAgentStats(_ context.Context, createdAfter tim
40024002
return stats, nil
40034003
}
40044004

4005+
func (q *fakeQuerier) GetWorkspaceAgentStatsAndLabels(ctx context.Context, createdAfter time.Time) ([]database.GetWorkspaceAgentStatsAndLabelsRow, error) {
4006+
q.mutex.RLock()
4007+
defer q.mutex.RUnlock()
4008+
4009+
agentStatsCreatedAfter := make([]database.WorkspaceAgentStat, 0)
4010+
latestAgentStats := map[uuid.UUID]database.WorkspaceAgentStat{}
4011+
4012+
for _, agentStat := range q.workspaceAgentStats {
4013+
if agentStat.CreatedAt.After(createdAfter) {
4014+
agentStatsCreatedAfter = append(agentStatsCreatedAfter, agentStat)
4015+
latestAgentStats[agentStat.AgentID] = agentStat
4016+
}
4017+
}
4018+
4019+
statByAgent := map[uuid.UUID]database.GetWorkspaceAgentStatsAndLabelsRow{}
4020+
4021+
// Session and connection metrics
4022+
for _, agentStat := range latestAgentStats {
4023+
stat := statByAgent[agentStat.AgentID]
4024+
stat.SessionCountVSCode += agentStat.SessionCountVSCode
4025+
stat.SessionCountJetBrains += agentStat.SessionCountJetBrains
4026+
stat.SessionCountReconnectingPTY += agentStat.SessionCountReconnectingPTY
4027+
stat.SessionCountSSH += agentStat.SessionCountSSH
4028+
stat.ConnectionCount += agentStat.ConnectionCount
4029+
if agentStat.ConnectionMedianLatencyMS >= 0 && stat.ConnectionMedianLatencyMS < agentStat.ConnectionMedianLatencyMS {
4030+
stat.ConnectionMedianLatencyMS = agentStat.ConnectionMedianLatencyMS
4031+
}
4032+
statByAgent[agentStat.AgentID] = stat
4033+
}
4034+
4035+
// Tx, Rx metrics
4036+
for _, agentStat := range agentStatsCreatedAfter {
4037+
stat := statByAgent[agentStat.AgentID]
4038+
stat.RxBytes += agentStat.RxBytes
4039+
stat.TxBytes += agentStat.TxBytes
4040+
statByAgent[agentStat.AgentID] = stat
4041+
}
4042+
4043+
// Labels
4044+
for _, agentStat := range agentStatsCreatedAfter {
4045+
stat := statByAgent[agentStat.AgentID]
4046+
4047+
user, err := q.getUserByIDNoLock(agentStat.UserID)
4048+
if err != nil {
4049+
return nil, err
4050+
}
4051+
4052+
stat.Username = user.Username
4053+
4054+
workspace, err := q.GetWorkspaceByID(ctx, agentStat.WorkspaceID)
4055+
if err != nil {
4056+
return nil, err
4057+
}
4058+
stat.WorkspaceName = workspace.Name
4059+
4060+
agent, err := q.GetWorkspaceAgentByID(ctx, agentStat.AgentID)
4061+
if err != nil {
4062+
return nil, err
4063+
}
4064+
stat.AgentName = agent.Name
4065+
4066+
statByAgent[agentStat.AgentID] = stat
4067+
}
4068+
4069+
stats := make([]database.GetWorkspaceAgentStatsAndLabelsRow, 0, len(statByAgent))
4070+
for _, agent := range statByAgent {
4071+
stats = append(stats, agent)
4072+
}
4073+
return stats, nil
4074+
}
4075+
40054076
func (q *fakeQuerier) GetWorkspacesEligibleForAutoStartStop(ctx context.Context, now time.Time) ([]database.Workspace, error) {
40064077
q.mutex.RLock()
40074078
defer q.mutex.RUnlock()

coderd/database/querier.go

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

coderd/database/queries.sql.go

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

coderd/database/queries/workspaceagentstats.sql

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,55 @@ WITH agent_stats AS (
103103
) AS a WHERE a.rn = 1 GROUP BY a.user_id, a.agent_id, a.workspace_id, a.template_id
104104
)
105105
SELECT * FROM agent_stats JOIN latest_agent_stats ON agent_stats.agent_id = latest_agent_stats.agent_id;
106+
107+
-- name: GetWorkspaceAgentStatsAndLabels :many
108+
WITH agent_stats AS (
109+
SELECT
110+
user_id,
111+
agent_id,
112+
workspace_id,
113+
coalesce(SUM(rx_bytes), 0)::bigint AS rx_bytes,
114+
coalesce(SUM(tx_bytes), 0)::bigint AS tx_bytes
115+
FROM workspace_agent_stats
116+
WHERE workspace_agent_stats.created_at > $1
117+
GROUP BY user_id, agent_id, workspace_id
118+
), latest_agent_stats AS (
119+
SELECT
120+
a.agent_id,
121+
coalesce(SUM(session_count_vscode), 0)::bigint AS session_count_vscode,
122+
coalesce(SUM(session_count_ssh), 0)::bigint AS session_count_ssh,
123+
coalesce(SUM(session_count_jetbrains), 0)::bigint AS session_count_jetbrains,
124+
coalesce(SUM(session_count_reconnecting_pty), 0)::bigint AS session_count_reconnecting_pty,
125+
coalesce(SUM(connection_count), 0)::bigint AS connection_count,
126+
coalesce(MAX(connection_median_latency_ms), 0)::float AS connection_median_latency_ms
127+
FROM (
128+
SELECT *, ROW_NUMBER() OVER(PARTITION BY agent_id ORDER BY created_at DESC) AS rn
129+
FROM workspace_agent_stats
130+
-- The greater than 0 is to support legacy agents that don't report connection_median_latency_ms.
131+
WHERE created_at > $1 AND connection_median_latency_ms > 0
132+
) AS a
133+
WHERE a.rn = 1
134+
GROUP BY a.user_id, a.agent_id, a.workspace_id
135+
)
136+
SELECT
137+
users.username, workspace_agents.name AS agent_name, workspaces.name AS workspace_name, rx_bytes, tx_bytes,
138+
session_count_vscode, session_count_ssh, session_count_jetbrains, session_count_reconnecting_pty,
139+
connection_count, connection_median_latency_ms
140+
FROM
141+
agent_stats
142+
JOIN
143+
latest_agent_stats
144+
ON
145+
agent_stats.agent_id = latest_agent_stats.agent_id
146+
JOIN
147+
users
148+
ON
149+
users.id = agent_stats.user_id
150+
JOIN
151+
workspace_agents
152+
ON
153+
workspace_agents.id = agent_stats.agent_id
154+
JOIN
155+
workspaces
156+
ON
157+
workspaces.id = agent_stats.workspace_id;

coderd/healthcheck/derp.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,7 @@ package healthcheck
22

33
import (
44
"context"
5-
"errors"
65
"fmt"
7-
"io"
86
"net"
97
"net/netip"
108
"net/url"
@@ -390,9 +388,7 @@ func (*DERPNodeReport) recvData(client *derphttp.Client) (derp.ReceivedPacket, e
390388
for {
391389
msg, err := client.Recv()
392390
if err != nil {
393-
if errors.Is(err, io.EOF) {
394-
return derp.ReceivedPacket{}, nil
395-
}
391+
return derp.ReceivedPacket{}, err
396392
}
397393

398394
switch msg := msg.(type) {

0 commit comments

Comments
 (0)