Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitcb975fc

Browse files
committed
fix user-activity response on no rows
1 parent4cae730 commitcb975fc

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

‎coderd/insights.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package coderd
22

33
import (
44
"context"
5+
"database/sql"
56
"fmt"
67
"net/http"
78
"strings"
@@ -102,6 +103,19 @@ func (api *API) insightsUserActivity(rw http.ResponseWriter, r *http.Request) {
102103
TemplateIDs:templateIDs,
103104
})
104105
iferr!=nil {
106+
// No data is not an error.
107+
ifxerrors.Is(err,sql.ErrNoRows) {
108+
httpapi.Write(ctx,rw,http.StatusOK, codersdk.UserActivityInsightsResponse{
109+
Report: codersdk.UserActivityInsightsReport{
110+
StartTime:startTime,
111+
EndTime:endTime,
112+
TemplateIDs: []uuid.UUID{},
113+
Users: []codersdk.UserActivity{},
114+
},
115+
})
116+
return
117+
}
118+
// Check authorization.
105119
ifhttpapi.Is404Error(err) {
106120
httpapi.ResourceNotFound(rw)
107121
return

‎coderd/insights_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,7 @@ func TestUserActivityInsights_SanityCheck(t *testing.T) {
136136
Pubsub:ps,
137137
Logger:&logger,
138138
IncludeProvisionerDaemon:true,
139-
AgentStatsRefreshInterval:time.Millisecond*50,
139+
AgentStatsRefreshInterval:time.Millisecond*100,
140140
DatabaseRolluper:dbrollup.New(
141141
logger.Named("dbrollup"),
142142
db,
@@ -170,7 +170,7 @@ func TestUserActivityInsights_SanityCheck(t *testing.T) {
170170
y,m,d:=time.Now().UTC().Date()
171171
today:=time.Date(y,m,d,0,0,0,0,time.UTC)
172172

173-
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitLong)
173+
ctx,cancel:=context.WithTimeout(context.Background(),testutil.WaitSuperLong)
174174
defercancel()
175175

176176
// Connect to the agent to generate usage/latency stats.
@@ -212,7 +212,7 @@ func TestUserActivityInsights_SanityCheck(t *testing.T) {
212212
returnfalse
213213
}
214214
returnlen(userActivities.Report.Users)>0&&userActivities.Report.Users[0].Seconds>0
215-
},testutil.WaitMedium,testutil.IntervalFast,"user activity is missing")
215+
},testutil.WaitSuperLong,testutil.IntervalMedium,"user activity is missing")
216216

217217
// We got our latency data, close the connection.
218218
_=sess.Close()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp