Skip to content

Commit d00802e

Browse files
committed
more rules
1 parent 8dcbafd commit d00802e

File tree

3 files changed

+16
-0
lines changed

3 files changed

+16
-0
lines changed

coderd/healthcheck/accessurl.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,11 @@ func (r *AccessURLReport) Run(ctx context.Context, opts *AccessURLReportOptions)
3535
ctx, cancel := context.WithTimeout(ctx, 5*time.Second)
3636
defer cancel()
3737

38+
r.Severity = health.SeverityOK
3839
r.Warnings = []string{}
3940
if opts.AccessURL == nil {
4041
r.Error = ptr.Ref("access URL is nil")
42+
r.Severity = health.SeverityError
4143
return
4244
}
4345
r.AccessURL = opts.AccessURL.String()
@@ -49,30 +51,37 @@ func (r *AccessURLReport) Run(ctx context.Context, opts *AccessURLReportOptions)
4951
accessURL, err := opts.AccessURL.Parse("/healthz")
5052
if err != nil {
5153
r.Error = convertError(xerrors.Errorf("parse healthz endpoint: %w", err))
54+
r.Severity = health.SeverityError
5255
return
5356
}
5457

5558
req, err := http.NewRequestWithContext(ctx, "GET", accessURL.String(), nil)
5659
if err != nil {
5760
r.Error = convertError(xerrors.Errorf("create healthz request: %w", err))
61+
r.Severity = health.SeverityError
5862
return
5963
}
6064

6165
res, err := opts.Client.Do(req)
6266
if err != nil {
6367
r.Error = convertError(xerrors.Errorf("get healthz endpoint: %w", err))
68+
r.Severity = health.SeverityError
6469
return
6570
}
6671
defer res.Body.Close()
6772

6873
body, err := io.ReadAll(res.Body)
6974
if err != nil {
7075
r.Error = convertError(xerrors.Errorf("read healthz response: %w", err))
76+
r.Severity = health.SeverityError
7177
return
7278
}
7379

7480
r.Reachable = true
7581
r.Healthy = res.StatusCode == http.StatusOK
7682
r.StatusCode = res.StatusCode
83+
if res.StatusCode != http.StatusOK {
84+
r.Severity = health.SeverityWarning
85+
}
7786
r.HealthzResponse = string(body)
7887
}

coderd/healthcheck/accessurl_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313

1414
"github.com/coder/coder/v2/coderd/coderdtest"
1515
"github.com/coder/coder/v2/coderd/healthcheck"
16+
"github.com/coder/coder/v2/coderd/healthcheck/health"
1617
)
1718

1819
func TestAccessURL(t *testing.T) {
@@ -34,6 +35,7 @@ func TestAccessURL(t *testing.T) {
3435

3536
assert.True(t, report.Healthy)
3637
assert.True(t, report.Reachable)
38+
assert.Equal(t, health.SeverityOK, report.Severity)
3739
assert.Equal(t, http.StatusOK, report.StatusCode)
3840
assert.Equal(t, "OK", report.HealthzResponse)
3941
assert.Nil(t, report.Error)
@@ -64,6 +66,7 @@ func TestAccessURL(t *testing.T) {
6466

6567
assert.False(t, report.Healthy)
6668
assert.True(t, report.Reachable)
69+
assert.Equal(t, health.SeverityWarning, report.Severity)
6770
assert.Equal(t, http.StatusNotFound, report.StatusCode)
6871
assert.Equal(t, string(resp), report.HealthzResponse)
6972
assert.Nil(t, report.Error)
@@ -100,6 +103,7 @@ func TestAccessURL(t *testing.T) {
100103

101104
assert.False(t, report.Healthy)
102105
assert.False(t, report.Reachable)
106+
assert.Equal(t, health.SeverityError, report.Severity)
103107
assert.Equal(t, 0, report.StatusCode)
104108
assert.Equal(t, "", report.HealthzResponse)
105109
require.NotNil(t, report.Error)

coderd/healthcheck/database_test.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ func TestDatabase(t *testing.T) {
6060

6161
assert.False(t, report.Healthy)
6262
assert.False(t, report.Reachable)
63+
assert.Equal(t, health.SeverityError, report.Severity)
6364
assert.Zero(t, report.Latency)
6465
require.NotNil(t, report.Error)
6566
assert.Equal(t, healthcheck.DatabaseDefaultThreshold.Milliseconds(), report.ThresholdMS)
@@ -86,6 +87,7 @@ func TestDatabase(t *testing.T) {
8687

8788
assert.True(t, report.Healthy)
8889
assert.True(t, report.Reachable)
90+
assert.Equal(t, health.SeverityOK, report.Severity)
8991
assert.Equal(t, time.Millisecond.String(), report.Latency)
9092
assert.EqualValues(t, 1, report.LatencyMS)
9193
assert.Equal(t, healthcheck.DatabaseDefaultThreshold.Milliseconds(), report.ThresholdMS)
@@ -112,6 +114,7 @@ func TestDatabase(t *testing.T) {
112114

113115
assert.False(t, report.Healthy)
114116
assert.True(t, report.Reachable)
117+
assert.Equal(t, health.SeverityWarning, report.Severity)
115118
assert.Equal(t, time.Second.String(), report.Latency)
116119
assert.EqualValues(t, 1000, report.LatencyMS)
117120
assert.Equal(t, time.Second.Milliseconds(), report.ThresholdMS)

0 commit comments

Comments
 (0)