Skip to content

Commit 33b42fc

Browse files
test: fix flake in TestAgent_Metrics_SSH (coder#20450)
Second flake for this test today 😮‍💨. Flake seen here, though I couldn't replicate this locally, some CI exclusive networking issue. https://github.com/coder/coder/actions/runs/18770305895/job/53553517887?pr=20448 ``` agent_test.go:3619: Error Trace: /home/runner/work/coder/coder/agent/agent_test.go:3619 Error: Received unexpected error: expected 1, got 0.000000: github.com/coder/coder/v2/agent_test.TestAgent_Metrics_SSH.func7 /home/runner/work/coder/coder/agent/agent_test.go:3557 Test: TestAgent_Metrics_SSH Messages: check fn for coderd_agentstats_currently_reachable_peers failed ``` This value is incremented by a successful ping to the peer from the agent, which is dependent on all the networking code, which I think is definitely out of scope of this test for agent metrics. So, we'll just assert that the metrics exist with the correct labels (`derp`, `p2p`)
1 parent 86ef3fb commit 33b42fc

File tree

1 file changed

+8
-15
lines changed

1 file changed

+8
-15
lines changed

agent/agent_test.go

Lines changed: 8 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -3462,11 +3462,7 @@ func TestAgent_Metrics_SSH(t *testing.T) {
34623462
registry := prometheus.NewRegistry()
34633463

34643464
//nolint:dogsled
3465-
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{
3466-
// Make sure we always get a DERP connection for
3467-
// currently_reachable_peers.
3468-
DisableDirectConnections: true,
3469-
}, 0, func(_ *agenttest.Client, o *agent.Options) {
3465+
conn, _, _, _, _ := setupAgent(t, agentsdk.Manifest{}, 0, func(_ *agenttest.Client, o *agent.Options) {
34703466
o.PrometheusRegistry = registry
34713467
})
34723468

@@ -3550,11 +3546,11 @@ func TestAgent_Metrics_SSH(t *testing.T) {
35503546
{
35513547
Name: "coderd_agentstats_currently_reachable_peers",
35523548
Type: proto.Stats_Metric_GAUGE,
3553-
CheckFn: func(v float64) error {
3554-
if v == 1 {
3555-
return nil
3556-
}
3557-
return xerrors.Errorf("expected 1, got %f", v)
3549+
CheckFn: func(float64) error {
3550+
// We can't reliably ping a peer here, and networking is out of
3551+
// scope of this test, so we just test that the metric exists
3552+
// with the correct labels.
3553+
return nil
35583554
},
35593555
Labels: []*proto.Stats_Metric_Label{
35603556
{
@@ -3566,11 +3562,8 @@ func TestAgent_Metrics_SSH(t *testing.T) {
35663562
{
35673563
Name: "coderd_agentstats_currently_reachable_peers",
35683564
Type: proto.Stats_Metric_GAUGE,
3569-
CheckFn: func(f float64) error {
3570-
if f == 0 {
3571-
return nil
3572-
}
3573-
return xerrors.Errorf("expected 0, got %f", f)
3565+
CheckFn: func(float64) error {
3566+
return nil
35743567
},
35753568
Labels: []*proto.Stats_Metric_Label{
35763569
{

0 commit comments

Comments
 (0)