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.

0 commit comments

Comments
 (0)