Skip to content

Commit 8538ec4

Browse files
committed
Merge remote-tracking branch 'origin/main' into email-notification-disable
2 parents 18b3f9a + 4f2202f commit 8538ec4

File tree

288 files changed

+11294
-3646
lines changed

Some content is hidden

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

288 files changed

+11294
-3646
lines changed

.github/workflows/ci.yaml

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -117,38 +117,40 @@ jobs:
117117
run: |
118118
echo "${{ toJSON(steps.filter )}}"
119119
120-
update-flake:
121-
needs: changes
122-
if: needs.changes.outputs.gomod == 'true'
123-
runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
124-
steps:
125-
- name: Checkout
126-
uses: actions/checkout@v4
127-
with:
128-
fetch-depth: 1
129-
# See: https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#commits-made-by-this-action-do-not-trigger-new-workflow-runs
130-
token: ${{ secrets.CDRCI_GITHUB_TOKEN }}
131-
132-
- name: Setup Go
133-
uses: ./.github/actions/setup-go
134-
135-
- name: Update Nix Flake SRI Hash
136-
run: ./scripts/update-flake.sh
137-
138-
# auto update flake for dependabot
139-
- uses: stefanzweifel/git-auto-commit-action@v5
140-
if: github.actor == 'dependabot[bot]'
141-
with:
142-
# Allows dependabot to still rebase!
143-
commit_message: "[dependabot skip] Update Nix Flake SRI Hash"
144-
commit_user_name: "dependabot[bot]"
145-
commit_user_email: "49699333+dependabot[bot]@users.noreply.github.com>"
146-
commit_author: "dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>"
147-
148-
# require everyone else to update it themselves
149-
- name: Ensure No Changes
150-
if: github.actor != 'dependabot[bot]'
151-
run: git diff --exit-code
120+
# Disabled due to instability. See: https://github.com/coder/coder/issues/14553
121+
# Re-enable once the flake hash calculation is stable.
122+
# update-flake:
123+
# needs: changes
124+
# if: needs.changes.outputs.gomod == 'true'
125+
# runs-on: ${{ github.repository_owner == 'coder' && 'depot-ubuntu-22.04-8' || 'ubuntu-latest' }}
126+
# steps:
127+
# - name: Checkout
128+
# uses: actions/checkout@v4
129+
# with:
130+
# fetch-depth: 1
131+
# # See: https://github.com/stefanzweifel/git-auto-commit-action?tab=readme-ov-file#commits-made-by-this-action-do-not-trigger-new-workflow-runs
132+
# token: ${{ secrets.CDRCI_GITHUB_TOKEN }}
133+
134+
# - name: Setup Go
135+
# uses: ./.github/actions/setup-go
136+
137+
# - name: Update Nix Flake SRI Hash
138+
# run: ./scripts/update-flake.sh
139+
140+
# # auto update flake for dependabot
141+
# - uses: stefanzweifel/git-auto-commit-action@v5
142+
# if: github.actor == 'dependabot[bot]'
143+
# with:
144+
# # Allows dependabot to still rebase!
145+
# commit_message: "[dependabot skip] Update Nix Flake SRI Hash"
146+
# commit_user_name: "dependabot[bot]"
147+
# commit_user_email: "49699333+dependabot[bot]@users.noreply.github.com>"
148+
# commit_author: "dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>"
149+
150+
# # require everyone else to update it themselves
151+
# - name: Ensure No Changes
152+
# if: github.actor != 'dependabot[bot]'
153+
# run: git diff --exit-code
152154

153155
lint:
154156
needs: changes
@@ -184,7 +186,7 @@ jobs:
184186
185187
# Check for any typos
186188
- name: Check for typos
187-
uses: crate-ci/typos@v1.23.6
189+
uses: crate-ci/typos@v1.24.3
188190
with:
189191
config: .github/workflows/typos.toml
190192

.github/workflows/stale.yaml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,10 @@ jobs:
1717
with:
1818
stale-issue-label: "stale"
1919
stale-pr-label: "stale"
20-
days-before-stale: 180
20+
# days-before-stale: 180
21+
# essentially disabled for now while we work through polish issues
22+
days-before-stale: 3650
23+
2124
# Pull Requests become stale more quickly due to merge conflicts.
2225
# Also, we promote minimizing WIP.
2326
days-before-pr-stale: 7

agent/agent.go

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1510,6 +1510,8 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
15101510
var mu sync.Mutex
15111511
status := a.network.Status()
15121512
durations := []float64{}
1513+
p2pConns := 0
1514+
derpConns := 0
15131515
pingCtx, cancelFunc := context.WithTimeout(ctx, 5*time.Second)
15141516
defer cancelFunc()
15151517
for nodeID, peer := range status.Peer {
@@ -1526,13 +1528,18 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
15261528
wg.Add(1)
15271529
go func() {
15281530
defer wg.Done()
1529-
duration, _, _, err := a.network.Ping(pingCtx, addresses[0].Addr())
1531+
duration, p2p, _, err := a.network.Ping(pingCtx, addresses[0].Addr())
15301532
if err != nil {
15311533
return
15321534
}
15331535
mu.Lock()
15341536
defer mu.Unlock()
15351537
durations = append(durations, float64(duration.Microseconds()))
1538+
if p2p {
1539+
p2pConns++
1540+
} else {
1541+
derpConns++
1542+
}
15361543
}()
15371544
}
15381545
wg.Wait()
@@ -1552,6 +1559,9 @@ func (a *agent) Collect(ctx context.Context, networkStats map[netlogtype.Connect
15521559
// Agent metrics are changing all the time, so there is no need to perform
15531560
// reflect.DeepEqual to see if stats should be transferred.
15541561

1562+
// currentConnections behaves like a hypothetical `GaugeFuncVec` and is only set at collection time.
1563+
a.metrics.currentConnections.WithLabelValues("p2p").Set(float64(p2pConns))
1564+
a.metrics.currentConnections.WithLabelValues("derp").Set(float64(derpConns))
15551565
metricsCtx, cancelFunc := context.WithTimeout(ctx, 5*time.Second)
15561566
defer cancelFunc()
15571567
a.logger.Debug(ctx, "collecting agent metrics for stats")

agent/agent_test.go

Lines changed: 52 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -2531,17 +2531,17 @@ func TestAgent_Metrics_SSH(t *testing.T) {
25312531
err = session.Shell()
25322532
require.NoError(t, err)
25332533

2534-
expected := []agentsdk.AgentMetric{
2534+
expected := []*proto.Stats_Metric{
25352535
{
25362536
Name: "agent_reconnecting_pty_connections_total",
2537-
Type: agentsdk.AgentMetricTypeCounter,
2537+
Type: proto.Stats_Metric_COUNTER,
25382538
Value: 0,
25392539
},
25402540
{
25412541
Name: "agent_sessions_total",
2542-
Type: agentsdk.AgentMetricTypeCounter,
2542+
Type: proto.Stats_Metric_COUNTER,
25432543
Value: 1,
2544-
Labels: []agentsdk.AgentMetricLabel{
2544+
Labels: []*proto.Stats_Metric_Label{
25452545
{
25462546
Name: "magic_type",
25472547
Value: "ssh",
@@ -2554,30 +2554,46 @@ func TestAgent_Metrics_SSH(t *testing.T) {
25542554
},
25552555
{
25562556
Name: "agent_ssh_server_failed_connections_total",
2557-
Type: agentsdk.AgentMetricTypeCounter,
2557+
Type: proto.Stats_Metric_COUNTER,
25582558
Value: 0,
25592559
},
25602560
{
25612561
Name: "agent_ssh_server_sftp_connections_total",
2562-
Type: agentsdk.AgentMetricTypeCounter,
2562+
Type: proto.Stats_Metric_COUNTER,
25632563
Value: 0,
25642564
},
25652565
{
25662566
Name: "agent_ssh_server_sftp_server_errors_total",
2567-
Type: agentsdk.AgentMetricTypeCounter,
2567+
Type: proto.Stats_Metric_COUNTER,
25682568
Value: 0,
25692569
},
25702570
{
2571-
Name: "coderd_agentstats_startup_script_seconds",
2572-
Type: agentsdk.AgentMetricTypeGauge,
2571+
Name: "coderd_agentstats_currently_reachable_peers",
2572+
Type: proto.Stats_Metric_GAUGE,
25732573
Value: 0,
2574-
Labels: []agentsdk.AgentMetricLabel{
2574+
Labels: []*proto.Stats_Metric_Label{
2575+
{
2576+
Name: "connection_type",
2577+
Value: "derp",
2578+
},
2579+
},
2580+
},
2581+
{
2582+
Name: "coderd_agentstats_currently_reachable_peers",
2583+
Type: proto.Stats_Metric_GAUGE,
2584+
Value: 1,
2585+
Labels: []*proto.Stats_Metric_Label{
25752586
{
2576-
Name: "success",
2577-
Value: "true",
2587+
Name: "connection_type",
2588+
Value: "p2p",
25782589
},
25792590
},
25802591
},
2592+
{
2593+
Name: "coderd_agentstats_startup_script_seconds",
2594+
Type: proto.Stats_Metric_GAUGE,
2595+
Value: 1,
2596+
},
25812597
}
25822598

25832599
var actual []*promgo.MetricFamily
@@ -2586,17 +2602,33 @@ func TestAgent_Metrics_SSH(t *testing.T) {
25862602
if err != nil {
25872603
return false
25882604
}
2589-
2590-
if len(expected) != len(actual) {
2591-
return false
2605+
count := 0
2606+
for _, m := range actual {
2607+
count += len(m.GetMetric())
25922608
}
2593-
2594-
return verifyCollectedMetrics(t, expected, actual)
2609+
return count == len(expected)
25952610
}, testutil.WaitLong, testutil.IntervalFast)
25962611

2597-
require.Len(t, actual, len(expected))
2598-
collected := verifyCollectedMetrics(t, expected, actual)
2599-
require.True(t, collected, "expected metrics were not collected")
2612+
i := 0
2613+
for _, mf := range actual {
2614+
for _, m := range mf.GetMetric() {
2615+
assert.Equal(t, expected[i].Name, mf.GetName())
2616+
assert.Equal(t, expected[i].Type.String(), mf.GetType().String())
2617+
// Value is max expected
2618+
if expected[i].Type == proto.Stats_Metric_GAUGE {
2619+
assert.GreaterOrEqualf(t, expected[i].Value, m.GetGauge().GetValue(), "expected %s to be greater than or equal to %f, got %f", expected[i].Name, expected[i].Value, m.GetGauge().GetValue())
2620+
} else if expected[i].Type == proto.Stats_Metric_COUNTER {
2621+
assert.GreaterOrEqualf(t, expected[i].Value, m.GetCounter().GetValue(), "expected %s to be greater than or equal to %f, got %f", expected[i].Name, expected[i].Value, m.GetCounter().GetValue())
2622+
}
2623+
for j, lbl := range expected[i].Labels {
2624+
assert.Equal(t, m.GetLabel()[j], &promgo.LabelPair{
2625+
Name: &lbl.Name,
2626+
Value: &lbl.Value,
2627+
})
2628+
}
2629+
i++
2630+
}
2631+
}
26002632

26012633
_ = stdin.Close()
26022634
err = session.Wait()
@@ -2828,28 +2860,6 @@ func TestAgent_ManageProcessPriority(t *testing.T) {
28282860
})
28292861
}
28302862

2831-
func verifyCollectedMetrics(t *testing.T, expected []agentsdk.AgentMetric, actual []*promgo.MetricFamily) bool {
2832-
t.Helper()
2833-
2834-
for i, e := range expected {
2835-
assert.Equal(t, e.Name, actual[i].GetName())
2836-
assert.Equal(t, string(e.Type), strings.ToLower(actual[i].GetType().String()))
2837-
2838-
for _, m := range actual[i].GetMetric() {
2839-
assert.Equal(t, e.Value, m.Counter.GetValue())
2840-
2841-
if len(m.GetLabel()) > 0 {
2842-
for j, lbl := range m.GetLabel() {
2843-
assert.Equal(t, e.Labels[j].Name, lbl.GetName())
2844-
assert.Equal(t, e.Labels[j].Value, lbl.GetValue())
2845-
}
2846-
}
2847-
m.GetLabel()
2848-
}
2849-
}
2850-
return true
2851-
}
2852-
28532863
type syncWriter struct {
28542864
mu sync.Mutex
28552865
w io.Writer

agent/agentssh/agentssh.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ type Config struct {
7979
// where users will land when they connect via SSH. Default is the home
8080
// directory of the user.
8181
WorkingDirectory func() string
82-
// X11SocketDir is the directory where X11 sockets are created. Default is
83-
// /tmp/.X11-unix.
84-
X11SocketDir string
82+
// X11DisplayOffset is the offset to add to the X11 display number.
83+
// Default is 10.
84+
X11DisplayOffset *int
8585
// BlockFileTransfer restricts use of file transfer applications.
8686
BlockFileTransfer bool
8787
}
@@ -124,8 +124,9 @@ func NewServer(ctx context.Context, logger slog.Logger, prometheusRegistry *prom
124124
if config == nil {
125125
config = &Config{}
126126
}
127-
if config.X11SocketDir == "" {
128-
config.X11SocketDir = filepath.Join(os.TempDir(), ".X11-unix")
127+
if config.X11DisplayOffset == nil {
128+
offset := X11DefaultDisplayOffset
129+
config.X11DisplayOffset = &offset
129130
}
130131
if config.UpdateEnv == nil {
131132
config.UpdateEnv = func(current []string) ([]string, error) { return current, nil }
@@ -273,13 +274,13 @@ func (s *Server) sessionHandler(session ssh.Session) {
273274
extraEnv := make([]string, 0)
274275
x11, hasX11 := session.X11()
275276
if hasX11 {
276-
handled := s.x11Handler(session.Context(), x11)
277+
display, handled := s.x11Handler(session.Context(), x11)
277278
if !handled {
278279
_ = session.Exit(1)
279280
logger.Error(ctx, "x11 handler failed")
280281
return
281282
}
282-
extraEnv = append(extraEnv, fmt.Sprintf("DISPLAY=:%d.0", x11.ScreenNumber))
283+
extraEnv = append(extraEnv, fmt.Sprintf("DISPLAY=localhost:%d.%d", display, x11.ScreenNumber))
283284
}
284285

285286
if s.fileTransferBlocked(session) {

0 commit comments

Comments
 (0)