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

Commit0789500

Browse files
authored
refactor(coderd/healthcheck): make Warnings an object with { Code, Message } (#10950)
- Adds health.Message { code string, mesasge string }- Refactors existing warnings []string to be of type []health.Message instead
1 parent4f92928 commit0789500

File tree

18 files changed

+458
-150
lines changed

18 files changed

+458
-150
lines changed

‎coderd/apidoc/docs.go

Lines changed: 56 additions & 6 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/apidoc/swagger.json

Lines changed: 56 additions & 6 deletions
Some generated files are not rendered by default. Learn more aboutcustomizing how changed files appear on GitHub.

‎coderd/healthcheck/accessurl.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,16 +8,15 @@ import (
88
"time"
99

1010
"github.com/coder/coder/v2/coderd/healthcheck/health"
11-
"github.com/coder/coder/v2/coderd/util/ptr"
1211
)
1312

1413
// @typescript-generate AccessURLReport
1514
typeAccessURLReportstruct {
1615
// Healthy is deprecated and left for backward compatibility purposes, use `Severity` instead.
17-
Healthybool`json:"healthy"`
18-
Severity health.Severity`json:"severity" enums:"ok,warning,error"`
19-
Warnings []string`json:"warnings"`
20-
Dismissedbool`json:"dismissed"`
16+
Healthybool`json:"healthy"`
17+
Severity health.Severity`json:"severity" enums:"ok,warning,error"`
18+
Warnings []health.Message`json:"warnings"`
19+
Dismissedbool`json:"dismissed"`
2120

2221
AccessURLstring`json:"access_url"`
2322
Reachablebool`json:"reachable"`
@@ -38,11 +37,11 @@ func (r *AccessURLReport) Run(ctx context.Context, opts *AccessURLReportOptions)
3837
defercancel()
3938

4039
r.Severity=health.SeverityOK
41-
r.Warnings= []string{}
40+
r.Warnings= []health.Message{}
4241
r.Dismissed=opts.Dismissed
4342

4443
ifopts.AccessURL==nil {
45-
r.Error=ptr.Ref(health.Messagef(health.CodeAccessURLNotSet,"Access URL not set"))
44+
r.Error=health.Errorf(health.CodeAccessURLNotSet,"Access URL not set")
4645
r.Severity=health.SeverityError
4746
return
4847
}
@@ -54,29 +53,29 @@ func (r *AccessURLReport) Run(ctx context.Context, opts *AccessURLReportOptions)
5453

5554
accessURL,err:=opts.AccessURL.Parse("/healthz")
5655
iferr!=nil {
57-
r.Error=ptr.Ref(health.Messagef(health.CodeAccessURLInvalid,"parse healthz endpoint: %s",err))
56+
r.Error=health.Errorf(health.CodeAccessURLInvalid,"parse healthz endpoint: %s",err)
5857
r.Severity=health.SeverityError
5958
return
6059
}
6160

6261
req,err:=http.NewRequestWithContext(ctx,"GET",accessURL.String(),nil)
6362
iferr!=nil {
64-
r.Error=ptr.Ref(health.Messagef(health.CodeAccessURLFetch,"create healthz request: %s",err))
63+
r.Error=health.Errorf(health.CodeAccessURLFetch,"create healthz request: %s",err)
6564
r.Severity=health.SeverityError
6665
return
6766
}
6867

6968
res,err:=opts.Client.Do(req)
7069
iferr!=nil {
71-
r.Error=ptr.Ref(health.Messagef(health.CodeAccessURLFetch,"get healthz endpoint: %s",err))
70+
r.Error=health.Errorf(health.CodeAccessURLFetch,"get healthz endpoint: %s",err)
7271
r.Severity=health.SeverityError
7372
return
7473
}
7574
deferres.Body.Close()
7675

7776
body,err:=io.ReadAll(res.Body)
7877
iferr!=nil {
79-
r.Error=ptr.Ref(health.Messagef(health.CodeAccessURLFetch,"read healthz response: %s",err))
78+
r.Error=health.Errorf(health.CodeAccessURLFetch,"read healthz response: %s",err)
8079
r.Severity=health.SeverityError
8180
return
8281
}

‎coderd/healthcheck/accessurl_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ func TestAccessURL(t *testing.T) {
131131
assert.Equal(t,string(resp),report.HealthzResponse)
132132
assert.Nil(t,report.Error)
133133
ifassert.NotEmpty(t,report.Warnings) {
134-
assert.Contains(t,report.Warnings[0],health.CodeAccessURLNotOK)
134+
assert.Equal(t,report.Warnings[0].Code,health.CodeAccessURLNotOK)
135135
}
136136
})
137137

‎coderd/healthcheck/database.go

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@ import (
44
"context"
55
"time"
66

7+
"golang.org/x/exp/slices"
8+
79
"github.com/coder/coder/v2/coderd/database"
810
"github.com/coder/coder/v2/coderd/healthcheck/health"
9-
"github.com/coder/coder/v2/coderd/util/ptr"
10-
11-
"golang.org/x/exp/slices"
1211
)
1312

1413
const (
@@ -18,10 +17,10 @@ const (
1817
// @typescript-generate DatabaseReport
1918
typeDatabaseReportstruct {
2019
// Healthy is deprecated and left for backward compatibility purposes, use `Severity` instead.
21-
Healthybool`json:"healthy"`
22-
Severity health.Severity`json:"severity" enums:"ok,warning,error"`
23-
Warnings []string`json:"warnings"`
24-
Dismissedbool`json:"dismissed"`
20+
Healthybool`json:"healthy"`
21+
Severity health.Severity`json:"severity" enums:"ok,warning,error"`
22+
Warnings []health.Message`json:"warnings"`
23+
Dismissedbool`json:"dismissed"`
2524

2625
Reachablebool`json:"reachable"`
2726
Latencystring`json:"latency"`
@@ -38,7 +37,7 @@ type DatabaseReportOptions struct {
3837
}
3938

4039
func (r*DatabaseReport)Run(ctx context.Context,opts*DatabaseReportOptions) {
41-
r.Warnings= []string{}
40+
r.Warnings= []health.Message{}
4241
r.Severity=health.SeverityOK
4342
r.Dismissed=opts.Dismissed
4443

@@ -55,7 +54,7 @@ func (r *DatabaseReport) Run(ctx context.Context, opts *DatabaseReportOptions) {
5554
fori:=0;i<pingCount;i++ {
5655
pong,err:=opts.DB.Ping(ctx)
5756
iferr!=nil {
58-
r.Error=ptr.Ref(health.Messagef(health.CodeDatabasePingFailed,"ping database: %s",err))
57+
r.Error=health.Errorf(health.CodeDatabasePingFailed,"ping database: %s",err)
5958
r.Severity=health.SeverityError
6059

6160
return

‎coderd/healthcheck/database_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ func TestDatabase(t *testing.T) {
143143
assert.Equal(t,time.Second.Milliseconds(),report.ThresholdMS)
144144
assert.Nil(t,report.Error)
145145
ifassert.NotEmpty(t,report.Warnings) {
146-
assert.Contains(t,report.Warnings[0],health.CodeDatabasePingSlow)
146+
assert.Equal(t,report.Warnings[0].Code,health.CodeDatabasePingSlow)
147147
}
148148
})
149149
}

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp