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

Commit7088e79

Browse files
committed
chore: fixTestServer/Prometheus/DBMetricsDisabled test flake
See:https://github.com/coder/coder/actions/runs/9352137263/job/25739550487#step:5:368
1 parent43ef004 commit7088e79

File tree

2 files changed

+44
-33
lines changed

2 files changed

+44
-33
lines changed

‎cli/server_test.go

Lines changed: 42 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -967,26 +967,32 @@ func TestServer(t *testing.T) {
967967
assert.NoError(t,err)
968968
// nolint:bodyclose
969969
res,err=http.DefaultClient.Do(req)
970-
returnerr==nil
971-
},testutil.WaitShort,testutil.IntervalFast)
972-
deferres.Body.Close()
973-
974-
scanner:=bufio.NewScanner(res.Body)
975-
hasActiveUsers:=false
976-
forscanner.Scan() {
977-
// This metric is manually registered to be tracked in the server. That's
978-
// why we test it's tracked here.
979-
ifstrings.HasPrefix(scanner.Text(),"coderd_api_active_users_duration_hour") {
980-
hasActiveUsers=true
981-
continue
970+
iferr!=nil {
971+
returnfalse
982972
}
983-
ifstrings.HasPrefix(scanner.Text(),"coderd_db_query_latencies_seconds") {
984-
t.Fatal("db metrics should not be tracked when --prometheus-collect-db-metrics is not enabled")
973+
deferres.Body.Close()
974+
975+
scanner:=bufio.NewScanner(res.Body)
976+
hasActiveUsers:=false
977+
forscanner.Scan() {
978+
// This metric is manually registered to be tracked in the server. That's
979+
// why we test it's tracked here.
980+
ifstrings.HasPrefix(scanner.Text(),"coderd_api_active_users_duration_hour") {
981+
hasActiveUsers=true
982+
continue
983+
}
984+
ifstrings.HasPrefix(scanner.Text(),"coderd_db_query_latencies_seconds") {
985+
t.Fatal("db metrics should not be tracked when --prometheus-collect-db-metrics is not enabled")
986+
}
987+
t.Logf("scanned %s",scanner.Text())
985988
}
986-
t.Logf("scanned %s",scanner.Text())
987-
}
988-
require.NoError(t,scanner.Err())
989-
require.True(t,hasActiveUsers)
989+
ifscanner.Err()!=nil {
990+
t.Logf("scanner err: %s",scanner.Err().Error())
991+
returnfalse
992+
}
993+
994+
returnhasActiveUsers
995+
},testutil.WaitShort,testutil.IntervalFast)
990996
})
991997

992998
t.Run("DBMetricsEnabled",func(t*testing.T) {
@@ -1017,20 +1023,25 @@ func TestServer(t *testing.T) {
10171023
assert.NoError(t,err)
10181024
// nolint:bodyclose
10191025
res,err=http.DefaultClient.Do(req)
1020-
returnerr==nil
1021-
},testutil.WaitShort,testutil.IntervalFast)
1022-
deferres.Body.Close()
1026+
iferr!=nil {
1027+
returnfalse
1028+
}
1029+
deferres.Body.Close()
10231030

1024-
scanner:=bufio.NewScanner(res.Body)
1025-
hasDBMetrics:=false
1026-
forscanner.Scan() {
1027-
ifstrings.HasPrefix(scanner.Text(),"coderd_db_query_latencies_seconds") {
1028-
hasDBMetrics=true
1031+
scanner:=bufio.NewScanner(res.Body)
1032+
hasDBMetrics:=false
1033+
forscanner.Scan() {
1034+
ifstrings.HasPrefix(scanner.Text(),"coderd_db_query_latencies_seconds") {
1035+
hasDBMetrics=true
1036+
}
1037+
t.Logf("scanned %s",scanner.Text())
10291038
}
1030-
t.Logf("scanned %s",scanner.Text())
1031-
}
1032-
require.NoError(t,scanner.Err())
1033-
require.True(t,hasDBMetrics)
1039+
ifscanner.Err()!=nil {
1040+
t.Logf("scanner err: %s",scanner.Err().Error())
1041+
returnfalse
1042+
}
1043+
returnhasDBMetrics
1044+
},testutil.WaitShort,testutil.IntervalFast)
10341045
})
10351046
})
10361047
t.Run("GitHubOAuth",func(t*testing.T) {
@@ -1347,7 +1358,7 @@ func TestServer(t *testing.T) {
13471358
}
13481359
returnlastStat.Size()>0
13491360
},
1350-
testutil.WaitShort,
1361+
dur,//nolint:gocritic
13511362
testutil.IntervalFast,
13521363
"file at %s should exist, last stat: %+v",
13531364
fiName,lastStat,

‎coderd/prometheusmetrics/prometheusmetrics.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,9 +120,9 @@ func Workspaces(ctx context.Context, logger slog.Logger, registerer prometheus.R
120120
iferrors.Is(err,sql.ErrNoRows) {
121121
// clear all series if there are no database entries
122122
workspaceLatestBuildTotals.Reset()
123+
}else {
124+
logger.Warn(ctx,"failed to load latest workspace builds",slog.Error(err))
123125
}
124-
125-
logger.Warn(ctx,"failed to load latest workspace builds",slog.Error(err))
126126
return
127127
}
128128
jobIDs:=make([]uuid.UUID,0,len(builds))

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp