From c8096dbbcfb75c33ee1c58d055bb309f5aa68e13 Mon Sep 17 00:00:00 2001 From: Mathias Fredriksson Date: Thu, 21 Mar 2024 12:06:01 +0000 Subject: [PATCH] fix(coderd/agentapi): always write agent stats when provided Previously we were discarding agent stats due to the length of connections by proto being zero. --- coderd/agentapi/stats.go | 4 ++-- coderd/agentapi/stats_test.go | 10 +++------- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/coderd/agentapi/stats.go b/coderd/agentapi/stats.go index 59706da305c6e..a214fda3f15d9 100644 --- a/coderd/agentapi/stats.go +++ b/coderd/agentapi/stats.go @@ -47,11 +47,11 @@ func (a *StatsAPI) now() time.Time { } func (a *StatsAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsRequest) (*agentproto.UpdateStatsResponse, error) { - // An empty stat means it's just looking for the report interval. res := &agentproto.UpdateStatsResponse{ ReportInterval: durationpb.New(a.AgentStatsRefreshInterval), } - if req.Stats == nil || len(req.Stats.ConnectionsByProto) == 0 { + // An empty stat means it's just looking for the report interval. + if req.Stats == nil { return res, nil } diff --git a/coderd/agentapi/stats_test.go b/coderd/agentapi/stats_test.go index 46e706c3e16e5..943c8e7ac0e17 100644 --- a/coderd/agentapi/stats_test.go +++ b/coderd/agentapi/stats_test.go @@ -222,9 +222,7 @@ func TestUpdateStates(t *testing.T) { req = &agentproto.UpdateStatsRequest{ Stats: &agentproto.Stats{ - ConnectionsByProto: map[string]int64{ - "tcp": 1, - }, + ConnectionsByProto: map[string]int64{}, ConnectionCount: 0, ConnectionMedianLatencyMs: 23, }, @@ -262,16 +260,14 @@ func TestUpdateStates(t *testing.T) { require.NoError(t, err) }) - t.Run("NoConnectionsByProto", func(t *testing.T) { + t.Run("NoStats", func(t *testing.T) { t.Parallel() var ( dbM = dbmock.NewMockStore(gomock.NewController(t)) ps = pubsub.NewInMemory() req = &agentproto.UpdateStatsRequest{ - Stats: &agentproto.Stats{ - ConnectionsByProto: map[string]int64{}, // len() == 0 - }, + Stats: nil, } ) api := agentapi.StatsAPI{