fix(coderd/agentapi): always write agent stats when provided (#12699)

This commit is contained in:
Mathias Fredriksson 2024-03-21 16:47:06 +02:00 committed by GitHub
parent bd6ad88077
commit 9c84fb7fb1
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 5 additions and 9 deletions

View File

@ -47,11 +47,11 @@ func (a *StatsAPI) now() time.Time {
} }
func (a *StatsAPI) UpdateStats(ctx context.Context, req *agentproto.UpdateStatsRequest) (*agentproto.UpdateStatsResponse, error) { 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{ res := &agentproto.UpdateStatsResponse{
ReportInterval: durationpb.New(a.AgentStatsRefreshInterval), 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 return res, nil
} }

View File

@ -222,9 +222,7 @@ func TestUpdateStates(t *testing.T) {
req = &agentproto.UpdateStatsRequest{ req = &agentproto.UpdateStatsRequest{
Stats: &agentproto.Stats{ Stats: &agentproto.Stats{
ConnectionsByProto: map[string]int64{ ConnectionsByProto: map[string]int64{},
"tcp": 1,
},
ConnectionCount: 0, ConnectionCount: 0,
ConnectionMedianLatencyMs: 23, ConnectionMedianLatencyMs: 23,
}, },
@ -262,16 +260,14 @@ func TestUpdateStates(t *testing.T) {
require.NoError(t, err) require.NoError(t, err)
}) })
t.Run("NoConnectionsByProto", func(t *testing.T) { t.Run("NoStats", func(t *testing.T) {
t.Parallel() t.Parallel()
var ( var (
dbM = dbmock.NewMockStore(gomock.NewController(t)) dbM = dbmock.NewMockStore(gomock.NewController(t))
ps = pubsub.NewInMemory() ps = pubsub.NewInMemory()
req = &agentproto.UpdateStatsRequest{ req = &agentproto.UpdateStatsRequest{
Stats: &agentproto.Stats{ Stats: nil,
ConnectionsByProto: map[string]int64{}, // len() == 0
},
} }
) )
api := agentapi.StatsAPI{ api := agentapi.StatsAPI{